合并后修改文件

This commit is contained in:
not-like-juvenile
2026-02-03 20:12:36 +08:00
parent a40dc816d8
commit 768140fda3
6 changed files with 25 additions and 221 deletions

View File

@@ -142,7 +142,8 @@
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 { getCurrentUser, logout, setIsLoggedIn, setUserProfile } from '@/utils/store.uts'
import { UserProfile } from '@/pages/user/types.uts'
const cssVars = {
'--bg': '#f5f6f8',
@@ -172,17 +173,20 @@ const codeCountdown = ref<number>(0)
onMounted(() => {
try {
if (IS_TEST_MODE) return
const sessionInfo = supa.getSession()
if (sessionInfo != null && sessionInfo.user != null) {
// 生产模式或主动进入登录页时,若已登录则尝试跳转回原页面或首页
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
// 注意IS_TEST_MODE 仅在 boot 页禁止自动跳转,在登录页若已有 Session建议还是允许其进入首页
if (redirect != null && redirect.length > 0) {
uni.redirectTo({ url: decodeURIComponent(redirect) })
} else {
uni.switchTab({ url: '/pages/mall/consumer/index' })
} else if (!IS_TEST_MODE) {
// 非测试模式下,自动跳转首页
uni.switchTab({ url: '/pages/mall/consumer/index' })
}
}
} catch (e) {
@@ -347,19 +351,18 @@ const handleLogin = async () => {
}
uni.showToast({ title: '登录成功', icon: 'success' })
if (!IS_TEST_MODE) {
setTimeout(() => {
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 {
// 登录成功后的跳转不应受 IS_TEST_MODE 限制,否则用户点击登录后无反馈
setTimeout(() => {
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' })
}
}, 500)
}
}
}, 500)
} catch (err) {
console.error('登录错误:', err)
let msg = '登录失败,请重试'