index.vue 8.2 KB

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