feat: 本次提交更新内容如下
格式更新一下
This commit is contained in:
@@ -1,171 +1,172 @@
|
||||
// 路由配置类型定义
|
||||
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", "/scene", "/work", "/mine"],
|
||||
},
|
||||
|
||||
// 设备管理
|
||||
devices: {
|
||||
name: "设备管理",
|
||||
routes: ["/devices", "/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: [
|
||||
"/content",
|
||||
"/content/new",
|
||||
"/content/edit/:id",
|
||||
"/content/materials/:id",
|
||||
"/content/materials/new/:id",
|
||||
"/content/materials/edit/:id/:materialId",
|
||||
],
|
||||
},
|
||||
|
||||
// 流量池
|
||||
trafficPool: {
|
||||
name: "流量池",
|
||||
routes: ["/traffic-pool", "/traffic-pool/:id"],
|
||||
},
|
||||
|
||||
// 其他功能
|
||||
other: {
|
||||
name: "其他功能",
|
||||
routes: [
|
||||
"/profile",
|
||||
"/plans",
|
||||
"/plans/:planId",
|
||||
"/orders",
|
||||
"/contact-import",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// 路由权限配置
|
||||
export const routePermissions = {
|
||||
// 管理员权限
|
||||
admin: Object.values(routeGroups).flatMap(group => group.routes),
|
||||
|
||||
// 普通用户权限
|
||||
user: [
|
||||
"/",
|
||||
"/login",
|
||||
"/scene",
|
||||
"/work",
|
||||
"/mine",
|
||||
"/devices",
|
||||
"/devices/:id",
|
||||
"/wechat-accounts",
|
||||
"/wechat-accounts/:id",
|
||||
"/workspace",
|
||||
"/scenarios",
|
||||
"/content",
|
||||
"/traffic-pool",
|
||||
"/traffic-pool/:id",
|
||||
"/profile",
|
||||
"/plans",
|
||||
"/plans/:planId",
|
||||
"/orders",
|
||||
"/contact-import",
|
||||
],
|
||||
|
||||
// 访客权限
|
||||
guest: ["/", "/login"],
|
||||
};
|
||||
|
||||
// 路由标题映射
|
||||
export const routeTitles: Record<string, string> = {
|
||||
"/": "首页",
|
||||
"/login": "登录",
|
||||
"/scene": "场景获客",
|
||||
"/work": "工作台",
|
||||
"/mine": "我的",
|
||||
"/devices": "设备管理",
|
||||
"/wechat-accounts": "微信号管理",
|
||||
"/workspace": "工作台",
|
||||
"/scenarios": "场景管理",
|
||||
"/content": "内容管理",
|
||||
"/traffic-pool": "流量池",
|
||||
"/profile": "个人中心",
|
||||
"/plans": "计划管理",
|
||||
"/orders": "订单管理",
|
||||
"/contact-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);
|
||||
});
|
||||
};
|
||||
// 路由配置类型定义
|
||||
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", "/scene", "/work", "/mine"],
|
||||
},
|
||||
|
||||
// 设备管理
|
||||
devices: {
|
||||
name: "设备管理",
|
||||
routes: ["/devices", "/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: [
|
||||
"/content",
|
||||
"/content/new",
|
||||
"/content/edit/:id",
|
||||
"/content/materials/:id",
|
||||
"/content/materials/new/:id",
|
||||
"/content/materials/edit/:id/:materialId",
|
||||
],
|
||||
},
|
||||
|
||||
// 流量池
|
||||
trafficPool: {
|
||||
name: "流量池",
|
||||
routes: ["/traffic-pool", "/traffic-pool/:id"],
|
||||
},
|
||||
|
||||
// 其他功能
|
||||
other: {
|
||||
name: "其他功能",
|
||||
routes: [
|
||||
"/profile",
|
||||
"/plans",
|
||||
"/plans/:planId",
|
||||
"/orders",
|
||||
"/contact-import",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
// 路由权限配置
|
||||
export const routePermissions = {
|
||||
// 管理员权限
|
||||
admin: Object.values(routeGroups).flatMap(group => group.routes),
|
||||
|
||||
// 普通用户权限
|
||||
user: [
|
||||
"/",
|
||||
"/login",
|
||||
"/scene",
|
||||
"/work",
|
||||
"/mine",
|
||||
"/devices",
|
||||
"/devices/:id",
|
||||
"/wechat-accounts",
|
||||
"/wechat-accounts/:id",
|
||||
"/workspace",
|
||||
"/scenarios",
|
||||
"/content",
|
||||
"/traffic-pool",
|
||||
"/traffic-pool/:id",
|
||||
"/profile",
|
||||
"/plans",
|
||||
"/plans/:planId",
|
||||
"/orders",
|
||||
"/contact-import",
|
||||
],
|
||||
|
||||
// 访客权限
|
||||
guest: ["/", "/login"],
|
||||
};
|
||||
|
||||
// 路由标题映射
|
||||
export const routeTitles: Record<string, string> = {
|
||||
"/": "首页",
|
||||
"/login": "登录",
|
||||
"/scene": "场景获客",
|
||||
"/work": "工作台",
|
||||
"/mine": "我的",
|
||||
"/devices": "设备管理",
|
||||
"/wechat-accounts": "微信号管理",
|
||||
"/workspace": "工作台",
|
||||
"/scenarios": "场景管理",
|
||||
"/content": "内容管理",
|
||||
"/traffic-pool": "流量池",
|
||||
"/profile": "个人中心",
|
||||
"/plans": "计划管理",
|
||||
"/orders": "订单管理",
|
||||
"/contact-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);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
import React from "react";
|
||||
import { BrowserRouter, useRoutes, RouteObject } from "react-router-dom";
|
||||
import PermissionRoute from "./permissionRoute";
|
||||
|
||||
// 动态导入所有 module 下的 ts/tsx 路由模块
|
||||
const modules = import.meta.glob("./module/*.{ts,tsx}", { eager: true });
|
||||
|
||||
// 合并所有模块的默认导出(假设每个模块都是 export default 路由数组)
|
||||
const allRoutes: (RouteObject & { auth?: boolean; requiredRole?: string })[] =
|
||||
[];
|
||||
Object.values(modules).forEach((mod: any) => {
|
||||
if (Array.isArray(mod.default)) {
|
||||
allRoutes.push(...mod.default);
|
||||
}
|
||||
});
|
||||
|
||||
// 权限包装
|
||||
function wrapWithPermission(
|
||||
route: RouteObject & { auth?: boolean; requiredRole?: string }
|
||||
) {
|
||||
if (route.auth) {
|
||||
return {
|
||||
...route,
|
||||
element: (
|
||||
<PermissionRoute requiredRole={route.requiredRole}>
|
||||
{route.element}
|
||||
</PermissionRoute>
|
||||
),
|
||||
};
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
const routes = allRoutes.map(wrapWithPermission);
|
||||
|
||||
const AppRoutes = () => useRoutes(routes);
|
||||
|
||||
const AppRouter: React.FC = () => (
|
||||
<BrowserRouter
|
||||
future={{
|
||||
v7_startTransition: true,
|
||||
v7_relativeSplatPath: true,
|
||||
}}
|
||||
>
|
||||
<AppRoutes />
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
||||
export default AppRouter;
|
||||
import React from "react";
|
||||
import { BrowserRouter, useRoutes, RouteObject } from "react-router-dom";
|
||||
import PermissionRoute from "./permissionRoute";
|
||||
|
||||
// 动态导入所有 module 下的 ts/tsx 路由模块
|
||||
const modules = import.meta.glob("./module/*.{ts,tsx}", { eager: true });
|
||||
|
||||
// 合并所有模块的默认导出(假设每个模块都是 export default 路由数组)
|
||||
const allRoutes: (RouteObject & { auth?: boolean; requiredRole?: string })[] =
|
||||
[];
|
||||
Object.values(modules).forEach((mod: any) => {
|
||||
if (Array.isArray(mod.default)) {
|
||||
allRoutes.push(...mod.default);
|
||||
}
|
||||
});
|
||||
|
||||
// 权限包装
|
||||
function wrapWithPermission(
|
||||
route: RouteObject & { auth?: boolean; requiredRole?: string }
|
||||
) {
|
||||
if (route.auth) {
|
||||
return {
|
||||
...route,
|
||||
element: (
|
||||
<PermissionRoute requiredRole={route.requiredRole}>
|
||||
{route.element}
|
||||
</PermissionRoute>
|
||||
),
|
||||
};
|
||||
}
|
||||
return route;
|
||||
}
|
||||
|
||||
const routes = allRoutes.map(wrapWithPermission);
|
||||
|
||||
const AppRoutes = () => useRoutes(routes);
|
||||
|
||||
const AppRouter: React.FC = () => (
|
||||
<BrowserRouter
|
||||
future={{
|
||||
v7_startTransition: true,
|
||||
v7_relativeSplatPath: true,
|
||||
}}
|
||||
>
|
||||
<AppRoutes />
|
||||
</BrowserRouter>
|
||||
);
|
||||
|
||||
export default AppRouter;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import Login from "@/pages/login/login";
|
||||
|
||||
const authRoutes = [
|
||||
{
|
||||
path: "/login",
|
||||
element: <Login />,
|
||||
auth: false, // 不需要权限
|
||||
},
|
||||
];
|
||||
|
||||
export default authRoutes;
|
||||
import Login from "@/pages/login/login";
|
||||
|
||||
const authRoutes = [
|
||||
{
|
||||
path: "/login",
|
||||
element: <Login />,
|
||||
auth: false, // 不需要权限
|
||||
},
|
||||
];
|
||||
|
||||
export default authRoutes;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import ComponentTest from "@/pages/mobile/component-test";
|
||||
|
||||
const componentTestRoutes = [
|
||||
{
|
||||
path: "/component-test",
|
||||
element: <ComponentTest />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default componentTestRoutes;
|
||||
import ComponentTest from "@/pages/mobile/component-test";
|
||||
|
||||
const componentTestRoutes = [
|
||||
{
|
||||
path: "/component-test",
|
||||
element: <ComponentTest />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default componentTestRoutes;
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
import ContentLibraryList from "@/pages/mobile/content/list/index";
|
||||
import ContentLibraryForm from "@/pages/mobile/content/form/index";
|
||||
import MaterialsList from "@/pages/mobile/content/materials/list/index";
|
||||
import MaterialForm from "@/pages/mobile/content/materials/form/index";
|
||||
|
||||
const contentRoutes = [
|
||||
{
|
||||
path: "/content",
|
||||
element: <ContentLibraryList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/new",
|
||||
element: <ContentLibraryForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/edit/:id",
|
||||
element: <ContentLibraryForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/:id",
|
||||
element: <MaterialsList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/new/:id",
|
||||
element: <MaterialForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/edit/:id/:materialId",
|
||||
element: <MaterialForm />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default contentRoutes;
|
||||
import ContentLibraryList from "@/pages/mobile/content/list/index";
|
||||
import ContentLibraryForm from "@/pages/mobile/content/form/index";
|
||||
import MaterialsList from "@/pages/mobile/content/materials/list/index";
|
||||
import MaterialForm from "@/pages/mobile/content/materials/form/index";
|
||||
|
||||
const contentRoutes = [
|
||||
{
|
||||
path: "/content",
|
||||
element: <ContentLibraryList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/new",
|
||||
element: <ContentLibraryForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/edit/:id",
|
||||
element: <ContentLibraryForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/:id",
|
||||
element: <MaterialsList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/new/:id",
|
||||
element: <MaterialForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/content/materials/edit/:id/:materialId",
|
||||
element: <MaterialForm />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default contentRoutes;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import Home from "@/pages/mobile/home/index";
|
||||
|
||||
const routes = [
|
||||
// 基础路由
|
||||
{
|
||||
path: "/",
|
||||
element: <Home />,
|
||||
auth: true, // 需要登录
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
import Home from "@/pages/mobile/home/index";
|
||||
|
||||
const routes = [
|
||||
// 基础路由
|
||||
{
|
||||
path: "/",
|
||||
element: <Home />,
|
||||
auth: true, // 需要登录
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
import Mine from "@/pages/mobile/mine/main/index";
|
||||
import Devices from "@/pages/mobile/mine/devices/index";
|
||||
import DeviceDetail from "@/pages/mobile/mine/devices/DeviceDetail";
|
||||
import TrafficPool from "@/pages/mobile/mine/traffic-pool/list/index";
|
||||
import TrafficPoolDetail from "@/pages/mobile/mine/traffic-pool/detail/index";
|
||||
import WechatAccounts from "@/pages/mobile/mine/wechat-accounts/list/index";
|
||||
import WechatAccountDetail from "@/pages/mobile/mine/wechat-accounts/detail/index";
|
||||
import Recharge from "@/pages/mobile/mine/recharge/index";
|
||||
import UserSetting from "@/pages/mobile/mine/userSet/index";
|
||||
const routes = [
|
||||
{
|
||||
path: "/mine",
|
||||
element: <Mine />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/devices",
|
||||
element: <Devices />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/devices/:id",
|
||||
element: <DeviceDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/traffic-pool",
|
||||
element: <TrafficPool />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/traffic-pool/detail/:id",
|
||||
element: <TrafficPoolDetail />,
|
||||
auth: true,
|
||||
},
|
||||
// 微信号管理路由
|
||||
{
|
||||
path: "/wechat-accounts",
|
||||
element: <WechatAccounts />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/wechat-accounts/detail/:id",
|
||||
element: <WechatAccountDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/recharge",
|
||||
element: <Recharge />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/settings",
|
||||
element: <UserSetting />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
import Mine from "@/pages/mobile/mine/main/index";
|
||||
import Devices from "@/pages/mobile/mine/devices/index";
|
||||
import DeviceDetail from "@/pages/mobile/mine/devices/DeviceDetail";
|
||||
import TrafficPool from "@/pages/mobile/mine/traffic-pool/list/index";
|
||||
import TrafficPoolDetail from "@/pages/mobile/mine/traffic-pool/detail/index";
|
||||
import WechatAccounts from "@/pages/mobile/mine/wechat-accounts/list/index";
|
||||
import WechatAccountDetail from "@/pages/mobile/mine/wechat-accounts/detail/index";
|
||||
import Recharge from "@/pages/mobile/mine/recharge/index";
|
||||
import UserSetting from "@/pages/mobile/mine/userSet/index";
|
||||
const routes = [
|
||||
{
|
||||
path: "/mine",
|
||||
element: <Mine />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/devices",
|
||||
element: <Devices />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/devices/:id",
|
||||
element: <DeviceDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/traffic-pool",
|
||||
element: <TrafficPool />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/traffic-pool/detail/:id",
|
||||
element: <TrafficPoolDetail />,
|
||||
auth: true,
|
||||
},
|
||||
// 微信号管理路由
|
||||
{
|
||||
path: "/wechat-accounts",
|
||||
element: <WechatAccounts />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/wechat-accounts/detail/:id",
|
||||
element: <WechatAccountDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/recharge",
|
||||
element: <Recharge />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/settings",
|
||||
element: <UserSetting />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import SelectionTest from "@/components/SelectionTest";
|
||||
|
||||
const otherRoutes = [
|
||||
{
|
||||
path: "/selection-test",
|
||||
element: <SelectionTest />,
|
||||
auth: false,
|
||||
},
|
||||
];
|
||||
|
||||
export default otherRoutes;
|
||||
import SelectionTest from "@/components/SelectionTest";
|
||||
|
||||
const otherRoutes = [
|
||||
{
|
||||
path: "/selection-test",
|
||||
element: <SelectionTest />,
|
||||
auth: false,
|
||||
},
|
||||
];
|
||||
|
||||
export default otherRoutes;
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
import ScenariosList from "@/pages/mobile/scenarios/list";
|
||||
import NewPlan from "@/pages/mobile/scenarios/plan/new";
|
||||
import ListPlan from "@/pages/mobile/scenarios/plan/list";
|
||||
|
||||
const scenarioRoutes = [
|
||||
{
|
||||
path: "/scenarios",
|
||||
element: <ScenariosList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/new",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/new/:scenarioId",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/edit/:planId",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/list/:scenarioId/:scenarioName",
|
||||
element: <ListPlan />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default scenarioRoutes;
|
||||
import ScenariosList from "@/pages/mobile/scenarios/list";
|
||||
import NewPlan from "@/pages/mobile/scenarios/plan/new";
|
||||
import ListPlan from "@/pages/mobile/scenarios/plan/list";
|
||||
|
||||
const scenarioRoutes = [
|
||||
{
|
||||
path: "/scenarios",
|
||||
element: <ScenariosList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/new",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/new/:scenarioId",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/edit/:planId",
|
||||
element: <NewPlan />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/scenarios/list/:scenarioId/:scenarioName",
|
||||
element: <ListPlan />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default scenarioRoutes;
|
||||
|
||||
@@ -1,158 +1,158 @@
|
||||
import Workspace from "@/pages/mobile/workspace/main";
|
||||
import ListAutoLike from "@/pages/mobile/workspace/auto-like/list";
|
||||
import NewAutoLike from "@/pages/mobile/workspace/auto-like/new";
|
||||
import RecordAutoLike from "@/pages/mobile/workspace/auto-like/record";
|
||||
import AutoGroupList from "@/pages/mobile/workspace/auto-group/list";
|
||||
import AutoGroupDetail from "@/pages/mobile/workspace/auto-group/detail";
|
||||
import AutoGroupForm from "@/pages/mobile/workspace/auto-group/form";
|
||||
import GroupPush from "@/pages/mobile/workspace/group-push/list";
|
||||
import FormGroupPush from "@/pages/mobile/workspace/group-push/form";
|
||||
import DetailGroupPush from "@/pages/mobile/workspace/group-push/detail";
|
||||
import MomentsSync from "@/pages/mobile/workspace/moments-sync/MomentsSync";
|
||||
import MomentsSyncDetail from "@/pages/mobile/workspace/moments-sync/Detail";
|
||||
import NewMomentsSync from "@/pages/mobile/workspace/moments-sync/new/index";
|
||||
import AIAssistant from "@/pages/mobile/workspace/ai-assistant/AIAssistant";
|
||||
import TrafficDistribution from "@/pages/mobile/workspace/traffic-distribution/list/index";
|
||||
import TrafficDistributionDetail from "@/pages/mobile/workspace/traffic-distribution/detail/index";
|
||||
import NewDistribution from "@/pages/mobile/workspace/traffic-distribution/form/index";
|
||||
import PlaceholderPage from "@/components/PlaceholderPage";
|
||||
import AiAnalyzer from "@/pages/mobile/workspace/ai-analyzer";
|
||||
|
||||
const workspaceRoutes = [
|
||||
{
|
||||
path: "/workspace",
|
||||
element: <Workspace />,
|
||||
auth: true,
|
||||
},
|
||||
// 自动点赞
|
||||
{
|
||||
path: "/workspace/auto-like",
|
||||
element: <ListAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/new",
|
||||
element: <NewAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/record/:id",
|
||||
element: <RecordAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/edit/:id",
|
||||
element: <NewAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
// 自动建群
|
||||
{
|
||||
path: "/workspace/auto-group",
|
||||
element: <AutoGroupList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/new",
|
||||
element: <AutoGroupForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/:id",
|
||||
element: <AutoGroupDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/:id/edit",
|
||||
element: <AutoGroupForm />,
|
||||
auth: true,
|
||||
},
|
||||
// 群发推送
|
||||
{
|
||||
path: "/workspace/group-push",
|
||||
element: <GroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/:id",
|
||||
element: <DetailGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/new",
|
||||
element: <FormGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/:id/edit",
|
||||
element: <FormGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
// 朋友圈同步
|
||||
{
|
||||
path: "/workspace/moments-sync",
|
||||
element: <MomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/new",
|
||||
element: <NewMomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/:id",
|
||||
element: <MomentsSyncDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/edit/:id",
|
||||
element: <NewMomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
// AI助手
|
||||
{
|
||||
path: "/workspace/ai-assistant",
|
||||
element: <AIAssistant />,
|
||||
auth: true,
|
||||
},
|
||||
// AI数据分析
|
||||
{
|
||||
path: "/workspace/ai-analyzer",
|
||||
element: <AiAnalyzer />,
|
||||
auth: true,
|
||||
},
|
||||
// AI策略优化
|
||||
{
|
||||
path: "/workspace/ai-strategy",
|
||||
element: <PlaceholderPage title="AI策略优化" />,
|
||||
auth: true,
|
||||
},
|
||||
// AI销售预测
|
||||
{
|
||||
path: "/workspace/ai-forecast",
|
||||
element: <PlaceholderPage title="AI销售预测" />,
|
||||
auth: true,
|
||||
},
|
||||
// 流量分发
|
||||
{
|
||||
path: "/workspace/traffic-distribution",
|
||||
element: <TrafficDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/new",
|
||||
element: <NewDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/edit/:id",
|
||||
element: <NewDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/:id",
|
||||
element: <TrafficDistributionDetail />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default workspaceRoutes;
|
||||
import Workspace from "@/pages/mobile/workspace/main";
|
||||
import ListAutoLike from "@/pages/mobile/workspace/auto-like/list";
|
||||
import NewAutoLike from "@/pages/mobile/workspace/auto-like/new";
|
||||
import RecordAutoLike from "@/pages/mobile/workspace/auto-like/record";
|
||||
import AutoGroupList from "@/pages/mobile/workspace/auto-group/list";
|
||||
import AutoGroupDetail from "@/pages/mobile/workspace/auto-group/detail";
|
||||
import AutoGroupForm from "@/pages/mobile/workspace/auto-group/form";
|
||||
import GroupPush from "@/pages/mobile/workspace/group-push/list";
|
||||
import FormGroupPush from "@/pages/mobile/workspace/group-push/form";
|
||||
import DetailGroupPush from "@/pages/mobile/workspace/group-push/detail";
|
||||
import MomentsSync from "@/pages/mobile/workspace/moments-sync/MomentsSync";
|
||||
import MomentsSyncDetail from "@/pages/mobile/workspace/moments-sync/Detail";
|
||||
import NewMomentsSync from "@/pages/mobile/workspace/moments-sync/new/index";
|
||||
import AIAssistant from "@/pages/mobile/workspace/ai-assistant/AIAssistant";
|
||||
import TrafficDistribution from "@/pages/mobile/workspace/traffic-distribution/list/index";
|
||||
import TrafficDistributionDetail from "@/pages/mobile/workspace/traffic-distribution/detail/index";
|
||||
import NewDistribution from "@/pages/mobile/workspace/traffic-distribution/form/index";
|
||||
import PlaceholderPage from "@/components/PlaceholderPage";
|
||||
import AiAnalyzer from "@/pages/mobile/workspace/ai-analyzer";
|
||||
|
||||
const workspaceRoutes = [
|
||||
{
|
||||
path: "/workspace",
|
||||
element: <Workspace />,
|
||||
auth: true,
|
||||
},
|
||||
// 自动点赞
|
||||
{
|
||||
path: "/workspace/auto-like",
|
||||
element: <ListAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/new",
|
||||
element: <NewAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/record/:id",
|
||||
element: <RecordAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-like/edit/:id",
|
||||
element: <NewAutoLike />,
|
||||
auth: true,
|
||||
},
|
||||
// 自动建群
|
||||
{
|
||||
path: "/workspace/auto-group",
|
||||
element: <AutoGroupList />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/new",
|
||||
element: <AutoGroupForm />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/:id",
|
||||
element: <AutoGroupDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/auto-group/:id/edit",
|
||||
element: <AutoGroupForm />,
|
||||
auth: true,
|
||||
},
|
||||
// 群发推送
|
||||
{
|
||||
path: "/workspace/group-push",
|
||||
element: <GroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/:id",
|
||||
element: <DetailGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/new",
|
||||
element: <FormGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/group-push/:id/edit",
|
||||
element: <FormGroupPush />,
|
||||
auth: true,
|
||||
},
|
||||
// 朋友圈同步
|
||||
{
|
||||
path: "/workspace/moments-sync",
|
||||
element: <MomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/new",
|
||||
element: <NewMomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/:id",
|
||||
element: <MomentsSyncDetail />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/moments-sync/edit/:id",
|
||||
element: <NewMomentsSync />,
|
||||
auth: true,
|
||||
},
|
||||
// AI助手
|
||||
{
|
||||
path: "/workspace/ai-assistant",
|
||||
element: <AIAssistant />,
|
||||
auth: true,
|
||||
},
|
||||
// AI数据分析
|
||||
{
|
||||
path: "/workspace/ai-analyzer",
|
||||
element: <AiAnalyzer />,
|
||||
auth: true,
|
||||
},
|
||||
// AI策略优化
|
||||
{
|
||||
path: "/workspace/ai-strategy",
|
||||
element: <PlaceholderPage title="AI策略优化" />,
|
||||
auth: true,
|
||||
},
|
||||
// AI销售预测
|
||||
{
|
||||
path: "/workspace/ai-forecast",
|
||||
element: <PlaceholderPage title="AI销售预测" />,
|
||||
auth: true,
|
||||
},
|
||||
// 流量分发
|
||||
{
|
||||
path: "/workspace/traffic-distribution",
|
||||
element: <TrafficDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/new",
|
||||
element: <NewDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/edit/:id",
|
||||
element: <NewDistribution />,
|
||||
auth: true,
|
||||
},
|
||||
{
|
||||
path: "/workspace/traffic-distribution/:id",
|
||||
element: <TrafficDistributionDetail />,
|
||||
auth: true,
|
||||
},
|
||||
];
|
||||
|
||||
export default workspaceRoutes;
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
|
||||
interface PermissionRouteProps {
|
||||
children: React.ReactNode;
|
||||
requiredRole?: string;
|
||||
}
|
||||
|
||||
const PermissionRoute: React.FC<PermissionRouteProps> = ({
|
||||
children,
|
||||
requiredRole,
|
||||
}) => {
|
||||
const { user, isLoggedIn } = useUserStore();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
// 检查是否已登录
|
||||
if (!isLoggedIn || !user) {
|
||||
const currentPath = location.pathname + location.search;
|
||||
navigate(`/login?returnUrl=${encodeURIComponent(currentPath)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查角色权限(如果需要)
|
||||
if (requiredRole && user.isAdmin !== 1) {
|
||||
navigate("/");
|
||||
return;
|
||||
}
|
||||
}, [isLoggedIn, user, requiredRole, navigate, location]);
|
||||
|
||||
// 如果未登录,不渲染子组件
|
||||
if (!isLoggedIn || !user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 如果角色不匹配,不渲染子组件
|
||||
if (requiredRole && user.isAdmin !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default PermissionRoute;
|
||||
import React, { useEffect } from "react";
|
||||
import { useNavigate, useLocation } from "react-router-dom";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
|
||||
interface PermissionRouteProps {
|
||||
children: React.ReactNode;
|
||||
requiredRole?: string;
|
||||
}
|
||||
|
||||
const PermissionRoute: React.FC<PermissionRouteProps> = ({
|
||||
children,
|
||||
requiredRole,
|
||||
}) => {
|
||||
const { user, isLoggedIn } = useUserStore();
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
// 检查是否已登录
|
||||
if (!isLoggedIn || !user) {
|
||||
const currentPath = location.pathname + location.search;
|
||||
navigate(`/login?returnUrl=${encodeURIComponent(currentPath)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查角色权限(如果需要)
|
||||
if (requiredRole && user.isAdmin !== 1) {
|
||||
navigate("/");
|
||||
return;
|
||||
}
|
||||
}, [isLoggedIn, user, requiredRole, navigate, location]);
|
||||
|
||||
// 如果未登录,不渲染子组件
|
||||
if (!isLoggedIn || !user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 如果角色不匹配,不渲染子组件
|
||||
if (requiredRole && user.isAdmin !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
};
|
||||
|
||||
export default PermissionRoute;
|
||||
|
||||
Reference in New Issue
Block a user