index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. const {
  173. appVersion
  174. } = uni.getAppBaseInfo()
  175. if (appVersion != res.versionCode) {
  176. uni.showModal({
  177. title: '发现新版本',
  178. content: '更新说明:' + res.releaseNotes,
  179. confirmText: '立即更新',
  180. success: (val) => {
  181. if (val.confirm) {
  182. uni.showLoading({
  183. title: "正在下载安装包...",
  184. mask: true,
  185. });
  186. uni.downloadFile({
  187. url: `${Vue.prototype.webviewUrl}/kd-aiot/${res.fileStorePath}`,
  188. success: (data) => {
  189. if (data.statusCode === 200) {
  190. uni.saveFile({
  191. tempFilePath: data
  192. .tempFilePath,
  193. success: (saveRes) => {
  194. uni.showToast({
  195. title: '下载成功',
  196. icon: 'success'
  197. });
  198. uni.hideLoading();
  199. uni.showLoading({
  200. title: "正在更新...",
  201. mask: true,
  202. });
  203. // 调用安装逻辑
  204. plus.runtime.install(
  205. saveRes
  206. .savedFilePath, {
  207. force: true
  208. },
  209. function() {
  210. uni
  211. .hideLoading();
  212. },
  213. function() {
  214. uni
  215. .hideLoading();
  216. uni.showToast({
  217. title: '更新失败',
  218. icon: 'error'
  219. });
  220. });
  221. }
  222. });
  223. }
  224. }
  225. });
  226. }
  227. }
  228. });
  229. }
  230. })
  231. // #endif
  232. },
  233. getbb() {
  234. get(this.apiUrl + '/versioning/getLatestData').then(res => {
  235. if (res.success) {
  236. this.Nversion = res.data.version
  237. }
  238. })
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. .u-slot-value {
  245. color: #157a2c;
  246. }
  247. .flex-buttom {
  248. position: fixed;
  249. bottom: 0;
  250. left: 0;
  251. width: 100%;
  252. padding: 20rpx;
  253. box-sizing: border-box;
  254. .btn {
  255. color: #157a2c;
  256. font-size: 28rpx;
  257. display: flex;
  258. justify-content: center;
  259. align-items: center;
  260. border: 1px solid #157a2c;
  261. border-radius: 10rpx;
  262. height: 80rpx;
  263. }
  264. }
  265. .copyright {
  266. color: #555;
  267. font-size: 28rpx;
  268. text-align: center;
  269. padding: 20rpx 0;
  270. }
  271. </style>