版本更新处理

main
许宏杰 4 days ago
parent 9c462ffe84
commit 5b9fae22e0

@ -4,9 +4,12 @@
import {
getToken
} from '@/utils/auth'
import {
getVersions
} from '@/utils/handlerColor.js'
export default {
onLaunch: function() {
this.initApp()
},
methods: {
@ -19,8 +22,31 @@
this.checkLogin()
//#endif
},
initConfig() {
async initConfig() {
this.globalData.config = config
//
const version = await getVersions()
const systemData = this.$u.sys()
if (systemData.appVersion != version) {
uni.showModal({
title: '发现新版本',
content: '版本V ' + version,
cancelText: '暂不更新',
confirmText: '立即更新',
success: (res) => {
if (res.confirm) {
const urlAndorid = 'https://www.pgyer.com/9B4d'
if (window.plus) window.plus.runtime.openURL(urlAndorid)
//
else window.open(urlAndorid)
}
}
})
}
console.log(systemData.appVersion, '当前版本', version, "最新版本")
},
checkLogin() {
if (!getToken()) {

@ -2,8 +2,8 @@
"name" : "若依移动端",
"appid" : "__UNI__25A9D80",
"description" : "",
"versionName" : "1.1.0",
"versionCode" : "100",
"versionName" : "1.2.0",
"versionCode" : 120,
"transformPx" : false,
"app-plus" : {
"usingComponents" : true,

@ -28,7 +28,6 @@
<view class="menu-list">
<view class="list-cell list-cell-arrow" @click="handleToEditInfo">
<view class="menu-item-box">
<view class="iconfont icon-password menu-icon"></view>
<view>修改密码</view>
</view>
@ -39,6 +38,13 @@
<view>个人信息</view>
</view>
</view>
<view class="list-cell list-cell-arrow" @click="updateVersion">
<view class="menu-item-box">
<view class="iconfont icon-version menu-icon"></view>
<view>版本更新</view>
<view class="version-box">发现新版本</view>
</view>
</view>
</view>
<view class="outLogin">
<u-button type="primary" @click="handleLogout">退</u-button>
@ -51,18 +57,25 @@
<script>
import storage from '@/utils/storage'
import {
getVersions
} from '@/utils/handlerColor.js'
export default {
data() {
return {
version: '',
showVersion: false,
localityVersion: '',
boxTop: 0,
name: this.$store.state.user.name,
version: getApp().globalData.config.appInfo.version
// version: getApp().globalData.config.appInfo.version
}
},
onLoad() {
const systemData = this.$u.sys()
this.localityVersion = systemData.appVersion
this.boxTop = systemData.statusBarHeight
this.getVersion()
},
computed: {
avatar() {
@ -73,6 +86,35 @@
}
},
methods: {
updateVersion() {
if (this.showVersion) {
uni.showModal({
title: '发现新版本',
content: '版本V ' + this.version,
cancelText: '暂不更新',
confirmText: '立即更新',
success: (res) => {
if (res.confirm) {
const urlAndorid = 'https://www.pgyer.com/9B4d'
if (window.plus) window.plus.runtime.openURL(urlAndorid)
//
else window.open(urlAndorid)
}
}
})
}
},
async getVersion() {
this.version = await getVersions()
if (this.localityVersion != this.version) {
this.showVersion = true
console.log(version, '版本', this.localityVersion)
} else {
this.showVersion = false
}
},
handleLogout() {
this.$modal.confirm('确定注销并退出系统吗?').then(() => {
this.$store.dispatch('LogOut').then(() => {
@ -193,4 +235,20 @@
margin-top: 30rpx;
}
.menu-item-box {
position: relative;
.version-box {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 30rpx;
background-color: red;
color: #fff;
font-size: 28rpx;
box-sizing: border-box;
padding: 0 10rpx;
}
}
</style>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 27 KiB

@ -18,7 +18,7 @@ const rightTopColor = {
NO: "#7f8c95",
NF: "#008c5e",
}
//颜色处理
export function handleColor(data) {
if (checkType(data) == "array") {
@ -63,7 +63,7 @@ function checkType(value) {
return "neither";
}
}
//根据身份证号算年纪/岁数等
export function validateAndParseIDCard(idCard, type) {
// 验证身份证号格式
const idCardPattern =
@ -110,4 +110,27 @@ export function validateAndParseIDCard(idCard, type) {
default:
return "无效的type参数";
}
}
//版本信息
export function getVersions() {
return new Promise((resolve, reject) => {
uni.request({
url: 'http://www.jichuanglanhai.com/demo/appVersion.json',
data: {
time: new Date().getTime(),
},
success: (res) => {
resolve(res.data.taicangVersion)
},
fail: (error) => {
uni.showToast({
title: '获取版本信息失败!',
icon: 'none'
})
reject()
}
})
})
}
Loading…
Cancel
Save