版本更新处理

main
许宏杰 3 months ago
parent 9c462ffe84
commit 5b9fae22e0

@ -4,9 +4,12 @@
import { import {
getToken getToken
} from '@/utils/auth' } from '@/utils/auth'
import {
getVersions
} from '@/utils/handlerColor.js'
export default { export default {
onLaunch: function() { onLaunch: function() {
this.initApp() this.initApp()
}, },
methods: { methods: {
@ -19,8 +22,31 @@
this.checkLogin() this.checkLogin()
//#endif //#endif
}, },
initConfig() { async initConfig() {
this.globalData.config = config 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() { checkLogin() {
if (!getToken()) { if (!getToken()) {

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

@ -28,7 +28,6 @@
<view class="menu-list"> <view class="menu-list">
<view class="list-cell list-cell-arrow" @click="handleToEditInfo"> <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
<view class="menu-item-box"> <view class="menu-item-box">
<view class="iconfont icon-password menu-icon"></view> <view class="iconfont icon-password menu-icon"></view>
<view>修改密码</view> <view>修改密码</view>
</view> </view>
@ -39,6 +38,13 @@
<view>个人信息</view> <view>个人信息</view>
</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>
<view class="outLogin"> <view class="outLogin">
<u-button type="primary" @click="handleLogout">退</u-button> <u-button type="primary" @click="handleLogout">退</u-button>
@ -51,18 +57,25 @@
<script> <script>
import storage from '@/utils/storage' import storage from '@/utils/storage'
import {
getVersions
} from '@/utils/handlerColor.js'
export default { export default {
data() { data() {
return { return {
version: '',
showVersion: false,
localityVersion: '',
boxTop: 0, boxTop: 0,
name: this.$store.state.user.name, name: this.$store.state.user.name,
version: getApp().globalData.config.appInfo.version // version: getApp().globalData.config.appInfo.version
} }
}, },
onLoad() { onLoad() {
const systemData = this.$u.sys() const systemData = this.$u.sys()
this.localityVersion = systemData.appVersion
this.boxTop = systemData.statusBarHeight this.boxTop = systemData.statusBarHeight
this.getVersion()
}, },
computed: { computed: {
avatar() { avatar() {
@ -73,6 +86,35 @@
} }
}, },
methods: { 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() { handleLogout() {
this.$modal.confirm('确定注销并退出系统吗?').then(() => { this.$modal.confirm('确定注销并退出系统吗?').then(() => {
this.$store.dispatch('LogOut').then(() => { this.$store.dispatch('LogOut').then(() => {
@ -193,4 +235,20 @@
margin-top: 30rpx; 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> </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", NO: "#7f8c95",
NF: "#008c5e", NF: "#008c5e",
} }
//颜色处理
export function handleColor(data) { export function handleColor(data) {
if (checkType(data) == "array") { if (checkType(data) == "array") {
@ -63,7 +63,7 @@ function checkType(value) {
return "neither"; return "neither";
} }
} }
//根据身份证号算年纪/岁数等
export function validateAndParseIDCard(idCard, type) { export function validateAndParseIDCard(idCard, type) {
// 验证身份证号格式 // 验证身份证号格式
const idCardPattern = const idCardPattern =
@ -110,4 +110,27 @@ export function validateAndParseIDCard(idCard, type) {
default: default:
return "无效的type参数"; 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