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

no message

parent 0434c41e
......@@ -41,7 +41,8 @@ http.validateStatus = (statusCode) => {
http.interceptor.request((config, cancel) => { /* 请求之前拦截器 */
config.header = {
...config.header,
'X-Access-Token':getTokenStorage()
'X-Access-Token':getTokenStorage(),
'GToken':getTokenStorage()||"notoken"
}
/*
if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行
......
//APP更新
import api from 'api/api.js'
import { http } from '@/common/service/service.js'
export default function appUpdate() {
http.post('/getAppVersion',{
/* version: plus.runtime.version,
imei: plus.device.imei, */
apptype:"0",
appid: plus.runtime.appid,
import api from 'api/api.js';
function versionStringCompare(preVersion, lastVersion) {
console.log(preVersion, lastVersion)
var sources = preVersion.split('.');
var dests = lastVersion.split('.');
if (dests.length == 2) {
if (dests[1].length >= 2) {
dests[2] = dests[1][dests[1].length - 1]
dests[1] = dests[1].slice(0, dests[1].length - 1)
}
}
var maxL = Math.max(sources.length, dests.length);
var result = 0;
for (let i = 0; i < maxL; i++) {
let preValue = sources.length > i ? sources[i] : 0;
let preNum = isNaN(Number(preValue)) ? preValue.charCodeAt() : Number(preValue);
let lastValue = dests.length > i ? dests[i] : 0;
let lastNum = isNaN(Number(lastValue)) ? lastValue.charCodeAt() : Number(lastValue);
if (preNum < lastNum) {
result = -1;
break;
} else if (preNum > lastNum) {
result = 1;
break;
}
}
return result;
}
export default function appUpdate(loginApp) {
loginApp.showProcess('正在检测版本更新', 10)
/* 0-安卓 1-ios*/
let appType = null;
let platform = uni.getSystemInfoSync().platform;
let hasLogin=loginApp.$store.state.hasLogin;
console.log(loginApp.$store.state.hasLogin);
if (platform == 'android') {
try {
appType = "0";
api.postData('/getAppVersion', {
apptype: appType,
appid: '__UNI__4557C88',
}).then((res) => {
if(res){
if (res) {
plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
let client_version = wgtinfo.version;
var flag_update_v =Number(client_version.split(".")[0]);
var flag_update_v2=Number(res.data.version);
var flag_hot =false;
if (flag_update_v<flag_update_v2) {
let client_version = parseInt(wgtinfo.version);
let now_version = parseInt(res.data.version)
/* 提示版本更新 */
loginApp.showProcess(('客户端版本:' + client_version + '。'), 30)
loginApp.showProcess(('最新版本:' + now_version + '。'), 40)
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'
})
}
}
if (verC < 0) {
loginApp.showProcess('检测到最新版本', 90)
uni.hideLoading()
if (flag_hot) {
downWgt(res.data.url, loginApp,hasLogin)
} else {
// 提醒用户更新
uni.showModal({
title: '更新提示',
content: "请进行版本更新",
content: "当前存在最新版本,建议进行版本更新",
success: (showResult) => {
if (showResult.confirm) {
plus.nativeUI.toast("正在准备环境,请稍后! ");
var dtask = plus.downloader.createDownload(res.data.url, {
loginApp.downLoad = true
var dtask = plus.downloader.createDownload(res
.data.url, {
method: 'GET',
filename: '_doc/update/'
}, function(d, status) {
},
function(d, status) {
if (status == 200) {
var path = d.filename; //下载apk
plus.runtime.install(path); // 自动安装apk文件
plus.runtime.install(
path); // 自动安装apk文件
} else {
plus.nativeUI.alert('版本更新失败:' + status);
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'
})
}
}
}
})
} else if (flag_hot) {
uni.downloadFile({
url: res.data.url,
success: (downloadResult) => {
console.log(downloadResult.tempFilePath)
if (downloadResult.statusCode === 200) {
plus.nativeUI.toast(`正在热更新!${res.data.versionCode}`);
plus.runtime.install(downloadResult.tempFilePath, {
force: false
}, function() {
plus.nativeUI.toast("热更新成功");
plus.runtime.restart();
}, function(e) {
console.log(e)
plus.nativeUI.toast(`热更新失败:${e.message}`);
}
}
});
}
}).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(()=>{
}).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 @@
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({
key: 'userName',
......@@ -326,10 +319,19 @@
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)
//ACCESS_TOKEN
this.$tip.success('登录成功!')
this.$Router.replaceAll({name:'index'})
}else{
this.loading=false;
this.$tip.alert(resp.data.message||"请求失败");
......
......@@ -240,13 +240,7 @@
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({
key: 'userName',
......@@ -262,17 +256,19 @@
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
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{
this.loading=false;
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