1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import dayjs, { Dayjs } from 'dayjs'
- import { unref } from 'vue'
- import XEUtils from 'xe-utils'
- export function buildChartOpt(option: any, metrics: any[]) {
- const tmp: any = {}
- const opt: any = {
- legend: { selected: {} },
- yAxis: [],
- series: [],
- }
- for (const info of metrics) {
- tmp[info.color] = info
- }
- for (const info of option.series) {
- const color = info.itemStyle.color
- const metricInfo = tmp[color]
- if (metricInfo) {
- opt.series.push({
- id: info.id,
- name: metricInfo.label,
- encode: { y: metricInfo.metric },
- })
- opt.yAxis.push({ id: info.id, name: metricInfo.label, show: true })
- } else {
- opt.yAxis.push({ id: info.id, show: false })
- }
- }
- for (const label of Object.keys(option.legend.selected)) {
- if (XEUtils.findIndexOf(metrics, (info) => info.label === label) === -1) {
- opt.legend.selected[label] = false
- } else {
- opt.legend.selected[label] = true
- }
- }
- //console.log(opt)
- return opt
- }
- export function parseQueryParams(body: any) {
- const ret: any = {};
- for (const key in body) {
- const val = unref(body[key]);
- if (key === 'currentDate') {
- if (val.dailyStartDate && val.dailyTime) {
- ret['data_start_date'] = val.dailyStartDate;
- ret['data_end_date'] = val.dailyTime;
- }
- if (val.weekStartDate && val.weekEndDate) {
- ret['data_start_date'] = val.weekStartDate;
- ret['data_end_date'] = val.weekEndDate;
- }
- if (val.startDate && val.endDate) {
- ret['data_start_date'] = val.startDate;
- ret['data_end_date'] = val.endDate;
- }
- } else if (key === 'taskIds') {
- ret['task_ids'] = val; // 将 task_ids 直接赋给返回对象的属性
- } else {
- ret[key] = val;
- }
- }
- return ret;
- }
- export function monthlyQueryParams(body: any) {
- const date: any = {}
- for (const key in body) {
- const val = unref(body[key])
- if (key === 'monthCurrentDate') {
- date['month_start_date'] = val.startDate
- date['month_end_date'] = val.endDate
- } else if (key === 'taskIds') {
- date['task_ids'] = val; // 将 task_ids 直接赋给返回对象的属性
- }else {
- date[key] = val
- }
- }
- return date
- }
|