feat: mock
This commit is contained in:
parent
63894ee4c8
commit
197c020a59
|
@ -413,55 +413,36 @@ export interface LoginRes {
|
|||
提供全局接口数据 mock 功能,避免因为调试而修改请求代码导致出现问题,按功能模块划分文件,通过`index.ts`暴露,示例如下:
|
||||
|
||||
```typescript
|
||||
import Mock from 'mockjs';
|
||||
import './user';
|
||||
import '@/views/dashboard/workplace/mock';
|
||||
import MOCK from '@/utils/setup-mock';
|
||||
|
||||
Mock.setup({
|
||||
timeout: '600-1000',
|
||||
});
|
||||
import './user';
|
||||
```
|
||||
|
||||
```typescript
|
||||
import Mock from 'mockjs';
|
||||
import setupMock, { successResponseWrap, failResponseWrap } from '@/utils/setup-mock';
|
||||
import { isLogin } from '@/utils/auth';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
import { MockParams } from '@/types/mock';
|
||||
|
||||
setupMock({
|
||||
setup() {
|
||||
// 用户信息
|
||||
Mock.mock(new RegExp('/api/user/info'), () => {
|
||||
if (isLogin()) {
|
||||
const role = window.localStorage.getItem('userRole') || 'admin';
|
||||
return successResponseWrap({
|
||||
name: '王立群',
|
||||
avatar: '//lf1-xgcdn-tos.pstatp.com/obj/vcloud/vadmin/start.8e0e4855ee346a46ccff8ff3e24db27b.png',
|
||||
email: 'wangliqun@email.com',
|
||||
job: 'frontend',
|
||||
jobName: '前端艺术家',
|
||||
organization: 'Frontend',
|
||||
organizationName: '前端',
|
||||
location: 'beijing',
|
||||
locationName: '北京',
|
||||
introduction: '人潇洒,性温存',
|
||||
personalWebsite: 'https://www.arco.design',
|
||||
phone: '150****0000',
|
||||
registrationDate: '2013-05-10 12:10:00',
|
||||
accountId: '15012312300',
|
||||
certification: 1,
|
||||
role,
|
||||
});
|
||||
}
|
||||
return failResponseWrap(null, '未登录', 50008);
|
||||
});
|
||||
// 登出
|
||||
Mock.mock(new RegExp('/api/user/logout'), () => {
|
||||
return successResponseWrap(null);
|
||||
});
|
||||
const getProjectList = () => {
|
||||
return [
|
||||
{
|
||||
id: '0283f238hf2',
|
||||
num: 0,
|
||||
organizationId: 'v3v4h434c3',
|
||||
name: '发了多少',
|
||||
description: 'string',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
updateUser: 'string',
|
||||
createUser: 'string',
|
||||
deleteTime: 0,
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
enable: true,
|
||||
},
|
||||
});
|
||||
];
|
||||
};
|
||||
|
||||
mock(RequestEnum.GET, '/system/project/list', getProjectList(), 200);
|
||||
```
|
||||
|
||||
<a name="QgxDQ"></a>
|
||||
|
@ -557,10 +538,11 @@ export default i18n;
|
|||
<a name="RwVcu"></a>
|
||||
|
||||
## -theme 主题配置
|
||||
1. 去Desing Lab 创建主题 https://arco.design/themes/home
|
||||
|
||||
1. 去 Desing Lab 创建主题 https://arco.design/themes/home
|
||||
2. 以`ms-theme-` 命名为开头
|
||||
3. 点击页面的配置主题
|
||||
**“CSS 变量” + “Tailwind 配置变量” + “基于 css 变量自行计算混合色覆盖 arco-theme 变量”**
|
||||
**“CSS 变量” + “Tailwind 配置变量” + “基于 css 变量自行计算混合色覆盖 arco-theme 变量”**
|
||||
|
||||
## -.env.\*环境变量配置
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
"dependencies": {
|
||||
"@7polo/kity": "2.0.8",
|
||||
"@7polo/kityminder-core": "1.4.53",
|
||||
"@arco-design/web-vue": "^2.47.0",
|
||||
"@arco-design/web-vue": "^2.48.0",
|
||||
"@arco-themes/vue-ms-theme-default": "^0.0.17",
|
||||
"@form-create/arco-design": "^3.1.21",
|
||||
"@vueuse/core": "^9.13.0",
|
||||
|
@ -49,6 +49,7 @@
|
|||
"lodash": "^4.17.21",
|
||||
"lodash-es": "^4.17.21",
|
||||
"mitt": "^3.0.0",
|
||||
"monaco-editor": "^0.39.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"pinia": "^2.1.3",
|
||||
"pinia-plugin-persistedstate": "^3.1.0",
|
||||
|
@ -67,7 +68,6 @@
|
|||
"@commitlint/config-conventional": "^17.6.5",
|
||||
"@types/lodash": "^4.14.195",
|
||||
"@types/lodash-es": "^4.17.7",
|
||||
"@types/mockjs": "^1.0.7",
|
||||
"@types/nprogress": "^0.2.0",
|
||||
"@types/sortablejs": "^1.15.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.9",
|
||||
|
@ -78,6 +78,7 @@
|
|||
"@vue/babel-plugin-jsx": "^1.1.1",
|
||||
"@vue/test-utils": "^2.3.2",
|
||||
"autoprefixer": "^10.4.14",
|
||||
"axios-mock-adapter": "^1.21.5",
|
||||
"consola": "^2.15.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.42.0",
|
||||
|
@ -93,7 +94,6 @@
|
|||
"less": "^4.1.3",
|
||||
"less-loader": "^11.1.2",
|
||||
"lint-staged": "^13.2.2",
|
||||
"mockjs": "^1.1.0",
|
||||
"postcss": "^8.4.24",
|
||||
"postcss-html": "^1.5.0",
|
||||
"postcss-import": "^15.1.0",
|
||||
|
@ -122,6 +122,7 @@
|
|||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-eslint": "^1.8.1",
|
||||
"vite-plugin-imagemin": "^0.6.1",
|
||||
"vite-plugin-monaco-editor": "^1.1.0",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vite-plugin-vue-setup-extend": "^0.4.0",
|
||||
"vite-svg-loader": "^3.6.0",
|
||||
|
|
|
@ -14,7 +14,7 @@ export * from './axiosTransform';
|
|||
* @description: 封装axios请求,返回重新封装的数据格式
|
||||
*/
|
||||
export class MSAxios {
|
||||
private axiosInstance: AxiosInstance;
|
||||
public axiosInstance: AxiosInstance;
|
||||
|
||||
private readonly options: CreateAxiosOptions;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { MSAxios } from './Axios';
|
||||
import checkStatus from './checkStatus';
|
||||
import { Message, Modal } from '@arco-design/web-vue';
|
||||
import { RequestEnum, ContentTypeEnum, ResultEnum } from '@/enums/httpEnum';
|
||||
import { RequestEnum, ContentTypeEnum } from '@/enums/httpEnum';
|
||||
import { isString } from '@/utils/is';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { setObjToUrlParams, deepMerge } from '@/utils';
|
||||
|
@ -31,7 +31,7 @@ const transform: AxiosTransform = {
|
|||
config.params = Object.assign(params || {}, joinTimestamp(joinTime, false));
|
||||
} else {
|
||||
// 兼容restful风格
|
||||
config.url = `${config.url}${params}${joinTimestamp(joinTime, true)}`;
|
||||
config.url = `${config.url}/${params}${joinTimestamp(joinTime, true)}`;
|
||||
config.params = undefined;
|
||||
}
|
||||
} else if (isString(params)) {
|
||||
|
@ -76,32 +76,33 @@ const transform: AxiosTransform = {
|
|||
throw new Error(t('api.apiRequestFailed'));
|
||||
}
|
||||
// 这里 code,result,message为 后台统一的字段
|
||||
const { code, data: dataResult, message } = data;
|
||||
const { data: dataResult } = data;
|
||||
|
||||
// TODO:定义完成功code后需要重写
|
||||
const hasSuccess = data && Reflect.has(data, 'code') && Number(code) === ResultEnum.SUCCESS;
|
||||
if (hasSuccess) {
|
||||
// 这里直接返回正常结果,因为拦截器已经拦截了非 200 的请求
|
||||
return dataResult;
|
||||
}
|
||||
// const hasSuccess = data && Reflect.has(data, 'code') && Number(code) === ResultEnum.SUCCESS;
|
||||
// if (hasSuccess) {
|
||||
// return dataResult;
|
||||
// }
|
||||
|
||||
// 在此处根据自己项目的实际情况对不同的code执行不同的操作
|
||||
// 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
|
||||
let timeoutMsg = '';
|
||||
if (Number(code) === ResultEnum.TIMEOUT) {
|
||||
timeoutMsg = t('api.timeoutMessage');
|
||||
} else if (message) {
|
||||
timeoutMsg = message;
|
||||
}
|
||||
// // 在此处根据自己项目的实际情况对不同的code执行不同的操作
|
||||
// // 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
|
||||
// let timeoutMsg = '';
|
||||
// if (Number(code) === ResultEnum.TIMEOUT) {
|
||||
// timeoutMsg = t('api.timeoutMessage');
|
||||
// } else if (message) {
|
||||
// timeoutMsg = message;
|
||||
// }
|
||||
|
||||
// errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
||||
// errorMessageMode='none' 一般是调用时明确表示不希望自动弹出错误提示
|
||||
if (options.errorMessageMode === 'modal') {
|
||||
Modal.error({ title: t('api.errorTip'), content: timeoutMsg });
|
||||
} else if (options.errorMessageMode === 'message') {
|
||||
Message.error(timeoutMsg);
|
||||
}
|
||||
// // errorMessageMode=‘modal’的时候会显示modal错误弹窗,而不是消息提示,用于一些比较重要的错误
|
||||
// // errorMessageMode='none' 一般是调用时明确表示不希望自动弹出错误提示
|
||||
// if (options.errorMessageMode === 'modal') {
|
||||
// Modal.error({ title: t('api.errorTip'), content: timeoutMsg });
|
||||
// } else if (options.errorMessageMode === 'message') {
|
||||
// Message.error(timeoutMsg);
|
||||
// }
|
||||
|
||||
throw new Error(timeoutMsg || t('api.apiRequestFailed'));
|
||||
// throw new Error(timeoutMsg || t('api.apiRequestFailed'));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ import { ProjectListUrl } from '@/api/requrls/system/project';
|
|||
import type { ProjectListItem } from '@/models/system/project';
|
||||
|
||||
export function getProjectList(organizationId: string) {
|
||||
return MSR.get<ProjectListItem[]>({ url: `${ProjectListUrl}/${organizationId}` });
|
||||
return MSR.get<ProjectListItem[]>({ url: ProjectListUrl, params: organizationId });
|
||||
}
|
||||
|
||||
export default {};
|
||||
|
|
|
@ -1,12 +1,24 @@
|
|||
import MSR from '@/api/http/index';
|
||||
import { PoolListUrl, UpdatePoolUrl } from '@/api/requrls/system/resourcePool';
|
||||
import type { ResourcePoolItem } from '@/models/system/resourcePool';
|
||||
import { PoolListUrl, UpdatePoolUrl, AddPoolUrl, DetailPoolUrl } from '@/api/requrls/system/resourcePool';
|
||||
import type { ResourcePoolItem, ResourcePoolInfo } from '@/models/system/resourcePool';
|
||||
import type { TableQueryParams } from '@/models/common';
|
||||
|
||||
// 获取资源池列表
|
||||
export function getPoolList(data: TableQueryParams) {
|
||||
return MSR.post<ResourcePoolItem[]>({ url: PoolListUrl, data });
|
||||
}
|
||||
|
||||
// 更新资源池信息
|
||||
export function updatePoolInfo(data: ResourcePoolItem) {
|
||||
return MSR.post({ url: UpdatePoolUrl, data });
|
||||
}
|
||||
|
||||
// 添加资源池
|
||||
export function addPool(data: ResourcePoolInfo) {
|
||||
return MSR.post({ url: AddPoolUrl, data });
|
||||
}
|
||||
|
||||
// 获取资源池详情
|
||||
export function getPoolInfo(poolId: string) {
|
||||
return MSR.get<ResourcePoolItem>({ url: DetailPoolUrl, params: poolId });
|
||||
}
|
||||
|
|
|
@ -2,3 +2,4 @@ export const PoolListUrl = '/test/resource/pool/page';
|
|||
export const UpdatePoolUrl = '/test/resource/pool/update';
|
||||
export const AddPoolUrl = '/test/resource/pool/add';
|
||||
export const DeletePoolUrl = '/test/resource/pool/delete';
|
||||
export const DetailPoolUrl = '/test/resource/pool/detail';
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 请求结果枚举
|
||||
*/
|
||||
export enum ResultEnum {
|
||||
SUCCESS = 0,
|
||||
SUCCESS = 100200,
|
||||
ERROR = 1,
|
||||
TIMEOUT = 401,
|
||||
TYPE = 'success',
|
||||
|
|
|
@ -2,6 +2,7 @@ import { createApp } from 'vue';
|
|||
import FormCreate from '@form-create/arco-design';
|
||||
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
|
||||
import SvgIcon from '@/components/pure/svg-icon/index.vue';
|
||||
import MSIcon from '@/components/pure/ms-icon-font/index.vue';
|
||||
import router from './router';
|
||||
import store from './store';
|
||||
import { setupI18n } from './locale';
|
||||
|
@ -23,6 +24,7 @@ async function bootstrap() {
|
|||
await setupI18n(app);
|
||||
|
||||
app.use(ArcoVueIcon);
|
||||
app.component('MsIcon', MSIcon);
|
||||
app.component('SvgIcon', SvgIcon);
|
||||
|
||||
app.use(router);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getList = () => {
|
||||
return {
|
||||
|
@ -108,10 +108,4 @@ const getList = () => {
|
|||
};
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/mock/api-test/define/list/'), () => {
|
||||
return successResponseWrap(getList());
|
||||
});
|
||||
},
|
||||
});
|
||||
mock(RequestEnum.POST, '/mock/api-test/define/list/', getList(), 200);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import Mock from 'mockjs';
|
||||
import MOCK from '@/utils/setup-mock';
|
||||
|
||||
import './user';
|
||||
import './message-box';
|
||||
|
@ -9,6 +9,4 @@ import './system/resourcePool';
|
|||
import './system/member';
|
||||
import './system/pluginManger';
|
||||
|
||||
Mock.setup({
|
||||
timeout: '600-1000',
|
||||
});
|
||||
MOCK.onAny().passThrough();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const haveReadIds: number[] = [];
|
||||
const getMessageList = () => {
|
||||
|
@ -70,16 +70,14 @@ const getMessageList = () => {
|
|||
}));
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/api/message/list'), () => {
|
||||
return successResponseWrap(getMessageList());
|
||||
});
|
||||
|
||||
Mock.mock(new RegExp('/api/message/read'), (params: { body: string }) => {
|
||||
mock(RequestEnum.GET, '/api/message/list', getMessageList(), 200);
|
||||
mock(
|
||||
RequestEnum.GET,
|
||||
'/api/message/read',
|
||||
(params: { body: string }) => {
|
||||
const { ids } = JSON.parse(params.body);
|
||||
haveReadIds.push(...(ids || []));
|
||||
return successResponseWrap(true);
|
||||
});
|
||||
return true;
|
||||
},
|
||||
});
|
||||
200
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successTableResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getMemberList = () => {
|
||||
return [
|
||||
|
@ -250,10 +250,4 @@ const getMemberList = () => {
|
|||
];
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/member/page'), () => {
|
||||
return successTableResponseWrap(getMemberList());
|
||||
});
|
||||
},
|
||||
});
|
||||
mock(RequestEnum.POST, '/member/page', getMemberList(), 200, true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successTableResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getPluginList = () => {
|
||||
return [
|
||||
|
@ -176,10 +176,4 @@ const getPluginList = () => {
|
|||
];
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/plugin/page'), () => {
|
||||
return successTableResponseWrap(getPluginList());
|
||||
});
|
||||
},
|
||||
});
|
||||
mock(RequestEnum.POST, '/plugin/page', getPluginList(), 200, true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getProjectList = () => {
|
||||
return [
|
||||
|
@ -51,10 +51,4 @@ const getProjectList = () => {
|
|||
];
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/system/project/list'), () => {
|
||||
return successResponseWrap(getProjectList());
|
||||
});
|
||||
},
|
||||
});
|
||||
mock(RequestEnum.GET, '/system/project/list', getProjectList(), 200);
|
||||
|
|
|
@ -1,166 +1,160 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { makeMockUrl, successTableResponseWrap } from '@/utils/setup-mock';
|
||||
import { PoolListUrl } from '@/api/requrls/system/resourcePool';
|
||||
// import { mock } from '@/utils/setup-mock';
|
||||
// import { PoolListUrl } from '@/api/requrls/system/resourcePool';
|
||||
// import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getPoolList = () => {
|
||||
return [
|
||||
{
|
||||
id: '938uh9',
|
||||
name: 'ksajdfkas',
|
||||
type: 'Node',
|
||||
description: '年卡是健康的就是肯德基富士康',
|
||||
enable: true,
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'hShdf',
|
||||
apiTest: true,
|
||||
loadTest: true,
|
||||
uiTest: true,
|
||||
serverUrl: 'fldskfsl.sdjks.com',
|
||||
deleted: false,
|
||||
configuration: 'akjfhbgkdjfsokdsdfs',
|
||||
organizationList: [
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 1',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 2',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 3',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 4',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
],
|
||||
resources: ['192.168.1.1', '192.168.11.23'],
|
||||
},
|
||||
{
|
||||
id: 'dfopi03wif3',
|
||||
name: 'ksajdfkas',
|
||||
type: 'K8s',
|
||||
description: '生动地很多次私董会佛山的',
|
||||
enable: false,
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'hShdf',
|
||||
apiTest: true,
|
||||
loadTest: true,
|
||||
uiTest: true,
|
||||
serverUrl: 'fldskfsl.sdjks.com',
|
||||
deleted: false,
|
||||
configuration: 'akjfhbgkdjfsokdsdfs',
|
||||
organizationList: [
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 1',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 2',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 3',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
{
|
||||
id: 'string',
|
||||
num: 0,
|
||||
name: '组织 4',
|
||||
description: 'blabla',
|
||||
createTime: 0,
|
||||
updateTime: 0,
|
||||
createUser: 'string',
|
||||
updateUser: 'string',
|
||||
deleted: true,
|
||||
deleteUser: 'string',
|
||||
deleteTime: 0,
|
||||
enable: true,
|
||||
},
|
||||
],
|
||||
resources: ['192.168.1.1', '192.168.11.23'],
|
||||
},
|
||||
];
|
||||
};
|
||||
// const getPoolList = () => {
|
||||
// return [
|
||||
// {
|
||||
// id: '938uh9',
|
||||
// name: 'ksajdfkas',
|
||||
// type: 'Node',
|
||||
// description: '年卡是健康的就是肯德基富士康',
|
||||
// enable: true,
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'hShdf',
|
||||
// apiTest: true,
|
||||
// loadTest: true,
|
||||
// uiTest: true,
|
||||
// serverUrl: 'fldskfsl.sdjks.com',
|
||||
// deleted: false,
|
||||
// configuration: 'akjfhbgkdjfsokdsdfs',
|
||||
// organizationList: [
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 1',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 2',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 3',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 4',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// ],
|
||||
// resources: ['192.168.1.1', '192.168.11.23'],
|
||||
// },
|
||||
// {
|
||||
// id: 'dfopi03wif3',
|
||||
// name: 'ksajdfkas',
|
||||
// type: 'K8s',
|
||||
// description: '生动地很多次私董会佛山的',
|
||||
// enable: false,
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'hShdf',
|
||||
// apiTest: true,
|
||||
// loadTest: true,
|
||||
// uiTest: true,
|
||||
// serverUrl: 'fldskfsl.sdjks.com',
|
||||
// deleted: false,
|
||||
// configuration: 'akjfhbgkdjfsokdsdfs',
|
||||
// organizationList: [
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 1',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 2',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 3',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// {
|
||||
// id: 'string',
|
||||
// num: 0,
|
||||
// name: '组织 4',
|
||||
// description: 'blabla',
|
||||
// createTime: 0,
|
||||
// updateTime: 0,
|
||||
// createUser: 'string',
|
||||
// updateUser: 'string',
|
||||
// deleted: true,
|
||||
// deleteUser: 'string',
|
||||
// deleteTime: 0,
|
||||
// enable: true,
|
||||
// },
|
||||
// ],
|
||||
// resources: ['192.168.1.1', '192.168.11.23'],
|
||||
// },
|
||||
// ];
|
||||
// };
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(makeMockUrl(PoolListUrl), () => {
|
||||
return successTableResponseWrap(getPoolList());
|
||||
});
|
||||
},
|
||||
});
|
||||
// mock(RequestEnum.POST, PoolListUrl, getPoolList(), 200, true);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successTableResponseWrap } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
|
||||
const getUserList = () => {
|
||||
return [
|
||||
|
@ -250,10 +250,4 @@ const getUserList = () => {
|
|||
];
|
||||
};
|
||||
|
||||
setupMock({
|
||||
setup: () => {
|
||||
Mock.mock(new RegExp('/user/page'), () => {
|
||||
return successTableResponseWrap(getUserList());
|
||||
});
|
||||
},
|
||||
});
|
||||
mock(RequestEnum.POST, '/user/page', getUserList(), 200, true);
|
||||
|
|
|
@ -1,143 +1,6 @@
|
|||
import Mock from 'mockjs';
|
||||
import setupMock, { successResponseWrap, failResponseWrap, makeMockUrl } from '@/utils/setup-mock';
|
||||
import { mock } from '@/utils/setup-mock';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
import { LogoutUrl, LoginUrl } from '@/api/requrls/user';
|
||||
|
||||
import { GetMenuListUrl, LogoutUrl, LoginUrl } from '@/api/requrls/user';
|
||||
import { isLogin } from '@/utils/auth';
|
||||
|
||||
setupMock({
|
||||
mock: false,
|
||||
setup() {
|
||||
// 用户信息
|
||||
Mock.mock(makeMockUrl('/api/userinfo'), async () => {
|
||||
if (await isLogin()) {
|
||||
const role = window.localStorage.getItem('userRole') || 'admin';
|
||||
return successResponseWrap({
|
||||
name: '王立群',
|
||||
avatar: '//lf1-xgcdn-tos.pstatp.com/obj/vcloud/vadmin/start.8e0e4855ee346a46ccff8ff3e24db27b.png',
|
||||
email: 'wangliqun@email.com',
|
||||
job: 'frontend',
|
||||
jobName: '前端艺术家',
|
||||
organization: 'Frontend',
|
||||
organizationName: '前端',
|
||||
location: 'beijing',
|
||||
locationName: '北京',
|
||||
introduction: '人潇洒,性温存',
|
||||
personalWebsite: 'https://www.arco.design',
|
||||
phone: '150****0000',
|
||||
registrationDate: '2013-05-10 12:10:00',
|
||||
accountId: '15012312300',
|
||||
certification: 1,
|
||||
role,
|
||||
});
|
||||
}
|
||||
return failResponseWrap(null, '未登录', 50008);
|
||||
});
|
||||
|
||||
// 登陆
|
||||
Mock.mock(makeMockUrl(LoginUrl), () => {
|
||||
return successResponseWrap({});
|
||||
});
|
||||
|
||||
// 登出
|
||||
Mock.mock(makeMockUrl(LogoutUrl), () => {
|
||||
return successResponseWrap(null);
|
||||
});
|
||||
|
||||
// 用户的服务端菜单
|
||||
Mock.mock(makeMockUrl(GetMenuListUrl), () => {
|
||||
const menuList = [
|
||||
{
|
||||
path: '/api-test',
|
||||
name: 'apiTest',
|
||||
meta: {
|
||||
locale: 'menu.apiTest',
|
||||
icon: 'icon-dashboard',
|
||||
order: 0,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'list',
|
||||
name: 'apiTest',
|
||||
meta: {
|
||||
locale: 'menu.apiTest',
|
||||
roles: ['*'],
|
||||
icon: 'icon-computer',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/setting',
|
||||
name: 'setting',
|
||||
meta: {
|
||||
locale: 'menu.settings',
|
||||
icon: 'icon-dashboard',
|
||||
order: 0,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'system',
|
||||
name: 'settingSystem',
|
||||
redirect: '/setting/system/user',
|
||||
meta: {
|
||||
locale: 'menu.settings.system',
|
||||
roles: ['*'],
|
||||
hideChildrenInMenu: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'user',
|
||||
name: 'settingSystemUser',
|
||||
meta: {
|
||||
locale: 'menu.settings.system.user',
|
||||
roles: ['*'],
|
||||
isTopMenu: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'usergroup',
|
||||
name: 'settingSystemUsergroup',
|
||||
meta: {
|
||||
locale: 'menu.settings.system.usergroup',
|
||||
roles: ['*'],
|
||||
isTopMenu: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'resourcePool',
|
||||
name: 'settingSystemResourcePool',
|
||||
meta: {
|
||||
locale: 'menu.settings.system.resourcePool',
|
||||
roles: ['*'],
|
||||
isTopMenu: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'resourcePoolDetail',
|
||||
name: 'settingSystemResourcePoolDetail',
|
||||
meta: {
|
||||
locale: 'menu.settings.system.resourcePoolDetail',
|
||||
roles: ['*'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/personal',
|
||||
name: 'personal',
|
||||
meta: {},
|
||||
children: [
|
||||
{
|
||||
path: '/personal/info',
|
||||
name: 'personalInfo',
|
||||
meta: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
return successResponseWrap(menuList);
|
||||
});
|
||||
},
|
||||
});
|
||||
// mock(RequestEnum.POST, LoginUrl, {}, 200);
|
||||
mock(RequestEnum.POST, LogoutUrl, null, 200);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import debug from './env';
|
||||
import MSR from '@/api/http';
|
||||
import { RequestEnum } from '@/enums/httpEnum';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
|
||||
export default ({ mock, setup }: { mock?: boolean; setup: () => void }) => {
|
||||
if (mock !== false && debug) setup();
|
||||
};
|
||||
const MOCK = new MockAdapter(MSR.axiosInstance, { onNoMatch: 'throwException' });
|
||||
|
||||
/**
|
||||
* mock- 成功返回结果结构体
|
||||
|
@ -39,15 +39,35 @@ export const successTableResponseWrap = (data: unknown) => {
|
|||
* @param code
|
||||
* @returns
|
||||
*/
|
||||
export const failResponseWrap = (data: unknown, message: string, code = 50000) => {
|
||||
export const failResponseWrap = (data: unknown, message?: string, messageDetail?: string) => {
|
||||
return {
|
||||
data,
|
||||
status: 'fail',
|
||||
message,
|
||||
code,
|
||||
message: message || '请求失败',
|
||||
messageDetail,
|
||||
};
|
||||
};
|
||||
|
||||
export const mock = (
|
||||
method: RequestEnum,
|
||||
url: string | RegExp,
|
||||
data: unknown,
|
||||
code: number,
|
||||
isTable?: boolean,
|
||||
message?: string,
|
||||
messageDetail?: string
|
||||
) => {
|
||||
const methodMap = {
|
||||
[RequestEnum.GET]: MOCK.onGet(url),
|
||||
[RequestEnum.POST]: MOCK.onPost(url),
|
||||
[RequestEnum.PUT]: MOCK.onPut(url),
|
||||
[RequestEnum.DELETE]: MOCK.onDelete(url),
|
||||
};
|
||||
if (code === 200) {
|
||||
return methodMap[method].reply(code, isTable ? successTableResponseWrap(data) : successResponseWrap(data));
|
||||
}
|
||||
return methodMap[method].reply(code, failResponseWrap(data, message, messageDetail));
|
||||
};
|
||||
|
||||
/**
|
||||
* 拼接 mock 匹配的 url
|
||||
* @param url 不含前缀的接口地址
|
||||
|
@ -57,3 +77,5 @@ export const makeMockUrl = (url: string) => {
|
|||
const mockOrigin = window.location.origin;
|
||||
return `${mockOrigin}/front${url}`;
|
||||
};
|
||||
|
||||
export default MOCK;
|
||||
|
|
|
@ -12,10 +12,8 @@
|
|||
"build/**/*.d.ts",
|
||||
"mock/**/*.ts",
|
||||
"__test__/**/*.ts",
|
||||
"node_modules/monaco-editor/monaco.d.ts"
|
||||
], // TS解析路径配置
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"allowJs": true, // 允许编译器编译JS,JSX文件
|
||||
"noEmit": true,
|
||||
|
|
Loading…
Reference in New Issue