fix:完善相关页面

This commit is contained in:
liangdong
2025-12-30 19:08:31 +08:00
parent fa4de6f71f
commit bfb6a1e500
22 changed files with 1886 additions and 23 deletions

52
src/mock/auth.ts Normal file
View File

@@ -0,0 +1,52 @@
/**
* 登录相关 Mock 数据
*/
/**
* Mock 登录响应
*/
export const getMockLoginResponse = (username: string, password: string) => {
// 模拟登录验证
if (username && password) {
return {
code: 0,
data: {
accessToken: 'mock_access_token_' + Date.now(),
refreshToken: 'mock_refresh_token_' + Date.now(),
expiresIn: 7200, // 2小时
userInfo: {
id: 1,
username: username,
name: username === 'admin' ? '管理员' : '普通用户',
role: username === 'admin' ? 'admin' : 'user',
avatar: '',
},
},
msg: '登录成功',
}
} else {
return {
code: 400,
data: null,
msg: '用户名或密码不能为空',
}
}
}
/**
* Mock 用户信息响应
*/
export const getMockUserInfoResponse = () => {
return {
code: 0,
data: {
id: 1,
username: 'admin',
name: '管理员',
role: 'admin',
avatar: '',
},
msg: '获取用户信息成功',
}
}

97
src/mock/index.ts Normal file
View File

@@ -0,0 +1,97 @@
/**
* Mock 数据管理
* 用于开发阶段模拟后端接口返回的数据
*/
import { getMockMenuResponse } from './menu'
import { getMockLoginResponse, getMockUserInfoResponse } from './auth'
// 是否启用 Mock可以通过环境变量控制
export const ENABLE_MOCK = import.meta.env.VITE_USE_MOCK === 'true' || import.meta.env.DEV
/**
* Mock API 响应映射
* key: API 路径
* value: 返回的 Mock 数据函数
*/
const mockApiMap: Record<string, (params?: any, data?: any) => any> = {
'/api/menus': () => getMockMenuResponse(),
'/api/auth/login': (_params?: any, data?: any) => {
return getMockLoginResponse(data?.username || '', data?.password || '')
},
'/api/user/info': () => getMockUserInfoResponse(),
// 可以在这里添加更多的 mock 接口
// '/api/user/list': getMockUserList,
}
/**
* 获取 Mock 数据
* @param url API 路径
* @param params 请求参数GET
* @param data 请求体POST/PUT
* @returns Mock 数据或 null
*/
export const getMockData = (url: string, params?: any, data?: any): any => {
if (!ENABLE_MOCK || !url) {
return null
}
// 精确匹配
if (mockApiMap[url]) {
return mockApiMap[url](params, data)
}
// 模糊匹配(支持带查询参数的 URL
const urlWithoutQuery = url.split('?')[0]
if (urlWithoutQuery && mockApiMap[urlWithoutQuery]) {
return mockApiMap[urlWithoutQuery](params, data)
}
return null
}
/**
* 检查是否应该使用 Mock 数据
* @param url API 路径
* @returns 是否应该使用 Mock
*/
export const shouldUseMock = (url: string): boolean => {
if (!ENABLE_MOCK || !url) {
return false
}
// 精确匹配
if (mockApiMap[url]) {
return true
}
// 模糊匹配(支持带查询参数的 URL
const urlWithoutQuery = url.split('?')[0]
return !!(urlWithoutQuery && mockApiMap[urlWithoutQuery])
}
/**
* 添加 Mock 接口
* @param url API 路径
* @param mockFn Mock 数据函数
*/
export const addMockApi = (url: string, mockFn: (params?: any, data?: any) => any) => {
mockApiMap[url] = mockFn
}
/**
* 移除 Mock 接口
* @param url API 路径
*/
export const removeMockApi = (url: string) => {
delete mockApiMap[url]
}
export default {
getMockData,
shouldUseMock,
addMockApi,
removeMockApi,
ENABLE_MOCK,
}

309
src/mock/menu.ts Normal file
View File

@@ -0,0 +1,309 @@
/**
* 菜单路由 Mock 数据
* 用于开发阶段模拟后端返回的菜单数据
*/
export interface MockMenuRoute {
path: string;
name?: string;
component?: string;
meta?: {
title?: string;
icon?: string;
requiresAuth?: boolean;
roles?: string[];
[key: string]: any;
};
children?: MockMenuRoute[];
}
/**
* Mock 菜单数据
* 根据实际后端接口返回的数据格式进行配置
*/
export const mockMenuData: MockMenuRoute[] = [
{
path: "/home",
name: "Home",
component: "Home", // 对应 @/pages/Home/index.vue
meta: {
title: "首页",
icon: "HomeFilled",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "business",
path: "/business",
meta: {
title: "商机管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [
{
name: "clue",
path: "clue",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "线索管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "customer",
path: "customer",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "客户管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "studio",
path: "studio",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "游戏与工作室",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "businessmanage",
path: "businessmanage",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "商机管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
],
},
{
name: "contract",
path: "/contract",
meta: {
title: "合同管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [
{
name: "income",
path: "income",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "收入合同",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
],
},
{
name: "project",
path: "/project",
meta:{
title: "项目管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [
{
name: "requirement",
path: "requirement",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "需求管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "projectmanage",
path: "projectmanage",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "项目管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "task",
path: "task",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "任务管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "work",
path: "work",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "工时管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
],
},
{
name: "team",
path: "/team",
meta:{
title: "团队管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [],
},
{
name: "recruit",
path: "/recruit",
meta:{
title: "招聘管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [
{
name: "resume",
path: "resume",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "流程管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "push",
path: "push",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "推送管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "job",
path: "job",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "主场岗位",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
],
},
{
name: "dashboard",
title: "dashboard",
path: "/stage",
meta: {
title: "后台管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
children: [
{
path: "flow",
name: "flow",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "流程管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "organization",
component: "@/pages/StageManage/organization/index.vue",
path: "organization",
meta: {
title: "组织管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "personnel",
path: "personnel",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "人员管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
},
},
{
name: "permission",
path: "permission",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "权限管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
}
},
{
name: "dict",
path: "dict",
component: "@/pages/StageManage/organization/index.vue",
meta: {
title: "字典管理",
icon: "",
requiresAuth: true,
roles: ["admin", "user"],
}
},
],
},
];
/**
* 获取 Mock 菜单数据的响应格式
* 模拟后端接口返回的数据结构
*/
export const getMockMenuResponse = () => {
return {
code: 0,
data: mockMenuData,
msg: "获取菜单成功",
};
};