2
0

_rule.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { HttpRequest } from '@angular/common/http';
  2. import { MockRequest } from '@delon/mock';
  3. const list: any[] = [];
  4. for (let i = 0; i < 46; i += 1) {
  5. list.push({
  6. key: i,
  7. disabled: i % 6 === 0,
  8. href: 'https://ant.design',
  9. avatar: [
  10. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  11. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  12. ][i % 2],
  13. no: `TradeCode ${i}`,
  14. title: `一个任务名称 ${i}`,
  15. owner: '曲丽丽',
  16. description: '这是一段描述',
  17. callNo: Math.floor(Math.random() * 1000),
  18. status: Math.floor(Math.random() * 10) % 4,
  19. updatedAt: new Date(`2017-07-${i < 18 ? '0' + (Math.floor(i / 2) + 1) : Math.floor(i / 2) + 1}`),
  20. createdAt: new Date(`2017-07-${i < 18 ? '0' + (Math.floor(i / 2) + 1) : Math.floor(i / 2) + 1}`),
  21. progress: Math.ceil(Math.random() * 100),
  22. });
  23. }
  24. function getRule(params: any): any[] {
  25. let ret = [...list];
  26. if (params.sorter) {
  27. const s = params.sorter.split('_');
  28. ret = ret.sort((prev, next) => {
  29. if (s[1] === 'descend') {
  30. return next[s[0]] - prev[s[0]];
  31. }
  32. return prev[s[0]] - next[s[0]];
  33. });
  34. }
  35. if (params.statusList && params.statusList.length > 0) {
  36. ret = ret.filter((data) => params.statusList.indexOf(data.status) > -1);
  37. }
  38. if (params.no) {
  39. ret = ret.filter((data) => data.no.indexOf(params.no) > -1);
  40. }
  41. return ret;
  42. }
  43. function removeRule(nos: string): boolean {
  44. nos.split(',').forEach((no) => {
  45. const idx = list.findIndex((w) => w.no === no);
  46. if (idx !== -1) {
  47. list.splice(idx, 1);
  48. }
  49. });
  50. return true;
  51. }
  52. function saveRule(description: string): void {
  53. const i = Math.ceil(Math.random() * 10000);
  54. list.unshift({
  55. key: i,
  56. href: 'https://ant.design',
  57. avatar: [
  58. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  59. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  60. ][i % 2],
  61. no: `TradeCode ${i}`,
  62. title: `一个任务名称 ${i}`,
  63. owner: '曲丽丽',
  64. description,
  65. callNo: Math.floor(Math.random() * 1000),
  66. status: Math.floor(Math.random() * 10) % 2,
  67. updatedAt: new Date(),
  68. createdAt: new Date(),
  69. progress: Math.ceil(Math.random() * 100),
  70. });
  71. }
  72. export const RULES = {
  73. '/rule': (req: MockRequest) => getRule(req.queryString),
  74. 'DELETE /rule': (req: MockRequest) => removeRule(req.queryString.nos),
  75. 'POST /rule': (req: MockRequest) => saveRule(req.body.description),
  76. };