Commit d00917d4 by Lin

fix:路由配置优化/冗余代码去除

1 parent 8b00fbe1
......@@ -2,13 +2,8 @@
* 路由和菜单相关 API
*/
import type { MenuItem, TopMenuItem } from '@/types/menu';
import type { RouteRecordRaw } from 'vue-router';
const ROUTER_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
// import { get } from '@/utils/request'; // 取消注释以使用真实 API
import { fetchMicroAppConfig } from '@/config/center';
/**
* 路由配置接口(从 API 返回的数据结构)
*/
......@@ -61,11 +56,7 @@ export interface MenuConfig {
* 获取路由和菜单配置
* @returns Promise<路由和菜单配置>
*/
export const getRouteConfig = async () => {
const response = await fetch(ROUTER_URL);
const result = await response.json();
return result;
};
export const getRouteConfig = fetchMicroAppConfig;
/**
* 将 API 返回的路由配置转换为 Vue Router 路由格式
......
......@@ -6,6 +6,12 @@ import { Request, Defaults } from 'glsk-toolkit';
import { getToken, clearAuth } from '@/utils/auth';
import { ElMessage } from 'element-plus';
import { localCache } from '@/utils/storage';
import {
CONFIG_CENTER_URL as CONFIG_URL,
ROUTER_CONFIG_URL as ROUTER_URL,
CONFIG_CACHE_KEY,
ROUTER_CONFIG_CACHE_KEY,
} from './constants'; // 导入常量配置
// 配置数据
let baseConfig: any = {};
// GSC API 请求实例(模块级单例,不挂载到 window)
......@@ -15,17 +21,6 @@ let gscApiInstance: null | Request = null;
let configReadyPromise: null | Promise<void> = null;
let configReadyResolve: (() => void) | null = null;
// 公共基础配置请求 URL
const CONFIG_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
// 路由菜单配置
const ROUTER_URL =
'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
// 缓存 key
const CONFIG_CACHE_KEY = 'venus_base_config';
const ROUTER_CONFIG_CACHE_KEY = 'venus_router_config';
/**
* @desc 与waitForConfigReady方法配套使用,
* @desc 用于创建一个“等待机制”(Promise)
......@@ -54,7 +49,6 @@ export async function fetchMicroAppConfig(): Promise<any> {
// 缓存不存在,从远程获取
const response = await fetch(ROUTER_URL);
console.log('AAAresponse',response);
const result = await response.json();
// 保存到本地缓存
......
/**
* 应用级别常量配置
* 用于管理 URL、缓存 key 等配置项
*/
// ==================== 配置中心相关 ====================
/** 公共基础配置请求 URL */
export const CONFIG_CENTER_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-base-system-config';
/** 路由菜单配置请求 URL */
export const ROUTER_CONFIG_URL = 'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=venus-agentic-router';
// ==================== 缓存 Key 配置 ====================
/** 基础配置缓存 key */
export const CONFIG_CACHE_KEY = 'venus_base_config';
/** 路由配置缓存 key */
export const ROUTER_CONFIG_CACHE_KEY = 'venus_router_config';
{
// 系统名字
"sysName": '汽车销售超级孪生智能体',
// 系统说明
"subName": '',
// 是否需要注册-true;false
"env": "dev",
// 是否需要配置账号权限;true-有权限,从后台获取权限信息;false-无需权限
"hasAuth": true,
"gsc": {
"baseURL": "http://gsc.dev.glsx.com.cn/gsc-agent-manage-facade",
"appId": "Web_DJia",
"appSecret": "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
"timeout": 30e3,
"sentry": {
enable: false,
dsn: "https://be4fb79a912b4c34a5d1c539a1618978@sentry.glsx.com.cn/1"
},
"security": {
enable: false,
address: "https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsx-common" // 自定义地址
},
"response": {
"code_key": "code", // 或者你后台实际使用的状态码字段名
"code_success_value": "0",
"data_key": "data",
"errId": "code",
"errId_logout_value": "401"
},
session: {
requiresSession: false,
sessionId: 'd5629aee-28c7-4def-a8fa-95d76c978dc7',
},
headers: {
'X-App-Version': '1.0.0'
},
retry: {
retries: 2,
retryDelay: 500,
shouldResetTimeout: false
},
}
}
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';
import { ElMessage } from 'element-plus';
import { getRouteConfig, transformMenuConfig } from '@/api/route';
import { getRouteConfig, transformMenuConfig, type MenuConfig } from '@/api/route';
import { getMicroAppByPath } from '@/qiankun/apps';
import { useAppStore, useMenuStore, useUserStore } from '@/stores';
import { getToken } from '@/utils/auth';
......@@ -136,11 +134,18 @@ export async function loadDynamicRoutes() {
isLoadingRoutes = true;
// 调用 API 获取路由和菜单配置
const response = await getRouteConfig();
if (response.code === 200 && response.data) {
const routerData: MenuConfig = {
topMenus: [],
routes: []
}
response.data.microApps.forEach((item: { routerList: any; routes: any; }) => {
routerData.topMenus.push(item.routerList as any);
routerData.routes.push(item.routes as any);
});
// 此处需要对路由配置数据进行格式化处理
const { topMenus, routes } = transformMenuConfig(response.data);
const { topMenus, routes } = transformMenuConfig(routerData);
// 更新菜单 store
menuStore.setTopMenus(topMenus);
......
......@@ -6,6 +6,9 @@ export default defineConfig({
description: '现代化的 Vue3 中后台管理系统框架',
lang: 'zh-CN',
// 忽略死链接检查(用于本地开发服务器链接)
ignoreDeadLinks: true,
// 主题配置
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
......
......@@ -552,5 +552,4 @@ app.use(VueGtag, {
## 下一步
- [环境变量](/guide/env-variables) - 了解环境变量配置
- [性能优化](/guide/performance) - 学习性能优化技巧
根据我对你的 monorepo 仓库的分析,你的项目已经配置了一套完善的 git 管理方案。这里为你详细介绍如何统一管理子应用的提交和改动记录:
📋 当前仓库已有的配置
## 📋 当前仓库已有的配置
你的仓库已经配置了以下工具:
commitlint + czg(commitizen-git) - 规范化提交信息
lefthook - Git hooks 管理
changeset - 版本管理和变更日志
pnpm workspace + turbo - Monorepo 构建管理
🎯 推荐的子应用提交管理方案
1. 使用规范化提交信息(已配置)
- commitlint + czg(commitizen-git) - 规范化提交信息
- lefthook - Git hooks 管理
- changeset - 版本管理和变更日志
- pnpm workspace + turbo - Monorepo 构建管理
## 🎯 推荐的子应用提交管理方案
### 1. 使用规范化提交信息(已配置)
你的仓库已配置了 commitlint,提交时使用 scope 来标识具体的子应用:
# 使用交互式提交命令pnpm commit# 提交格式示例:feat(scrm-base): 添加用户管理功能fix(micro-app-template): 修复路由跳转问题chore(scrm-base): 更新依赖包
```bash
# 使用交互式提交命令
pnpm commit
# 提交格式示例:
feat(scrm-base): 添加用户管理功能
fix(micro-app-template): 修复路由跳转问题
chore(scrm-base): 更新依赖包
```
查看你的配置文件,系统会自动检测改动的包,并提供可选的 scope 列表。
2. 查看特定子应用的提交历史
# 查看 scrm-base 应用的所有提交git log --all --oneline -- apps/frontend-micro/scrm-base# 查看详细提交信息git log --all -- apps/frontend-micro/scrm-base# 只查看提交信息(不显示 diff)git log --oneline --grep="scrm-base"# 查看某个应用最近10次提交git log --oneline -n 10 -- apps/frontend-micro/scrm-base# 查看某个时间段内的提交git log --since="2024-01-01" --until="2024-12-31" -- apps/frontend-micro/scrm-base# 生成变更统计git log --stat -- apps/frontend-micro/scrm-base
3. 使用 Changeset 管理变更(已配置)
### 2. 查看特定子应用的提交历史
```bash
# 查看 scrm-base 应用的所有提交
git log --all --oneline -- apps/frontend-micro/scrm-base
# 查看详细提交信息
git log --all -- apps/frontend-micro/scrm-base
# 只查看提交信息(不显示 diff)
git log --oneline --grep="scrm-base"
# 查看某个应用最近10次提交
git log --oneline -n 10 -- apps/frontend-micro/scrm-base
# 查看某个时间段内的提交
git log --since="2024-01-01" --until="2024-12-31" -- apps/frontend-micro/scrm-base
# 生成变更统计
git log --stat -- apps/frontend-micro/scrm-base
```
### 3. 使用 Changeset 管理变更(已配置)
当你修改某个子应用后,创建 changeset 来记录变更:
# 创建变更记录pnpm changeset# 系统会提示你:# 1. 选择受影响的包(子应用)# 2. 选择版本变更类型(major/minor/patch)# 3. 编写变更说明
4. 实用的 Git 别名配置
```bash
# 创建变更记录
pnpm changeset
# 系统会提示你:
# 1. 选择受影响的包(子应用)
# 2. 选择版本变更类型(major/minor/patch)
# 3. 编写变更说明
```
### 4. 实用的 Git 别名配置
在项目根目录或全局 .gitconfig 中添加:
# 添加到 .git/config 或 ~/.gitconfig[alias] # 查看指定应用的提交日志 app-log = "!f() { git log --oneline --all -- apps/frontend-micro/$1; }; f" # 查看指定应用的详细变更 app-diff = "!f() { git diff -- apps/frontend-micro/$1; }; f" # 查看指定应用未提交的变更 app-status = "!f() { git status -- apps/frontend-micro/$1; }; f" # 只暂存指定应用的变更 app-add = "!f() { git add apps/frontend-micro/$1; }; f"
```ini
# 添加到 .git/config 或 ~/.gitconfig
[alias]
# 查看指定应用的提交日志
app-log = "!f() { git log --oneline --all -- apps/frontend-micro/$1; }; f"
# 查看指定应用的详细变更
app-diff = "!f() { git diff -- apps/frontend-micro/$1; }; f"
# 查看指定应用未提交的变更
app-status = "!f() { git status -- apps/frontend-micro/$1; }; f"
# 只暂存指定应用的变更
app-add = "!f() { git add apps/frontend-micro/$1; }; f"
```
使用示例:
git app-log scrm-basegit app-diff scrm-base
5. 查看子应用的文件变更统计
# 查看 scrm-base 应用的贡献者统计git shortlog -sn -- apps/frontend-micro/scrm-base# 查看代码行数变更git log --numstat --pretty="%H" -- apps/frontend-micro/scrm-base | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'# 查看最近修改的文件git log --name-only --pretty="" -- apps/frontend-micro/scrm-base | sort | uniq
6. 创建子应用发布标签
# 为特定子应用创建标签git tag -a scrm-base-v1.0.0 -m "scrm-base: 发布 v1.0.0"# 推送标签git push origin scrm-base-v1.0.0# 查看某个应用的所有标签git tag -l "scrm-base-*"
7. 生成子应用变更日志
创建一个脚本 scripts/changelog.sh:
#!/bin/bashAPP_NAME=$1OUTPUT_FILE="apps/frontend-micro/$APP_NAME/CHANGELOG.md"echo "# Changelog for $APP_NAME" > $OUTPUT_FILEecho "" >> $OUTPUT_FILEgit log --pretty=format:"- %s (%h) - %an, %ar" -- apps/frontend-micro/$APP_NAME >> $OUTPUT_FILE
```bash
git app-log scrm-base
git app-diff scrm-base
```
### 5. 查看子应用的文件变更统计
```bash
# 查看 scrm-base 应用的贡献者统计
git shortlog -sn -- apps/frontend-micro/scrm-base
# 查看代码行数变更
git log --numstat --pretty="%H" -- apps/frontend-micro/scrm-base | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
# 查看最近修改的文件
git log --name-only --pretty="" -- apps/frontend-micro/scrm-base | sort | uniq
```
### 6. 创建子应用发布标签
```bash
# 为特定子应用创建标签
git tag -a scrm-base-v1.0.0 -m "scrm-base: 发布 v1.0.0"
# 推送标签
git push origin scrm-base-v1.0.0
# 查看某个应用的所有标签
git tag -l "scrm-base-*"
```
### 7. 生成子应用变更日志
创建一个脚本 `scripts/changelog.sh`:
```bash
#!/bin/bash
APP_NAME=$1
OUTPUT_FILE="apps/frontend-micro/$APP_NAME/CHANGELOG.md"
echo "# Changelog for $APP_NAME" > $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
git log --pretty=format:"- %s (%h) - %an, %ar" -- apps/frontend-micro/$APP_NAME >> $OUTPUT_FILE
```
使用:
```bash
bash scripts/changelog.sh scrm-base
8. 使用过滤分支工作(高级)
```
### 8. 使用过滤分支工作(高级)
如果需要更系统的管理,可以使用 git sparse-checkout:
# 只检出特定子应用(用于性能优化)git sparse-checkout init --conegit sparse-checkout set apps/frontend-micro/scrm-base
📊 推荐的工作流程
# 1. 修改代码后,查看当前应用的改动git status apps/frontend-micro/scrm-base# 2. 使用规范化提交pnpm commit# 选择 type: feat/fix/etc# 选择 scope: scrm-base# 填写描述# 3. 创建 changeset(可选,用于版本发布)pnpm changeset# 4. 推送代码git push# 5. 查看该应用的提交历史git log --oneline --all -- apps/frontend-micro/scrm-base
🔍 查看跨应用的影响
# 查看同时修改了多个应用的提交git log --oneline --all --format="%h %s" | grep -E "(scrm-base|micro-app-template)"# 查看某次提交影响了哪些应用git show <commit-hash> --stat | grep "apps/frontend-micro"
你的仓库配置已经很完善了,只需要按照规范使用 pnpm commit 命令并正确选择 scope,就能很好地管理各个子应用的提交记录。
```bash
# 只检出特定子应用(用于性能优化)
git sparse-checkout init --cone
git sparse-checkout set apps/frontend-micro/scrm-base
```
## 📊 推荐的工作流程
```bash
# 1. 修改代码后,查看当前应用的改动
git status apps/frontend-micro/scrm-base
# 2. 使用规范化提交
pnpm commit
# 选择 type: feat/fix/etc
# 选择 scope: scrm-base
# 填写描述
# 3. 创建 changeset(可选,用于版本发布)
pnpm changeset
# 4. 推送代码
git push
# 5. 查看该应用的提交历史
git log --oneline --all -- apps/frontend-micro/scrm-base
```
## 🔍 查看跨应用的影响
```bash
# 查看同时修改了多个应用的提交
git log --oneline --all --format="%h %s" | grep -E "(scrm-base|micro-app-template)"
# 查看某次提交影响了哪些应用
git show <commit-hash> --stat | grep "apps/frontend-micro"
```
你的仓库配置已经很完善了,只需要按照规范使用 `pnpm commit` 命令并正确选择 scope,就能很好地管理各个子应用的提交记录。
......@@ -216,7 +216,7 @@ const USE_MOCK_API = true; // true: 使用模拟API, false: 使用真实API
创建 `.env.development` 文件:
```env
```bash
VITE_API_BASE_URL=http://your-api-server.com/api
```
......
......@@ -77,7 +77,7 @@ const USE_MOCK_API = false; // 使用真实 API
创建或修改 `.env.development` 文件:
```env
```bash
# API 基础路径
VITE_API_BASE_URL=http://your-api-server.com/api
```
......
......@@ -212,7 +212,6 @@ prefetch: true // 预加载所有微应用
- [qiankun 官方文档](https://qiankun.umijs.org/zh)
- [qiankun 最佳实践](https://qiankun.umijs.org/zh/guide/tutorial)
- [微应用开发指南](../../../micro-app-template/PROJECT_OVERVIEW.md)
## 🤝 贡献指南
......
......@@ -210,7 +210,7 @@ const USE_MOCK_API = false; // 改为 false
### 配置后端地址
创建 `.env.development`:
```env
```bash
VITE_API_BASE_URL=http://your-backend-api.com/api
```
......
......@@ -175,7 +175,7 @@ const USE_MOCK_API = false; // 改为 false
创建 `.env.development` 文件(如果没有):
```env
```bash
VITE_API_BASE_URL=http://your-backend-server.com/api
```
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!