init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<script>
|
||||
import { wxLogin } from '@/config/user'
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
console.log('App Launch')
|
||||
// 登录
|
||||
this.autoLogin()
|
||||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
},
|
||||
methods: {
|
||||
autoLogin() {
|
||||
// 获取登录状态
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
try {
|
||||
// 获取到小程序 code
|
||||
const code = loginRes.code
|
||||
console.log(code);
|
||||
|
||||
// 发送 code 到后台换取 openId, sessionKey, unionId
|
||||
// const res = await wxLogin(code)
|
||||
// if (res.code === 200) {
|
||||
// // 保存token
|
||||
// uni.setStorageSync('token', res.data.token)
|
||||
// // 可以保存其他用户信息
|
||||
// uni.setStorageSync('userInfo', res.data.userInfo)
|
||||
// } else {
|
||||
// uni.showToast({
|
||||
// title: '登录失败',
|
||||
// icon: 'none'
|
||||
// })
|
||||
// }
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error)
|
||||
uni.showToast({
|
||||
title: '登录失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('微信登录失败:', err)
|
||||
uni.showToast({
|
||||
title: '微信登录失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/*每个页面公共css */
|
||||
</style>
|
||||
Reference in New Issue
Block a user