_rule.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { HttpRequest } from '@angular/common/http';
  17. import { MockRequest } from '@delon/mock';
  18. const list: any[] = [];
  19. for (let i = 0; i < 46; i += 1) {
  20. list.push({
  21. key: i,
  22. disabled: i % 6 === 0,
  23. href: 'https://ant.design',
  24. avatar: [
  25. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  26. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  27. ][i % 2],
  28. no: `TradeCode ${i}`,
  29. title: `一个任务名称 ${i}`,
  30. owner: '曲丽丽',
  31. description: '这是一段描述',
  32. callNo: Math.floor(Math.random() * 1000),
  33. status: Math.floor(Math.random() * 10) % 4,
  34. updatedAt: new Date(`2017-07-${i < 18 ? '0' + (Math.floor(i / 2) + 1) : Math.floor(i / 2) + 1}`),
  35. createdAt: new Date(`2017-07-${i < 18 ? '0' + (Math.floor(i / 2) + 1) : Math.floor(i / 2) + 1}`),
  36. progress: Math.ceil(Math.random() * 100),
  37. });
  38. }
  39. function getRule(params: any): any[] {
  40. let ret = [...list];
  41. if (params.sorter) {
  42. const s = params.sorter.split('_');
  43. ret = ret.sort((prev, next) => {
  44. if (s[1] === 'descend') {
  45. return next[s[0]] - prev[s[0]];
  46. }
  47. return prev[s[0]] - next[s[0]];
  48. });
  49. }
  50. if (params.statusList && params.statusList.length > 0) {
  51. ret = ret.filter((data) => params.statusList.indexOf(data.status) > -1);
  52. }
  53. if (params.no) {
  54. ret = ret.filter((data) => data.no.indexOf(params.no) > -1);
  55. }
  56. return ret;
  57. }
  58. function removeRule(nos: string): boolean {
  59. nos.split(',').forEach((no) => {
  60. const idx = list.findIndex((w) => w.no === no);
  61. if (idx !== -1) {
  62. list.splice(idx, 1);
  63. }
  64. });
  65. return true;
  66. }
  67. function saveRule(description: string): void {
  68. const i = Math.ceil(Math.random() * 10000);
  69. list.unshift({
  70. key: i,
  71. href: 'https://ant.design',
  72. avatar: [
  73. 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png',
  74. 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png',
  75. ][i % 2],
  76. no: `TradeCode ${i}`,
  77. title: `一个任务名称 ${i}`,
  78. owner: '曲丽丽',
  79. description,
  80. callNo: Math.floor(Math.random() * 1000),
  81. status: Math.floor(Math.random() * 10) % 2,
  82. updatedAt: new Date(),
  83. createdAt: new Date(),
  84. progress: Math.ceil(Math.random() * 100),
  85. });
  86. }
  87. export const RULES = {
  88. '/rule': (req: MockRequest) => getRule(req.queryString),
  89. 'DELETE /rule': (req: MockRequest) => removeRule(req.queryString.nos),
  90. 'POST /rule': (req: MockRequest) => saveRule(req.body.description),
  91. };