增加更新功能

master
guoshuang 2 years ago
parent 4cc8355b60
commit 6ce8b41cf0

@ -34,7 +34,7 @@
</view>
</view>
<view class="astyle">
<view> 检查更</view>
<view @click="checkupdate"> </view>
<!-- <u-button
@click.native="
uni.navigateTo({
@ -64,9 +64,75 @@ export default class RawHome extends BasePage {
model = model;
src: 'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg';
today = dayjs().format('YYYY-MM-DD dddd');
version: '0.01';
checkversion: any = {};
onLoad() {
// this.model.getMenuList();
}
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 {
this.checkversion = await model.checkupdate();
let versionNumber = this.compareVersion(this.version, this.checkversion.Version);
versionNumber = 1;
if (versionNumber == -1) {
//
uni.showModal({
content: '新版本为:' + this.checkversion.Version + ',' + '是否更新?',
success: (res) => {
if (res.confirm) {
//
let downloadApkUrl = this.checkversion.url;
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();
}
},
});
return;
}
} catch (e) {
console.log('error', e);
}
}
}
</script>
@ -167,7 +233,7 @@ export default class RawHome extends BasePage {
padding: 32rpx;
margin-top: 4rpx;
text-align: center;
border: 1rpx solid #F2F2F2;
border: 1rpx solid #f2f2f2;
border-radius: 8rpx;
}
}

@ -1,6 +1,6 @@
import { getModule, Module, VuexModule } from 'vuex-module-decorators';
import { getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators';
import store from '@/store';
//import http from '@/utils/request';
import http from '@/utils/request';
//import { url } from '@/utils/url';
//import { session } from '@/store/modules/session';
//import { stringify } from 'query-string';
@ -33,6 +33,12 @@ export class ReceiptModule extends VuexModule {
// const menuList = result.data;
// return { menuList };
// }
@MutationAction
async checkupdate() {
const result = await http.post('///');
const checkversion = result.data;
return checkversion;
}
}
export default getModule(ReceiptModule);

Loading…
Cancel
Save