From fbfce10afbe6ff3d8778c2520001c4e3d0586f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E8=80=81=E7=99=BD=E5=85=94?= Date: Thu, 11 Sep 2025 16:48:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(router):=20=E5=90=88=E5=B9=B6=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=A8=A1=E5=9D=97=E5=B9=B6=E5=88=A0=E9=99=A4=E5=86=97?= =?UTF-8?q?=E4=BD=99=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将auth.tsx和index.tsx中的路由配置合并到common.tsx中,并删除不再使用的config.ts文件 --- Touchkebao/src/router/config.ts | 174 ------------------ .../router/module/{auth.tsx => common.tsx} | 13 ++ Touchkebao/src/router/module/index.tsx | 18 -- 3 files changed, 13 insertions(+), 192 deletions(-) delete mode 100644 Touchkebao/src/router/config.ts rename Touchkebao/src/router/module/{auth.tsx => common.tsx} (53%) delete mode 100644 Touchkebao/src/router/module/index.tsx diff --git a/Touchkebao/src/router/config.ts b/Touchkebao/src/router/config.ts deleted file mode 100644 index b6a8f394..00000000 --- a/Touchkebao/src/router/config.ts +++ /dev/null @@ -1,174 +0,0 @@ -// 路由配置类型定义 -export interface RouteConfig { - path: string; - element: React.ReactNode; - auth: boolean; - requiredRole?: string; - title?: string; - icon?: string; - children?: RouteConfig[]; -} - -// 路由分组配置 -export const routeGroups = { - // 基础路由 - basic: { - name: "基础功能", - routes: ["/", "/login", "/guide", "/scene", "/work", "/mine"], - }, - - // 设备管理 - devices: { - name: "设备管理", - routes: ["/mine/devices", "/mine/devices/:id"], - }, - - // 微信号管理 - wechatAccounts: { - name: "微信号管理", - routes: ["/wechat-accounts", "/wechat-accounts/:id"], - }, - - // 工作台 - workspace: { - name: "工作台", - routes: [ - "/workspace", - "/workspace/auto-like", - "/workspace/auto-like/new", - "/workspace/auto-like/:id", - "/workspace/auto-like/:id/edit", - "/workspace/auto-group", - "/workspace/auto-group/:id", - "/workspace/group-push", - "/workspace/group-push/new", - "/workspace/group-push/:id", - "/workspace/group-push/:id/edit", - "/workspace/moments-sync", - "/workspace/moments-sync/new", - "/workspace/moments-sync/:id", - "/workspace/moments-sync/edit/:id", - "/workspace/ai-assistant", - "/workspace/traffic-distribution", - "/workspace/traffic-distribution/new", - "/workspace/traffic-distribution/edit/:id", - "/workspace/traffic-distribution/:id", - ], - }, - - // 场景管理 - scenarios: { - name: "场景管理", - routes: [ - "/scenarios", - "/scenarios/new", - "/scenarios/new/:scenarioId", - "/scenarios/edit/:planId", - "/scenarios/list/:scenarioId/:scenarioName", - ], - }, - - // 内容管理 - content: { - name: "内容管理", - routes: [ - "/mine/content", - "/mine/content/new", - "/mine/content/edit/:id", - "/mine/content/materials/:id", - "/mine/content/materials/new/:id", - "/mine/content/materials/edit/:id/:materialId", - ], - }, - - // 流量池 - trafficPool: { - name: "流量池", - routes: ["/traffic-pool", "/traffic-pool/:id"], - }, - - // 其他功能 - other: { - name: "其他功能", - routes: [ - "/profile", - "/plans", - "/plans/:planId", - "/orders", - "/contract-import", - ], - }, -}; - -// 路由权限配置 -export const routePermissions = { - // 管理员权限 - admin: Object.values(routeGroups).flatMap(group => group.routes), - - // 普通用户权限 - user: [ - "/", - "/login", - "/guide", - "/scene", - "/work", - "/mine", - "/mine/devices", - "/mine/devices/:id", - "/wechat-accounts", - "/wechat-accounts/:id", - "/workspace", - "/scenarios", - "/content", - "/traffic-pool", - "/traffic-pool/:id", - "/profile", - "/plans", - "/plans/:planId", - "/orders", - "/contract-import", - ], - - // 访客权限 - guest: ["/", "/login"], -}; - -// 路由标题映射 -export const routeTitles: Record = { - "/": "首页", - "/login": "登录", - "/guide": "设备绑定引导", - "/scene": "场景获客", - "/work": "工作台", - "/mine": "我的", - "/mine/devices": "设备管理", - "/wechat-accounts": "微信号管理", - "/workspace": "工作台", - "/scenarios": "场景管理", - "/content": "内容管理", - "/traffic-pool": "流量池", - "/profile": "个人中心", - "/plans": "计划管理", - "/orders": "订单管理", - "/contract-import": "联系人导入", -}; - -// 获取路由标题 -export const getRouteTitle = (path: string): string => { - return routeTitles[path] || "页面"; -}; - -// 检查路由权限 -export const checkRoutePermission = ( - path: string, - userRole: string = "user", -): boolean => { - const allowedRoutes = - routePermissions[userRole as keyof typeof routePermissions] || []; - return allowedRoutes.some(route => { - // 简单的路径匹配,支持动态参数 - const routePattern = route.replace(/:[^/]+/g, "[^/]+"); - const regex = new RegExp(`^${routePattern}$`); - return regex.test(path); - }); -}; diff --git a/Touchkebao/src/router/module/auth.tsx b/Touchkebao/src/router/module/common.tsx similarity index 53% rename from Touchkebao/src/router/module/auth.tsx rename to Touchkebao/src/router/module/common.tsx index c2188278..c059889f 100644 --- a/Touchkebao/src/router/module/auth.tsx +++ b/Touchkebao/src/router/module/common.tsx @@ -1,7 +1,20 @@ import Login from "@/pages/login/Login"; import Guide from "@/pages/guide"; +import Home from "@/pages/mobile/home/index"; +import Init from "@/pages/iframe/init"; const authRoutes = [ + // 基础路由 + { + path: "/", + element: , + auth: true, // 需要登录 + }, + { + path: "/init", + element: , + auth: false, // 需要登录 + }, { path: "/login", element: , diff --git a/Touchkebao/src/router/module/index.tsx b/Touchkebao/src/router/module/index.tsx deleted file mode 100644 index 4adcd781..00000000 --- a/Touchkebao/src/router/module/index.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import Home from "@/pages/mobile/home/index"; -import Init from "@/pages/iframe/init"; - -const routes = [ - // 基础路由 - { - path: "/", - element: , - auth: true, // 需要登录 - }, - { - path: "/init", - element: , - auth: false, // 需要登录 - }, -]; - -export default routes;