Files
anxinyan/admin-web/src/router/index.ts

313 lines
8.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createRouter, createWebHashHistory } from "vue-router";
import { adminApi } from "../api/admin";
import { clearAdminSession, getAdminInfo, getAdminToken, hasPermission, setAdminInfo } from "../utils/auth";
const adminChildren = [
{
path: "dashboard",
name: "dashboard",
component: () => import("../pages/dashboard/index.vue"),
meta: {
title: "工作台",
desc: "查看当前订单、报告与处理进度概览。",
permission: "dashboard.view",
},
},
{
path: "orders",
name: "orders",
component: () => import("../pages/orders/index.vue"),
meta: {
title: "订单中心",
desc: "管理订单流转、查看补图任务与处理详情。",
permission: "orders.manage",
},
},
{
path: "warehouse-workbench",
name: "warehouse-workbench",
component: () => import("../pages/warehouse-workbench/index.vue"),
meta: {
title: "仓管作业台",
desc: "扫码处理入库、中检送检出入库与物品寄回。",
permission: "warehouse_workbench.manage",
},
},
{
path: "appraisal-tasks",
name: "appraisal-tasks",
component: () => import("../pages/appraisal-tasks/index.vue"),
meta: {
title: "鉴定作业台",
desc: "查看鉴定任务、资料详情与当前作业结论。",
permission: "appraisal_tasks.manage",
},
},
{
path: "catalog",
name: "catalog",
component: () => import("../pages/catalog/index.vue"),
meta: {
title: "商品资料中心",
desc: "查看品类、品牌、上传模板与鉴定模板等基础配置数据。",
permission: "catalog.manage",
},
},
{
path: "reports",
name: "reports",
component: () => import("../pages/reports/index.vue"),
meta: {
title: "报告中心",
desc: "查看已生成报告、报告状态与验真信息。",
permission: "reports.manage",
},
},
{
path: "messages",
name: "messages",
component: () => import("../pages/messages/index.vue"),
meta: {
title: "消息中心",
desc: "查看消息模板、触发规则与发送记录概览。",
permission: "messages.manage",
},
},
{
path: "tickets",
name: "tickets",
component: () => import("../pages/tickets/index.vue"),
meta: {
title: "客服与售后",
desc: "查看工单、用户留言与售后处理记录。",
permission: "tickets.manage",
},
},
{
path: "users",
name: "users",
component: () => import("../pages/users/index.vue"),
meta: {
title: "用户管理",
desc: "查看用户资料、地址、消息和工单等用户侧资产概览。",
permission: "users.manage",
},
},
{
path: "customers",
name: "customers",
component: () => import("../pages/customers/index.vue"),
meta: {
title: "客户管理",
desc: "维护大客户资料、开放接口应用 Key、订单映射和 Webhook 推送记录。",
permission: "customers.manage",
},
},
{
path: "warehouses",
name: "warehouses",
component: () => import("../pages/warehouses/index.vue"),
meta: {
title: "仓库中心",
desc: "维护收货仓库、检测中心地址信息,并为后续多仓库扩展预留能力。",
permission: "warehouses.manage",
},
},
{
path: "service-prices",
name: "service-prices",
component: () => import("../pages/service-prices/index.vue"),
meta: {
title: "服务价格",
desc: "维护安心验与中检服务的可选价格套餐。",
permission: "service_prices.manage",
},
},
{
path: "express-companies",
name: "express-companies",
component: () => import("../pages/express-companies/index.vue"),
meta: {
title: "快递公司",
desc: "维护仓管寄回时可选择的快递公司和默认项。",
permission: "warehouses.manage",
},
},
{
path: "materials",
name: "materials",
component: () => import("../pages/materials/index.vue"),
meta: {
title: "物料管理",
desc: "批量生成吊牌二维码,管理批次下载、条码搜索与报告绑定状态。",
permission: "materials.manage",
},
},
{
path: "access",
name: "access",
component: () => import("../pages/access/index.vue"),
meta: {
title: "权限中心",
desc: "管理管理员账号、角色配置与权限点分配。",
permission: "access.manage",
},
},
{
path: "content",
name: "content",
component: () => import("../pages/content/index.vue"),
redirect: { name: "content-home" },
meta: {
title: "内容中心",
desc: "维护首页展示内容与帮助中心文章等用户端内容配置。",
permission: "system.manage",
},
children: [
{
path: "home",
name: "content-home",
component: () => import("../pages/content/home.vue"),
meta: {
title: "内容中心",
desc: "首页内容维护Banner、服务入口、快捷入口和信任信息。",
permission: "system.manage",
menuIndex: "content",
contentTab: "home",
},
},
{
path: "policy",
name: "content-policy",
component: () => import("../pages/content/policy.vue"),
meta: {
title: "内容中心",
desc: "协议与说明维护:设置页说明入口和下单确认协议。",
permission: "system.manage",
menuIndex: "content",
contentTab: "policy",
},
},
{
path: "meta",
name: "content-meta",
component: () => import("../pages/content/meta.vue"),
meta: {
title: "内容中心",
desc: "分类与文案维护:帮助分类、消息事件、工单文案和风险提示。",
permission: "system.manage",
menuIndex: "content",
contentTab: "meta",
},
},
{
path: "articles",
name: "content-articles",
component: () => import("../pages/content/articles.vue"),
meta: {
title: "内容中心",
desc: "帮助文章维护:文章正文、推荐状态和排序。",
permission: "system.manage",
menuIndex: "content",
contentTab: "articles",
},
},
{
path: "articles/create",
name: "content-article-create",
component: () => import("../pages/content/article-edit.vue"),
meta: {
title: "内容中心",
desc: "新增帮助文章:编辑分类、摘要、关键词和富文本正文。",
permission: "system.manage",
menuIndex: "content",
contentTab: "articles",
},
},
{
path: "articles/:id/edit",
name: "content-article-edit",
component: () => import("../pages/content/article-edit.vue"),
meta: {
title: "内容中心",
desc: "编辑帮助文章:维护富文本正文、推荐状态和排序。",
permission: "system.manage",
menuIndex: "content",
contentTab: "articles",
},
},
],
},
{
path: "system-config",
name: "system-config",
component: () => import("../pages/system-config/index.vue"),
meta: {
title: "系统配置",
desc: "配置小程序、H5、支付与商户平台等上线核心参数。",
permission: "system.manage",
},
},
];
const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: "/login",
name: "login",
component: () => import("../pages/login/index.vue"),
meta: {
public: true,
title: "登录",
},
},
{
path: "/",
component: () => import("../layouts/AdminLayout.vue"),
redirect: "/dashboard",
children: adminChildren,
},
],
});
function firstAccessibleRoute() {
const target = adminChildren.find((route) => hasPermission(route.meta.permission as string));
return target?.name || "dashboard";
}
router.beforeEach(async (to) => {
if (to.meta.public) {
if (getAdminToken()) {
return { name: firstAccessibleRoute() };
}
return true;
}
const token = getAdminToken();
if (!token) {
clearAdminSession();
return { name: "login" };
}
if (!getAdminInfo()) {
try {
const response = await adminApi.getAuthMe();
setAdminInfo(response.data.admin_info);
} catch (error) {
console.error(error);
clearAdminSession();
return { name: "login" };
}
}
const permission = to.meta.permission as string | undefined;
if (permission && !hasPermission(permission)) {
return { name: firstAccessibleRoute() };
}
return true;
});
export default router;