feat:
This commit is contained in:
365
mock/list.ts
Normal file
365
mock/list.ts
Normal file
@ -0,0 +1,365 @@
|
||||
import { Request, Response } from 'express';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { AdminAPI } from '../src/constants/api';
|
||||
import { DeclarationType } from '../src/constants/product';
|
||||
|
||||
const genJobList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.JobListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
id: `${index}-id`,
|
||||
jobId: `${index}-id`,
|
||||
title: '招聘主播',
|
||||
jobDescription: '招聘主播',
|
||||
sourceText: '招聘主播',
|
||||
cityCode: index % 2 === 0 ? '110100' : '430100',
|
||||
category: 'ALL',
|
||||
employType: 'ALL',
|
||||
publisher: '甲子',
|
||||
blPublisherId: `${index}-blPublisherId`,
|
||||
publisherAcctNo: `${index}-publisherAcctNo`,
|
||||
blGroupId: `${index}-blGroupId`,
|
||||
imGroupId: `${index}-imGroupId`,
|
||||
imGroupNick: '杭州主播群3',
|
||||
robotId: `${index}-robotId`,
|
||||
robotImNo: `${index}-robotImNo`,
|
||||
robotImNick: `${index}-robotImNick`,
|
||||
relateGroupCount: 100,
|
||||
created: Date.now().toString(),
|
||||
updated: Date.now().toString(),
|
||||
disable: index % 2 === 0,
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
const genGroupList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.GroupListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
id: `${index}-id`,
|
||||
imGroupId: `${index}-groupId`,
|
||||
imGroupNick: '杭州主播群3',
|
||||
groupType: '',
|
||||
groupOwnerNick: '甲子',
|
||||
groupOwnerAcctNo: `${index}-boluoId`,
|
||||
groupOwnerImAcctNo: `${index}-wxId`,
|
||||
robotId: `${index}-robotId`,
|
||||
robotImNo: `${index}-robotImNo`,
|
||||
robotImNick: `${index}-robotImNick`,
|
||||
city: index % 2 === 0 ? '110100' : '430100',
|
||||
jobCount: 10,
|
||||
// created: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
created: Date.now().toString(),
|
||||
updated: Date.now().toString(),
|
||||
disable: index % 2 === 0,
|
||||
isDeleted: index % 2 === 0,
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
const genAnchorGroupList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.AnchorGroupListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
userId: `${index}-id`,
|
||||
nickName: '甲子',
|
||||
userPhone: '18222020020',
|
||||
blGroupId: `${index}-blGroupId`,
|
||||
imGroupId: `${index}-imGroupId`,
|
||||
imGroupNick: '杭州主播群3',
|
||||
creator: '甲子',
|
||||
payed: index % 2 === 0,
|
||||
payType: 'wx',
|
||||
created: Date.now().toString(),
|
||||
status: 0,
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
const genPublisherList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.PublisherListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
publisher: '甲子',
|
||||
blPublisherId: `${index}-blPublisherId`,
|
||||
publisherAcctNo: `${index}-publisherAcctNo`,
|
||||
publisherAcctStatus: index % 2 === 0 ? 0 : 1,
|
||||
status: index % 2 === 0 ? 0 : 1,
|
||||
addAcctStatus: index % 2 === 0 ? 0 : index % 3 === 0 ? 1 : index % 4 === 0 ? 2 : 3,
|
||||
robotImNick: `${index}-robotImNick`,
|
||||
phone: `${index}-phone`,
|
||||
email: `${index}-email`,
|
||||
operator: '宵夜',
|
||||
imGroupId: `${index}-imGroupId`,
|
||||
blGroupId: `${index}-blGroupId`,
|
||||
imGroupNick: `${index}-imGroupNick`,
|
||||
created: Date.now().toString(),
|
||||
updated: Date.now().toString(),
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
const genAnchorList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.AnchorListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
userId: `${index}-id`,
|
||||
nickName: '甲子',
|
||||
userPhone: index % 2 === 0 ? '18222020020' : '',
|
||||
isBindPhone: index % 2 === 0,
|
||||
created: Date.now().toString(),
|
||||
lastLoginDate: Date.now().toString(),
|
||||
status: index % 2 === 0 ? 0 : 1,
|
||||
city: '400100',
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
const genDeclarationList = (current: number, pageSize: number) => {
|
||||
const tableListDataSource: API.DeclarationListItem[] = [];
|
||||
for (let i = 0; i < pageSize; i += 1) {
|
||||
const index = (current - 1) * 10 + i;
|
||||
tableListDataSource.push({
|
||||
id: `${index}-id`,
|
||||
type: index % 2 === 0 ? DeclarationType.CS : DeclarationType.Direct,
|
||||
userId: `${index}-userId`,
|
||||
nickName: '甲子',
|
||||
userPhone: '18222020020',
|
||||
jobId: `${index}-id`,
|
||||
title: '招聘主播',
|
||||
useDate: Date.now().toString(),
|
||||
publisher: '甲子',
|
||||
blPublisherId: `${index}-blPublisherId`,
|
||||
publisherAcctNo: `${index}-publisherAcctNo`,
|
||||
declaredStatus: index % 2 === 0 ? 0 : 1,
|
||||
declarationDate: Date.now().toString(),
|
||||
declaredDate: Date.now().toString(),
|
||||
weComStatus: index % 2 === 0 ? 0 : 1,
|
||||
jobCityCode: '400100',
|
||||
});
|
||||
}
|
||||
tableListDataSource.reverse();
|
||||
return tableListDataSource;
|
||||
};
|
||||
|
||||
let jobListDataSource = genJobList(1, 100);
|
||||
let groupListDataSource = genGroupList(1, 100);
|
||||
let anchorGroupListDataSource = genAnchorGroupList(1, 100);
|
||||
let publisherListDataSource = genPublisherList(1, 100);
|
||||
let anchorListDataSource = genAnchorList(1, 100);
|
||||
let declarationListDataSource = genDeclarationList(1, 100);
|
||||
|
||||
function getGroupList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...groupListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: groupListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
// res.status(417).send({
|
||||
// data: {
|
||||
// code: 'NEED_LOGIN',
|
||||
// },
|
||||
// errorCode: '401',
|
||||
// errorMessage: '请先登录!',
|
||||
// });
|
||||
// return;
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function updateGroup(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { id } = body;
|
||||
let newRule = {};
|
||||
groupListDataSource = groupListDataSource.map(item => {
|
||||
if (item.id === id) {
|
||||
newRule = { ...item, ...body };
|
||||
return { ...item, ...body };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
res.json(newRule);
|
||||
}
|
||||
|
||||
function getJobList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...jobListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: jobListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function updateJob(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { jobId } = body;
|
||||
let newRule = {};
|
||||
jobListDataSource = jobListDataSource.map(item => {
|
||||
if (item.jobId === jobId) {
|
||||
newRule = { ...item, ...body };
|
||||
return { ...item, ...body };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
res.json(newRule);
|
||||
}
|
||||
|
||||
function getAnchorGroupList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...anchorGroupListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: anchorGroupListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function addAnchorGroup(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
anchorGroupListDataSource.unshift({ ...body, creator: '小叶' });
|
||||
res.json({ success: true });
|
||||
}
|
||||
|
||||
function getPublisherList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...publisherListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: publisherListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function updatePublisher(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { blPublisherId } = body;
|
||||
let newRule = {};
|
||||
publisherListDataSource = publisherListDataSource.map(item => {
|
||||
if (item.blPublisherId === blPublisherId) {
|
||||
newRule = { ...item, ...body };
|
||||
return { ...item, ...body };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
res.json(newRule);
|
||||
}
|
||||
|
||||
function getAnchorList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...anchorListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: anchorListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function getDeclarationList(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { page = 1, pageSize = 10 } = body;
|
||||
|
||||
const dataSource = [...declarationListDataSource].slice(
|
||||
((page as number) - 1) * (pageSize as number),
|
||||
(page as number) * (pageSize as number),
|
||||
);
|
||||
|
||||
const result = {
|
||||
data: dataSource,
|
||||
total: declarationListDataSource.length,
|
||||
pageSize,
|
||||
page: parseInt(`${page}`, 10) || 1,
|
||||
};
|
||||
|
||||
return res.json(result);
|
||||
}
|
||||
|
||||
function updateDeclaration(req: Request, res: Response, u: string, b: Request) {
|
||||
const body = (b && b.body) || req.body;
|
||||
const { id } = body;
|
||||
let newRule = {};
|
||||
declarationListDataSource = declarationListDataSource.map(item => {
|
||||
if (item.id === id) {
|
||||
newRule = { ...item, ...body };
|
||||
return { ...item, ...body };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
res.json(newRule);
|
||||
}
|
||||
|
||||
export default {
|
||||
[`POST ${AdminAPI.GROUP_LIST}`]: getGroupList,
|
||||
[`POST ${AdminAPI.GROUP_UPDATE}`]: updateGroup,
|
||||
[`POST ${AdminAPI.JOB_LIST}`]: getJobList,
|
||||
[`POST ${AdminAPI.JOB_UPDATE}`]: updateJob,
|
||||
[`POST ${AdminAPI.ANCHOR_GROUP_LIST}`]: getAnchorGroupList,
|
||||
[`POST ${AdminAPI.ADD_ANCHOR_GROUP}`]: addAnchorGroup,
|
||||
[`POST ${AdminAPI.PUBLISHER_LIST}`]: getPublisherList,
|
||||
[`POST ${AdminAPI.PUBLISHER_UPDATE}`]: updatePublisher,
|
||||
[`POST ${AdminAPI.ANCHOR_LIST}`]: getAnchorList,
|
||||
[`POST ${AdminAPI.DECLARATION_LIST}`]: getDeclarationList,
|
||||
[`POST ${AdminAPI.DECLARATION_UPDATE}`]: updateDeclaration,
|
||||
};
|
5
mock/route.ts
Normal file
5
mock/route.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
'/api/auth_routes': {
|
||||
'/form/advanced-form': { authority: ['admin', 'user'] },
|
||||
},
|
||||
};
|
79
mock/user.ts
Normal file
79
mock/user.ts
Normal file
@ -0,0 +1,79 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { md5 } from 'js-md5';
|
||||
|
||||
import { AdminAPI } from '../src/constants/api';
|
||||
|
||||
const waitTime = (time: number = 100) => {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
resolve(true);
|
||||
}, time);
|
||||
});
|
||||
};
|
||||
|
||||
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env;
|
||||
|
||||
/**
|
||||
* 当前用户的权限,如果为空代表没登录
|
||||
* current user access, if is '', user need login
|
||||
* 如果是 pro 的预览,默认是有权限的
|
||||
*/
|
||||
let access = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ? 'admin' : '';
|
||||
|
||||
const getAccess = () => {
|
||||
return access;
|
||||
};
|
||||
|
||||
export default {
|
||||
[`POST ${AdminAPI.USER}`]: (req: Request, res: Response) => {
|
||||
if (!getAccess()) {
|
||||
res.status(401).send({
|
||||
data: {
|
||||
isLogin: false,
|
||||
},
|
||||
errorCode: '401',
|
||||
errorMessage: '请先登录!',
|
||||
success: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.send({
|
||||
id: '1',
|
||||
userId: '00000001',
|
||||
userName: '小叶',
|
||||
created: Date.now().toString(),
|
||||
updated: Date.now().toString(),
|
||||
});
|
||||
},
|
||||
[`POST ${AdminAPI.LOGIN}`]: async (req: Request, res: Response) => {
|
||||
const { pwd, userName, type } = req.body;
|
||||
await waitTime(2000);
|
||||
if (pwd === md5('boluo') && userName === 'admin') {
|
||||
res.json({
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
||||
expires: 3600,
|
||||
});
|
||||
access = 'admin';
|
||||
return;
|
||||
}
|
||||
if (pwd === md5('user') && userName === 'user') {
|
||||
res.json({
|
||||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
||||
expires: 3600,
|
||||
});
|
||||
access = 'user';
|
||||
return;
|
||||
}
|
||||
|
||||
res.send({
|
||||
status: 'error',
|
||||
type,
|
||||
currentAuthority: 'guest',
|
||||
});
|
||||
access = 'guest';
|
||||
},
|
||||
[`POST ${AdminAPI.OUT_LOGIN}`]: (req: Request, res: Response) => {
|
||||
access = '';
|
||||
res.send({ data: {}, success: true });
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user