Initial commit: 网络验证平台
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
import pinia from '@/plugins/pinia/setup'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
export function authGuard(router: Router) {
|
||||
router.beforeEach((to, _from) => {
|
||||
const authStore = useAuthStore(pinia)
|
||||
authStore.checkAuth()
|
||||
const { isLogin } = storeToRefs(authStore)
|
||||
|
||||
if (to.meta.auth && !unref(isLogin) && to.name !== '/auth/sign-in') {
|
||||
return {
|
||||
name: '/auth/sign-in',
|
||||
query: { redirect: to.fullPath },
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { Router } from 'vue-router'
|
||||
|
||||
export function createRouterGuard(router: Router) {
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('token')
|
||||
const userStr = localStorage.getItem('user')
|
||||
|
||||
let user = null
|
||||
if (userStr) {
|
||||
try {
|
||||
user = JSON.parse(userStr)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Failed to parse user data:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const requiresAuth = to.path.startsWith('/admin') || to.path.startsWith('/developer')
|
||||
const isAuthPage = to.path === '/login' || to.path === '/register'
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
if (to.path !== '/login') {
|
||||
next('/login')
|
||||
}
|
||||
else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
else if (isAuthPage && token && user) {
|
||||
if (user.role === 'admin') {
|
||||
next('/admin')
|
||||
}
|
||||
else if (user.role === 'developer') {
|
||||
next('/developer')
|
||||
}
|
||||
else {
|
||||
next('/')
|
||||
}
|
||||
}
|
||||
else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
import { createRouterGuard } from './guard'
|
||||
import routes from './routes'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: routes as RouteRecordRaw[],
|
||||
scrollBehavior() {
|
||||
return { left: 0, top: 0, behavior: 'smooth' }
|
||||
},
|
||||
})
|
||||
|
||||
createRouterGuard(router)
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,406 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login',
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/pages/auth/login.vue'),
|
||||
meta: {
|
||||
title: '登录 - 开发者平台',
|
||||
layout: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
name: 'Register',
|
||||
component: () => import('@/pages/auth/register.vue'),
|
||||
meta: {
|
||||
title: '注册 - 开发者平台',
|
||||
layout: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/developer',
|
||||
component: () => import('@/layouts/developer.vue'),
|
||||
meta: { auth: true, role: 'developer' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'DeveloperDashboard',
|
||||
component: () => import('@/pages/developer/index.vue'),
|
||||
meta: { title: '控制台 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'applications',
|
||||
name: 'DeveloperApplications',
|
||||
component: () => import('@/pages/developer/applications.vue'),
|
||||
meta: { title: '应用管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'applications/create',
|
||||
name: 'DeveloperApplicationCreate',
|
||||
component: () => import('@/pages/developer/applications/create.vue'),
|
||||
meta: { title: '创建应用 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'applications/:id',
|
||||
redirect: to => `/developer/applications/${to.params.id}/settings`,
|
||||
},
|
||||
{
|
||||
path: 'applications/:id/settings',
|
||||
name: 'DeveloperApplicationSettings',
|
||||
component: () => import('@/pages/developer/applications/[id]/settings.vue'),
|
||||
meta: { title: '基本设置 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'applications/:id/security',
|
||||
name: 'DeveloperApplicationSecurity',
|
||||
component: () => import('@/pages/developer/applications/[id]/security.vue'),
|
||||
meta: { title: '安全设置 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'applications/:id/email',
|
||||
name: 'DeveloperApplicationEmail',
|
||||
component: () => import('@/pages/developer/applications/[id]/email.vue'),
|
||||
meta: { title: '邮箱设置 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cards',
|
||||
name: 'DeveloperCards',
|
||||
component: () => import('@/pages/developer/cards/index.vue'),
|
||||
meta: { title: '卡密管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cards/create',
|
||||
name: 'DeveloperCardCreate',
|
||||
component: () => import('@/pages/developer/cards/create.vue'),
|
||||
meta: { title: '生成卡密 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'announcements',
|
||||
name: 'DeveloperAnnouncements',
|
||||
component: () => import('@/pages/developer/announcements/index.vue'),
|
||||
meta: { title: '公告管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'announcements/create',
|
||||
name: 'DeveloperAnnouncementCreate',
|
||||
component: () => import('@/pages/developer/announcements/create.vue'),
|
||||
meta: { title: '创建公告 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'announcements/:id',
|
||||
name: 'DeveloperAnnouncementEdit',
|
||||
component: () => import('@/pages/developer/announcements/[id].vue'),
|
||||
meta: { title: '编辑公告 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'versions',
|
||||
name: 'DeveloperVersions',
|
||||
component: () => import('@/pages/developer/versions/index.vue'),
|
||||
meta: { title: '版本管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'versions/create',
|
||||
name: 'DeveloperVersionCreate',
|
||||
component: () => import('@/pages/developer/versions/create.vue'),
|
||||
meta: { title: '创建版本 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'versions/:id',
|
||||
name: 'DeveloperVersionEdit',
|
||||
component: () => import('@/pages/developer/versions/[id].vue'),
|
||||
meta: { title: '编辑版本 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'card-types',
|
||||
name: 'DeveloperCardTypes',
|
||||
component: () => import('@/pages/developer/card-types/index.vue'),
|
||||
meta: { title: '卡类管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'card-types/create',
|
||||
name: 'DeveloperCardTypeCreate',
|
||||
component: () => import('@/pages/developer/card-types/create.vue'),
|
||||
meta: { title: '创建卡类 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'card-types/:id',
|
||||
name: 'DeveloperCardTypeEdit',
|
||||
component: () => import('@/pages/developer/card-types/[id].vue'),
|
||||
meta: { title: '编辑卡类 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'DeveloperUsers',
|
||||
component: () => import('@/pages/developer/users/index.vue'),
|
||||
meta: { title: '用户管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'users/create',
|
||||
name: 'DeveloperUserCreate',
|
||||
component: () => import('@/pages/developer/users/create.vue'),
|
||||
meta: { title: '添加用户 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'users/:id',
|
||||
name: 'DeveloperUserEdit',
|
||||
component: () => import('@/pages/developer/users/[id].vue'),
|
||||
meta: { title: '编辑用户 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'devices',
|
||||
name: 'DeveloperDevices',
|
||||
component: () => import('@/pages/developer/devices/index.vue'),
|
||||
meta: { title: '设备管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'sessions',
|
||||
name: 'DeveloperSessions',
|
||||
component: () => import('@/pages/developer/sessions/index.vue'),
|
||||
meta: { title: '在线实例 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps',
|
||||
name: 'DeveloperAgentApps',
|
||||
component: () => import('@/pages/developer/agent-apps/index.vue'),
|
||||
meta: { title: '代理授权 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agents',
|
||||
name: 'DeveloperAgents',
|
||||
component: () => import('@/pages/developer/agents/index.vue'),
|
||||
meta: { title: '代理管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agents/create',
|
||||
name: 'DeveloperAgentsCreate',
|
||||
component: () => import('@/pages/developer/agents/create.vue'),
|
||||
meta: { title: '添加代理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agents/:id/edit',
|
||||
name: 'DeveloperAgentsEdit',
|
||||
component: () => import('@/pages/developer/agents/[id].vue'),
|
||||
meta: { title: '编辑代理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps/request',
|
||||
name: 'DeveloperAgentAppRequest',
|
||||
component: () => import('@/pages/developer/agent-apps/request.vue'),
|
||||
meta: { title: '申请授权 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps/invite',
|
||||
name: 'DeveloperAgentAppInvite',
|
||||
component: () => import('@/pages/developer/agent-apps/invite.vue'),
|
||||
meta: { title: '邀请授权 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps/:id/edit',
|
||||
name: 'DeveloperAgentAppEdit',
|
||||
component: () => import('@/pages/developer/agent-apps/[id]/edit.vue'),
|
||||
meta: { title: '编辑授权 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps/:id/card-types',
|
||||
name: 'DeveloperAgentAppCardTypes',
|
||||
component: () => import('@/pages/developer/agent-apps/[id]/card-types.vue'),
|
||||
meta: { title: '卡密权限配置 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'agent-apps/:id/recharge',
|
||||
name: 'DeveloperAgentAppRecharge',
|
||||
component: () => import('@/pages/developer/agent-apps/[id]/recharge.vue'),
|
||||
meta: { title: '充值余额 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'finance',
|
||||
name: 'DeveloperFinance',
|
||||
component: () => import('@/pages/developer/finance/index.vue'),
|
||||
meta: { title: '财务管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'logs',
|
||||
name: 'DeveloperLogs',
|
||||
component: () => import('@/pages/developer/logs/index.vue'),
|
||||
meta: { title: '日志记录 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'tickets',
|
||||
name: 'DeveloperTickets',
|
||||
component: () => import('@/pages/developer/tickets.vue'),
|
||||
meta: { title: '工单系统 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'tickets/create',
|
||||
name: 'DeveloperTicketCreate',
|
||||
component: () => import('@/pages/developer/tickets/create.vue'),
|
||||
meta: { title: '创建工单 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'tickets/:id',
|
||||
name: 'DeveloperTicketDetail',
|
||||
component: () => import('@/pages/developer/tickets/[id].vue'),
|
||||
meta: { title: '工单详情 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-constants',
|
||||
name: 'DeveloperCloudConstants',
|
||||
component: () => import('@/pages/developer/cloud-constants/index.vue'),
|
||||
meta: { title: '云端常量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-constants/create',
|
||||
name: 'DeveloperCloudConstantCreate',
|
||||
component: () => import('@/pages/developer/cloud-constants/create.vue'),
|
||||
meta: { title: '添加云端常量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-constants/:id',
|
||||
name: 'DeveloperCloudConstantEdit',
|
||||
component: () => import('@/pages/developer/cloud-constants/[id].vue'),
|
||||
meta: { title: '编辑云端常量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-variables',
|
||||
name: 'DeveloperCloudVariables',
|
||||
component: () => import('@/pages/developer/cloud-variables/index.vue'),
|
||||
meta: { title: '云端变量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-variables/create',
|
||||
name: 'DeveloperCloudVariableCreate',
|
||||
component: () => import('@/pages/developer/cloud-variables/create.vue'),
|
||||
meta: { title: '添加云端变量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-variables/:id',
|
||||
name: 'DeveloperCloudVariableEdit',
|
||||
component: () => import('@/pages/developer/cloud-variables/[id].vue'),
|
||||
meta: { title: '编辑云端变量 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-function',
|
||||
name: 'DeveloperCloudFunction',
|
||||
component: () => import('@/pages/developer/dynamic-code/index.vue'),
|
||||
meta: { title: '云端函数 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-function/create',
|
||||
name: 'DeveloperCloudFunctionCreate',
|
||||
component: () => import('@/pages/developer/dynamic-code/create.vue'),
|
||||
meta: { title: '创建云端函数 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'cloud-function/:id',
|
||||
name: 'DeveloperCloudFunctionEdit',
|
||||
component: () => import('@/pages/developer/dynamic-code/[id].vue'),
|
||||
meta: { title: '编辑云端函数 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'risk-control',
|
||||
name: 'DeveloperRiskControl',
|
||||
component: () => import('@/pages/developer/risk-control/index.vue'),
|
||||
meta: { title: '风控管理 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'risk-control/create',
|
||||
name: 'DeveloperRiskControlCreate',
|
||||
component: () => import('@/pages/developer/risk-control/create.vue'),
|
||||
meta: { title: '添加风控规则 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'risk-control/:id',
|
||||
name: 'DeveloperRiskControlEdit',
|
||||
component: () => import('@/pages/developer/risk-control/[id].vue'),
|
||||
meta: { title: '编辑风控规则 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'extension',
|
||||
name: 'DeveloperExtension',
|
||||
component: () => import('@/pages/developer/extension/index.vue'),
|
||||
meta: { title: '扩展配置 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'extension/webhooks/create',
|
||||
name: 'DeveloperExtensionWebhookCreate',
|
||||
component: () => import('@/pages/developer/extension/webhooks/create.vue'),
|
||||
meta: { title: '创建Webhook - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'extension/api-keys/create',
|
||||
name: 'DeveloperExtensionAPIKeyCreate',
|
||||
component: () => import('@/pages/developer/extension/api-keys/create.vue'),
|
||||
meta: { title: '创建API密钥 - 开发者后台' },
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
name: 'DeveloperProfile',
|
||||
component: () => import('@/pages/profile/index.vue'),
|
||||
meta: { title: '个人中心 - 开发者后台' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/agent',
|
||||
component: () => import('@/layouts/agent.vue'),
|
||||
meta: { auth: true, role: 'agent' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'AgentDashboard',
|
||||
component: () => import('@/pages/agent/index.vue'),
|
||||
meta: { title: '控制台 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'apps',
|
||||
name: 'AgentApps',
|
||||
component: () => import('@/pages/agent/apps/index.vue'),
|
||||
meta: { title: '应用管理 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'apps/:id',
|
||||
name: 'AgentAppDetail',
|
||||
component: () => import('@/pages/agent/apps/[id].vue'),
|
||||
meta: { title: '应用详情 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'cards',
|
||||
name: 'AgentCards',
|
||||
component: () => import('@/pages/agent/cards/index.vue'),
|
||||
meta: { title: '卡密管理 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'cards/create',
|
||||
name: 'AgentCardCreate',
|
||||
component: () => import('@/pages/agent/cards/create.vue'),
|
||||
meta: { title: '生成卡密 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'AgentUsers',
|
||||
component: () => import('@/pages/agent/users/index.vue'),
|
||||
meta: { title: '用户管理 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'finance',
|
||||
name: 'AgentFinance',
|
||||
component: () => import('@/pages/agent/finance/index.vue'),
|
||||
meta: { title: '财务管理 - 代理商后台' },
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
name: 'AgentProfile',
|
||||
component: () => import('@/pages/profile/index.vue'),
|
||||
meta: { title: '个人中心 - 代理商后台' },
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export default routes
|
||||
Reference in New Issue
Block a user