Merge remote-tracking branch 'origin/ysj-delivery'
This commit is contained in:
@@ -141,8 +141,10 @@
|
||||
<script setup lang="uts">
|
||||
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 { AkReq } from '@/uni_modules/ak-req/index.uts'
|
||||
import { IS_TEST_MODE, PUSH_SERVER_URL } from '@/ak/config.uts'
|
||||
import { getCurrentUser, logout, setIsLoggedIn, setUserProfile } from '@/utils/store.uts'
|
||||
import { UserProfile } from '@/pages/user/types.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
|
||||
const cssVars = {
|
||||
@@ -173,17 +175,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) {
|
||||
@@ -277,6 +282,7 @@ const handleLogin = async () => {
|
||||
class_id: ''
|
||||
} as UserProfile
|
||||
setUserProfile(adminProfile)
|
||||
uni.setStorageSync('user_id', 'admin')
|
||||
|
||||
uni.showToast({ title: '管理员登录成功(测试模式)', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
@@ -358,23 +364,53 @@ const handleLogin = async () => {
|
||||
if (uid != null) {
|
||||
uni.setStorageSync('user_id', uid)
|
||||
console.log('用户ID已保存到本地存储:', uid)
|
||||
// 获取并上报推送 CID(若可用)
|
||||
try {
|
||||
uni.getPushClientId({
|
||||
success: async (res: any) => {
|
||||
const cid = (res && (res.clientid || res.cid)) ? (res.clientid || res.cid) : (typeof res === 'string' ? res : null)
|
||||
if (cid != null && cid !== '') {
|
||||
try {
|
||||
uni.setStorageSync('uni_push2_cid', cid)
|
||||
} catch (e) {}
|
||||
try {
|
||||
const uidStored = uni.getStorageSync('user_id') || null
|
||||
const currentUid = uidStored || (currentSession.user ? currentSession.user.getString('id') : null)
|
||||
await AkReq.request({
|
||||
url: `${PUSH_SERVER_URL}/api/v1/push/register`,
|
||||
method: 'POST',
|
||||
data: { cid, platform: 'android', user_id: currentUid },
|
||||
contentType: 'application/json'
|
||||
})
|
||||
console.log('CID 已上报后台:', cid, 'user_id:', currentUid)
|
||||
} catch (e) {
|
||||
console.warn('上报 CID 失败:', e)
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (err: any) => {
|
||||
console.warn('获取 Push CID 失败:', err)
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn('getPushClientId 调用异常:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 = '登录失败,请重试'
|
||||
|
||||
@@ -94,6 +94,8 @@
|
||||
import { ref } from 'vue'
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { ensureUserProfile } from '@/utils/sapi.uts'
|
||||
import { AkReq } from '@/uni_modules/ak-req/index.uts'
|
||||
import { PUSH_SERVER_URL } from '@/ak/config.uts'
|
||||
|
||||
// 响应式数据
|
||||
const email = ref<string>('')
|
||||
@@ -293,6 +295,33 @@
|
||||
console.log('ℹ️ 需要邮箱验证,验证后登录时会自动创建用户资料')
|
||||
}
|
||||
|
||||
// 获取并上报推送 CID(若可用)
|
||||
try {
|
||||
uni.getPushClientId({
|
||||
success: async (res: any) => {
|
||||
const cid = (res && (res.clientid || res.cid)) ? (res.clientid || res.cid) : (typeof res === 'string' ? res : null)
|
||||
if (cid != null && cid !== '') {
|
||||
try { uni.setStorageSync('uni_push2_cid', cid) } catch (e) {}
|
||||
try {
|
||||
const uidStored = uni.getStorageSync('user_id') || null
|
||||
const currentSession = supa.getSession()
|
||||
const currentUid = uidStored || (currentSession && currentSession.user ? currentSession.user.getString('id') : null)
|
||||
await AkReq.request({
|
||||
url: `${PUSH_SERVER_URL}/api/v1/push/register`,
|
||||
method: 'POST',
|
||||
data: { cid, platform: 'android', user_id: currentUid },
|
||||
contentType: 'application/json'
|
||||
})
|
||||
console.log('CID 已上报后台:', cid)
|
||||
} catch (e) { console.warn('上报 CID 失败:', e) }
|
||||
}
|
||||
},
|
||||
fail: (err: any) => { console.warn('获取 Push CID 失败:', err) }
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn('getPushClientId 调用异常:', e)
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '注册成功',
|
||||
icon: 'success'
|
||||
|
||||
Reference in New Issue
Block a user