From 95a503fee52795bf50a45b4fc89f0b71fba6dc0a Mon Sep 17 00:00:00 2001
From: “mitao” <“2763622819@qq.com”>
Date: 星期五, 27 三月 2026 10:45:17 +0800
Subject: [PATCH] feat:首页帐号设计、重置密码
---
tcm-training-admin/src/utils/utils.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 1 deletions(-)
diff --git a/tcm-training-admin/src/utils/utils.js b/tcm-training-admin/src/utils/utils.js
index ac3ef48..7d84455 100644
--- a/tcm-training-admin/src/utils/utils.js
+++ b/tcm-training-admin/src/utils/utils.js
@@ -1,6 +1,57 @@
import { uploadFile } from './service'
import CryptoJS from 'crypto-js';
+const normalizePath = (path) => {
+ if (typeof path !== 'string') {
+ return '';
+ }
+ if (path.length > 1 && path.endsWith('/')) {
+ return path.replace(/\/+$/, '');
+ }
+ return path;
+};
+
+const isRouteMatch = (targetPath, routePath) => {
+ const normalizedTargetPath = normalizePath(targetPath);
+ const normalizedRoutePath = normalizePath(routePath);
+ return (
+ normalizedTargetPath === normalizedRoutePath ||
+ normalizedTargetPath.startsWith(`${normalizedRoutePath}/`)
+ );
+};
+
+const flattenRoutes = (routes = [], parentAuthority) => {
+ return routes.reduce((accumulator, route) => {
+ const routeAuthority = route.authority || parentAuthority;
+ accumulator.push({
+ path: normalizePath(route.path),
+ authority: routeAuthority,
+ });
+ if (Array.isArray(route.routes) && route.routes.length > 0) {
+ accumulator.push(...flattenRoutes(route.routes, routeAuthority));
+ }
+ return accumulator;
+ }, []);
+};
+
+export const isUrl = (path) => {
+ if (typeof path !== 'string' || !path) {
+ return false;
+ }
+ return /^(https?:\/\/)((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3}))(:\d+)?(\/[^\s]*)?$/i.test(
+ path,
+ );
+};
+
+export const getRouteAuthority = (path, routeData = []) => {
+ const matchedRoute = flattenRoutes(routeData)
+ .filter((route) => route.path && isRouteMatch(path, route.path))
+ .sort((prev, next) => next.path.length - prev.path.length)
+ .find((route) => route.authority !== undefined);
+
+ return matchedRoute?.authority;
+};
+
export const customRequest = (params, type) => {
const { file, onSuccess, onError } = params;
uploadFile(file)
@@ -94,4 +145,4 @@
if (!cipherText) return null;
const bytes = CryptoJS.AES.decrypt(cipherText, 'your-secret-key-123');
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
-};
\ No newline at end of file
+};
--
Gitblit v1.7.1