index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. // uni.showLoading({
  184. // title: "正在下载安装包...",
  185. // mask: true,
  186. // });
  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. downloadTask.onProgressUpdate((res) => {
  228. console.log('下载进度:', res)
  229. // uni.showModal({
  230. // content: '下载进度:' + res.progress + '%',
  231. // showCancel: false,
  232. // success: (val) => {
  233. // if (val.confirm) {
  234. // }
  235. // }
  236. // })
  237. uni.showLoading({
  238. title: "正在下载安装包: " + res.progress + "%",
  239. mask: true,
  240. });
  241. if (res.progress == 100) {
  242. uni.hideLoading();
  243. }
  244. })
  245. }
  246. }
  247. });
  248. }
  249. }).catch(err => {
  250. console.log('err:', err)
  251. })
  252. // #endif
  253. },
  254. getbb() {
  255. get(this.apiUrl + '/versioning/getLatestData').then(res => {
  256. if (res.success) {
  257. this.Nversion = res.data.version
  258. }
  259. })
  260. }
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. .u-slot-value {
  266. color: #157a2c;
  267. }
  268. .flex-buttom {
  269. position: fixed;
  270. bottom: 0;
  271. left: 0;
  272. width: 100%;
  273. padding: 20rpx;
  274. box-sizing: border-box;
  275. .btn {
  276. color: #157a2c;
  277. font-size: 28rpx;
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. border: 1px solid #157a2c;
  282. border-radius: 10rpx;
  283. height: 80rpx;
  284. }
  285. }
  286. .copyright {
  287. color: #555;
  288. font-size: 28rpx;
  289. text-align: center;
  290. padding: 20rpx 0;
  291. }
  292. </style>