更新0.1.1版本

This commit is contained in:
Ah jung
2021-07-07 10:26:14 +08:00
parent b74b6e61a4
commit d423f27e94
174 changed files with 15966 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
const modules = import.meta.globEager('./**/*.ts');
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);
}
+73
View File
@@ -0,0 +1,73 @@
import Mock from 'mockjs'
export function resultSuccess(result, { message = 'ok' } = {}) {
return Mock.mock({
code: 200,
result,
message,
type: 'success',
});
}
export function resultPageSuccess<T = any>(
page: number,
pageSize: number,
list: T[],
{ message = 'ok' } = {}
) {
const pageData = pagination(page, pageSize, list);
return {
...resultSuccess({
page,
pageSize,
pageCount: list.length,
list: pageData,
}),
message,
};
}
export function resultError(message = 'Request failed', { code = -1, result = null } = {}) {
return {
code,
result,
message,
type: 'error',
};
}
export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] {
const offset = (pageNo - 1) * Number(pageSize);
const ret =
offset + Number(pageSize) >= array.length
? array.slice(offset, array.length)
: array.slice(offset, offset + Number(pageSize));
return ret;
}
/**
* @param {Number} times 回调函数需要执行的次数
* @param {Function} callback 回调函数
*/
export function doCustomTimes (times:number, callback:any) {
let i = -1
while (++i < times) {
callback(i)
}
}
export interface requestParams {
method: string;
body: any;
headers?: { token?: string };
query: any;
}
/**
* @description 本函数用于从request数据中获取token,请根据项目的实际情况修改
*
*/
export function getRequestToken({ headers }: requestParams): string | undefined {
return headers?.token;
}
+47
View File
@@ -0,0 +1,47 @@
import { Random } from 'mockjs'
import { resultSuccess } from '../_util'
const consoleInfo = {
//访问量
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),
},
//销售额
saleroom:{
weekSaleroom:Random.float(10000,99999,2,2),
amount:Random.float(99999,999999,2,2),
degree:Random.float(10,99)
},
//订单量
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),
},
//成交额度
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)
},
}
export default [
//主控台 卡片数据
{
url: '/api/dashboard/console',
timeout: 1000,
method: 'get',
response: () => {
return resultSuccess(consoleInfo);
},
}
]
+44
View File
@@ -0,0 +1,44 @@
import { Random } from 'mockjs'
import { resultSuccess, doCustomTimes, resultPageSuccess } from '../_util'
const tableList = ((pageSize) => {
const result:any[] = []
doCustomTimes(pageSize,()=> {
result.push({
id: '@integer(10,100)',
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': ['normal', 'enable', 'disable'],
});
})
return result
});
export default [
//表格数据列表
{
url: '/api/table/list',
timeout: 1000,
method: 'get',
response: ({ query }) => {
const { pageNumber = 1, pageSize = 10 } = query;
const list = tableList(Number(pageSize))
return resultSuccess({
pageNumber:Number(pageNumber),
pageSize:Number(pageSize),
total: list.length,
list
}
);
},
}
]
+53
View File
@@ -0,0 +1,53 @@
import { MockMethod } from 'vite-plugin-mock'
import { resultSuccess, getRequestToken } from '../_util'
const menusList = [
{
path: '/dashboard',
name: 'Dashboard',
component: 'Layout',
redirect: '/dashboard/console',
meta: {
icon: 'DashboardOutlined',
title: 'Dashboard',
},
children: [
{
path: 'console',
name: 'dashboard_console',
component: 'DashboardConsole',
meta: {
title: '主控台',
}
},
{
path: 'monitor',
name: 'dashboard_monitor',
component: 'DashboardMonitor',
meta: {
title: '监控页',
}
},
{
path: 'workplace',
name: 'dashboard_workplace',
component: 'DashboardWorkplace',
meta: {
hidden: true,
title: '工作台',
}
},
],
}
]
export default [
{
url: '/api/menus',
timeout: 1000,
method: 'get',
response: () => {
return resultSuccess(menusList);
},
}
]
+51
View File
@@ -0,0 +1,51 @@
import Mock from 'mockjs'
import { resultSuccess, getRequestToken } from '../_util'
const Random = Mock.Random
const token = Random.string('upper', 32, 32)
const adminInfo = {
userId: '1',
username: 'admin',
realName: 'Admin',
avatar: Random.image(),
desc: 'manager',
password: Random.string('upper', 4, 16),
token,
roles: [
{
roleName: '主控台',
value: 'dashboard_console',
},
{
roleName: '监控页',
value: 'dashboard_monitor',
},
{
roleName: '工作台',
value: 'dashboard_workplace',
}
],
}
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);
},
},
]