feat: 新增通用组件数据

This commit is contained in:
huanghao1412 2024-01-19 19:15:12 +08:00
parent 338641e9d1
commit e36022a9d0
14 changed files with 294 additions and 117 deletions

View File

@ -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)
}

View File

@ -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,

View File

@ -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)
}

View File

@ -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)
}

View File

@ -144,7 +144,7 @@ export interface PublicConfigType {
overFlowHidden?: boolean
}
filter?: string
commonData?: commonDataType
commonData: commonDataType
customData?: { [key: string]: any }
status: StatusType
interactActions?: InteractActionsType[]

View File

@ -58,6 +58,12 @@ const commonData: commonDataType = {
enable: false,
strategy_ids: [],
dateType: DateTypeEnum.DAY
},
recordValueHistory: {
enable: false,
policy: [],
strategy_ids: [],
dateType: DateTypeEnum.DAY
}
}

View File

@ -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 类型

View File

@ -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
}
]

View File

@ -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
},
]

View File

@ -1,6 +1,4 @@
<template>
<setting-item-box name="测点历史记录" :alone="true">
</setting-item-box>
<setting-item-box name="启用数据" :alone="true">
<n-space justify="start">
<n-switch v-model:value="energyUseHistory.enable" />
@ -9,13 +7,15 @@
<setting-item-box name="时间" :alone="true">
<n-select v-model:value="energyUseHistory.dateType" :options="DateOptions" size="small"/>
</setting-item-box>
<setting-item-box name="测点ID" :alone="true">
<setting-item-box name="报表ID" :alone="true">
<n-space vertical>
<n-space v-for="(item, i) in computeIds" :key="item.id" align="center" :wrap="false">
<n-input
<n-input-number
:value="item.value"
@update:value="(v: string) => handleChange(v, i)"
placeholder="请输入测点ID"
@update:value.trim="(v: number) => handleChange(v, i)"
min="1"
:show-button="false"
placeholder="请输入报表ID"
size="small"
clearable
/>
@ -24,66 +24,44 @@
<n-icon><CloseIcon /></n-icon>
</template>
</n-button>
</n-space>
<n-space align="center" :wrap="false">
<n-input v-model:value="templateValue" placeholder="请输入测点ID" size="small" clearable/>
<n-button @click="handleAdd" circle size="tiny">
<n-button v-if="i === computeIds.length - 1" @click="handleAdd" circle size="tiny">
<template #icon>
<n-icon><AddIcon /></n-icon>
</template>
</n-button>
<div v-else style="width: 22px"></div>
</n-space>
</n-space>
</setting-item-box>
<setting-item-box name="更新间隔" :alone="true">
<n-input-group>
<n-input-number
v-model:value.trim="targetData.request.requestInterval"
min="1"
:show-button="false"
placeholder="请输入"
size="small"
style="flex: 1;"
>
</n-input-number>
<!-- 单位 -->
<n-select class="select-time-options" v-model:value="targetData.request.requestIntervalUnit" :options="selectTimeOptions" size="small" style="width: 80px"/>
</n-input-group>
</setting-item-box>
</template>
<script lang="ts" setup>
import { ref, watch, reactive, toRefs, computed } from 'vue'
import { watch, reactive, computed } from 'vue'
import type { Ref } from 'vue'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { useTargetData } from '../../hooks/useTargetData.hook'
import { DateOptions } from './EnergyUseHistory.d'
import { nanoid } from 'nanoid'
import { DateOptions } from './ComponentsType.d'
import { icon } from '@/plugins/icon'
import { commonDataType, RequestConfigType, EnergyUseHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
import { selectTimeOptions } from '../index.d'
import { commonDataType, EnergyUseHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
const { CloseIcon, AddIcon } = icon.ionicons5
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string, request: RequestConfigType }> }
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string }> }
// const commonData: Ref<commonDataType> = computed(() => targetData.value.commonData)
const energyUseHistory: Ref<EnergyUseHistoryType> = computed(() => targetData.value.commonData.energyUseHistory)
type computeIdsItemType = {
id: string,
value: string
value: number | null
}
const computeIds: computeIdsItemType[] = reactive([])
let templateValue = ref('')
watch(() => [targetData.value?.id, energyUseHistory.value], () => {
templateValue.value = ''
let arr = energyUseHistory.value.strategy_ids.map(item => {
watch(() => [targetData.value.id, energyUseHistory.value], () => {
if(!energyUseHistory.value.strategy_ids.length) targetData.value.commonData.energyUseHistory.strategy_ids.push(null)
let arr = energyUseHistory.value.strategy_ids.map((item, i) => {
return {
id: nanoid(),
id: `${targetData.value.id}_${i}`,
value: item
}
})
@ -93,15 +71,12 @@ watch(() => [targetData.value?.id, energyUseHistory.value], () => {
immediate: true
})
const handleChange = (v: string, i: number) => {
const handleChange = (v: number, i: number) => {
targetData.value.commonData.energyUseHistory.strategy_ids[i] = v
}
const handleAdd = () => {
if(templateValue.value) {
targetData.value.commonData.energyUseHistory.strategy_ids.push(templateValue.value)
templateValue.value = ''
}
targetData.value.commonData.energyUseHistory.strategy_ids.push(null)
}
const handleDelete = (i: number) => {

View File

@ -1,6 +1,4 @@
<template>
<setting-item-box name="测点历史记录" :alone="true">
</setting-item-box>
<setting-item-box name="启用数据" :alone="true">
<n-space justify="start">
<n-switch v-model:value="pointHistory.enable" />
@ -27,50 +25,30 @@
<n-icon><CloseIcon /></n-icon>
</template>
</n-button>
</n-space>
<n-space align="center" :wrap="false">
<n-input v-model:value="templateValue" placeholder="请输入测点ID" size="small" clearable/>
<n-button @click="handleAdd" circle size="tiny">
<n-button v-if="i === computeIds.length - 1" @click="handleAdd" circle size="tiny">
<template #icon>
<n-icon><AddIcon /></n-icon>
</template>
</n-button>
<div v-else style="width: 22px"></div>
</n-space>
</n-space>
</setting-item-box>
<setting-item-box name="更新间隔" :alone="true">
<n-input-group>
<n-input-number
v-model:value.trim="targetData.request.requestInterval"
min="1"
:show-button="false"
placeholder="请输入"
size="small"
style="flex: 1;"
>
</n-input-number>
<!-- 单位 -->
<n-select class="select-time-options" v-model:value="targetData.request.requestIntervalUnit" :options="selectTimeOptions" size="small" style="width: 80px"/>
</n-input-group>
</setting-item-box>
</template>
<script lang="ts" setup>
import { ref, watch, reactive, toRefs, computed } from 'vue'
import { watch, reactive, computed } from 'vue'
import type { Ref } from 'vue'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { useTargetData } from '../../hooks/useTargetData.hook'
import { DateOptions, MethodsOptions } from './PointHistory.d'
import { nanoid } from 'nanoid'
import { DateOptions, MethodsOptions } from './ComponentsType.d'
import { icon } from '@/plugins/icon'
import { commonDataType, RequestConfigType, PointHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
import { selectTimeOptions } from '../index.d'
import { commonDataType, PointHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
const { CloseIcon, AddIcon } = icon.ionicons5
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string, request: RequestConfigType }> }
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string }> }
// const commonData: Ref<commonDataType> = computed(() => targetData.value.commonData)
const pointHistory: Ref<PointHistoryType> = computed(() => targetData.value.commonData.pointHistory)
type computeIdsItemType = {
@ -80,13 +58,12 @@ type computeIdsItemType = {
const computeIds: computeIdsItemType[] = reactive([])
let templateValue = ref('')
watch(() => [targetData.value?.id, pointHistory.value.dems_device_points_uid], () => {
templateValue.value = ''
let arr = pointHistory.value.dems_device_points_uid.map(item => {
watch(() => [targetData.value.id, pointHistory.value.dems_device_points_uid], () => {
if(!pointHistory.value.dems_device_points_uid.length) pointHistory.value.dems_device_points_uid.push('')
let arr = pointHistory.value.dems_device_points_uid.map((item, i) => {
return {
id: nanoid(),
id: `${targetData.value.id}_${i}`,
value: item
}
})
@ -101,10 +78,7 @@ const handleChange = (v: string, i: number) => {
}
const handleAdd = () => {
if(templateValue.value) {
targetData.value.commonData.pointHistory.dems_device_points_uid.push(templateValue.value)
templateValue.value = ''
}
targetData.value.commonData.pointHistory.dems_device_points_uid.push('')
}
const handleDelete = (i: number) => {

View File

@ -0,0 +1,95 @@
<template>
<setting-item-box name="启用数据" :alone="true">
<n-space justify="start">
<n-switch v-model:value="recordValueHistory.enable" />
</n-space>
</setting-item-box>
<setting-item-box name="时间" :alone="true">
<n-select v-model:value="recordValueHistory.dateType" :options="DateOptions" size="small"/>
</setting-item-box>
<setting-item-box name="统计方式" :alone="true">
<n-select multiple v-model:value="recordValueHistory.policy" :options="PolicyOptions" size="small" />
</setting-item-box>
<setting-item-box name="报表ID" :alone="true">
<n-space vertical>
<n-space v-for="(item, i) in computeIds" :key="item.id" align="center" :wrap="false">
<n-input-number
:value="item.value"
@update:value.trim="(v: number) => handleChange(v, i)"
min="1"
:show-button="false"
placeholder="请输入报表ID"
size="small"
clearable
/>
<n-button @click="handleDelete(i)" circle size="tiny">
<template #icon>
<n-icon><CloseIcon /></n-icon>
</template>
</n-button>
<n-button v-if="i === computeIds.length - 1" @click="handleAdd" circle size="tiny">
<template #icon>
<n-icon><AddIcon /></n-icon>
</template>
</n-button>
<div v-else style="width: 22px"></div>
</n-space>
</n-space>
</setting-item-box>
</template>
<script lang="ts" setup>
import { watch, reactive, computed } from 'vue'
import type { Ref } from 'vue'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { useTargetData } from '../../hooks/useTargetData.hook'
import { DateOptions, PolicyOptions } from './ComponentsType.d'
import { icon } from '@/plugins/icon'
import { commonDataType, RecordValueHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
const { CloseIcon, AddIcon } = icon.ionicons5
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string }> }
const recordValueHistory: Ref<RecordValueHistoryType> = computed(() => targetData.value.commonData.recordValueHistory)
type computeIdsItemType = {
id: string,
value: number | null
}
const computeIds: computeIdsItemType[] = reactive([])
watch(() => [targetData.value.id, recordValueHistory.value.strategy_ids], () => {
if(!recordValueHistory.value.strategy_ids.length) recordValueHistory.value.strategy_ids.push(null)
let arr = recordValueHistory.value.strategy_ids.map((item, i) => {
return {
id: `${targetData.value.id}_${i}`,
value: item
}
})
computeIds.splice(0, computeIds.length, ...arr)
}, {
deep: true,
immediate: true
})
const handleChange = (v: number, i: number) => {
targetData.value.commonData.recordValueHistory.strategy_ids[i] = v
}
const handleAdd = () => {
targetData.value.commonData.recordValueHistory.strategy_ids.push(null)
}
const handleDelete = (i: number) => {
targetData.value.commonData.recordValueHistory.strategy_ids.splice(i, 1)
}
</script>
<style lang="scss" scoped>
</style>

View File

@ -124,4 +124,8 @@ export const sourceOptions: sourceOptionsItemType[] = [
label: '能耗历史',
value: CurrentSourceEnum.ENERGYUSEHISTORY
},
{
label: '记录值历史',
value: CurrentSourceEnum.RECORDVALUEHISTORY
},
]

View File

@ -4,7 +4,23 @@
<n-select v-model:value="targetData.commonData.currentSource" :options="sourceOptions" size="small"/>
</setting-item-box>
<PointHistory v-if="targetData.commonData.currentSource === CurrentSourceEnum.POINTHISTORY"/>
<EnergyUseHistory v-if="targetData.commonData.currentSource === CurrentSourceEnum.ENERGYUSEHISTORY"/>
<EnergyUseHistory v-else-if="targetData.commonData.currentSource === CurrentSourceEnum.ENERGYUSEHISTORY"/>
<RecordValueHistoryType v-else-if="targetData.commonData.currentSource === CurrentSourceEnum.RECORDVALUEHISTORY"/>
<setting-item-box name="更新间隔" :alone="true">
<n-input-group>
<n-input-number
v-model:value.trim="targetData.request.requestInterval"
min="0"
:show-button="false"
placeholder="请输入"
size="small"
style="flex: 1;"
>
</n-input-number>
<!-- 单位 -->
<n-select class="select-time-options" v-model:value="targetData.request.requestIntervalUnit" :options="selectTimeOptions" size="small" style="width: 80px"/>
</n-input-group>
</setting-item-box>
</div>
<div v-if="targetData && targetData.chartConfig.conDataKey">
<component :is="targetData.chartConfig.conDataKey" :customData="targetData.customData" :request="targetData.request"></component>
@ -29,16 +45,17 @@
<script setup lang="ts">
import PointHistory from './components/PointHistory.vue'
import EnergyUseHistory from './components/EnergyUseHistory.vue'
import { computed } from 'vue'
import RecordValueHistoryType from './components/RecordValueHistory.vue'
import type { Ref } from 'vue'
import { loadAsyncComponent } from '@/utils'
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
import { useTargetData } from '../hooks/useTargetData.hook'
import { sourceOptions, selectTimeOptions } from './index.d'
import { CurrentSourceEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { CreateComponentType, CreateComponentGroupType } from '@/packages/index.d'
// const ChartDataStatic = loadAsyncComponent(() => import('./components/ChartDataStatic/index.vue'))
const { targetData } = useTargetData()
console.log(targetData)
const { targetData } = useTargetData() as { targetData: Ref<CreateComponentType | CreateComponentGroupType> }
</script>