index.vue 9.3 KB

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