mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-04 13:42:27 +08:00
2.0.0
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
|
||||
|
||||
interface IModuleType {
|
||||
default: any[];
|
||||
}
|
||||
|
||||
const modules = import.meta.glob<IModuleType>('./**/*.ts', { eager: true });
|
||||
|
||||
const mockModules: any[] = [];
|
||||
Object.keys(modules).forEach((key) => {
|
||||
if (key.includes('/_')) {
|
||||
return;
|
||||
}
|
||||
mockModules.push(...modules[key].default);
|
||||
});
|
||||
|
||||
/**
|
||||
* Used in a production environment. Need to manually import all modules
|
||||
*/
|
||||
export function setupProdMockServer() {
|
||||
createProdMockServer(mockModules);
|
||||
}
|
||||
@@ -1,44 +1,44 @@
|
||||
import { Random } from 'mockjs';
|
||||
import { defineMock } from '@alova/mock';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { resultSuccess } from '../_util';
|
||||
|
||||
const consoleInfo = {
|
||||
function getRandom(options) {
|
||||
return Number(faker.commerce.price(options));
|
||||
}
|
||||
|
||||
const result = {
|
||||
//访问量
|
||||
visits: {
|
||||
dayVisits: Random.float(10000, 99999, 2, 2),
|
||||
rise: Random.float(10, 99),
|
||||
decline: Random.float(10, 99),
|
||||
amount: Random.float(99999, 999999, 3, 5),
|
||||
dayVisits: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
rise: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
decline: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
amount: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
},
|
||||
//销售额
|
||||
saleroom: {
|
||||
weekSaleroom: Random.float(10000, 99999, 2, 2),
|
||||
amount: Random.float(99999, 999999, 2, 2),
|
||||
degree: Random.float(10, 99),
|
||||
weekSaleroom: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
amount: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
degree: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
},
|
||||
//订单量
|
||||
orderLarge: {
|
||||
weekLarge: Random.float(10000, 99999, 2, 2),
|
||||
rise: Random.float(10, 99),
|
||||
decline: Random.float(10, 99),
|
||||
amount: Random.float(99999, 999999, 2, 2),
|
||||
weekLarge: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
rise: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
decline: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
amount: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
},
|
||||
//成交额度
|
||||
volume: {
|
||||
weekLarge: Random.float(10000, 99999, 2, 2),
|
||||
rise: Random.float(10, 99),
|
||||
decline: Random.float(10, 99),
|
||||
amount: Random.float(99999, 999999, 2, 2),
|
||||
weekLarge: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
rise: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
decline: getRandom({ min: 10000, max: 99999, dec: 0 }),
|
||||
amount: getRandom({ min: 10000, max: 99999, dec: 2 }),
|
||||
},
|
||||
};
|
||||
|
||||
export default [
|
||||
//主控台 卡片数据
|
||||
{
|
||||
url: '/api/dashboard/console',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: () => {
|
||||
return resultSuccess(consoleInfo);
|
||||
},
|
||||
export default defineMock({
|
||||
// 主控台数据
|
||||
'/api/dashboard/console': () => {
|
||||
return resultSuccess(result);
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
import { defineMock } from '@alova/mock';
|
||||
import { resultSuccess } from '../_util';
|
||||
|
||||
export interface ListDate {
|
||||
label: string;
|
||||
key: string;
|
||||
type: number;
|
||||
subtitle: string;
|
||||
openType: number;
|
||||
auth: string;
|
||||
path: string;
|
||||
children?: ListDate[];
|
||||
}
|
||||
|
||||
const menuList = () => {
|
||||
const result: any[] = [
|
||||
const result: ListDate[] = [
|
||||
{
|
||||
label: 'Dashboard',
|
||||
key: 'dashboard',
|
||||
@@ -74,16 +86,11 @@ const menuList = () => {
|
||||
return result;
|
||||
};
|
||||
|
||||
export default [
|
||||
{
|
||||
url: '/api/menu/list',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: () => {
|
||||
const list = menuList();
|
||||
return resultSuccess({
|
||||
list,
|
||||
});
|
||||
},
|
||||
export default defineMock({
|
||||
'/api/menu/list': () => {
|
||||
const list = menuList();
|
||||
return resultSuccess({
|
||||
list,
|
||||
});
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { defineMock } from '@alova/mock';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { resultSuccess, doCustomTimes } from '../_util';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
function getMenuKeys() {
|
||||
const keys = ['dashboard', 'console', 'workplace', 'basic-form', 'step-form', 'detail'];
|
||||
const newKeys = [];
|
||||
doCustomTimes(parseInt(Math.random() * 6), () => {
|
||||
const key = keys[Math.floor(Math.random() * keys.length)];
|
||||
newKeys.push(key);
|
||||
newKeys.push(key as never);
|
||||
});
|
||||
return Array.from(new Set(newKeys));
|
||||
}
|
||||
@@ -14,32 +16,30 @@ const roleList = (pageSize) => {
|
||||
const result: any[] = [];
|
||||
doCustomTimes(pageSize, () => {
|
||||
result.push({
|
||||
id: '@integer(10,100)',
|
||||
name: '@cname()',
|
||||
explain: '@cname()',
|
||||
isDefault: '@boolean()',
|
||||
id: faker.string.numeric(4),
|
||||
name: faker.person.firstName(),
|
||||
explain: faker.lorem.sentence({ min: 2, max: 4 }),
|
||||
isDefault: faker.helpers.arrayElement([true, false]),
|
||||
menu_keys: getMenuKeys(),
|
||||
create_date: `@date('yyyy-MM-dd hh:mm:ss')`,
|
||||
'status|1': ['normal', 'enable', 'disable'],
|
||||
create_date: dayjs(faker.date.anytime()).format('YYYY-MM-DD HH:mm'),
|
||||
status: faker.helpers.arrayElement(['normal', 'enable', 'disable']),
|
||||
});
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
export default [
|
||||
{
|
||||
url: '/api/role/list',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: ({ query }) => {
|
||||
const { page = 1, pageSize = 10 } = query;
|
||||
const list = roleList(Number(pageSize));
|
||||
return resultSuccess({
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
pageCount: 60,
|
||||
list,
|
||||
});
|
||||
},
|
||||
export default defineMock({
|
||||
'/api/role/list': ({ query }) => {
|
||||
const { page = 1, pageSize = 10, name } = query;
|
||||
const list = roleList(Number(pageSize));
|
||||
// 并非真实,只是为了模拟搜索结果
|
||||
const count = name ? 30 : 60;
|
||||
return resultSuccess({
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
pageCount: count,
|
||||
itemCount: count * Number(pageSize),
|
||||
list,
|
||||
});
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,43 +1,39 @@
|
||||
import { Random } from 'mockjs';
|
||||
import { resultSuccess, doCustomTimes } from '../_util';
|
||||
|
||||
const tableList = (pageSize) => {
|
||||
import { defineMock } from '@alova/mock';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { doCustomTimes, resultSuccess } from '../_util';
|
||||
import dayjs from 'dayjs';
|
||||
function tableList(pageSize: number) {
|
||||
const result: any[] = [];
|
||||
doCustomTimes(pageSize, () => {
|
||||
result.push({
|
||||
id: '@integer(10,999999)',
|
||||
beginTime: '@datetime',
|
||||
endTime: '@datetime',
|
||||
address: '@city()',
|
||||
name: '@cname()',
|
||||
avatar: Random.image('400x400', Random.color(), Random.color(), Random.first()),
|
||||
date: `@date('yyyy-MM-dd')`,
|
||||
time: `@time('HH:mm')`,
|
||||
'no|100000-10000000': 100000,
|
||||
'status|1': [true, false],
|
||||
id: faker.string.numeric(4),
|
||||
name: faker.person.firstName(),
|
||||
sex: faker.person.sexType(),
|
||||
avatar: `https://picsum.photos/200/200?v=${faker.string.numeric(4)}`,
|
||||
email: faker.internet.email({ firstName: 'admin' }),
|
||||
city: faker.location.city(),
|
||||
status: faker.helpers.arrayElement(['close', 'refuse', 'pass']),
|
||||
type: faker.helpers.arrayElement(['person', 'company']),
|
||||
// createDate: faker.helpers.arrayElement(dateStrs),
|
||||
createDate: dayjs(faker.date.anytime()).format('YYYY-MM-DD HH:mm'),
|
||||
});
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export default [
|
||||
//表格数据列表
|
||||
{
|
||||
url: '/api/table/list',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: ({ query }) => {
|
||||
const { page = 1, pageSize = 10, name } = query;
|
||||
const list = tableList(Number(pageSize));
|
||||
//并非真实,只是为了模拟搜索结果
|
||||
const count = name ? 30 : 60;
|
||||
return resultSuccess({
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
pageCount: count,
|
||||
itemCount: count * Number(pageSize),
|
||||
list,
|
||||
});
|
||||
},
|
||||
export default defineMock({
|
||||
// 表格数据列表
|
||||
'/api/table/list': ({ query }) => {
|
||||
const { page = 1, pageSize = 10, name } = query;
|
||||
const list = tableList(Number(pageSize));
|
||||
// 并非真实,只是为了模拟搜索结果
|
||||
const count = name ? 30 : 60;
|
||||
return resultSuccess({
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
pageCount: count,
|
||||
itemCount: count * Number(pageSize),
|
||||
list,
|
||||
});
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Mock from 'mockjs';
|
||||
import { resultSuccess } from '../_util';
|
||||
import { defineMock } from '@alova/mock';
|
||||
|
||||
const Random = Mock.Random;
|
||||
|
||||
@@ -37,23 +38,7 @@ const adminInfo = {
|
||||
],
|
||||
};
|
||||
|
||||
export default [
|
||||
{
|
||||
url: '/api/login',
|
||||
timeout: 1000,
|
||||
method: 'post',
|
||||
response: () => {
|
||||
return resultSuccess({ token });
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/api/admin_info',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: () => {
|
||||
// const token = getRequestToken(request);
|
||||
// if (!token) return resultError('Invalid token');
|
||||
return resultSuccess(adminInfo);
|
||||
},
|
||||
},
|
||||
];
|
||||
export default defineMock({
|
||||
'[POST]/api/login': () => resultSuccess({ token }),
|
||||
'/api/admin_info': () => resultSuccess(adminInfo),
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { defineMock } from '@alova/mock';
|
||||
import { resultSuccess } from '../_util';
|
||||
|
||||
const menusList = [
|
||||
@@ -40,13 +41,6 @@ const menusList = [
|
||||
},
|
||||
];
|
||||
|
||||
export default [
|
||||
{
|
||||
url: '/api/menus',
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: () => {
|
||||
return resultSuccess(menusList);
|
||||
},
|
||||
},
|
||||
];
|
||||
export default defineMock({
|
||||
'/api/menus': () => resultSuccess(menusList),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user