From e36022a9d092c2e55573b34e1513b844b75cdc90 Mon Sep 17 00:00:00 2001 From: huanghao1412 Date: Fri, 19 Jan 2024 19:15:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../useEnergyUseHistoryRes.ts | 35 +++++++ .../usePointHistoryRes.ts | 2 +- .../useRecordValueHistoryRes.ts | 38 ++++++++ src/hooks/useChartCommonData.hook.ts | 25 ++++- src/packages/index.d.ts | 2 +- src/packages/public/publicConfig.ts | 6 ++ .../chartEditStore/chartEditStore.d.ts | 21 +++- ...{PointHistory.d.ts => ComponentsType.d.ts} | 22 ++++- .../components/EnergyUseHistory.d.ts | 25 ----- .../components/EnergyUseHistory.vue | 63 ++++-------- .../ChartDataV2/components/PointHistory.vue | 48 +++------- .../components/RecordValueHistory.vue | 95 +++++++++++++++++++ .../components/ChartDataV2/index.d.ts | 4 + .../components/ChartDataV2/index.vue | 25 ++++- 14 files changed, 294 insertions(+), 117 deletions(-) create mode 100644 src/hooks/commonDataComponents/useEnergyUseHistoryRes.ts create mode 100644 src/hooks/commonDataComponents/useRecordValueHistoryRes.ts rename src/views/chart/ContentConfigurations/components/ChartDataV2/components/{PointHistory.d.ts => ComponentsType.d.ts} (64%) delete mode 100644 src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts create mode 100644 src/views/chart/ContentConfigurations/components/ChartDataV2/components/RecordValueHistory.vue diff --git a/src/hooks/commonDataComponents/useEnergyUseHistoryRes.ts b/src/hooks/commonDataComponents/useEnergyUseHistoryRes.ts new file mode 100644 index 00000000..7019006d --- /dev/null +++ b/src/hooks/commonDataComponents/useEnergyUseHistoryRes.ts @@ -0,0 +1,35 @@ +import moment from "moment"; +import { publicInterface } from "@/api/path"; +import { DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' +import { commonDataType, EnergyUseHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d' +import { CreateComponentType } from '@/packages/index.d' + +export const handleEnergyUseHistory = (targetComponent: CreateComponentType) => { + let { strategy_ids, dateType, enable } = (targetComponent.commonData as commonDataType).energyUseHistory as EnergyUseHistoryType + if(!enable) return + let start_time: string = '', end_time: string = '', duration: number = 0 + const formatter = 'yyyy-MM-DD HH:mm:ss' + if(dateType === DateTypeEnum.DAY) { + start_time = moment().subtract(1, 'd').format(formatter) + end_time = moment().format(formatter) + duration = 2 + } + else if(dateType === DateTypeEnum.MONTH) { + start_time = moment().subtract(1, 'M').format(formatter) + end_time = moment().format(formatter) + duration = 3 + } + else if(dateType === DateTypeEnum.YEAR) { + start_time = moment().subtract(1, 'y').format(formatter) + end_time = moment().format(formatter) + duration = 4 + } + + const query = { + start_time, + end_time, + duration, + strategy_ids + } + return publicInterface('/dcim/system/custom_large_screen', 'err', query) +} diff --git a/src/hooks/commonDataComponents/usePointHistoryRes.ts b/src/hooks/commonDataComponents/usePointHistoryRes.ts index 94303e05..8b57bc36 100644 --- a/src/hooks/commonDataComponents/usePointHistoryRes.ts +++ b/src/hooks/commonDataComponents/usePointHistoryRes.ts @@ -27,7 +27,7 @@ export const handlePointHistory = (targetComponent: CreateComponentType) => { const query = { methods, - dems_device_points_uid, + dems_device_points_uid: dems_device_points_uid.filter(_ => _), start_time, end_time, duration, diff --git a/src/hooks/commonDataComponents/useRecordValueHistoryRes.ts b/src/hooks/commonDataComponents/useRecordValueHistoryRes.ts new file mode 100644 index 00000000..d2aa9f17 --- /dev/null +++ b/src/hooks/commonDataComponents/useRecordValueHistoryRes.ts @@ -0,0 +1,38 @@ +import moment from "moment"; +import { publicInterface } from "@/api/path"; +import { DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' +import { commonDataType, RecordValueHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d' +import { CreateComponentType } from '@/packages/index.d' + +export const handleRecordValueHistory = (targetComponent: CreateComponentType) => { + let { policy, strategy_ids, dateType, enable } = (targetComponent.commonData as commonDataType).recordValueHistory as RecordValueHistoryType + if(!enable) return + let start_time: string = '', end_time: string = '', duration: number = 0 + const formatter = 'yyyy-MM-DD HH:mm:ss' + if(dateType === DateTypeEnum.DAY) { + start_time = moment().subtract(1, 'd').format(formatter) + end_time = moment().format(formatter) + duration = 2 + } + else if(dateType === DateTypeEnum.MONTH) { + start_time = moment().subtract(1, 'M').format(formatter) + end_time = moment().format(formatter) + duration = 3 + } + else if(dateType === DateTypeEnum.YEAR) { + start_time = moment().subtract(1, 'y').format(formatter) + end_time = moment().format(formatter) + duration = 4 + } + + const query = { + amount: 1, + chart_type: 'line', + duration, + policy, + strategy_ids: strategy_ids.filter(_ => _), + start_time, + end_time, + } + return publicInterface('/dcim/system/custom_large_screen', 'sum', query) +} diff --git a/src/hooks/useChartCommonData.hook.ts b/src/hooks/useChartCommonData.hook.ts index 8a3d5eff..a320bbff 100644 --- a/src/hooks/useChartCommonData.hook.ts +++ b/src/hooks/useChartCommonData.hook.ts @@ -3,9 +3,12 @@ import { setOption } from "@/packages/public"; import { ref, toRefs, watch } from "vue"; import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; +import { CurrentSourceEnum } from '@/store/modules/chartEditStore/chartEditStore.d' import { intervalUnitHandle, newFunctionHandle, isPreview } from "@/utils"; import { cloneDeep } from 'lodash' import { handlePointHistory } from './commonDataComponents/usePointHistoryRes' +import { handleEnergyUseHistory } from './commonDataComponents/useEnergyUseHistoryRes'; +import { handleRecordValueHistory } from './commonDataComponents/useRecordValueHistoryRes' import { ResultErrcode } from '@/enums/httpEnum' // 获取类型 @@ -73,11 +76,29 @@ export const useChartCommonData = ( clearInterval(fetchInterval) const fetchFn = async () => { - const res = await handlePointHistory(targetComponent) + let res + switch (targetComponent.commonData?.currentSource) { + case CurrentSourceEnum.POINTHISTORY: + res = await handlePointHistory(targetComponent) + break; + case CurrentSourceEnum.ENERGYUSEHISTORY: + res = await handleEnergyUseHistory(targetComponent) + break; + case CurrentSourceEnum.RECORDVALUEHISTORY: + res = await handleRecordValueHistory(targetComponent) + break; + default: + break; + } if (res && res.errcode === ResultErrcode.SUCCESS) { try { const { data } = res - if(data.length) echartsUpdateHandle(data[0]) + if(Object.prototype.toString.call(data) === '[object Array]') { + if(data.length) echartsUpdateHandle(data[0]) + } + else if(Object.prototype.toString.call(data) === '[object Object]'){ + echartsUpdateHandle(data) + } } catch (error) { console.error(error) } diff --git a/src/packages/index.d.ts b/src/packages/index.d.ts index 85434a71..6080292e 100644 --- a/src/packages/index.d.ts +++ b/src/packages/index.d.ts @@ -144,7 +144,7 @@ export interface PublicConfigType { overFlowHidden?: boolean } filter?: string - commonData?: commonDataType + commonData: commonDataType customData?: { [key: string]: any } status: StatusType interactActions?: InteractActionsType[] diff --git a/src/packages/public/publicConfig.ts b/src/packages/public/publicConfig.ts index dbf76182..6f2aa324 100644 --- a/src/packages/public/publicConfig.ts +++ b/src/packages/public/publicConfig.ts @@ -58,6 +58,12 @@ const commonData: commonDataType = { enable: false, strategy_ids: [], dateType: DateTypeEnum.DAY + }, + recordValueHistory: { + enable: false, + policy: [], + strategy_ids: [], + dateType: DateTypeEnum.DAY } } diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 01f56e94..e4d906f4 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -255,7 +255,9 @@ export enum CurrentSourceEnum { // 测点历史 POINTHISTORY = 'pointHistory', // 能耗历史 - ENERGYUSEHISTORY = 'energyUseHistory' + ENERGYUSEHISTORY = 'energyUseHistory', + // 记录值历史 + RECORDVALUEHISTORY = 'recordValueHistory' } // 测点历史参数 @@ -269,7 +271,21 @@ export interface PointHistoryType { // 能耗历史参数 export interface EnergyUseHistoryType { enable: boolean - strategy_ids: string[] + strategy_ids: (number | null)[] + dateType: DateTypeEnum +} + +export enum PolicyTypeEnum { + AVG = 3, + MIN = 0, + MAX = 1 +} + +// 记录值历史 +export interface RecordValueHistoryType { + enable: boolean + policy: PolicyTypeEnum[] + strategy_ids: (number | null)[] dateType: DateTypeEnum } @@ -278,6 +294,7 @@ export interface commonDataType { currentSource: CurrentSourceEnum, pointHistory: PointHistoryType, energyUseHistory: EnergyUseHistoryType, + recordValueHistory: RecordValueHistoryType } // Store 类型 diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/ComponentsType.d.ts similarity index 64% rename from src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.d.ts rename to src/views/chart/ContentConfigurations/components/ChartDataV2/components/ComponentsType.d.ts index 73ff4131..3bc63788 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.d.ts +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/ComponentsType.d.ts @@ -1,4 +1,4 @@ -import { DateTypeEnum, MethodsTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' +import { DateTypeEnum, MethodsTypeEnum, PolicyTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' type DateOptionsItemType = { label: string, @@ -42,3 +42,23 @@ export const MethodsOptions: MethodsOptionsItemType[] = [ value: MethodsTypeEnum.MAX } ] + +type PolicyOptionsItemType = { + label: string, + value: PolicyTypeEnum +} + +export const PolicyOptions: PolicyOptionsItemType[] = [ + { + label: '平均值', + value: PolicyTypeEnum.AVG + }, + { + label: '最小值', + value: PolicyTypeEnum.MIN + }, + { + label: '最大值', + value: PolicyTypeEnum.MAX + } +] \ No newline at end of file diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts deleted file mode 100644 index 8bd4cd8a..00000000 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { DateTypeEnum, MethodsTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' - -type DateOptionsItemType = { - label: string, - value: DateTypeEnum, - // duration: number -} -export const DateOptions: DateOptionsItemType[] = [ - { - label: '近一天', - value: DateTypeEnum.DAY, - // 颗粒度为 秒数 - // duration: 60 * 60 - }, - { - label: '近一月', - value: DateTypeEnum.MONTH, - // duration: 24 * 60 * 60 - }, - { - label: '近一年', - value: DateTypeEnum.YEAR, - // duration: 30 * 24 * 60 * 60 - }, -] diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue index f82bae33..97342135 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue @@ -1,6 +1,4 @@ - - - - + +
- - - - - - - - + + + \ No newline at end of file diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts index 1d933d69..ede9133e 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts @@ -124,4 +124,8 @@ export const sourceOptions: sourceOptionsItemType[] = [ label: '能耗历史', value: CurrentSourceEnum.ENERGYUSEHISTORY }, + { + label: '记录值历史', + value: CurrentSourceEnum.RECORDVALUEHISTORY + }, ] diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue index ab37078d..b7a57ae7 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue @@ -4,7 +4,23 @@ - + + + + + + + + + +
@@ -29,16 +45,17 @@