更新机制修改,请在登录页修改每次的版本号

master
guoshuang 1 year ago
parent 53d9732785
commit b5696e5e17

@ -87,13 +87,16 @@ import { Component, Ref, Watch } from 'vue-property-decorator';
import Alerts from '@/components/alert/alerts.vue'; import Alerts from '@/components/alert/alerts.vue';
import { page } from '@/utils/page'; import { page } from '@/utils/page';
import { session } from '@/store/modules/session'; import { session } from '@/store/modules/session';
import { auth } from '@/store/modules/auth';
import { BasePage } from '@/components/base/page'; import { BasePage } from '@/components/base/page';
import { VForm } from 'vue/types/form'; import { VForm } from 'vue/types/form';
import model from './model';
// mixin // mixin
@Component({ @Component({
components: { Alerts }, components: { Alerts },
}) })
export default class LoginPage extends BasePage { export default class LoginPage extends BasePage {
model = model;
/** /**
* 访客权限 * 访客权限
*/ */
@ -131,7 +134,6 @@ export default class LoginPage extends BasePage {
const languages = ['cn', 'en', 'ru']; const languages = ['cn', 'en', 'ru'];
this.$i18n.locale = languages[index]; this.$i18n.locale = languages[index];
} }
Version = '';
onReady(): void { onReady(): void {
this.$form.setRules(this.rules); this.$form.setRules(this.rules);
//this.customToast('' + plus.runtime.version); //this.customToast('' + plus.runtime.version);
@ -139,6 +141,86 @@ export default class LoginPage extends BasePage {
// console.log('image', this.image); // console.log('image', this.image);
// console.log('Version////', this.Version); // 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 { onShow(): void {
// console.log('......', server.serverAddress); // console.log('......', server.serverAddress);
@ -262,15 +344,17 @@ export default class LoginPage extends BasePage {
nickName, nickName,
roles, roles,
}); });
auth.setVersion(this.version);
uni.showToast({ uni.showToast({
//icon: 'success', //icon: 'success',
duration: 2000, duration: 2000,
title: this.$t('message.LoginSuccessful') as string, title: this.$t('message.LoginSuccessful') as string,
image: '/static/icons/icon-51.png', image: '/static/icons/icon-51.png',
}); });
uni.navigateTo({ this.checkupdate();
url: page.shouye, // uni.navigateTo({
}); // url: page.shouye,
// });
} }
} }
</script> </script>

@ -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);

@ -35,8 +35,8 @@
</view> </view>
</view> </view>
<view class="astyle astyleversion"> <view class="astyle astyleversion">
<view @click="checkupdate()"> </view> <view> 版本 </view>
<view @click="checkupdate()"> Version:{{ version }} </view> <view> Version:{{ version }} </view>
<!-- <u-button <!-- <u-button
@click.native=" @click.native="
uni.navigateTo({ uni.navigateTo({
@ -60,90 +60,92 @@ import { BasePage } from '@/components/base/page';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import model from './model'; import model from './model';
import { session } from '@/store/modules/session'; import { session } from '@/store/modules/session';
import { auth } from '@/store/modules/auth';
@Component @Component
export default class RawHome extends BasePage { export default class RawHome extends BasePage {
model = model; model = model;
src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'; src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
today = dayjs().format('YYYY-MM-DD dddd'); today = dayjs().format('YYYY-MM-DD dddd');
version = '0.0.55'; version = '';
checkversion: any = {}; checkversion: any = {};
sessiondata: any = ''; sessiondata: any = '';
onLoad() { onLoad() {
// this.model.getMenuList(); // this.model.getMenuList();
uni.setStorageSync('version', this.version); uni.setStorageSync('version', this.version);
this.sessiondata = session; this.sessiondata = session;
this.version = auth.getVersion;
} }
compareVersion(version1: any, version2: any) { // compareVersion(version1: any, version2: any) {
//version1 1 &&& version2 -1 // //version1 1 &&& version2 -1
const newVersion1 = `${version1}`.split('.').length < 3 ? `${version1}`.concat('.0') : `${version1}`; // const newVersion1 = `${version1}`.split('.').length < 3 ? `${version1}`.concat('.0') : `${version1}`;
const newVersion2 = `${version2}`.split('.').length < 3 ? `${version2}`.concat('.0') : `${version2}`; // const newVersion2 = `${version2}`.split('.').length < 3 ? `${version2}`.concat('.0') : `${version2}`;
//, // //,
function toNum(a) { // function toNum(a) {
const c = a.toString().split('.'); // const c = a.toString().split('.');
const num_place = ['', '0', '00', '000', '0000'], // const num_place = ['', '0', '00', '000', '0000'],
r = num_place.reverse(); // r = num_place.reverse();
for (let i = 0; i < c.length; i++) { // for (let i = 0; i < c.length; i++) {
const len = c[i].length; // const len = c[i].length;
c[i] = r[len] + c[i]; // c[i] = r[len] + c[i];
} // }
return c.join(''); // return c.join('');
} // }
// // //
function checkPlugin(a: any, b: any) { // function checkPlugin(a: any, b: any) {
const numA = toNum(a); // const numA = toNum(a);
const numB = toNum(b); // const numB = toNum(b);
return numA > numB ? 1 : numA < numB ? -1 : 0; // return numA > numB ? 1 : numA < numB ? -1 : 0;
} // }
return checkPlugin(newVersion1, newVersion2); // return checkPlugin(newVersion1, newVersion2);
} // }
async checkupdate() { // async checkupdate() {
try { // try {
await this.model.checkupdate(); // await this.model.checkupdate();
const queryversion = this.model.checkversion.version; // const queryversion = this.model.checkversion.version;
//const queryversion = this.checkversion.Version.match(/\d+\.\d+\.\d+/)[0]; // //const queryversion = this.checkversion.Version.match(/\d+\.\d+\.\d+/)[0];
let versionNumber = this.compareVersion(this.version, queryversion); //this.version, queryversion // let versionNumber = this.compareVersion(this.version, queryversion); //this.version, queryversion
if (versionNumber == -1) { // if (versionNumber == -1) {
// // //
uni.showModal({ // uni.showModal({
content: '新版本为:' + this.model.checkversion.version + ',' + '是否更新?', // content: '' + this.model.checkversion.version + ',' + '',
success: (res) => { // success: (res) => {
if (res.confirm) { // if (res.confirm) {
// // //
let downloadApkUrl = this.model.checkversion.fileAddress; // let downloadApkUrl = this.model.checkversion.fileAddress;
uni.showLoading({ // uni.showLoading({
title: '下载中', // title: '',
}); // });
////////////////uni, // ////////////////uni,
uni.downloadFile({ // uni.downloadFile({
url: downloadApkUrl, // url: downloadApkUrl,
success: (downloadResult) => { // success: (downloadResult) => {
uni.hideLoading(); // uni.hideLoading();
if (downloadResult.statusCode == 200) { // if (downloadResult.statusCode == 200) {
// // //
plus.runtime.install(downloadResult.tempFilePath as any, { force: true }, function () { // plus.runtime.install(downloadResult.tempFilePath as any, { force: true }, function () {
//uni.showToast(''); // //uni.showToast('');
plus.runtime.restart(); // plus.runtime.restart();
}); // });
} // }
}, // },
}); // });
} else if (res.cancel) { // } else if (res.cancel) {
console.log(); // console.log();
} // }
}, // },
}); // });
return; // return;
} else { // } else {
uni.showToast({ // uni.showToast({
title: '无更新内容', // title: '',
icon: 'none', // icon: 'none',
}); // });
} // }
} catch (e) { // } catch (e) {
console.log('error', e); // console.log('error', e);
} // }
} // }
} }
</script> </script>

@ -1,22 +1,12 @@
import { getModule, Module, VuexModule } from 'vuex-module-decorators'; import { getModule, Mutation, Module, VuexModule } from 'vuex-module-decorators';
//import request from '@/utils/request'; //import request from '@/utils/request';
import store from '@/store'; import store from '@/store';
//import { User } from '@/store/modules/session'; //import { User } from '@/store/modules/session';
//import { url } from '@/utils/url'; //import { url } from '@/utils/url';
export interface UserInfo { // export interface UserInfo {
factoryCode: string; // version:string;
factoryName: string; // }
factoryType?: any;
warehouseCode?: any;
warehouseName?: any;
warehouseType?: any;
loginName: string;
userName: string;
sapFactoryCode?: any;
locationCode?: any;
workareaCode?: any;
}
@Module({ @Module({
dynamic: true, dynamic: true,
@ -25,6 +15,14 @@ export interface UserInfo {
name: 'auth', name: 'auth',
}) })
class AuthService extends VuexModule { class AuthService extends VuexModule {
version = '';
get getVersion(): string {
return this.version;
}
@Mutation
setVersion(version: string) {
this.version = version;
}
// @Action // @Action
// async getUserInfo({ loginName }: { loginName: User['loginName'] }): Promise<UserInfo> { // async getUserInfo({ loginName }: { loginName: User['loginName'] }): Promise<UserInfo> {
// const r: any = await request.post(url.auth.userInfo, { // const r: any = await request.post(url.auth.userInfo, {

Loading…
Cancel
Save