tools.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import dayjs, { Dayjs } from 'dayjs'
  2. import { unref } from 'vue'
  3. import XEUtils from 'xe-utils'
  4. export function buildChartOpt(option: any, metrics: any[]) {
  5. const tmp: any = {}
  6. const opt: any = {
  7. legend: { selected: {} },
  8. yAxis: [],
  9. series: [],
  10. }
  11. for (const info of metrics) {
  12. tmp[info.color] = info
  13. }
  14. for (const info of option.series) {
  15. const color = info.itemStyle.color
  16. const metricInfo = tmp[color]
  17. if (metricInfo) {
  18. opt.series.push({
  19. id: info.id,
  20. name: metricInfo.label,
  21. encode: { y: metricInfo.metric },
  22. })
  23. opt.yAxis.push({ id: info.id, name: metricInfo.label, show: true })
  24. } else {
  25. opt.yAxis.push({ id: info.id, show: false })
  26. }
  27. }
  28. for (const label of Object.keys(option.legend.selected)) {
  29. if (XEUtils.findIndexOf(metrics, (info) => info.label === label) === -1) {
  30. opt.legend.selected[label] = false
  31. } else {
  32. opt.legend.selected[label] = true
  33. }
  34. }
  35. //console.log(opt)
  36. return opt
  37. }
  38. export function parseQueryParams(body: any) {
  39. const ret: any = {};
  40. for (const key in body) {
  41. const val = unref(body[key]);
  42. if (key === 'currentDate') {
  43. if (val.dailyStartDate && val.dailyTime) {
  44. ret['data_start_date'] = val.dailyStartDate;
  45. ret['data_end_date'] = val.dailyTime;
  46. }
  47. if (val.weekStartDate && val.weekEndDate) {
  48. ret['data_start_date'] = val.weekStartDate;
  49. ret['data_end_date'] = val.weekEndDate;
  50. }
  51. if (val.startDate && val.endDate) {
  52. ret['data_start_date'] = val.startDate;
  53. ret['data_end_date'] = val.endDate;
  54. }
  55. } else if (key === 'taskIds') {
  56. ret['task_ids'] = val; // 将 task_ids 直接赋给返回对象的属性
  57. } else {
  58. ret[key] = val;
  59. }
  60. }
  61. return ret;
  62. }
  63. export function monthlyQueryParams(body: any) {
  64. const date: any = {}
  65. for (const key in body) {
  66. const val = unref(body[key])
  67. if (key === 'monthCurrentDate') {
  68. date['month_start_date'] = val.startDate
  69. date['month_end_date'] = val.endDate
  70. } else if (key === 'taskIds') {
  71. date['task_ids'] = val; // 将 task_ids 直接赋给返回对象的属性
  72. }else {
  73. date[key] = val
  74. }
  75. }
  76. return date
  77. }