settings.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view class="content">
  3. <!-- 功能列表 -->
  4. <uni-list class="mt10" :border="false">
  5. <uni-list-item :title="$t('settings.userInfo')" to="/pages/info/userInfo?changePwd=0"
  6. link="navigateTo">
  7. </uni-list-item>
  8. <!-- <uni-list-item v-if="userInfo.mobile" :title="$t('settings.changePassword')" :to="'/subpages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='+ userInfo.mobile" link="navigateTo"></uni-list-item> -->
  9. </uni-list>
  10. <uni-list class="mt10" :border="false">
  11. <uni-list-item :title="$t('settings.changePassword')" to="/pages/info/userInfo?changePwd=1"
  12. link="navigateTo">
  13. </uni-list-item>
  14. <!-- <uni-list-item v-if="userInfo.mobile" :title="$t('settings.changePassword')" :to="'/subpages/ucenter/login-page/pwd-retrieve/pwd-retrieve?phoneNumber='+ userInfo.mobile" link="navigateTo"></uni-list-item> -->
  15. </uni-list>
  16. <uni-list class="mt10" :border="false">
  17. <!-- #ifndef H5 -->
  18. <!-- #ifdef APP-PLUS -->
  19. <!-- 检查push过程未结束不显示,push设置项 -->
  20. <uni-list-item :title="$t('settings.clearTmp')" @click="clearTmp" link></uni-list-item>
  21. <!-- <uni-list-item v-show="pushIsOn != 'wait'" :title="$t('settings.pushServer')" @click.native="pushIsOn?pushServer.off():pushServer.on()" showSwitch :switchChecked="pushIsOn"></uni-list-item> -->
  22. <!-- #endif -->
  23. <!-- <uni-list-item v-if="supportMode.includes('fingerPrint')" :title="$t('settings.fingerPrint')" @click.native="startSoterAuthentication('fingerPrint')" link></uni-list-item> -->
  24. <!-- <uni-list-item v-if="supportMode.includes('facial')" :title="$t('settings.facial')" @click="startSoterAuthentication('facial')" link></uni-list-item> -->
  25. <!-- #endif -->
  26. <!-- <uni-list-item :title="$t('settings.changeLanguage')" @click="changeLanguage"
  27. :rightText="currentLanguage" link></uni-list-item> -->
  28. <!-- #ifdef APP-PLUS -->
  29. <uni-list-item :title="$t('settings.version')" @click="onVersionClick" link></uni-list-item>
  30. <!-- #endif -->
  31. </uni-list>
  32. <!-- #ifdef MP-WEIXIN -->
  33. <uni-list class="mt10" :border="false">
  34. <uni-list-item clickable @click="deactivate" :title="$t('settings.deactivate')"></uni-list-item>
  35. </uni-list>
  36. <!-- #endif -->
  37. <!-- 退出/登录 按钮 -->
  38. <view class="bottom-back">
  39. <u-button type="primary" @click="clickLogout">{{hasLogin?$t('settings.logOut'):$t('settings.login')}}</u-button>
  40. </view>
  41. <u-loading-page :loading="loadingShow" fontSize="50" iconSize="50" loadingMode="spinner" color="green"
  42. bgColor="#e8e8e8" :loading-text="percentage+'%'"></u-loading-page>
  43. </view>
  44. </template>
  45. <script>
  46. // import pushServer from './dc-push/push.js';
  47. import {
  48. mapMutations,
  49. mapGetters,
  50. mapActions
  51. } from 'vuex';
  52. import {
  53. logoff
  54. } from "../../api/login";
  55. export default {
  56. data() {
  57. return {
  58. // pushServer:pushServer,
  59. supportMode: [],
  60. pushIsOn: "wait",
  61. currentLanguage: "",
  62. versionShow: false,
  63. version: "",
  64. versionCode: "",
  65. downloadUrl: "http://218.201.62.165:8003/Log/E%E8%BF%90%E8%90%A5.apk",
  66. isForceUpdate: "1",
  67. percentage: 0,
  68. loadingShow: false,
  69. }
  70. },
  71. computed: {
  72. ...mapGetters({
  73. 'userInfo': 'user/info',
  74. 'hasLogin': 'user/hasLogin',
  75. }),
  76. i18nEnable() {
  77. return getApp().globalData.config.i18n.enable
  78. }
  79. },
  80. onLoad() {
  81. if (uni.getStorageSync('CURRENT_LANG') == "en") {
  82. this.currentLanguage = 'English';
  83. } else if (uni.getStorageSync('CURRENT_LANG') == "pt") {
  84. this.currentLanguage = 'Português';
  85. } else if (uni.getStorageSync('CURRENT_LANG') == "uz") {
  86. this.currentLanguage = "O'zbekcha";
  87. } else {
  88. this.currentLanguage = '简体中文';
  89. }
  90. // uni.setNavigationBarTitle({
  91. // })
  92. // // #ifdef APP-PLUS || MP-WEIXIN
  93. // uni.checkIsSupportSoterAuthentication({
  94. // success: (res) => {
  95. // console.log(res);
  96. // this.supportMode = res.supportMode
  97. // },
  98. // fail: (err) => {
  99. // console.log(err);
  100. // }
  101. // })
  102. // // #endif
  103. },
  104. onShow() {
  105. // 检查手机端获取推送是否开启
  106. //#ifdef APP-PLUS
  107. // setTimeout(()=>{
  108. // this.pushIsOn = pushServer.isOn();
  109. // },300)
  110. //#endif
  111. },
  112. methods: {
  113. clickLogout() {
  114. if (this.hasLogin) {
  115. uni.showModal({
  116. title: this.$t('settings.tips'),
  117. content: this.$t('settings.exitLogin'),
  118. cancelText: this.$t('settings.cancelText'),
  119. confirmText: this.$t('settings.confirmText'),
  120. success: res => {
  121. if (res.confirm) {
  122. // this.logout()
  123. // uni.navigateBack();
  124. this.reloadInfo()
  125. }
  126. },
  127. fail: () => {},
  128. complete: () => {}
  129. });
  130. } else {
  131. uni.reLaunch({
  132. url: '/pages/login/login'
  133. });
  134. }
  135. },
  136. reloadInfo(){
  137. uni.removeStorageSync('token')
  138. uni.removeStorageSync('tenantId')
  139. uni.removeStorageSync('userId')
  140. uni.removeStorageSync('userName')
  141. uni.removeStorageSync('userInfo')
  142. uni.removeStorageSync('userType')
  143. uni.removeStorageSync('tenantInfo')
  144. uni.removeStorageSync('currentTenantId')
  145. uni.removeStorageSync('currentVehicleInfo')
  146. uni.removeStorageSync('isAuditUser')
  147. uni.removeStorageSync('isDealerUser')
  148. uni.removeStorageSync('isDriverUser')
  149. uni.removeStorageSync('enterpriseInfo')
  150. uni.removeStorageSync('serverAddress');
  151. uni.removeStorageSync('serverPrefix');
  152. uni.reLaunch({
  153. url: '/pages/login/login'
  154. });
  155. getApp().globalData.tabIndex = 'home';
  156. },
  157. clearTmp() {
  158. uni.showLoading({
  159. title: this.$t('settings.clearing'),
  160. mask: true
  161. });
  162. /*
  163. 任何临时存储或删除不直接影响程序运行逻辑(清除缓存必定造成业务逻辑的变化,如:打开页面的图片不从缓存中读取而从网络请求)的内容都可以视为缓存。主要有storage、和file写入。
  164. 缓存分为三部分
  165. 原生层(如:webview、x5播放器的、第三方sdk的、地图组件等)
  166. 前端框架(重启就会自动清除)
  167. 开发者自己的逻辑(如:
  168. 本示例的 检测更新功能下载了apk安装包,
  169. 其他逻辑需要根据开发者自己的业务设计
  170. 比如:有聊天功能的应用,聊天记录是否视为缓存,还是单独提供清除聊天记录的功能由开发者自己设计
  171. */
  172. uni.getSavedFileList({
  173. success: res => {
  174. if (res.fileList.length > 0) {
  175. uni.removeSavedFile({
  176. filePath: res.fileList[0].filePath,
  177. complete: res => {
  178. console.log(res);
  179. uni.hideLoading()
  180. uni.showToast({
  181. title: this.$t('settings.clearedSuccessed'),
  182. icon: 'none'
  183. });
  184. }
  185. });
  186. } else {
  187. uni.hideLoading()
  188. uni.showToast({
  189. title: this.$t('settings.clearedSuccessed'),
  190. icon: 'none'
  191. });
  192. }
  193. },
  194. complete: e => {
  195. console.log(e);
  196. }
  197. });
  198. },
  199. deactivate() {
  200. console.log('注销用户')
  201. console.log(uni.getStorageSync("userInfo"))
  202. let tenantInfo = uni.getStorageSync('tenantInfo').filter(item => item.statusFlag == '1')
  203. console.log(tenantInfo)
  204. if (tenantInfo.length > 0&&!uni.getStorageSync('isDriverUser')) {
  205. uni.showModal({
  206. // title: '提示',
  207. content: this.$t('settings.havaTenantInfo'),
  208. showCancel: false,
  209. confirmText: this.$t('settings.confirmText'),
  210. success: function(r) {
  211. if (r.confirm) {
  212. uni.redirectTo({
  213. url: '/subpages/tenant/list'
  214. })
  215. }
  216. }
  217. })
  218. } else {
  219. uni.showModal({
  220. // title: '提示',
  221. content: this.$t('settings.confirmdeactivate'),
  222. showCancel: true,
  223. cancelText: this.$t('settings.cancelText'),
  224. confirmText: this.$t('settings.confirmText'),
  225. success: (r) =>{
  226. if (r.confirm) {
  227. logoff(uni.getStorageSync("userInfo")).then(res => {
  228. if (res.statusCode == 200) {
  229. this.reloadInfo()
  230. }
  231. })
  232. }
  233. }
  234. })
  235. }
  236. },
  237. //切换语言
  238. changeLanguage() {
  239. console.log('语言切换')
  240. uni.showActionSheet({
  241. itemList: ["English", "简体中文", "Português","O'zbekcha",'Russian'],
  242. success: res => {
  243. let language = uni.getStorageSync('CURRENT_LANG')
  244. console.log(res.tapIndex,language);
  245. if ((res.tapIndex === 0 && language != 'en') || (res.tapIndex === 1 && language !=
  246. 'zh-Hans') || (res.tapIndex === 2 && language != 'pt') || (res.tapIndex === 3 && language != 'uz') || (res.tapIndex === 4 && language != 'ru')) {
  247. const globalData = getApp().globalData
  248. console.log(globalData, '--------------');
  249. console.log(language);
  250. if (res.tapIndex === 0) {
  251. language = globalData.locale = 'en'
  252. } else if (res.tapIndex === 1) {
  253. language = globalData.locale = 'zh-Hans'
  254. } else if (res.tapIndex === 2) {
  255. language = globalData.locale = 'pt'
  256. } else if (res.tapIndex === 3) {
  257. language = globalData.locale = 'uz'
  258. }else if (res.tapIndex === 4) {
  259. language = globalData.locale = 'ru'
  260. }
  261. uni.setStorageSync('CURRENT_LANG', language)
  262. getApp().globalData.$i18n.locale = language
  263. if (res.tapIndex === 0) {
  264. this.currentLanguage = 'English'
  265. } else if (res.tapIndex === 1) {
  266. this.currentLanguage = '简体中文'
  267. } else if (res.tapIndex === 2) {
  268. this.currentLanguage = 'Português'
  269. } else if (res.tapIndex === 3) {
  270. this.currentLanguage = "O'zbekcha"
  271. }else if (res.tapIndex === 4) {
  272. this.currentLanguage = "Russian"
  273. }
  274. if (uni.setLocale) {
  275. uni.setLocale(language)
  276. }
  277. uni.reLaunch({
  278. url: '/pages/login/login',
  279. complete: () => {
  280. uni.$emit("changeLanguage", language)
  281. }
  282. })
  283. }
  284. },
  285. fail: () => {},
  286. complete: () => {}
  287. });
  288. },
  289. onVersionClick() {
  290. //#ifdef APP-PLUS
  291. var that = this;
  292. // 获取本地应用资源版本号
  293. plus.runtime.getProperty(plus.runtime.appid, (info) => {
  294. console.log(JSON.stringify(info));
  295. that.version = info.version;
  296. that.versionCode = info.versionCode;
  297. console.log("获取到的版本信息、", that.version, that.versionCode);
  298. uni.showActionSheet({
  299. itemList: ["版本号 " + that.versionCode + that.version],
  300. success: res => {
  301. uni.getSystemInfo({
  302. success: (res) => {
  303. console.log("当前平台信息、", res.platform);
  304. //检测当前平台,如果是安卓则启动安卓更新
  305. if (res.platform == "android") {
  306. that.AndroidCheckUpdate();
  307. }
  308. }
  309. })
  310. },
  311. fail: () => {},
  312. complete: () => {}
  313. });
  314. })
  315. //#endif
  316. },
  317. AndroidCheckUpdate() {
  318. let that = this;
  319. plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
  320. that.version = wgtinfo.version //客户端版本号
  321. console.log('当前app版本信息:' + that.version);
  322. })
  323. that.getUpdateVersion()
  324. },
  325. getUpdateVersion() {
  326. let that = this;
  327. // 是否强制更新(0 否;1 是)
  328. uni.showModal({
  329. // 更新提醒
  330. title: '发现新版本,是否更新',
  331. content: '此版本号:' + that.version + '\xa0\xa0\xa0' + '待更新版本号:11',
  332. success: res => {
  333. if (res.confirm) {
  334. that.downWgt(); //下载文件
  335. } else if (res.cancel) {
  336. console.log('that.isForceUpdate:' + that.isForceUpdate);
  337. // 不更新强制退出app
  338. if (that.isForceUpdate == 1) {
  339. console.log('that.isForceUpdate1:' + that.isForceUpdate);
  340. uni.showModal({
  341. // 更新提醒
  342. title: '发现新版本,是否更新',
  343. content: '此版本为强制更新版本如不升级将退出APP',
  344. success: res => {
  345. if (res.confirm) {
  346. console.log('不更新强制退出app');
  347. plus.runtime.quit();
  348. } else if (res.cancel) {
  349. that.AndroidCheckUpdate();
  350. }
  351. }
  352. });
  353. }
  354. }
  355. }
  356. });
  357. complete: () => {}
  358. },
  359. downWgt() {
  360. let that = this;
  361. console.log('url:' + that.downloadUrl)
  362. that.loadingShow = true;
  363. const downloadTask = uni.downloadFile({ //执行下载
  364. url: that.downloadUrl, //下载地址
  365. timeout: 1000 * 30, //30秒超时时间
  366. success: downloadResult => { //下载成功
  367. that.showdownLine = false
  368. uni.hideLoading();
  369. console.log('downloadResult.statusCode' + downloadResult.statusCode)
  370. if (downloadResult.statusCode == 200) {
  371. console.log('更新中')
  372. uni.showModal({
  373. title: '',
  374. showCancel: false,
  375. content: '更新成功,马上重启',
  376. confirmText: '重启',
  377. confirmColor: '#EE8F57',
  378. success: function(res) {
  379. if (res.confirm == true) {
  380. plus.runtime.install( //安装
  381. downloadResult.tempFilePath, {
  382. force: true
  383. },
  384. function(res) {
  385. utils.showToast('更新成功,重启中');
  386. plus.runtime.restart();
  387. }
  388. );
  389. }
  390. }
  391. });
  392. }
  393. },
  394. fail: err => {
  395. uni.hideLoading();
  396. that.showdownLine = false
  397. that.$u.toast(err.errMsg)
  398. console.log(err)
  399. },
  400. complete: com => {
  401. console.log(com)
  402. }
  403. });
  404. // 下载进度
  405. downloadTask.onProgressUpdate(res => {
  406. // that.$u.toast(res.progress)
  407. that.percentage = res.progress
  408. console.log('下载进度' + that.percentage);
  409. });
  410. },
  411. }
  412. }
  413. </script>
  414. <style>
  415. .progress-box {
  416. display: flex;
  417. height: 50rpx;
  418. margin-bottom: 60rpx;
  419. }
  420. /* #ifndef APP-NVUE */
  421. page {
  422. flex: 1;
  423. width: 100%;
  424. height: 100%;
  425. }
  426. uni-button:after {
  427. border: none;
  428. border-radius: 0;
  429. }
  430. /* #endif */
  431. .content {
  432. /* #ifndef APP-NVUE */
  433. /* display: flex; */
  434. width: 750rpx;
  435. height: 100vh;
  436. /* #endif */
  437. flex-direction: column;
  438. flex: 1;
  439. background-color: #F9F9F9;
  440. }
  441. .versionMain {
  442. width: 200rpx;
  443. height: 200rpx;
  444. }
  445. .bottom-back {
  446. padding: 0 40rpx;
  447. }
  448. .bottom-back-text {
  449. font-size: 33rpx;
  450. }
  451. .mt10 {
  452. margin-top: 10px;
  453. }
  454. /* #ifndef APP-NVUE || VUE3 */
  455. .content /deep/ .uni-list {
  456. background-color: #F9F9F9;
  457. }
  458. .content /deep/ .uni-list-item--disabled,
  459. .list-item {
  460. height: 50px;
  461. margin-bottom: 1px;
  462. }
  463. /* #endif */
  464. </style>