From 338641e9d1f0deeac9d4776c3ab2ae5d308f367a Mon Sep 17 00:00:00 2001 From: huanghao1412 Date: Fri, 19 Jan 2024 14:02:01 +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=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/axios.ts | 1 + .../usePointHistoryRes.ts | 36 ++++++ src/hooks/useChartCommonData.hook.ts | 40 ++---- .../components/ThemesAndLayouts/index.d.ts | 7 ++ src/packages/public/publicConfig.ts | 18 ++- .../chartEditStore/chartEditStore.d.ts | 26 +++- .../components/EnergyUseHistory.d.ts | 25 ++++ ...aPointHistory.vue => EnergyUseHistory.vue} | 27 ++-- ...ataPointHistory.d.ts => PointHistory.d.ts} | 0 .../ChartDataV2/components/PointHistory.vue | 118 ++++++++++++++++++ .../components/ChartDataV2/index.d.ts | 17 +++ .../components/ChartDataV2/index.vue | 13 +- 12 files changed, 270 insertions(+), 58 deletions(-) create mode 100644 src/hooks/commonDataComponents/usePointHistoryRes.ts create mode 100644 src/packages/components/ThemesAndLayouts/index.d.ts create mode 100644 src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts rename src/views/chart/ContentConfigurations/components/ChartDataV2/components/{ChartDataPointHistory.vue => EnergyUseHistory.vue} (73%) rename src/views/chart/ContentConfigurations/components/ChartDataV2/components/{ChartDataPointHistory.d.ts => PointHistory.d.ts} (100%) create mode 100644 src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.vue diff --git a/src/api/axios.ts b/src/api/axios.ts index 149e103c..4444fa27 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -14,6 +14,7 @@ export interface MyResponseType { message: string // 兼顾主系统 errcode: string + errmsg: string } export interface MyRequestInstance extends Axios { diff --git a/src/hooks/commonDataComponents/usePointHistoryRes.ts b/src/hooks/commonDataComponents/usePointHistoryRes.ts new file mode 100644 index 00000000..94303e05 --- /dev/null +++ b/src/hooks/commonDataComponents/usePointHistoryRes.ts @@ -0,0 +1,36 @@ +import moment from "moment"; +import { publicInterface } from "@/api/path"; +import { DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' +import { commonDataType, PointHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d' +import { CreateComponentType } from '@/packages/index.d' + +export const handlePointHistory = (targetComponent: CreateComponentType) => { + let { methods, dems_device_points_uid, dateType, enable } = (targetComponent.commonData as commonDataType).pointHistory as PointHistoryType + 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 = 60 * 60 + } + else if(dateType === DateTypeEnum.MONTH) { + start_time = moment().subtract(1, 'M').format(formatter) + end_time = moment().format(formatter) + duration = 24 * 60 * 60 + } + else if(dateType === DateTypeEnum.YEAR) { + start_time = moment().subtract(1, 'y').format(formatter) + end_time = moment().format(formatter) + duration = 30 * 24 * 60 * 60 + } + + const query = { + methods, + dems_device_points_uid, + start_time, + end_time, + duration, + } + return publicInterface('/dcim/system/custom_large_screen', 'row_reports', query) +} diff --git a/src/hooks/useChartCommonData.hook.ts b/src/hooks/useChartCommonData.hook.ts index d0e75d09..8a3d5eff 100644 --- a/src/hooks/useChartCommonData.hook.ts +++ b/src/hooks/useChartCommonData.hook.ts @@ -4,11 +4,9 @@ import { ref, toRefs, watch } from "vue"; import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; import { intervalUnitHandle, newFunctionHandle, isPreview } from "@/utils"; -import { publicInterface } from "@/api/path"; -import { DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' -import moment from 'moment' -import { commonDataType } from '@/store/modules/chartEditStore/chartEditStore.d' import { cloneDeep } from 'lodash' +import { handlePointHistory } from './commonDataComponents/usePointHistoryRes' +import { ResultErrcode } from '@/enums/httpEnum' // 获取类型 type ChartEditStoreType = typeof useChartEditStore @@ -75,35 +73,8 @@ export const useChartCommonData = ( clearInterval(fetchInterval) const fetchFn = async () => { - let { methods, dems_device_points_uid, dateType, enable } = targetComponent.commonData as commonDataType - 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 = 60 * 60 - } - else if(dateType === DateTypeEnum.MONTH) { - start_time = moment().subtract(1, 'M').format(formatter) - end_time = moment().format(formatter) - duration = 24 * 60 * 60 - } - else if(dateType === DateTypeEnum.YEAR) { - start_time = moment().subtract(1, 'y').format(formatter) - end_time = moment().format(formatter) - duration = 30 * 24 * 60 * 60 - } - - const query = { - methods, - dems_device_points_uid, - start_time, - end_time, - duration, - } - const res = await publicInterface('/dcim/system/custom_large_screen', 'row_reports', query) - if (res) { + const res = await handlePointHistory(targetComponent) + if (res && res.errcode === ResultErrcode.SUCCESS) { try { const { data } = res if(data.length) echartsUpdateHandle(data[0]) @@ -111,6 +82,9 @@ export const useChartCommonData = ( console.error(error) } } + else if(res && res.errmsg){ + window['$message'].warning(res.errmsg) + } } // 普通初始化与组件交互处理监听 watch( diff --git a/src/packages/components/ThemesAndLayouts/index.d.ts b/src/packages/components/ThemesAndLayouts/index.d.ts new file mode 100644 index 00000000..d6ed6394 --- /dev/null +++ b/src/packages/components/ThemesAndLayouts/index.d.ts @@ -0,0 +1,7 @@ +export enum ChatCategoryEnum { + THEMES = 'Themes', +} + +export enum ChatCategoryEnumName { + THEMES = '主题', +} diff --git a/src/packages/public/publicConfig.ts b/src/packages/public/publicConfig.ts index 08c61047..dbf76182 100644 --- a/src/packages/public/publicConfig.ts +++ b/src/packages/public/publicConfig.ts @@ -1,5 +1,5 @@ import { getUUID } from '@/utils' -import { RequestConfigType, commonDataType, DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' +import { RequestConfigType, commonDataType, CurrentSourceEnum, DateTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d' import { groupTitle } from '@/settings/designSetting' import { BaseEvent, EventLife } from '@/enums/eventEnum' import { @@ -47,10 +47,18 @@ export const requestConfig: RequestConfigType = { } const commonData: commonDataType = { - enable: false, - methods: [], - dems_device_points_uid: [], - dateType: DateTypeEnum.DAY + currentSource: CurrentSourceEnum.POINTHISTORY, + pointHistory: { + enable: false, + methods: [], + dems_device_points_uid: [], + dateType: DateTypeEnum.DAY + }, + energyUseHistory: { + enable: false, + strategy_ids: [], + dateType: DateTypeEnum.DAY + } } // 单实例类 diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 0f108748..01f56e94 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -250,14 +250,36 @@ export enum DateTypeEnum { YEAR = 'year' } -// 通用组件数据 -export interface commonDataType { +// common数据源选项 +export enum CurrentSourceEnum { + // 测点历史 + POINTHISTORY = 'pointHistory', + // 能耗历史 + ENERGYUSEHISTORY = 'energyUseHistory' +} + +// 测点历史参数 +export interface PointHistoryType { enable: boolean methods: MethodsTypeEnum[] dems_device_points_uid: string[] dateType: DateTypeEnum } +// 能耗历史参数 +export interface EnergyUseHistoryType { + enable: boolean + strategy_ids: string[] + dateType: DateTypeEnum +} + +// 通用组件数据 +export interface commonDataType { + currentSource: CurrentSourceEnum, + pointHistory: PointHistoryType, + energyUseHistory: EnergyUseHistoryType, +} + // Store 类型 export interface ChartEditStoreType { [ChartEditStoreEnum.PROJECT_INFO]: ProjectInfoType diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts new file mode 100644 index 00000000..8bd4cd8a --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts @@ -0,0 +1,25 @@ +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/ChartDataPointHistory.vue b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue similarity index 73% rename from src/views/chart/ContentConfigurations/components/ChartDataV2/components/ChartDataPointHistory.vue rename to src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue index 6d0a1991..f82bae33 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/ChartDataPointHistory.vue +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.vue @@ -3,14 +3,11 @@ - + - - - - + @@ -58,20 +55,20 @@ diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/ChartDataPointHistory.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.d.ts similarity index 100% rename from src/views/chart/ContentConfigurations/components/ChartDataV2/components/ChartDataPointHistory.d.ts rename to src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.d.ts diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.vue b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.vue new file mode 100644 index 00000000..2f66433a --- /dev/null +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/components/PointHistory.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts index 9920a64e..1d933d69 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.d.ts @@ -1,4 +1,5 @@ import { RequestHttpEnum, RequestHttpIntervalEnum, RequestDataTypeEnum, SelectHttpTimeNameObj } from '@/enums/httpEnum' +import { CurrentSourceEnum } from '@/store/modules/chartEditStore/chartEditStore.d' // 匹配结果 export enum DataResultEnum { @@ -108,3 +109,19 @@ export const selectTimeOptions: SelectHttpTimeType[] = [ unit: 86400000, }, ] + +export interface sourceOptionsItemType { + label: string, + value: CurrentSourceEnum, +} +// 通用组件数据源选项 +export const sourceOptions: sourceOptionsItemType[] = [ + { + label: '测点历史', + value: CurrentSourceEnum.POINTHISTORY + }, + { + label: '能耗历史', + value: CurrentSourceEnum.ENERGYUSEHISTORY + }, +] diff --git a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue index feff5476..ab37078d 100644 --- a/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartDataV2/index.vue @@ -1,6 +1,10 @@