From 8a8d2f6dfbe430838efcbe64f3d4f771675b8b08 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Tue, 3 Dec 2024 14:36:59 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=88=A0=E9=99=A4=20moment=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/mock/listTableList.ts | 176 --------------------------------- react-ui/package.json | 1 - 2 files changed, 177 deletions(-) delete mode 100644 react-ui/mock/listTableList.ts diff --git a/react-ui/mock/listTableList.ts b/react-ui/mock/listTableList.ts deleted file mode 100644 index 35ec3cec..00000000 --- a/react-ui/mock/listTableList.ts +++ /dev/null @@ -1,176 +0,0 @@ -import { Request, Response } from 'express'; -import moment from 'moment'; -import { parse } from 'url'; - -// mock tableListDataSource -const genList = (current: number, pageSize: number) => { - const tableListDataSource: API.RuleListItem[] = []; - - for (let i = 0; i < pageSize; i += 1) { - const index = (current - 1) * 10 + i; - tableListDataSource.push({ - key: index, - disabled: i % 6 === 0, - href: 'https://ant.design', - avatar: [ - 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png', - 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png', - ][i % 2], - name: `TradeCode ${index}`, - owner: '曲丽丽', - desc: '这是一段描述', - callNo: Math.floor(Math.random() * 1000), - status: Math.floor(Math.random() * 10) % 4, - updatedAt: moment().format('YYYY-MM-DD'), - createdAt: moment().format('YYYY-MM-DD'), - progress: Math.ceil(Math.random() * 100), - }); - } - tableListDataSource.reverse(); - return tableListDataSource; -}; - -let tableListDataSource = genList(1, 100); - -function getRule(req: Request, res: Response, u: string) { - let realUrl = u; - if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') { - realUrl = req.url; - } - const { current = 1, pageSize = 10 } = req.query; - const params = parse(realUrl, true).query as unknown as API.PageParams & - API.RuleListItem & { - sorter: any; - filter: any; - }; - - let dataSource = [...tableListDataSource].slice( - ((current as number) - 1) * (pageSize as number), - (current as number) * (pageSize as number), - ); - if (params.sorter) { - const sorter = JSON.parse(params.sorter); - dataSource = dataSource.sort((prev, next) => { - let sortNumber = 0; - (Object.keys(sorter) as Array).forEach((key) => { - let nextSort = next?.[key] as number; - let preSort = prev?.[key] as number; - if (sorter[key] === 'descend') { - if (preSort - nextSort > 0) { - sortNumber += -1; - } else { - sortNumber += 1; - } - return; - } - if (preSort - nextSort > 0) { - sortNumber += 1; - } else { - sortNumber += -1; - } - }); - return sortNumber; - }); - } - if (params.filter) { - const filter = JSON.parse(params.filter as any) as { - [key: string]: string[]; - }; - if (Object.keys(filter).length > 0) { - dataSource = dataSource.filter((item) => { - return (Object.keys(filter) as Array).some((key) => { - if (!filter[key]) { - return true; - } - if (filter[key].includes(`${item[key]}`)) { - return true; - } - return false; - }); - }); - } - } - - if (params.name) { - dataSource = dataSource.filter((data) => data?.name?.includes(params.name || '')); - } - const result = { - data: dataSource, - total: tableListDataSource.length, - success: true, - pageSize, - current: parseInt(`${params.current}`, 10) || 1, - }; - - return res.json(result); -} - -function postRule(req: Request, res: Response, u: string, b: Request) { - let realUrl = u; - if (!realUrl || Object.prototype.toString.call(realUrl) !== '[object String]') { - realUrl = req.url; - } - - const body = (b && b.body) || req.body; - const { method, name, desc, key } = body; - - switch (method) { - /* eslint no-case-declarations:0 */ - case 'delete': - tableListDataSource = tableListDataSource.filter((item) => key.indexOf(item.key) === -1); - break; - case 'post': - (() => { - const i = Math.ceil(Math.random() * 10000); - const newRule: API.RuleListItem = { - key: tableListDataSource.length, - href: 'https://ant.design', - avatar: [ - 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png', - 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png', - ][i % 2], - name, - owner: '曲丽丽', - desc, - callNo: Math.floor(Math.random() * 1000), - status: Math.floor(Math.random() * 10) % 2, - updatedAt: moment().format('YYYY-MM-DD'), - createdAt: moment().format('YYYY-MM-DD'), - progress: Math.ceil(Math.random() * 100), - }; - tableListDataSource.unshift(newRule); - return res.json(newRule); - })(); - return; - - case 'update': - (() => { - let newRule = {}; - tableListDataSource = tableListDataSource.map((item) => { - if (item.key === key) { - newRule = { ...item, desc, name }; - return { ...item, desc, name }; - } - return item; - }); - return res.json(newRule); - })(); - return; - default: - break; - } - - const result = { - list: tableListDataSource, - pagination: { - total: tableListDataSource.length, - }, - }; - - res.json(result); -} - -export default { - 'GET /api/rule': getRule, - 'POST /api/rule': postRule, -}; diff --git a/react-ui/package.json b/react-ui/package.json index aebf21ca..dc5be1c5 100644 --- a/react-ui/package.json +++ b/react-ui/package.json @@ -67,7 +67,6 @@ "fabric": "^5.3.0", "highlight.js": "^11.7.0", "lodash": "^4.17.21", - "moment": "^2.30.1", "omit.js": "^2.0.2", "pnpm": "^8.9.0", "query-string": "^8.1.0",