diff --git a/src/pages/login/login/index.vue b/src/pages/login/login/index.vue index 15ef875..cd5bce5 100644 --- a/src/pages/login/login/index.vue +++ b/src/pages/login/login/index.vue @@ -151,10 +151,34 @@ export default class LoginPage extends BasePage { console.log('Version////', this.Version); } Version = '1.0.9'; + 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, b) { + const numA = toNum(a); + const numB = toNum(b); + return numA > numB ? 1 : numA < numB ? -1 : 0; + } + return checkPlugin(newVersion1, newVersion2); + } async update() { try { await session.QueryVersion(server.serverAddress); - if (this.Version < session.Version) { + let versionNumber = this.compareVersion(this.Version, session.Version); + if (versionNumber == -1) { // 版本更新提示 uni.showModal({ content: (this.$t('message.Tip3') + session.Version + ',' + this.$t('message.Tip1')) as string,