更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

+1 -56
View File
@@ -2,27 +2,21 @@ import { createRouter, createWebHashHistory } from "vue-router";
import { convertMenusToRoutes } from "./dynamicRoutes";
import { redirectToAuthorize, ensureUserInfo } from "@/utils/authClient";
// 本地登录已停用的历史路径:命中后统一改送认证中心,避免书签/后端回跳落到 404
const LEGACY_LOCAL_LOGIN_PATHS = ["/login", "/register", "/forget"];
// 静态子路由:需要在 Main 框架内显示的页面
const staticMainChildren = [
// 默认首页:访问 / 时直接展示工作台,URL 保持为 /
{
path: "",
name: "Dashboard",
component: () => import("@/views/dashboard/index.vue"),
meta: { requiresAuth: true, title: "工作台" }
},
// 审批流配置(租户侧):静态注册保证 URL 直达,菜单入口由数据库驱动
{
path: "/system/approval",
name: "BackendApprovalFlow",
component: () => import("@/views/system/approval/index.vue"),
meta: { requiresAuth: true, title: "审批流", modulePath: "/systemManager" }
},
// ERP 工作台目录内的两个页面:静态注册保证 URL 直达,菜单入口由数据库驱动
{
path: "/apps/erp/dashboard",
name: "ErpWorkbenchDashboard",
@@ -35,7 +29,6 @@ const staticMainChildren = [
component: () => import("@/views/apps/erp/workbench/approvalList.vue"),
meta: { requiresAuth: true, title: "审批列表", modulePath: "/apps/erp" }
},
// OA 审批中心:待我审批 / 审批列表 / 审批设置(静态注册保证 URL 直达)
{
path: "/apps/oa/approvalcenter/mine",
name: "OaApprovalCenterMine",
@@ -54,36 +47,30 @@ const staticMainChildren = [
component: () => import("@/views/apps/oa/approvalcenter/settings.vue"),
meta: { requiresAuth: true, title: "审批设置", modulePath: "/apps/oa" }
},
// OA 工作排班(静态注册兜底:三级菜单在动态路由重建前/菜单缓存未刷新时直链会落到 404)
{
path: "/apps/oa/scheduling/board",
name: "OaSchedulingBoard",
component: () => import("@/views/apps/oa/scheduling/index.vue"),
meta: { requiresAuth: true, title: "工作排班", modulePath: "/apps/oa" }
},
// OA 考勤管理(移动端打卡产生的数据,后台汇总 / 明细 / 备注)
{
path: "/apps/oa/attendance",
name: "OaAttendance",
component: () => import("@/views/apps/oa/attendance/index.vue"),
meta: { requiresAuth: true, title: "考勤管理", modulePath: "/apps/oa" }
},
// OA AI办公(AI 广场):三级菜单直链兜底
{
path: "/apps/oa/ai",
name: "OaAiPlayground",
component: () => import("@/views/apps/oa/ai/index.vue"),
meta: { requiresAuth: true, title: "AI办公", modulePath: "/apps/oa" }
},
// OA 基础设置 → AI设置(租户级接入配置)
{
path: "/basic-settings/ai",
name: "BasicSettingsAi",
component: () => import("@/views/basicSettings/ai/index.vue"),
meta: { requiresAuth: true, title: "AI设置", modulePath: "/apps/oa" }
},
// CMS 文章/产品/解决方案是系统内置功能,不依赖数据库菜单配置。
// 统一结构:index 为列表页,type 为分类页。
{
path: "/apps/cms/analytics/content",
name: "CmsContentAnalytics",
@@ -126,14 +113,12 @@ const staticMainChildren = [
component: () => import("@/views/apps/cms/solution/type/index.vue"),
meta: { requiresAuth: true, title: "解决方案分类", modulePath: "/apps/cms" }
},
// CRM 产品管理(产品台账/目录):项目生成时自动写入产品参数
{
path: "/apps/crm/product",
name: "CrmProduct",
component: () => import("@/views/apps/crm/product/index.vue"),
meta: { requiresAuth: true, title: "产品管理", modulePath: "/apps/crm" }
},
// 兼容旧路径:articles/* -> article/*
{
path: "/apps/cms/articles",
redirect: "/apps/cms/article"
@@ -142,33 +127,28 @@ const staticMainChildren = [
path: "/apps/cms/articles/category",
redirect: "/apps/cms/article/type"
},
// CRM 产品分类(用户自定义产品归类):产品表单的分类下拉取自该表
{
path: "/apps/crm/product/cate",
name: "CrmProductCategory",
component: () => import("@/views/apps/crm/product/cate.vue"),
meta: { requiresAuth: true, title: "产品分类", modulePath: "/apps/crm" }
},
// 兼容带 .vue 后缀的菜单路径
{
path: "/apps/crm/product/cate.vue",
redirect: "/apps/crm/product/cate"
},
// CRM 基本设置(单位设置等基础数据维护入口)
{
path: "/apps/crm/setting",
name: "CrmSetting",
component: () => import("@/views/apps/crm/setting/index.vue"),
meta: { requiresAuth: true, title: "基本设置", modulePath: "/apps/crm" }
},
// CRM 单位设置(产品等业务的「单位」下拉取自该表)
{
path: "/apps/crm/setting/unit",
name: "CrmSettingUnit",
component: () => import("@/views/apps/crm/setting/unit/index.vue"),
meta: { requiresAuth: true, title: "单位设置", modulePath: "/apps/crm" }
},
// 兼容带 .vue 后缀的菜单路径
{
path: "/apps/crm/setting/unit.vue",
redirect: "/apps/crm/setting/unit"
@@ -191,31 +171,25 @@ const staticMainChildren = [
component: () => import("@/views/apps/ai/index.vue"),
meta: { requiresAuth: true, title: "AI广场" }
},
// 兼容拼写错误的路径重定向
{
path: "/apps/erp/dashborad",
redirect: "/apps/erp/dashboard"
}
];
// 静态路由:home 导航门户独立、404 页面独立
// 注意:本地账号密码登录入口(/login、/register、/forget)已下线,登录一律走统一认证中心
const staticRoutes = [
// 统一认证中心回跳页(接收 code 换取令牌,页面自身不展示业务内容)
{
path: "/auth/callback",
name: "AuthCallback",
component: () => import("@/views/auth/callback.vue"),
meta: { requiresAuth: false }
},
// 微信公众号一次性链接登录页(公众号发「登录」/扫码确认 → 链接跳到这里兑换令牌)
{
path: "/mp-login",
name: "MpLogin",
component: () => import("@/views/auth/mpLogin.vue"),
meta: { requiresAuth: false }
},
// 移动端免登录页(uniapp APP / 小程序带一次性票据 → 换发 Web 端令牌,避免二次登录)
{
path: "/app-login",
name: "AppLogin",
@@ -228,19 +202,16 @@ const staticRoutes = [
component: () => import("@/views/home/index.vue"),
meta: { requiresAuth: true, title: "系统导航", isStandalone: true }
},
// 兼容路径拼写错误:dashborad -> dashboard
{
path: "/apps/erp/dashborad",
redirect: "/apps/erp/dashboard"
},
// 产品购买页:home 未开通卡片「购买」按钮跳转,独立于 Main 框架展示
{
path: "/product/:code",
name: "ProductPurchase",
component: () => import("@/views/product/index.vue"),
meta: { requiresAuth: true, title: "产品购买", isStandalone: true }
},
// 套餐购买列表页:独立于 Main 框架展示
{
path: "/packages",
name: "PackageList",
@@ -290,17 +261,12 @@ export async function loadAndAddDynamicRoutes() {
routesLoadingPromise = null;
return Promise.resolve();
} else {
// 即使权限菜单为空,也要注册内置文章中心路由。
addDynamicRoutes([]);
dynamicRoutesAdded = true;
routesLoadingPromise = null;
return Promise.resolve();
}
} catch (error) {
// 菜单接口异常时不要把错误抛给导航守卫,否则应用会卡在白屏;
// 保留内置静态路由(工作台、审批列表、审批流配置等)继续可用。
// 不重置 dynamicRoutesAdded,避免每次路由切换都重试失败的接口,
// 刷新页面或手动刷新菜单即可重新拉取。
console.error('加载动态路由失败,已保留内置路由:', error);
dynamicRoutesAdded = true;
routesLoadingPromise = null;
@@ -311,42 +277,31 @@ export async function loadAndAddDynamicRoutes() {
return routesLoadingPromise;
}
/**
* 重新拉取菜单并重建动态路由。
* 动态路由在构建时会把「未开通模块」的菜单注册为锁定占位页(views/locked),
* 仅调用 menuStore.refreshMenus() 只更新菜单数据、不会重建路由,
* 因此支付开通/套餐变更后必须调用本方法,才能让占位页切换为真实页面。
*/
export async function reloadMenusAndDynamicRoutes() {
const { useMenuStore } = await import("@/stores/menu");
const menuStore = useMenuStore();
// 强制从接口拉取最新菜单(含 locked 标记),写入 store 与缓存
await menuStore.refreshMenus();
// 重置加载标志后重建路由表
resetDynamicRoutes();
await loadAndAddDynamicRoutes();
}
// 核心修改:移除扁平化,直接使用嵌套菜单生成路由
function addDynamicRoutes(menus) {
if (!menus?.length) {
return;
}
// 直接转换嵌套菜单为嵌套路由(不再扁平化)
const dynamicRoutes = convertMenusToRoutes(menus);
if (router.hasRoute('Main')) {
router.removeRoute('Main');
}
// 重新添加主路由,合并静态子路由和动态路由
router.addRoute({
path: "/",
name: "Main",
component: () => import("@/views/Main.vue"),
meta: { requiresAuth: true },
children: [...staticMainChildren, ...dynamicRoutes] // 合并静态和动态子路由
children: [...staticMainChildren, ...dynamicRoutes]
});
dynamicRoutesAdded = true;
@@ -382,7 +337,6 @@ function findFirstValidRoute(routes) {
return null;
}
/** 跳转统一认证中心;地址未配置/检测到循环时给出提示,避免白屏或无限跳转 */
async function gotoAuthorize() {
try {
await redirectToAuthorize();
@@ -397,7 +351,6 @@ async function gotoAuthorize() {
router.beforeEach(async (to, from, next) => {
const token = localStorage.getItem("token");
// 认证中心回跳页 / 微信登录兑换页 / 移动端免登录页:始终放行,由页面自身完成令牌兑换
if (
to.path === "/auth/callback" ||
to.path === "/mp-login" ||
@@ -407,7 +360,6 @@ router.beforeEach(async (to, from, next) => {
return;
}
// 已下线的本地登录入口:已登录回首页,未登录送认证中心
if (LEGACY_LOCAL_LOGIN_PATHS.includes(to.path)) {
if (token) {
if (!dynamicRoutesAdded) {
@@ -421,20 +373,14 @@ router.beforeEach(async (to, from, next) => {
return;
}
// 未登录:统一走认证中心(本地登录已停用)
if (!token) {
const ok = await gotoAuthorize();
if (!ok) next(false);
return;
}
// 补全用户信息(旧会话可能只有 token 没有 userInfo,或迁移后 userInfo 缺失 id,
// 会导致菜单等接口报「用户ID不存在」)。
// 令牌失效时 ensureUserInfo 会清空登录态并返回 null,此时重新登录。
const info = await ensureUserInfo();
if (!info) {
// 只有登录态确实被清空(确认令牌失效)才重新授权;userinfo 接口临时故障
// 时保留 token 放行,避免「登录成功 → 接口抖动 → 回认证中心」的循环。
if (localStorage.getItem("token")) {
next();
return;
@@ -446,7 +392,6 @@ router.beforeEach(async (to, from, next) => {
if (!dynamicRoutesAdded) {
await loadAndAddDynamicRoutes();
// 路由加载后重新导航,确保路由匹配正确
next({ path: to.path, replace: true });
return;
}