index.vue 8.8 KB

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