Commit 521092d1 authored by 沈翠玲's avatar 沈翠玲

app自动更新

parent 84d0139c
<script>
import checkappupdate from 'common/checkappupdate.js'
export default {
onLaunch: function () {
// #ifdef APP-PLUS
plus.navigator.setFullscreen(true);
plus.screen.lockOrientation('landscape-primary');
const fn = () => {
checkappupdate.check({
title: '检测到有新版本!',
content: '请升级app到最新版本!',
canceltext: '暂不升级',
oktext: '立即升级',
func: this.$u.api.getCurrentsys
})
return fn // 函数中返回自身
}
setInterval(fn(), 3600 * 1000)
// #endif
},
//把想要全局的数据放在globalData对象里,globalData是uniapp的不可以自定义命名。
......
import config from './config.js'
function check(param = {}) {
// 合并默认参数
param = Object.assign({
title: "检测到有新版本!",
content: "请升级app到最新版本!",
canceltext: "暂不升级",
oktext: "立即升级"
}, param)
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
let platform = plus.os.name.toLocaleLowerCase()
try {
param.func().then(result => {
let data = result.data ? result.data[0] : null;
if (widgetInfo.version === data.version) {
return;
}
if (result.code == 200) {
// android进行如下操作
uni.showModal({
title: param.title,
content: data.updateDesc ? data.updateDesc + '' : param.content,
showCancel: false,
confirmText: param.oktext,
cancelText: param.canceltext,
success: res => {
if (!res.confirm) {
console.log('取消了升级');
plus.runtime.quit();
}
// 清除缓存
// request.clearLogin();
// 开始下载
// 创建下载任务
var dtask = plus.downloader.createDownload(data.url, {
filename: "_downloads/"
},
function (d, status) {
// 下载完成
if (status == 200) {
plus.runtime.install(d.filename, {
force: true
}, function () {
//进行重新启动;
plus.runtime.restart();
}, (e) => {
uni.showToast({
title: '安装升级包失败:' + JSON
.stringify(e),
icon: 'none'
})
});
} else {
this.tui.toast("下载升级包失败,请手动去站点下载安装,错误码: " +
status);
}
});
let view = new plus.nativeObj.View("maskView", {
backgroundColor: "rgba(0,0,0,.6)",
left: '0px',
bottom: "0px",
width: plus.screen.resolutionWidth,
height: plus.screen.resolutionHeight
})
view.drawText('开始下载', {}, {
size: '12px',
color: '#FFFFFF'
});
view.show()
dtask.addEventListener("statechanged", (e) => {
if (e && e.downloadedSize > 0) {
let jindu = ((e.downloadedSize / e.totalSize) *
100).toFixed(2)
view.reset();
view.drawText('进度:' + jindu + '%', {}, {
size: '12px',
color: '#FFFFFF'
});
}
}, false);
dtask.start();
}
})
}
})
} catch (e) {
console.log('eee',e)
}
});
}
export default {
check
}
......@@ -22,8 +22,8 @@ const config = {
// 设置后台接口服务的基础地址
// config.baseUrl = 'http://192.168.3.91:8080';
// config.baseUrl = 'http://192.168.3.91:8100';
config.baseUrl = '/api';
config.baseUrl = 'http://192.168.3.91:8100';
// config.baseUrl = '/api';
//测试环境
// config.baseUrl = 'http://192.168.3.91:8080';
......
......@@ -29,7 +29,10 @@ const install = (Vue, vm) => {
vm.$u.post(config.adminPath + '/mobile/login/sendCode', params),
registerUser: (params = {}) =>
vm.$u.post(config.adminPath + '/mobile/user/registerUser', params),
getCurrentsys: (params = {}) =>
vm.$u.get(
config.adminPath + '/md/appconfig/getVersion'
),
/**
* 系统设置API
*/
......
{
"name" : "mes-pad",
"appid" : "__UNI__EA378AB",
"appid" : "__UNI__EFAA56F",
"description" : "MES-PAD",
"versionName" : "1.0.0",
"versionCode" : "100",
......@@ -61,13 +61,13 @@
},
"icons" : {
"android" : {
"hdpi" : "unpackage/res/icons/72x72.png",
"xhdpi" : "unpackage/res/icons/96x96.png",
"xxhdpi" : "unpackage/res/icons/144x144.png",
"xxxhdpi" : "unpackage/res/icons/192x192.png"
"hdpi" : "static/logo.png",
"xhdpi" : "static/logo.png",
"xxhdpi" : "static/logo.png",
"xxxhdpi" : "static/logo.png"
},
"ios" : {
"appstore" : "unpackage/res/icons/1024x1024.png",
"appstore" : "static/logo.png",
"ipad" : {
"app" : "unpackage/res/icons/76x76.png",
"app@2x" : "unpackage/res/icons/152x152.png",
......@@ -80,14 +80,14 @@
"spotlight@2x" : "unpackage/res/icons/80x80.png"
},
"iphone" : {
"app@2x" : "unpackage/res/icons/120x120.png",
"app@3x" : "unpackage/res/icons/180x180.png",
"notification@2x" : "unpackage/res/icons/40x40.png",
"notification@3x" : "unpackage/res/icons/60x60.png",
"settings@2x" : "unpackage/res/icons/58x58.png",
"settings@3x" : "unpackage/res/icons/87x87.png",
"spotlight@2x" : "unpackage/res/icons/80x80.png",
"spotlight@3x" : "unpackage/res/icons/120x120.png"
"app@2x" : "static/logo.png",
"app@3x" : "static/logo.png",
"notification@2x" : "static/logo.png",
"notification@3x" : "static/logo.png",
"settings@2x" : "static/logo.png",
"settings@3x" : "static/logo.png",
"spotlight@2x" : "static/logo.png",
"spotlight@3x" : "static/logo.png"
}
}
}
......
......@@ -291,7 +291,7 @@
</view>
<view v-else>
<u-form label-width="80px" :model="feedback" :rules="rules" labelAlign="right">
<u-form label-width="100px" :model="feedback" :rules="rules" labelAlign="right">
<u-row>
<u-col span="6">
<u-form-item label="任务单号:" prop="quantity">
......
......@@ -17,7 +17,7 @@ module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:8080/',
target: 'http://192.168.3.91:8100',
changeOrigin: true,
pathRewrite: {
'^/api': ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment