167 lines
4.2 KiB
Vue
167 lines
4.2 KiB
Vue
<script>
|
|
export default {
|
|
data() {
|
|
return {}
|
|
},
|
|
onLaunch: function() {
|
|
this.checkForUpdates()
|
|
uni.switchTab({
|
|
url: "/pages/index/index"
|
|
})
|
|
console.log('App Launch')
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
methods: {
|
|
// 版本信息监测
|
|
checkForUpdates() {
|
|
let that = this
|
|
let platform = ""
|
|
// 返回的是apk包信息
|
|
uni.getSystemInfo({
|
|
success(e) {
|
|
platform = e.platform
|
|
that.$store.commit('changePhoneInfo', {
|
|
platform: e.platform
|
|
})
|
|
}
|
|
})
|
|
plus.runtime.getProperty(plus.runtime.appid, function(info) {
|
|
uni.setStorageSync('VERSION', info.version)
|
|
let res_version = info.version;
|
|
that.$store.commit('changePhoneInfo', {
|
|
info: info
|
|
})
|
|
that.$model.getloginversion({}).then(res => {
|
|
let downloadUrl = res.data.url
|
|
let latestVersion = res.data.version
|
|
console.log("当前应用版本号", info)
|
|
console.log("服务器版本号", res)
|
|
that.$store.commit('changePhoneInfo', {
|
|
versionUrl: res.data
|
|
})
|
|
// 比对版本号
|
|
if (latestVersion !== res_version) {
|
|
uni.showModal({
|
|
title: '发现新版本',
|
|
content: '检查到新版本' + res.data.version + ',是否更新?',
|
|
success: (modalRes) => {
|
|
if (modalRes.confirm) {
|
|
if (platform === 'android') {
|
|
uni.setStorageSync('VERSION', res.data.version)
|
|
let showLoading = plus.nativeUI.showWaiting('正在下载')
|
|
const dtask = uni.downloadFile({
|
|
url: downloadUrl,
|
|
success: (downloadRes) => {
|
|
if (downloadRes.statusCode ===200) {
|
|
plus.nativeUI.closeWaiting()
|
|
plus.runtime.install(
|
|
downloadRes
|
|
.tempFilePath, {
|
|
force: false
|
|
},
|
|
function() {
|
|
console.log('install success...');
|
|
plus.runtime.restart();
|
|
},
|
|
function(e) {
|
|
console.error('install fail...');
|
|
});
|
|
}
|
|
},
|
|
fail: () => {
|
|
uni.showToast({
|
|
title: '升级失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
dtask.onProgressUpdate((res) => {
|
|
showLoading.setTitle(" 正在下载" + res.progress + "% ");
|
|
console.log('下载进度' + res.progress +'%');
|
|
});
|
|
} else {
|
|
uni.showModal({
|
|
title: '发现新版本 ' + res.data.version,
|
|
content: '请到App store进行升级',
|
|
showCancel: false
|
|
})
|
|
}
|
|
} else {
|
|
console.log("用户放弃更新")
|
|
if (res.code == 0) {
|
|
that.handleUserList()
|
|
} else {
|
|
setTimeout(() => {
|
|
uni.reLaunch({
|
|
url: '/pages/login/login'
|
|
})
|
|
}, 800);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
console.log("版本号相同")
|
|
if (res.code == 0) {
|
|
that.handleUserList()
|
|
} else {
|
|
setTimeout(() => {
|
|
uni.reLaunch({
|
|
url: '/pages/login/login'
|
|
})
|
|
}, 500);
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
|
|
// 下载新版本
|
|
downloadNewVersion(downloadUrl, code) {
|
|
|
|
},
|
|
|
|
|
|
// 成员列表
|
|
handleUserList() {
|
|
let that = this
|
|
that.$model.getUserList({
|
|
type: 2
|
|
}).then(res => {
|
|
console.log("用户列表", res)
|
|
if (res.code != 0) {
|
|
that.$tools.msg(res.msg)
|
|
return
|
|
}
|
|
that.$store.commit('changeFamilay', res.data)
|
|
if (res.data.length) {
|
|
that.$store.dispatch('getUserInfo', {
|
|
aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
|
|
0].id
|
|
})
|
|
that.$store.dispatch("getCardList", {
|
|
aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
|
|
0].id
|
|
})
|
|
}
|
|
}).catch(err => {})
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
/*每个页面公共css */
|
|
/* #ifndef APP-NVUE */
|
|
@import "/uni.scss";
|
|
@import "/assets/common.scss";
|
|
@import "/assets/iconfont.css";
|
|
@import "/assets/iconfont-weapp-icon.css";
|
|
|
|
/* #endif*/
|
|
</style> |