| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import { defineMock } from '@umijs/max';
- const blacklistDataSource: any[] = [
- {
- id: '1',
- name: 'Example Company A',
- creditCode: '91110108551111111A',
- createdAt: '2023-01-01',
- },
- {
- id: '2',
- name: 'Example Company B',
- creditCode: '91110108551111111B',
- createdAt: '2023-02-15',
- },
- ];
- export default defineMock({
- 'POST /api/login': (req, res) => {
- const { username, password } = req.body || {};
- if (username && password) {
- res.json({
- token: 'mock-token-' + Date.now(),
- username,
- });
- } else {
- res.status(400).json({ message: '用户名或密码错误' });
- }
- },
- 'GET /api/blacklist': (req, res) => {
- const { current = 1, pageSize = 10, name, creditCode } = req.query;
- let dataSource = [...blacklistDataSource];
- if (name) {
- dataSource = dataSource.filter(item => item.name.includes(name));
- }
- if (creditCode) {
- dataSource = dataSource.filter(item => item.creditCode.includes(creditCode));
- }
- const total = dataSource.length;
- // Simple pagination
- const startIndex = (Number(current) - 1) * Number(pageSize);
- const endIndex = startIndex + Number(pageSize);
- const list = dataSource.slice(startIndex, endIndex);
- res.json({
- data: list,
- total,
- success: true,
- });
- },
- 'POST /api/blacklist': (req, res) => {
- const newEntry = {
- id: Date.now().toString(),
- createdAt: new Date().toISOString().split('T')[0],
- ...req.body,
- };
- blacklistDataSource.unshift(newEntry);
- res.json({ success: true });
- },
- 'PUT /api/blacklist/:id': (req, res) => {
- const { id } = req.params;
- const index = blacklistDataSource.findIndex((item) => item.id === id);
- if (index > -1) {
- blacklistDataSource[index] = { ...blacklistDataSource[index], ...req.body };
- }
- res.json({ success: true });
- },
- 'DELETE /api/blacklist/:id': (req, res) => {
- const { id } = req.params;
- const index = blacklistDataSource.findIndex((item) => item.id === id);
- if (index > -1) {
- blacklistDataSource.splice(index, 1);
- }
- res.json({ success: true });
- },
- });
|