settings.vue 13 KB

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