_rule.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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) {
  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) list.splice(idx, 1);
  47. });
  48. return true;
  49. }
  50. function saveRule(description: string) {
  51. const i = Math.ceil(Math.random() * 10000);
  52. list.unshift({
  53. key: i,
  54. href: 'https://ant.design',
  55. avatar: [
  56. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  57. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  58. ][i % 2],
  59. no: `TradeCode ${i}`,
  60. title: `一个任务名称 ${i}`,
  61. owner: '曲丽丽',
  62. description,
  63. callNo: Math.floor(Math.random() * 1000),
  64. status: Math.floor(Math.random() * 10) % 2,
  65. updatedAt: new Date(),
  66. createdAt: new Date(),
  67. progress: Math.ceil(Math.random() * 100),
  68. });
  69. }
  70. export const RULES = {
  71. '/rule': (req: MockRequest) => getRule(req.queryString),
  72. 'DELETE /rule': (req: MockRequest) => removeRule(req.queryString.nos),
  73. 'POST /rule': (req: MockRequest) => saveRule(req.body.description),
  74. };