|
|
@ -2,21 +2,24 @@ |
|
|
|
<view class="content" v-if="bannerShow"> |
|
|
|
<view class="content" v-if="bannerShow"> |
|
|
|
<!-- 弹出层 --> |
|
|
|
<!-- 弹出层 --> |
|
|
|
<view class="uni-banner"> |
|
|
|
<view class="uni-banner"> |
|
|
|
<image src="/static/img/startUpHeader01.png" class="startUpHeaderLogo" /> |
|
|
|
<!-- <image src="../static/logo.png" class="startUpHeaderLogo" /> --> |
|
|
|
<view class="banner_box"> |
|
|
|
<view class="banner_box"> |
|
|
|
<view class="startUpHeaderBox h6">发现新版本</view> |
|
|
|
<view class="startUpHeaderBox h6">发现新版本</view> |
|
|
|
<view class="conter">{{ msg }}</view> |
|
|
|
<view class="conter">{{ msg }}</view> |
|
|
|
<view class="banner_foot"><button @click="goUpdate(updateApkObj)" class="banner_foot_button">前往升级</button></view> |
|
|
|
<view class="banner_foot"><button @click="goUpdate()" class="banner_foot_button">前往升级</button></view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="uni-mask"></view> |
|
|
|
<view class="uni-mask"></view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import { comparisonVersionHandler } from '@/common/js/tools'; |
|
|
|
// import { |
|
|
|
import { getUpgrade } from '@/common/js/apis'; |
|
|
|
// getUpgrade |
|
|
|
|
|
|
|
// } from '@/common/js/apis'; |
|
|
|
export default { |
|
|
|
import { |
|
|
|
|
|
|
|
queryVersion |
|
|
|
|
|
|
|
} from '../Utils/Api.js' |
|
|
|
|
|
|
|
export default { |
|
|
|
data() { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
return { |
|
|
|
bannerShow: false, // 是否需要強制更新app |
|
|
|
bannerShow: false, // 是否需要強制更新app |
|
|
@ -28,42 +31,36 @@ export default { |
|
|
|
created() { |
|
|
|
created() { |
|
|
|
const appUpdate = uni.getStorageSync('platform'); |
|
|
|
const appUpdate = uni.getStorageSync('platform'); |
|
|
|
// #ifdef APP-PLUS |
|
|
|
// #ifdef APP-PLUS |
|
|
|
this.type = appUpdate == 'android' ? 2 : 1; |
|
|
|
|
|
|
|
this.checkUpdate(); |
|
|
|
this.checkUpdate(); |
|
|
|
// #endif |
|
|
|
// #endif |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
checkUpdate() { |
|
|
|
checkUpdate() { |
|
|
|
const self = this, |
|
|
|
let that = this; |
|
|
|
localAppVersonName = uni.getStorageSync('version'), |
|
|
|
let localAppVersonName = uni.getStorageSync('version'); |
|
|
|
localAppVerson = uni.getStorageSync('versionCode'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #ifdef APP-PLUS |
|
|
|
// #ifdef APP-PLUS |
|
|
|
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) { |
|
|
|
let datas = { |
|
|
|
getUpgrade({ |
|
|
|
termType: "app" |
|
|
|
appType: self.type |
|
|
|
} |
|
|
|
}).then(res => { |
|
|
|
queryVersion(datas).then(res => { |
|
|
|
const { data } = res.data; |
|
|
|
if (res.return_code == '000000') { |
|
|
|
if (res.data.code !== '200') return; |
|
|
|
if (res.return_data.versionType == 1 && that.comparisonVersionHandler(localAppVersonName, |
|
|
|
// 大版本更新 |
|
|
|
res.return_data.version)) { |
|
|
|
if (data.apkVersion && comparisonVersionHandler(localAppVersonName, data.apkVersion.appVersonName)) { |
|
|
|
that.downloadWgt(res.return_data.fileUrl); |
|
|
|
uni.hideTabBar() |
|
|
|
|
|
|
|
self.updateApkObj = data.apkVersion; |
|
|
|
|
|
|
|
self.msg = data.apkVersion.versonLog; |
|
|
|
|
|
|
|
self.bannerShow = true; |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
// app热更新 |
|
|
|
|
|
|
|
} else if (data.wgtVersion && comparisonVersionHandler(localAppVerson, data.wgtVersion.appVerson)) { |
|
|
|
|
|
|
|
self.downloadWgt(data.wgtVersion.downloadUrl); |
|
|
|
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
if (res.return_data.versionType == 2 && that.comparisonVersionHandler(localAppVersonName, |
|
|
|
|
|
|
|
res.return_data.version)) { |
|
|
|
|
|
|
|
that.updateApkObj = res.return_data; |
|
|
|
|
|
|
|
that.bannerShow = true; // 显示弹窗 |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
// #endif |
|
|
|
// #endif |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
downloadWgt(updateWgtUrl) { |
|
|
|
downloadWgt(updateWgtUrl) { |
|
|
|
// 热更新 |
|
|
|
// 热更新 |
|
|
|
// 下载wgt方法 |
|
|
|
// 下载wgt方法 |
|
|
@ -72,8 +69,7 @@ export default { |
|
|
|
plus.nativeUI.showWaiting('正在更新...'); |
|
|
|
plus.nativeUI.showWaiting('正在更新...'); |
|
|
|
plus.downloader |
|
|
|
plus.downloader |
|
|
|
.createDownload( |
|
|
|
.createDownload( |
|
|
|
updateWgtUrl, |
|
|
|
updateWgtUrl, { |
|
|
|
{ |
|
|
|
|
|
|
|
filename: '_doc/update/' |
|
|
|
filename: '_doc/update/' |
|
|
|
}, |
|
|
|
}, |
|
|
|
function(d, status) { |
|
|
|
function(d, status) { |
|
|
@ -89,8 +85,9 @@ export default { |
|
|
|
// 安装wgt方法 |
|
|
|
// 安装wgt方法 |
|
|
|
plus.nativeUI.showWaiting('安装文件...'); |
|
|
|
plus.nativeUI.showWaiting('安装文件...'); |
|
|
|
plus.runtime.install( |
|
|
|
plus.runtime.install( |
|
|
|
path, |
|
|
|
path, { |
|
|
|
{ force: true }, |
|
|
|
force: true |
|
|
|
|
|
|
|
}, |
|
|
|
function() { |
|
|
|
function() { |
|
|
|
plus.nativeUI.closeWaiting(); |
|
|
|
plus.nativeUI.closeWaiting(); |
|
|
|
plus.nativeUI.alert('应用资源更新完成!', function() { |
|
|
|
plus.nativeUI.alert('应用资源更新完成!', function() { |
|
|
@ -102,14 +99,17 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|
goUpdate(updateApkObj) { |
|
|
|
goUpdate() { |
|
|
|
if (this.type == 2) { |
|
|
|
if (this.type == 2) { |
|
|
|
// 弹出系统等待对话框 |
|
|
|
// 弹出系统等待对话框 |
|
|
|
var dtask = plus.downloader.createDownload(updateApkObj.downloadUrl, {}, function(d, status) { |
|
|
|
var dtask = plus.downloader.createDownload( |
|
|
|
|
|
|
|
this.updateApkObj.fileUrl, {}, |
|
|
|
|
|
|
|
function(d, status) { |
|
|
|
this.bannerShow = false; |
|
|
|
this.bannerShow = false; |
|
|
|
// 下载完成 |
|
|
|
// 下载完成 |
|
|
|
if (status == 200) { |
|
|
|
if (status == 200) { |
|
|
|
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(error) { |
|
|
|
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function( |
|
|
|
|
|
|
|
error) { |
|
|
|
uni.showToast({ |
|
|
|
uni.showToast({ |
|
|
|
title: '安装失败', |
|
|
|
title: '安装失败', |
|
|
|
mask: false, |
|
|
|
mask: false, |
|
|
@ -138,7 +138,8 @@ export default { |
|
|
|
showLoading.setTitle('已连接到服务器'); |
|
|
|
showLoading.setTitle('已连接到服务器'); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
prg = parseInt((parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100); |
|
|
|
prg = parseInt((parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * |
|
|
|
|
|
|
|
100); |
|
|
|
showLoading.setTitle(' 正在下载' + prg + '% '); |
|
|
|
showLoading.setTitle(' 正在下载' + prg + '% '); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
case 4: |
|
|
@ -158,26 +159,55 @@ export default { |
|
|
|
} else if (this.type == 1) { // ios跳转到app store |
|
|
|
} else if (this.type == 1) { // ios跳转到app store |
|
|
|
plus.runtime.openURL(updateApkObj.downloadUrl); |
|
|
|
plus.runtime.openURL(updateApkObj.downloadUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
//判断是否升级 |
|
|
|
|
|
|
|
comparisonVersionHandler(reqV, curV) { |
|
|
|
|
|
|
|
/* 版本号名比较是否需要升级 |
|
|
|
|
|
|
|
curV string :当前最新 |
|
|
|
|
|
|
|
reqV string :之前 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
返回 true 表示需要升级 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
if (curV && reqV) { |
|
|
|
|
|
|
|
curV = String(curV); |
|
|
|
|
|
|
|
reqV = String(reqV); |
|
|
|
|
|
|
|
//将两个版本号拆成数字 |
|
|
|
|
|
|
|
let arr1 = curV.split('.'), //當前 |
|
|
|
|
|
|
|
arr2 = reqV.split('.'); |
|
|
|
|
|
|
|
let minLength = Math.min(arr1.length, arr2.length), |
|
|
|
|
|
|
|
position = 0, |
|
|
|
|
|
|
|
diff = 0; |
|
|
|
|
|
|
|
//依次比较版本号每一位大小,当对比得出结果后跳出循环 |
|
|
|
|
|
|
|
while (position < minLength && ((diff = parseInt(arr1[position]) - parseInt(arr2[position])) == 0)) { |
|
|
|
|
|
|
|
position++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
diff = (diff != 0) ? diff : (arr1.length - arr2.length); |
|
|
|
|
|
|
|
//若curV大于reqV,则返回true |
|
|
|
|
|
|
|
return diff > 0; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//输入为空 |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped> |
|
|
|
<style lang="scss" scoped> |
|
|
|
.content, |
|
|
|
.content, |
|
|
|
#img { |
|
|
|
#img { |
|
|
|
width: 100%; |
|
|
|
width: 100%; |
|
|
|
height: 100%; |
|
|
|
height: 100%; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.content .con { |
|
|
|
.content .con { |
|
|
|
font-size: 0; |
|
|
|
font-size: 0; |
|
|
|
display: flex; |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
align-items: center; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#info { |
|
|
|
#info { |
|
|
|
position: absolute; |
|
|
|
position: absolute; |
|
|
|
top: 0; |
|
|
|
top: 0; |
|
|
|
left: 0; |
|
|
|
left: 0; |
|
|
@ -189,24 +219,24 @@ export default { |
|
|
|
text-align: center; |
|
|
|
text-align: center; |
|
|
|
color: #fff; |
|
|
|
color: #fff; |
|
|
|
font-size: 24rpx; |
|
|
|
font-size: 24rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.wrapper { |
|
|
|
.wrapper { |
|
|
|
width: 36rpx; |
|
|
|
width: 36rpx; |
|
|
|
height: 72rpx; |
|
|
|
height: 72rpx; |
|
|
|
position: absolute; |
|
|
|
position: absolute; |
|
|
|
top: 0; |
|
|
|
top: 0; |
|
|
|
overflow: hidden; |
|
|
|
overflow: hidden; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.right { |
|
|
|
.right { |
|
|
|
right: 0; |
|
|
|
right: 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.left { |
|
|
|
.left { |
|
|
|
left: 0; |
|
|
|
left: 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -214,8 +244,8 @@ export default { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 弹出层形式的广告 */ |
|
|
|
/* 弹出层形式的广告 */ |
|
|
|
.uni-banner { |
|
|
|
.uni-banner { |
|
|
|
display: flex; |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
align-items: center; |
|
|
|
flex-direction: column; |
|
|
|
flex-direction: column; |
|
|
@ -240,33 +270,33 @@ export default { |
|
|
|
.startUpHeaderBox { |
|
|
|
.startUpHeaderBox { |
|
|
|
width: 100%; |
|
|
|
width: 100%; |
|
|
|
height: 96rpx; |
|
|
|
height: 96rpx; |
|
|
|
background-image: url('/static/img/startUpHeader02.png'); |
|
|
|
background-image: url('/static/logo.png'); |
|
|
|
background-position: left top; |
|
|
|
background-position: left top; |
|
|
|
background-repeat: no-repeat; |
|
|
|
background-repeat: no-repeat; |
|
|
|
background-size: cover; |
|
|
|
background-size: cover; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.banner_box .h6 { |
|
|
|
.banner_box .h6 { |
|
|
|
text-align: center; |
|
|
|
text-align: center; |
|
|
|
line-height: 96rpx; |
|
|
|
line-height: 96rpx; |
|
|
|
font-size: 36rpx; |
|
|
|
font-size: 36rpx; |
|
|
|
color: #fff; |
|
|
|
color: #fff; |
|
|
|
font-weight: bold; |
|
|
|
font-weight: bold; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.banner_box .conter { |
|
|
|
.banner_box .conter { |
|
|
|
font-size: 28rpx; |
|
|
|
font-size: 28rpx; |
|
|
|
color: #333; |
|
|
|
color: #333; |
|
|
|
margin: 48rpx; |
|
|
|
margin: 48rpx; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.banner_foot { |
|
|
|
.banner_foot { |
|
|
|
width: 238rpx; |
|
|
|
width: 238rpx; |
|
|
|
margin: 48rpx auto; |
|
|
|
margin: 48rpx auto; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.banner_foot_button { |
|
|
|
.banner_foot_button { |
|
|
|
background-image: linear-gradient(to right, #3aaf7a, #41bf7f); |
|
|
|
background-image: linear-gradient(to right, #3aaf7a, #41bf7f); |
|
|
|
line-height: 72rpx; |
|
|
|
line-height: 72rpx; |
|
|
|
height: 72rpx; |
|
|
|
height: 72rpx; |
|
|
@ -276,13 +306,13 @@ export default { |
|
|
|
border-radius: 40rpx; |
|
|
|
border-radius: 40rpx; |
|
|
|
border: none; |
|
|
|
border: none; |
|
|
|
box-shadow: 0 8rpx 20rpx 0 rgba(46, 189, 88, 0.36); |
|
|
|
box-shadow: 0 8rpx 20rpx 0 rgba(46, 189, 88, 0.36); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.banner_foot_button:active { |
|
|
|
.banner_foot_button:active { |
|
|
|
background-image: linear-gradient(to right, #41bf7f, #3aaf7a); |
|
|
|
background-image: linear-gradient(to right, #41bf7f, #3aaf7a); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
.uni-mask { |
|
|
|
.uni-mask { |
|
|
|
background: rgba(0, 0, 0, 0.6); |
|
|
|
background: rgba(0, 0, 0, 0.6); |
|
|
|
position: fixed; |
|
|
|
position: fixed; |
|
|
|
width: 100%; |
|
|
|
width: 100%; |
|
|
@ -290,5 +320,5 @@ export default { |
|
|
|
left: 0; |
|
|
|
left: 0; |
|
|
|
top: 0; |
|
|
|
top: 0; |
|
|
|
z-index: 2; |
|
|
|
z-index: 2; |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |