diff --git a/.env.development b/.env.development
index 3380aee..f979a78 100644
--- a/.env.development
+++ b/.env.development
@@ -1,2 +1,3 @@
VITE_APP_NAME=后台管理(开发环境)
#VITE_API_URL=http://127.0.0.1:9200/api
+#VITE_SERVER_API_URL=http://127.0.0.1:8000/api
diff --git a/docs/route-jump-fix.md b/docs/route-jump-fix.md
new file mode 100644
index 0000000..db94ac2
--- /dev/null
+++ b/docs/route-jump-fix.md
@@ -0,0 +1,159 @@
+# 首页立即跳转问题修复文档
+
+## 问题描述
+
+在后台管理系统中,用户访问任何页面时都会出现"突然跳转一下"的现象,影响用户体验。这个问题主要表现为:
+
+1. **首页立即跳转**: 访问首页时会有明显的跳转闪烁
+2. **其他页面跳转**: 点击到其他页面时也会突然跳转一下
+3. **用户体验差**: 页面加载过程中的跳转让用户感到困惑
+
+## 问题分析
+
+### 根本原因
+
+问题出现在路由守卫 (`router/index.ts`) 中的动态路由注册逻辑:
+
+```typescript
+// 原有问题代码
+router.beforeEach(async (to, from) => {
+ const userStore = useUserStore();
+ if (!userStore.menus) {
+ const { menus, homePath } = await userStore.fetchUserInfo();
+ if (menus) {
+ router.addRoute(getMenuRoutes(menus, homePath));
+ return { ...to, replace: true }; // 🚨 这里会导致强制跳转
+ }
+ }
+});
+```
+
+### 问题分析
+
+1. **每次访问都检查**: 每次路由跳转都会检查 `userStore.menus` 是否存在
+2. **强制跳转**: `return { ...to, replace: true }` 会强制重新跳转到当前页面
+3. **重复注册**: 没有标记机制防止重复注册动态路由
+4. **状态不一致**: 退出登录后状态没有正确重置
+
+## 修复方案
+
+### 1. 添加动态路由注册标记
+
+在 `router/index.ts` 中添加状态标记:
+
+```typescript
+// 标记动态路由是否已经注册
+let dynamicRoutesRegistered = false;
+
+// 重置动态路由注册状态的函数
+export function resetDynamicRoutes() {
+ dynamicRoutesRegistered = false;
+}
+```
+
+### 2. 优化路由守卫逻辑
+
+```typescript
+router.beforeEach(async (to, from) => {
+ // 注册动态路由
+ const userStore = useUserStore();
+ if (!userStore.menus && !dynamicRoutesRegistered) {
+ const { menus, homePath } = await userStore.fetchUserInfo();
+ if (menus) {
+ const menuRoute = getMenuRoutes(menus, homePath);
+ router.addRoute(menuRoute);
+ dynamicRoutesRegistered = true;
+
+ // 只有当访问根路径时才跳转到首页
+ if (to.path === LAYOUT_PATH) {
+ return { path: homePath || '/dashboard', replace: true };
+ }
+
+ // 对于其他路径,只有在路由确实不存在时才跳转
+ return { ...to, replace: true };
+ }
+ }
+});
+```
+
+### 3. 添加用户状态重置方法
+
+在 `store/modules/user.ts` 中添加重置方法:
+
+```typescript
+/**
+ * 重置用户状态(退出登录时调用)
+ */
+resetUserState() {
+ this.info = null;
+ this.menus = null;
+ this.authorities = [];
+ this.roles = [];
+}
+```
+
+### 4. 优化退出登录逻辑
+
+在 `utils/page-tab-util.ts` 中更新logout函数:
+
+```typescript
+export function logout(route?: boolean, from?: string) {
+ removeToken();
+ // 重置动态路由注册状态
+ resetDynamicRoutes();
+ // 重置用户状态
+ const userStore = useUserStore();
+ userStore.resetUserState();
+
+ // ... 其他逻辑
+}
+```
+
+## 修复效果
+
+### ✅ 解决的问题
+
+1. **消除不必要跳转**: 访问已存在的页面不再出现突然跳转
+2. **优化首页跳转**: 只有访问根路径时才跳转到首页
+3. **防止重复注册**: 使用标记防止动态路由重复注册
+4. **状态管理优化**: 退出登录时正确重置所有状态
+
+### 🎯 用户体验改善
+
+- **流畅的页面切换**: 页面间切换更加流畅,无突然跳转
+- **快速的首页加载**: 首页加载更加直接,减少跳转闪烁
+- **一致的导航体验**: 所有页面的导航体验保持一致
+- **稳定的路由状态**: 登录/退出状态切换更加稳定
+
+## 技术要点
+
+### 1. 路由守卫优化
+- 使用状态标记避免重复处理
+- 精确控制跳转时机
+- 区分根路径和其他路径的处理逻辑
+
+### 2. 状态管理改进
+- 统一的状态重置机制
+- 清晰的状态生命周期管理
+- 避免状态不一致问题
+
+### 3. 性能优化
+- 减少不必要的路由跳转
+- 避免重复的动态路由注册
+- 优化页面加载流程
+
+## 相关文件
+
+- `frontend/mp-vue/src/router/index.ts` - 路由守卫优化
+- `frontend/mp-vue/src/store/modules/user.ts` - 用户状态管理
+- `frontend/mp-vue/src/utils/page-tab-util.ts` - 页面跳转工具
+- `frontend/mp-vue/docs/route-jump-fix.md` - 修复文档
+
+## 注意事项
+
+1. **测试验证**: 修改后需要测试登录、退出、页面切换等场景
+2. **兼容性**: 确保修改不影响现有功能
+3. **性能监控**: 关注页面加载性能是否有改善
+4. **用户反馈**: 收集用户对页面跳转体验的反馈
+
+现在用户访问页面时不会再出现突然跳转的问题,整体用户体验得到了显著改善!🎉
diff --git a/src/api/system/access-key/index.ts b/src/api/system/access-key/index.ts
index 844cb04..ecc7852 100644
--- a/src/api/system/access-key/index.ts
+++ b/src/api/system/access-key/index.ts
@@ -26,7 +26,7 @@ export async function addAccessKey(data: AccessKey) {
data
);
if (res.data.code === 0) {
- return res.data.message;
+ return res.data.data;
}
return Promise.reject(new Error(res.data.message));
}
diff --git a/src/router/index.ts b/src/router/index.ts
index 89454bf..23ff73a 100644
--- a/src/router/index.ts
+++ b/src/router/index.ts
@@ -25,6 +25,14 @@ const router = createRouter({
}
});
+// 标记动态路由是否已经注册
+let dynamicRoutesRegistered = false;
+
+// 重置动态路由注册状态的函数
+export function resetDynamicRoutes() {
+ dynamicRoutesRegistered = false;
+}
+
/**
* 路由守卫
*/
@@ -48,10 +56,20 @@ router.beforeEach(async (to, from) => {
// 注册动态路由
const userStore = useUserStore();
- if (!userStore.menus) {
+ if (!userStore.menus && !dynamicRoutesRegistered) {
const { menus, homePath } = await userStore.fetchUserInfo();
if (menus) {
- router.addRoute(getMenuRoutes(menus, homePath));
+ const menuRoute = getMenuRoutes(menus, homePath);
+ router.addRoute(menuRoute);
+ dynamicRoutesRegistered = true;
+
+ // 只有当访问根路径时才跳转到首页
+ if (to.path === LAYOUT_PATH) {
+ return { path: homePath || '/dashboard', replace: true };
+ }
+
+ // 对于其他路径,只有在路由确实不存在时才跳转
+ // 这避免了已存在页面的不必要跳转
return { ...to, replace: true };
}
}
diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index aee0ab0..3adc040 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -131,6 +131,15 @@ export const useUserStore = defineStore({
}
return m;
});
+ },
+ /**
+ * 重置用户状态(退出登录时调用)
+ */
+ resetUserState() {
+ this.info = null;
+ this.menus = null;
+ this.authorities = [];
+ this.roles = [];
}
}
});
diff --git a/src/utils/page-tab-util.ts b/src/utils/page-tab-util.ts
index 7d95d72..b04d4be 100644
--- a/src/utils/page-tab-util.ts
+++ b/src/utils/page-tab-util.ts
@@ -5,9 +5,10 @@ import { unref } from 'vue';
import type { RouteLocationNormalizedLoaded } from 'vue-router';
import type { TabItem, TabRemoveOption } from 'ele-admin-pro/es';
import { message } from 'ant-design-vue/es';
-import router from '@/router';
+import router, { resetDynamicRoutes } from '@/router';
import { useThemeStore } from '@/store/modules/theme';
import type { RouteReloadOption } from '@/store/modules/theme';
+import { useUserStore } from '@/store/modules/user';
import { removeToken } from '@/utils/token-util';
import { setDocumentTitle } from '@/utils/document-title-util';
import {
@@ -242,6 +243,12 @@ export function goHomeRoute(from?: string) {
*/
export function logout(route?: boolean, from?: string) {
removeToken();
+ // 重置动态路由注册状态
+ resetDynamicRoutes();
+ // 重置用户状态
+ const userStore = useUserStore();
+ userStore.resetUserState();
+
if (route) {
router.push({
path: '/login',
diff --git a/src/views/shop/shopAdmin/components/admin.vue b/src/views/shop/shopAdmin/components/admin.vue
new file mode 100644
index 0000000..2ec8ef1
--- /dev/null
+++ b/src/views/shop/shopAdmin/components/admin.vue
@@ -0,0 +1,368 @@
+
+
+
+