consumer模块完成度95%,准备部署消费者端测试
This commit is contained in:
53
App.uvue
53
App.uvue
@@ -2,16 +2,12 @@
|
||||
import { setIsLoggedIn, setUserProfile, getCurrentUser } from '@/utils/store.uts'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
|
||||
// 自动登录凭据(开发测试用)
|
||||
const AUTO_LOGIN_EMAIL = 'test@mall.com'
|
||||
const AUTO_LOGIN_PASSWORD = 'Hf2152111'
|
||||
|
||||
export default {
|
||||
onLaunch: function () {
|
||||
console.log('App Launch')
|
||||
|
||||
// 尝试自动登录并跳转(使用 Promise 链)
|
||||
this.tryAutoLogin()
|
||||
// 检查是否已有有效会话,有则恢复登录状态
|
||||
this.checkExistingSession()
|
||||
},
|
||||
onShow: function () {
|
||||
console.log('App Show')
|
||||
@@ -20,11 +16,11 @@
|
||||
console.log('App Hide')
|
||||
},
|
||||
methods: {
|
||||
tryAutoLogin: function(): void {
|
||||
checkExistingSession: function(): void {
|
||||
// 检查是否已有有效会话
|
||||
const session = supa.getSession()
|
||||
if (session.user != null) {
|
||||
console.log('已有有效会话,跳过自动登录')
|
||||
console.log('已有有效会话,恢复登录状态')
|
||||
setIsLoggedIn(true)
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
return
|
||||
@@ -39,49 +35,14 @@
|
||||
console.log('会话恢复成功')
|
||||
setIsLoggedIn(true)
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
return
|
||||
}
|
||||
// 恢复失败,执行自动登录
|
||||
this.doAutoLogin()
|
||||
}).catch(() => {
|
||||
console.log('会话恢复失败,尝试自动登录')
|
||||
this.doAutoLogin()
|
||||
console.log('会话恢复失败,需要重新登录')
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 执行自动登录
|
||||
this.doAutoLogin()
|
||||
},
|
||||
doAutoLogin: function(): void {
|
||||
console.log('开始自动登录...')
|
||||
supa.signIn(AUTO_LOGIN_EMAIL, AUTO_LOGIN_PASSWORD).then((result) => {
|
||||
if (result.user != null) {
|
||||
console.log('自动登录成功')
|
||||
setIsLoggedIn(true)
|
||||
|
||||
// 保存用户ID到本地存储
|
||||
const uid = result.user.getString('id')
|
||||
if (uid != null) {
|
||||
uni.setStorageSync('user_id', uid)
|
||||
console.log('用户ID已保存:', uid)
|
||||
}
|
||||
|
||||
// 获取用户资料
|
||||
getCurrentUser().then(() => {
|
||||
console.log('获取用户资料成功')
|
||||
}).catch((e) => {
|
||||
console.log('获取用户资料失败(忽略)')
|
||||
})
|
||||
|
||||
// 直接跳转到首页
|
||||
uni.reLaunch({ url: '/pages/mall/consumer/index' })
|
||||
} else {
|
||||
console.log('自动登录失败,用户需要手动登录')
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('自动登录异常:', e)
|
||||
})
|
||||
// 没有有效会话,显示登录页
|
||||
console.log('无有效会话,显示登录页')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user