diff --git a/src/pages/login/login/index.vue b/src/pages/login/login/index.vue index ae4f5b5..48fe218 100644 --- a/src/pages/login/login/index.vue +++ b/src/pages/login/login/index.vue @@ -87,13 +87,16 @@ import { Component, Ref, Watch } from 'vue-property-decorator'; import Alerts from '@/components/alert/alerts.vue'; import { page } from '@/utils/page'; import { session } from '@/store/modules/session'; +import { auth } from '@/store/modules/auth'; import { BasePage } from '@/components/base/page'; import { VForm } from 'vue/types/form'; +import model from './model'; // mixin 引入示例目前用于弹窗自定义 @Component({ components: { Alerts }, }) export default class LoginPage extends BasePage { + model = model; /** * 访客权限 */ @@ -131,7 +134,6 @@ export default class LoginPage extends BasePage { const languages = ['cn', 'en', 'ru']; this.$i18n.locale = languages[index]; } - Version = ''; onReady(): void { this.$form.setRules(this.rules); //this.customToast('版本号' + plus.runtime.version); @@ -139,6 +141,86 @@ export default class LoginPage extends BasePage { // console.log('image', this.image); // console.log('Version////', this.Version); } + ///********版本号修改区域********** + version = '0.0.56'; + + compareVersion(version1: any, version2: any) { + //如果version1 大 会返回1 &&& 如果version2 大 会返回 -1 + const newVersion1 = `${version1}`.split('.').length < 3 ? `${version1}`.concat('.0') : `${version1}`; + const newVersion2 = `${version2}`.split('.').length < 3 ? `${version2}`.concat('.0') : `${version2}`; + //计算版本号大小,转化大小 + function toNum(a) { + const c = a.toString().split('.'); + const num_place = ['', '0', '00', '000', '0000'], + r = num_place.reverse(); + for (let i = 0; i < c.length; i++) { + const len = c[i].length; + c[i] = r[len] + c[i]; + } + return c.join(''); + } + //检测版本号是否需要更新 + function checkPlugin(a: any, b: any) { + const numA = toNum(a); + const numB = toNum(b); + return numA > numB ? 1 : numA < numB ? -1 : 0; + } + return checkPlugin(newVersion1, newVersion2); + } + //检查更新 + async checkupdate() { + try { + await this.model.checkupdate(); + const queryversion = this.model.checkversion.version; + //const queryversion = this.checkversion.Version.match(/\d+\.\d+\.\d+/)[0]; + let versionNumber = this.compareVersion(this.version, queryversion); //this.version, queryversion + if (versionNumber == -1) { + // 版本更新提示 + uni.showModal({ + content: '新版本为:' + this.model.checkversion.version + ',' + '是否更新?', + success: (res) => { + if (res.confirm) { + //确定执行下载 + let downloadApkUrl = this.model.checkversion.fileAddress; + uni.showLoading({ + title: '下载中', + }); + ////////////////uni下载方法, + uni.downloadFile({ + url: downloadApkUrl, + success: (downloadResult) => { + uni.hideLoading(); + if (downloadResult.statusCode == 200) { + //安装更新 + plus.runtime.install(downloadResult.tempFilePath as any, { force: true }, function () { + //uni.showToast('更新成功,重启'); + plus.runtime.restart(); + }); + } + }, + }); + } else if (res.cancel) { + console.log(); + uni.navigateTo({ + url: page.shouye, + }); + } + }, + }); + return; + } else { + uni.navigateTo({ + url: page.shouye, + }); + // uni.showToast({ + // title: '无更新内容', + // icon: 'none', + // }); + } + } catch (e) { + console.log('error', e); + } + } //不同国家设置不同版本号 onShow(): void { // console.log('......', server.serverAddress); @@ -262,15 +344,17 @@ export default class LoginPage extends BasePage { nickName, roles, }); + auth.setVersion(this.version); uni.showToast({ //icon: 'success', duration: 2000, title: this.$t('message.LoginSuccessful') as string, image: '/static/icons/icon-51.png', }); - uni.navigateTo({ - url: page.shouye, - }); + this.checkupdate(); + // uni.navigateTo({ + // url: page.shouye, + // }); } } diff --git a/src/pages/login/login/model.ts b/src/pages/login/login/model.ts new file mode 100644 index 0000000..7abe725 --- /dev/null +++ b/src/pages/login/login/model.ts @@ -0,0 +1,24 @@ +import { getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators'; +import store from '@/store'; +import http from '@/utils/request'; +// import { url } from '@/utils/url'; +// import { session } from '@/store/modules/session'; +@Module({ + namespaced: true, + dynamic: true, + store, + name: 'page.login', +}) +export class login extends VuexModule { + checkversion: any = {}; + @MutationAction + async checkupdate() { + const result: any = await http.post('/prod-api/system/apkFile/getLastApkVersion', { + factory: 1000, + }); + const checkversion: any = result.data; + return { checkversion }; + } +} + +export default getModule(login); diff --git a/src/pages/shouye/me.vue b/src/pages/shouye/me.vue index a43d22e..b85a66e 100644 --- a/src/pages/shouye/me.vue +++ b/src/pages/shouye/me.vue @@ -35,8 +35,8 @@ - 检查更新 - Version:{{ version }} + 版本 + Version:{{ version }}