settings.vue 14 KB

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