index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" @clickLeft="back" title="系统设置">
  4. </uni-nav-bar>
  5. <u-cell-group>
  6. <picker @change="handlePicker" :range="['是', '否']">
  7. <u-cell title="记住密码" :isLink="true" arrow-direction="right">
  8. <text slot="value" class="u-slot-value">{{
  9. isMemo ? '是' : '否'
  10. }}</text>
  11. </u-cell>
  12. </picker>
  13. <u-cell title="修改密码" :isLink="true" arrow-direction="right" @click="$refs.passwordModalRef.open()">
  14. </u-cell>
  15. <u-cell title="服务器地址" :isLink="true" arrow-direction="right" @click="handleServerSettings">
  16. <text slot="value" class="u-slot-value" :key="apiAdress">{{
  17. apiAdress
  18. }}</text>
  19. </u-cell>
  20. <u-cell :title="'当前版本 ' + currentVersion" :isLink="true" arrow-direction="right">
  21. <text slot="value" class="u-slot-value" @click="handlUpdate">{{
  22. Nversion == currentVersion ? '' : `发现新版本(${Nversion})`}}
  23. </text>
  24. </u-cell>
  25. </u-cell-group>
  26. <view class="flex-buttom">
  27. <view class="btn" @click="loginOut"> 退出登录 </view>
  28. <view class="copyright">
  29. <view>版权所有© 2019-2025中赢合力</view>
  30. <view>湘ICP备20015098号</view>
  31. </view>
  32. </view>
  33. <updatePop ref="updatePop" :versionNum="versionNum" :downloadUrl="downloadUrl" :sizes="VersionInfo.fileSize">
  34. </updatePop>
  35. <passwordModal ref="passwordModalRef"></passwordModal>
  36. <ServerSetting ref="serverSettingRef" @setServerStatus="setServerStatus" />
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. postJ,
  42. get
  43. } from '@/utils/api.js'
  44. import updatePop from './components/updatePop.vue'
  45. import passwordModal from './components/password-modal.vue'
  46. import {
  47. setMemo,
  48. isMemo,
  49. removeMemo
  50. } from '@/utils/passwordMemo.js'
  51. import ServerSetting from '@/components/ServerSetting/index'
  52. import {
  53. getLatestVersion
  54. } from '@/api/common.js'
  55. export default {
  56. components: {
  57. updatePop,
  58. ServerSetting,passwordModal
  59. },
  60. data() {
  61. return {
  62. show: false,
  63. versionNum: '',
  64. downloadUrl: '',
  65. currentVersion: '',
  66. isMemo: isMemo(),
  67. apiAdress: '',
  68. Nversion: '',
  69. VersionInfo: ''
  70. }
  71. },
  72. onLoad() {
  73. const apiInfo = uni.getStorageSync('apiInfo')
  74. this.apiAdress =
  75. apiInfo.hostname &&
  76. `${apiInfo.protocal || ''}${apiInfo.hostname || ''}:${apiInfo.port || ''}`
  77. const {
  78. appVersion
  79. } = uni.getAppBaseInfo()
  80. this.currentVersion = appVersion
  81. getLatestVersion().then(res => {
  82. this.Nversion = res.versionCode
  83. })
  84. // this.currentVersion = plus?.runtime.version
  85. // this.getbb()
  86. },
  87. created() {
  88. },
  89. methods: {
  90. handlePicker(e) {
  91. this.isMemo = e.detail.value === 0
  92. if (e.detail.value === 0) {
  93. setMemo()
  94. } else {
  95. removeMemo()
  96. }
  97. },
  98. setServerStatus(val) {
  99. if (val) {
  100. const apiInfo = uni.getStorageSync('apiInfo')
  101. this.apiAdress = `${apiInfo.protocal || ''}${apiInfo.hostname || ''}:${
  102. apiInfo.port || ''
  103. }`
  104. }
  105. },
  106. handleServerSettings() {
  107. this.$refs.serverSettingRef.open()
  108. },
  109. loginOut() {
  110. uni.showModal({
  111. title: '提示',
  112. content: '确认退出登录',
  113. success: res => {
  114. console.log(res, res.confirm, '-----确认退出登录');
  115. if (res.confirm) {
  116. console.log('-----确认退出登录9999999');
  117. // uni.clearStorage()
  118. try {
  119. postJ(this.apiUrl + '/main/user/logout')
  120. .then(res => {
  121. uni.showToast({
  122. title: '退出成功',
  123. icon: 'success',
  124. duration: 500
  125. })
  126. setTimeout(() => {
  127. uni.removeStorageSync('token')
  128. uni.removeStorageSync('userInfo')
  129. uni.removeStorageSync('treeList')
  130. uni.reLaunch({
  131. url: '/pages/login/login'
  132. })
  133. }, 500)
  134. })
  135. .catch(err => {
  136. console.log(err);
  137. uni.showToast({
  138. title: '退出失败',
  139. icon: 'none'
  140. })
  141. })
  142. } catch (error) {
  143. console.log(error, 'error----')
  144. uni.reLaunch({
  145. url: '/pages/login/login'
  146. })
  147. }
  148. } else if (res.cancel) {
  149. console.log('用户点击取消')
  150. }
  151. }
  152. })
  153. },
  154. handlUpdate() {
  155. // get(this.apiUrl + '/versioning/getLatestData').then(res => {
  156. // console.log(res);
  157. // if (res.success) {
  158. // const currentVersion = this.currentVersion
  159. // const Nversion = res.data.version
  160. // console.log(currentVersion, Nversion);
  161. // this.VersionInfo = res.data
  162. // if (currentVersion !== Nversion) {
  163. // this.$refs.updatePop.open()
  164. // this.versionNum = Nversion
  165. // this.downloadUrl = this.apiUrl + res.data.path
  166. // } else {
  167. // uni.showToast({
  168. // title: '暂无新版本',
  169. // icon: 'none'
  170. // })
  171. // }
  172. // }
  173. // })
  174. // #ifdef APP-PLUS
  175. getLatestVersion().then(res => {
  176. console.log('res:', res)
  177. const {
  178. appVersion
  179. } = uni.getAppBaseInfo()
  180. if (appVersion != res.versionCode) {
  181. uni.showModal({
  182. title: '发现新版本',
  183. content: '更新说明:' + res.releaseNotes,
  184. confirmText: '立即更新',
  185. success: (val) => {
  186. if (val.confirm) {
  187. const downloadTask = uni.downloadFile({
  188. url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
  189. success: (data) => {
  190. if (data.statusCode === 200) {
  191. uni.saveFile({
  192. tempFilePath: data
  193. .tempFilePath,
  194. success: (saveRes) => {
  195. // uni.showToast({
  196. // title: '下载成功',
  197. // icon: 'success'
  198. // });
  199. // uni.hideLoading();
  200. // uni.showLoading({
  201. // title: "正在更新...",
  202. // mask: true,
  203. // });
  204. // 调用安装逻辑
  205. plus.runtime.install(
  206. saveRes
  207. .savedFilePath, {
  208. force: true
  209. },
  210. function() {
  211. // uni
  212. // .hideLoading();
  213. },
  214. function() {
  215. // uni
  216. // .hideLoading();
  217. uni.showToast({
  218. title: '更新失败',
  219. icon: 'error'
  220. });
  221. });
  222. }
  223. });
  224. }
  225. }
  226. });
  227. // 先显示初始的loading提示
  228. uni.showLoading({
  229. title: "正在下载安装包: 0%",
  230. mask: true,
  231. });
  232. // 记录上次显示的进度,避免频繁更新
  233. let lastProgress = 0;
  234. let loadingVisible = true;
  235. downloadTask.onProgressUpdate((ress) => {
  236. console.log('下载进度:', ress)
  237. // 只在进度有明显变化(每10%)或者达到100%时更新提示
  238. if ((ress.progress > lastProgress && ress.progress %
  239. 10 === 0) || ress.progress === 100) {
  240. // 先隐藏再显示以更新内容
  241. if (loadingVisible) {
  242. uni.hideLoading();
  243. }
  244. if (ress.progress < 100) {
  245. uni.showLoading({
  246. title: "正在下载安装包: " + ress
  247. .progress + "%",
  248. mask: true,
  249. });
  250. loadingVisible = true;
  251. } else {
  252. loadingVisible = false;
  253. }
  254. lastProgress = ress.progress;
  255. }
  256. })
  257. // 确保任务完成时隐藏loading
  258. downloadTask.onStop(() => {
  259. if (loadingVisible) {
  260. uni.hideLoading();
  261. loadingVisible = false;
  262. }
  263. })
  264. downloadTask.onError(() => {
  265. if (loadingVisible) {
  266. uni.hideLoading();
  267. loadingVisible = false;
  268. }
  269. })
  270. }
  271. }
  272. });
  273. }
  274. }).catch(err => {
  275. console.log('err:', err)
  276. })
  277. // #endif
  278. },
  279. getbb() {
  280. get(this.apiUrl + '/versioning/getLatestData').then(res => {
  281. if (res.success) {
  282. this.Nversion = res.data.version
  283. }
  284. })
  285. }
  286. }
  287. }
  288. </script>
  289. <style lang="scss" scoped>
  290. .u-slot-value {
  291. color: #157a2c;
  292. }
  293. .flex-buttom {
  294. position: fixed;
  295. bottom: 0;
  296. left: 0;
  297. width: 100%;
  298. padding: 20rpx;
  299. box-sizing: border-box;
  300. .btn {
  301. color: #157a2c;
  302. font-size: 28rpx;
  303. display: flex;
  304. justify-content: center;
  305. align-items: center;
  306. border: 1px solid #157a2c;
  307. border-radius: 10rpx;
  308. height: 80rpx;
  309. }
  310. }
  311. .copyright {
  312. color: #555;
  313. font-size: 28rpx;
  314. text-align: center;
  315. padding: 20rpx 0;
  316. }
  317. </style>