sql数据流,amdin业务逻辑接入
This commit is contained in:
@@ -143,6 +143,7 @@ import { ref, onMounted } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { IS_TEST_MODE } from '@/ak/config.uts'
|
||||
import { getCurrentUser, logout } from '@/utils/store.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
|
||||
const cssVars = {
|
||||
'--bg': '#f5f6f8',
|
||||
@@ -256,8 +257,8 @@ const getCode = async () => {
|
||||
const handleLogin = async () => {
|
||||
if (!validateAccount()) return
|
||||
|
||||
// 特殊账号处理:admin/admin 直接跳转
|
||||
if (account.value === 'admin' && password.value === 'admin') {
|
||||
// 特殊账号处理:仅在测试模式允许本地绕过登录(不推荐生产使用)
|
||||
if (IS_TEST_MODE && account.value === 'admin' && password.value === 'admin') {
|
||||
setIsLoggedIn(true)
|
||||
const adminProfile = {
|
||||
id: 'admin',
|
||||
@@ -277,7 +278,7 @@ const handleLogin = async () => {
|
||||
} as UserProfile
|
||||
setUserProfile(adminProfile)
|
||||
|
||||
uni.showToast({ title: '管理员登录成功', icon: 'success' })
|
||||
uni.showToast({ title: '管理员登录成功(测试模式)', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
}, 500)
|
||||
@@ -328,12 +329,26 @@ const handleLogin = async () => {
|
||||
return
|
||||
}
|
||||
|
||||
// 尝试获取/补全用户资料,但失败时不再阻塞登录
|
||||
// 登录成功后强制同步用户资料到 ak_users(确保 auth_id 与 role 落表)
|
||||
try {
|
||||
const profile = await getCurrentUser()
|
||||
console.log('current user profile:', profile)
|
||||
const sessionInfo = supa.getSession()
|
||||
if (sessionInfo?.user != null) {
|
||||
const syncResult = await ensureUserProfile(sessionInfo.user)
|
||||
console.log('ensureUserProfile sync result:', syncResult)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('获取用户信息失败(忽略,不阻塞登录):', e)
|
||||
console.error('同步用户资料到 ak_users 失败(不阻塞登录):', e)
|
||||
}
|
||||
|
||||
// 登录成功后按 redirect 参数跳转(守卫放在需要权限的页面入口)
|
||||
const pages = getCurrentPages() as any[]
|
||||
const currentPage = pages.length > 0 ? pages[pages.length - 1] : null
|
||||
const opts = currentPage?.options as any
|
||||
const redirect = opts?.redirect as string | null
|
||||
if (redirect != null && redirect.length > 0) {
|
||||
uni.redirectTo({ url: decodeURIComponent(redirect) })
|
||||
} else {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
}
|
||||
|
||||
// 显式保存用户ID到本地存储,确保页面刷新或重启后 SupabaseService 能恢复身份
|
||||
|
||||
Reference in New Issue
Block a user