Commit 057a258a authored by 王向前's avatar 王向前

no message

parent 0434c41e
...@@ -41,7 +41,8 @@ http.validateStatus = (statusCode) => { ...@@ -41,7 +41,8 @@ http.validateStatus = (statusCode) => {
http.interceptor.request((config, cancel) => { /* 请求之前拦截器 */ http.interceptor.request((config, cancel) => { /* 请求之前拦截器 */
config.header = { config.header = {
...config.header, ...config.header,
'X-Access-Token':getTokenStorage() 'X-Access-Token':getTokenStorage(),
'GToken':getTokenStorage()||"notoken"
} }
/* /*
if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行 if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行
......
//APP更新 //APP更新
import api from 'api/api.js' import api from 'api/api.js';
import { http } from '@/common/service/service.js'
export default function appUpdate() { function versionStringCompare(preVersion, lastVersion) {
http.post('/getAppVersion',{ console.log(preVersion, lastVersion)
/* version: plus.runtime.version, var sources = preVersion.split('.');
imei: plus.device.imei, */ var dests = lastVersion.split('.');
apptype:"0", if (dests.length == 2) {
appid: plus.runtime.appid, if (dests[1].length >= 2) {
}).then((res) => { dests[2] = dests[1][dests[1].length - 1]
if(res){ dests[1] = dests[1].slice(0, dests[1].length - 1)
plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) { }
let client_version = wgtinfo.version; }
var flag_update_v =Number(client_version.split(".")[0]); var maxL = Math.max(sources.length, dests.length);
var flag_update_v2=Number(res.data.version); var result = 0;
var flag_hot =false; for (let i = 0; i < maxL; i++) {
if (flag_update_v<flag_update_v2) { let preValue = sources.length > i ? sources[i] : 0;
// 提醒用户更新 let preNum = isNaN(Number(preValue)) ? preValue.charCodeAt() : Number(preValue);
uni.showModal({ let lastValue = dests.length > i ? dests[i] : 0;
title: '更新提示', let lastNum = isNaN(Number(lastValue)) ? lastValue.charCodeAt() : Number(lastValue);
content: "请进行版本更新", if (preNum < lastNum) {
success: (showResult) => { result = -1;
if (showResult.confirm) { break;
plus.nativeUI.toast("正在准备环境,请稍后! "); } else if (preNum > lastNum) {
var dtask = plus.downloader.createDownload(res.data.url, { result = 1;
method: 'GET', break;
filename: '_doc/update/' }
}, function(d, status) { }
if (status == 200) {
var path = d.filename; //下载apk return result;
plus.runtime.install(path); // 自动安装apk文件 }
} else { export default function appUpdate(loginApp) {
plus.nativeUI.alert('版本更新失败:' + status); loginApp.showProcess('正在检测版本更新', 10)
} /* 0-安卓 1-ios*/
}); let appType = null;
dtask.start(); let platform = uni.getSystemInfoSync().platform;
} let hasLogin=loginApp.$store.state.hasLogin;
} console.log(loginApp.$store.state.hasLogin);
}) if (platform == 'android') {
} else if (flag_hot) { try {
uni.downloadFile({ appType = "0";
url: res.data.url, api.postData('/getAppVersion', {
success: (downloadResult) => { apptype: appType,
console.log(downloadResult.tempFilePath) appid: '__UNI__4557C88',
if (downloadResult.statusCode === 200) { }).then((res) => {
plus.nativeUI.toast(`正在热更新!${res.data.versionCode}`); if (res) {
plus.runtime.install(downloadResult.tempFilePath, { plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
force: false let client_version = parseInt(wgtinfo.version);
}, function() { let now_version = parseInt(res.data.version)
plus.nativeUI.toast("热更新成功");
plus.runtime.restart(); /* 提示版本更新 */
}, function(e) { loginApp.showProcess(('客户端版本:' + client_version + '。'), 30)
console.log(e) loginApp.showProcess(('最新版本:' + now_version + '。'), 40)
plus.nativeUI.toast(`热更新失败:${e.message}`); let verC = versionStringCompare(wgtinfo.version, res.data.version + '');
}); var flag_hot = true;
} console.log(verC)
} if (verC >=0) {
}); loginApp.showProcess('无版本更新,欢迎使用格物云ERP', 100)
} uni.hideLoading()
}); if(!hasLogin){
} loginApp.$Router.replaceAll({
name: 'cusmerLogin'
}).catch((err) => { })
}
}).finally(()=>{ }
if (verC < 0) {
loginApp.showProcess('检测到最新版本', 90)
uni.hideLoading()
if (flag_hot) {
downWgt(res.data.url, loginApp,hasLogin)
} else {
// 提醒用户更新
uni.showModal({
title: '更新提示',
content: "当前存在最新版本,建议进行版本更新",
success: (showResult) => {
if (showResult.confirm) {
loginApp.downLoad = true
var dtask = plus.downloader.createDownload(res
.data.url, {
method: 'GET',
filename: '_doc/update/'
},
function(d, status) {
if (status == 200) {
var path = d.filename; //下载apk
plus.runtime.install(
path); // 自动安装apk文件
} else {
plus.nativeUI.alert('版本更新失败:' +
status);
loginApp.downLoad = false
}
});
dtask.addEventListener("statechanged", function(
task, status) {
if (!task) {
return;
}
switch (task.state) {
case 1:
loginApp.showProcess(
'开始下载资源包', 0)
break;
case 2:
loginApp.showProcess(
'已经连接到服务器', 0)
break;
case 3:
// 已接收到数据
let progress = Math.floor(
dtask
.downloadedSize *
100 / dtask
.totalSize);
loginApp.showProcess('正在下载',
progress)
break;
case 4:
// 下载完成,打开文件完成更新动作.
plus.runtime.install(task
.filename);
plus.runtime.quit()
break;
}
}, false);
dtask.start();
} else {
if(!hasLogin){
loginApp.$Router.replaceAll({
name: 'cusmerLogin'
})
}
}
}
})
}
}
});
}
}).catch((err) => {
}).finally(() => {
})
} catch (e) {
uni.hideLoading()
if(!hasLogin){
loginApp.$Router.replaceAll({
name: 'cusmerLogin'
})
}
// loginApp.$Router.replaceAll({name:'login'})
// alert("error:" + e.message);
}
} else {
appType = "1";
try {
api.postData('/getAppVersion', {
apptype: appType,
appid: '__UNI__4557C88',
}).then((res) => {
if (res) {
plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
let client_version = parseInt(wgtinfo.version);
let now_version = parseInt(res.data.version)
console.log(client_version, now_version)
let verC = versionStringCompare(wgtinfo.version, res.data.version + '');
var flag_hot = true;
if (verC > 0) {
loginApp.showProcess('无版本更新,欢迎使用格物云ERP', 100)
if(!hasLogin){
loginApp.$Router.replaceAll({
name: 'cusmerLogin'
})
}
}
if (verC < 0) {
if (flag_hot) {
downWgt(res.data.url, loginApp,hasLogin)
} else {
uni.showModal({
title: '更新提示',
content: "当前存在最新版本,建议进行版本更新",
success: (showResult) => {
if (showResult.confirm) {
let appurl =
"https://itunes.apple.com/cn/app/com.gavelinfo.erp/1609168603"
plus.runtime.openURL(appurl, function(res) {
console.log(res);
});
} else {
if(!hasLogin){
loginApp.$Router.replaceAll({
name: 'cusmerLogin'
})
}
}
}
})
}
}
});
}
}).catch((err) => {
}).finally(() => {
})
} catch (e) {
uni.hideLoading()
loginApp.$Router.replaceAll({name:'cusmerLogin'})
}
}
}
function downWgt(wgtUrl, loginApp,hasLogin) {
// plus.nativeUI.showWaiting("下载最新资源...");
uni.hideLoading()
uni.showLoading({
title: '开始热更新'
})
loginApp.showProcess('开始版本热更新', 5)
var dtasks = plus.downloader.createDownload(wgtUrl, {
filename: "_doc/update/"
}, function(d, status) {
uni.hideLoading()
if (status == 200) {
console.log("下载资源成功:"+d.filename);
} else {
}) plus.nativeUI.alert("下载资源失败!");
// loginApp.$Router.replaceAll({name:'login'})
}
plus.nativeUI.closeWaiting();
})
if(!dtasks){
uni.hideLoading()
if(!hasLogin){
loginApp.$Router.replaceAll({name:'cusmerLogin'})
}
}
dtasks.addEventListener("statechanged", function(task, status) {
if (!task) {
return;
}
switch (task.state) {
case 1:
loginApp.showProcess('开始下载资源包', 0)
break;
case 2:
loginApp.showProcess('已经连接到服务器', 0)
break;
case 3:
// 已接收到数据
let progress = Math.floor(dtasks.downloadedSize * 100 / dtasks.totalSize);
loginApp.showProcess('正在下载', progress)
break;
case 4:
installWgt(task.filename,loginApp);
break;
}
}, false);
dtasks.start();
}
// 更新应用资源
function installWgt(path,loginApp) {
plus.nativeUI.showWaiting("正在更新...");
plus.runtime.install(path,{},function(){
plus.nativeUI.closeWaiting();
console.log("安装wgt文件成功!");
plus.nativeUI.alert("应用资源更新完成!",function(){
plus.runtime.restart();
});
},function(e){
plus.nativeUI.closeWaiting();
console.log("安装wgt文件失败["+e.code+"]:"+e.message);
plus.nativeUI.alert("安装wgt文件失败["+e.code+"]:"+e.message);
loginApp.$Router.replaceAll({name:'cusmerLogin'})
});
} }
...@@ -304,13 +304,6 @@ ...@@ -304,13 +304,6 @@
console.log(resp.data.data.username); console.log(resp.data.data.username);
} }
}); });
uni.setStorage({
key: 'ACCESS_TOKEN',
data: resp.data.data.token,
success: function () {
console.log(resp.data.data.token)
}
});
// 本地存储信息 // 本地存储信息
uni.setStorage({ uni.setStorage({
key: 'userName', key: 'userName',
...@@ -326,10 +319,19 @@ ...@@ -326,10 +319,19 @@
console.log("用户名获取成功") console.log("用户名获取成功")
} }
}); });
uni.setStorage({
key: 'ACCESS_TOKEN',
data: resp.data.data.token,
success: function () {
console.log(resp.data.data.token)
_this.$tip.success('登录成功!')
_this.$Router.replaceAll({name:'index'})
}
});
// this.$router.go(0) // this.$router.go(0)
//ACCESS_TOKEN //ACCESS_TOKEN
this.$tip.success('登录成功!')
this.$Router.replaceAll({name:'index'})
}else{ }else{
this.loading=false; this.loading=false;
this.$tip.alert(resp.data.message||"请求失败"); this.$tip.alert(resp.data.message||"请求失败");
......
...@@ -240,13 +240,7 @@ ...@@ -240,13 +240,7 @@
console.log(res.data.data.username); console.log(res.data.data.username);
} }
}); });
uni.setStorage({
key: 'ACCESS_TOKEN',
data: res.data.data.token,
success: function () {
console.log(res.data.data.token)
}
});
// 本地存储信息 // 本地存储信息
uni.setStorage({ uni.setStorage({
key: 'userName', key: 'userName',
...@@ -262,17 +256,19 @@ ...@@ -262,17 +256,19 @@
console.log("用户名获取成功") console.log("用户名获取成功")
} }
}); });
uni.setStorage({
key: 'ACCESS_TOKEN',
data: res.data.data.token,
success: function () {
_this.$tip.success('登录成功!')
_this.$Router.replaceAll({name:'index'})
console.log(res.data.data.token)
}
});
//ACCESS_TOKEN //ACCESS_TOKEN
this.$tip.success('登录成功!')
this.$Router.replaceAll({name:'index'})
// #ifdef APP-PLUS
// this.saveClientId()
// #endif
// #ifndef APP-PLUS
this.$tip.success('登录成功!')
this.$Router.replaceAll({name:'index'})
// #endif
}else{ }else{
this.loading=false; this.loading=false;
this.$tip.alert(res.data.message); this.$tip.alert(res.data.message);
......
<template>
<view class="page uodateMain">
<!-- 升级模态框 -->
<view class="text-center">
<image :src="imgsrc" mode='aspectFit' class="zai-logo "></image>
<view class="zai-title text-shadow">欢迎格物云ERP</view>
</view>
<!-- 进度条 -->
<view class="progress">
<view class="tips">
tips:{{text}}
</view>
<view class="">
<view class="uni-padding-wrap uni-common-mt">
<view class="progress-box">
<progress :percent="percent" activeColor="#10AEFF" stroke-width="8" />
</view>
<view class="percent">
{{percent}}%
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import appUpdate from 'common/util/appUpdate.js'
export default {
onLoad() {
// this.showLoading()
// #ifdef APP-PLUS
setTimeout(()=>{
appUpdate(this)
},500)
// #endif
// #ifdef H5
this.$Router.replaceAll({name:'cusmerLogin'})
// #endif
},
data() {
return {
downLoad:false,
imgsrc: "/static/image/logon.png",
percent:0,
text:'正在检测版本'
}
},
methods: {
/* 修改进度 */
showProcess(text,percent){
this.text=text
this.percent=percent
},
showLoading(){
uni.showLoading({
title: this.text
})
},
hideLoading(){
uni.hideLoading()
}
}
}
</script>
<style>
.percent{
height: 25px;line-height: 25px;text-align: center;
font-size: 12px;
}
.tips{
height: 30px;
font-size: 12px;
}
.progress {
width: 100%;
position: absolute;
bottom: 4vh;
padding: 20px;
}
.zai-title {
font-size: 20px;
color: #000000;
text-align: center;
}
.uodateMain {
height: 100vh;
width: 100vw;
padding-top: 80px;
background-color: #fff;
}
.zai-logo {
/* width: 200upx; */
height: 200upx;
}
</style>
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