116 lines
2.7 KiB
Vue
116 lines
2.7 KiB
Vue
<script>
|
|
export default {
|
|
onLaunch: function() {
|
|
// #ifndef MP-WEIXIN
|
|
uni.hideTabBar()
|
|
// #endif
|
|
this.updateManager();
|
|
|
|
},
|
|
onShow: function(options) {
|
|
if(options?.referrerInfo?.extraData){
|
|
this.getDyqc(options.referrerInfo.extraData);
|
|
}
|
|
console.log('App Show')
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
|
|
methods: {
|
|
//自动更新
|
|
updateManager() {
|
|
if (uni.canIUse('getUpdateManager')) {
|
|
const updateManager = uni.getUpdateManager()
|
|
updateManager.onCheckForUpdate(res => {
|
|
if (res.hasUpdate) {
|
|
updateManager.onUpdateReady(function() {
|
|
uni.showModal({
|
|
title: '更新提示',
|
|
content: '新版本已经准备好,需要重启应用',
|
|
showCancel: false,
|
|
success: ({
|
|
confirm,
|
|
cancel
|
|
}) => {
|
|
updateManager.applyUpdate()
|
|
}
|
|
})
|
|
})
|
|
updateManager.onUpdateFailed(function() {
|
|
// 新的版本下载失败
|
|
uni.showModal({
|
|
title: '已经有新版本了哟~',
|
|
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
|
|
})
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
})
|
|
}
|
|
},
|
|
//获取多样青春的跳转参数
|
|
getDyqc(extraData){
|
|
uni.$u.http.post('/api/user/activityMiniLogin', extraData).then(res => {
|
|
if (res.code == 1) {
|
|
uni.setStorageSync('token', res.data.userinfo.token)
|
|
this.getUserInfo();
|
|
} else {
|
|
uni.showToast({
|
|
title: res.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
uni.clearStorageSync();
|
|
|
|
}
|
|
}).catch(error => {
|
|
console.log('error', error);
|
|
});
|
|
},
|
|
// 获取个人信息
|
|
getUserInfo() {
|
|
uni.$u.http.get('/api/user/index', {}).then(res => {
|
|
if (res.code == 1) {
|
|
uni.setStorageSync('userInfo', res.data.user_info);
|
|
uni.showToast({
|
|
title: '登陆成功',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
uni.setStorageSync("niName", res.data.user_info.nickname);
|
|
} else {
|
|
uni.showToast({
|
|
title: '登陆失败',
|
|
icon: 'error',
|
|
duration: 2000
|
|
})
|
|
}
|
|
|
|
}).catch(error => {
|
|
console.log('error', error);
|
|
|
|
uni.showToast({
|
|
title: '登陆失败',
|
|
icon: 'error',
|
|
duration: 2000
|
|
})
|
|
})
|
|
},
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "uview-ui/index.scss";
|
|
|
|
/*每个页面公共css */
|
|
.uni-input-input {
|
|
font-size: 35rpx;
|
|
}
|
|
</style> |