index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. showCancel: false,
  186. success: (val) => {
  187. if (val.confirm) {
  188. const downloadTask = uni.downloadFile({
  189. url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
  190. success: (data) => {
  191. if (data.statusCode === 200) {
  192. uni.saveFile({
  193. tempFilePath: data
  194. .tempFilePath,
  195. success: (saveRes) => {
  196. // uni.showToast({
  197. // title: '下载成功',
  198. // icon: 'success'
  199. // });
  200. // uni.hideLoading();
  201. // uni.showLoading({
  202. // title: "正在更新...",
  203. // mask: true,
  204. // });
  205. // 调用安装逻辑
  206. plus.runtime.install(
  207. saveRes
  208. .savedFilePath, {
  209. force: true
  210. },
  211. function() {
  212. // uni
  213. // .hideLoading();
  214. },
  215. function() {
  216. // uni
  217. // .hideLoading();
  218. uni.showToast({
  219. title: '更新失败',
  220. icon: 'error'
  221. });
  222. });
  223. }
  224. });
  225. }
  226. }
  227. });
  228. // 先显示初始的loading提示
  229. uni.showLoading({
  230. title: "正在下载安装包: 0%",
  231. mask: true,
  232. });
  233. // 记录上次显示的进度,避免频繁更新
  234. let lastProgress = 0;
  235. let loadingVisible = true;
  236. downloadTask.onProgressUpdate((ress) => {
  237. console.log('下载进度:', ress)
  238. // 只在进度有明显变化(每10%)或者达到100%时更新提示
  239. if ((ress.progress > lastProgress && ress.progress %
  240. 10 === 0) || ress.progress === 100) {
  241. // 先隐藏再显示以更新内容
  242. if (loadingVisible) {
  243. uni.hideLoading();
  244. }
  245. if (ress.progress < 100) {
  246. uni.showLoading({
  247. title: "正在下载安装包: " + (ress
  248. .progress > lastProgress ? ress.progress : lastProgress) + "%",
  249. mask: true,
  250. });
  251. loadingVisible = true;
  252. } else {
  253. loadingVisible = false;
  254. }
  255. lastProgress = ress.progress > lastProgress ? ress.progress : lastProgress;
  256. }
  257. })
  258. // 确保任务完成时隐藏loading
  259. downloadTask.onStop(() => {
  260. if (loadingVisible) {
  261. uni.hideLoading();
  262. loadingVisible = false;
  263. }
  264. })
  265. downloadTask.onError(() => {
  266. if (loadingVisible) {
  267. uni.hideLoading();
  268. loadingVisible = false;
  269. }
  270. })
  271. }
  272. }
  273. });
  274. }
  275. }).catch(err => {
  276. console.log('err:', err)
  277. })
  278. // #endif
  279. },
  280. getbb() {
  281. get(this.apiUrl + '/versioning/getLatestData').then(res => {
  282. if (res.success) {
  283. this.Nversion = res.data.version
  284. }
  285. })
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss" scoped>
  291. .u-slot-value {
  292. color: #157a2c;
  293. }
  294. .flex-buttom {
  295. position: fixed;
  296. bottom: 0;
  297. left: 0;
  298. width: 100%;
  299. padding: 20rpx;
  300. box-sizing: border-box;
  301. .btn {
  302. color: #157a2c;
  303. font-size: 28rpx;
  304. display: flex;
  305. justify-content: center;
  306. align-items: center;
  307. border: 1px solid #157a2c;
  308. border-radius: 10rpx;
  309. height: 80rpx;
  310. }
  311. }
  312. .copyright {
  313. color: #555;
  314. font-size: 28rpx;
  315. text-align: center;
  316. padding: 20rpx 0;
  317. }
  318. </style>