合并代码
This commit is contained in:
@@ -198,7 +198,19 @@ const routes = [
|
||||
name: 'AgentDashboard',
|
||||
component: () => import('@/views/AgentDashboard.vue'),
|
||||
meta: {
|
||||
title: '代理后台'
|
||||
title: '代理后台',
|
||||
requiresAuth: true,
|
||||
isAgent: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/agent/withdrawals',
|
||||
name: 'AgentWithdrawals',
|
||||
component: () => import('@/views/AgentWithdrawals.vue'),
|
||||
meta: {
|
||||
title: '佣金提现',
|
||||
requiresAuth: true,
|
||||
isAgent: true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -252,17 +264,33 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
// 检查是否需要认证
|
||||
if (to.meta.requiresAuth) {
|
||||
if (!userStore.isAuthenticated) {
|
||||
// 尝试从本地存储恢复登录状态
|
||||
await userStore.checkAuth()
|
||||
// 检查是否是代理页面
|
||||
if (to.meta.isAgent) {
|
||||
// 代理页面认证逻辑
|
||||
const agentInfo = localStorage.getItem('agentInfo')
|
||||
const agentToken = localStorage.getItem('token')
|
||||
|
||||
if (!userStore.isAuthenticated) {
|
||||
if (!agentInfo || !agentToken) {
|
||||
next({
|
||||
name: 'MyLogin',
|
||||
path: '/agent/login',
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 普通用户页面认证逻辑
|
||||
if (!userStore.isAuthenticated) {
|
||||
// 尝试从本地存储恢复登录状态
|
||||
await userStore.checkAuth()
|
||||
|
||||
if (!userStore.isAuthenticated) {
|
||||
next({
|
||||
name: 'MyLogin',
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,11 +64,20 @@ api.interceptors.response.use(
|
||||
|
||||
switch (status) {
|
||||
case 401:
|
||||
// 未授权,清除token并跳转到登录页
|
||||
// 未授权,清除token并根据当前路由跳转到相应的登录页
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('agentInfo') // 清除代理信息
|
||||
delete api.defaults.headers.common['Authorization']
|
||||
router.push({ name: 'Login' })
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
|
||||
// 判断当前是否在代理相关页面
|
||||
const currentPath = router.currentRoute.value.path
|
||||
if (currentPath.startsWith('/agent')) {
|
||||
router.push('/agent/login')
|
||||
ElMessage.error('代理登录已过期,请重新登录')
|
||||
} else {
|
||||
router.push({ name: 'Login' })
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
}
|
||||
break
|
||||
|
||||
case 403:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -243,8 +243,9 @@ const handleLogin = async () => {
|
||||
const { data } = await api.post('/agents/login', loginForm)
|
||||
|
||||
if (data.success) {
|
||||
// 保存代理信息到localStorage
|
||||
// 保存代理信息和token到localStorage
|
||||
localStorage.setItem('agentInfo', JSON.stringify(data.data))
|
||||
localStorage.setItem('token', data.data.token)
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/agent/dashboard')
|
||||
}
|
||||
|
||||
1204
src/views/AgentWithdrawals.vue
Normal file
1204
src/views/AgentWithdrawals.vue
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user