mirror of
https://gitee.com/dromara/go-view.git
synced 2025-06-30 00:29:16 +08:00
feat: 新增通用组件数据接口
This commit is contained in:
parent
9894da9c89
commit
338641e9d1
@ -14,6 +14,7 @@ export interface MyResponseType<T> {
|
||||
message: string
|
||||
// 兼顾主系统
|
||||
errcode: string
|
||||
errmsg: string
|
||||
}
|
||||
|
||||
export interface MyRequestInstance extends Axios {
|
||||
|
36
src/hooks/commonDataComponents/usePointHistoryRes.ts
Normal file
36
src/hooks/commonDataComponents/usePointHistoryRes.ts
Normal file
@ -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)
|
||||
}
|
@ -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(
|
||||
|
7
src/packages/components/ThemesAndLayouts/index.d.ts
vendored
Normal file
7
src/packages/components/ThemesAndLayouts/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
export enum ChatCategoryEnum {
|
||||
THEMES = 'Themes',
|
||||
}
|
||||
|
||||
export enum ChatCategoryEnumName {
|
||||
THEMES = '主题',
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
// 单实例类
|
||||
|
@ -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
|
||||
|
25
src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts
vendored
Normal file
25
src/views/chart/ContentConfigurations/components/ChartDataV2/components/EnergyUseHistory.d.ts
vendored
Normal file
@ -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
|
||||
},
|
||||
]
|
@ -3,14 +3,11 @@
|
||||
</setting-item-box>
|
||||
<setting-item-box name="启用数据" :alone="true">
|
||||
<n-space justify="start">
|
||||
<n-switch v-model:value="commonData.enable" />
|
||||
<n-switch v-model:value="energyUseHistory.enable" />
|
||||
</n-space>
|
||||
</setting-item-box>
|
||||
<setting-item-box name="时间" :alone="true">
|
||||
<n-select v-model:value="commonData.dateType" :options="DateOptions" size="small"/>
|
||||
</setting-item-box>
|
||||
<setting-item-box name="统计方式" :alone="true">
|
||||
<n-select multiple v-model:value="commonData.methods" :options="MethodsOptions" size="small" />
|
||||
<n-select v-model:value="energyUseHistory.dateType" :options="DateOptions" size="small"/>
|
||||
</setting-item-box>
|
||||
<setting-item-box name="测点ID" :alone="true">
|
||||
<n-space vertical>
|
||||
@ -58,20 +55,20 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch, reactive, toRefs, computed } from 'vue'
|
||||
import type { Ref } from 'vue'
|
||||
import moment from 'moment'
|
||||
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
|
||||
import { useTargetData } from '../../hooks/useTargetData.hook'
|
||||
import { DateOptions, MethodsOptions } from './ChartDataPointHistory.d'
|
||||
import { DateOptions } from './EnergyUseHistory.d'
|
||||
import { nanoid } from 'nanoid'
|
||||
import { icon } from '@/plugins/icon'
|
||||
import { commonDataType, RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
import { commonDataType, RequestConfigType, EnergyUseHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
import { selectTimeOptions } from '../index.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, request: RequestConfigType }> }
|
||||
|
||||
const commonData: Ref<commonDataType> = computed(() => targetData.value.commonData)
|
||||
// const commonData: Ref<commonDataType> = computed(() => targetData.value.commonData)
|
||||
const energyUseHistory: Ref<EnergyUseHistoryType> = computed(() => targetData.value.commonData.energyUseHistory)
|
||||
|
||||
type computeIdsItemType = {
|
||||
id: string,
|
||||
@ -82,9 +79,9 @@ const computeIds: computeIdsItemType[] = reactive([])
|
||||
|
||||
let templateValue = ref('')
|
||||
|
||||
watch(() => [targetData.value?.id, commonData.value], () => {
|
||||
watch(() => [targetData.value?.id, energyUseHistory.value], () => {
|
||||
templateValue.value = ''
|
||||
let arr = commonData.value.dems_device_points_uid.map(item => {
|
||||
let arr = energyUseHistory.value.strategy_ids.map(item => {
|
||||
return {
|
||||
id: nanoid(),
|
||||
value: item
|
||||
@ -97,18 +94,18 @@ watch(() => [targetData.value?.id, commonData.value], () => {
|
||||
})
|
||||
|
||||
const handleChange = (v: string, i: number) => {
|
||||
targetData.value.commonData.dems_device_points_uid[i] = v
|
||||
targetData.value.commonData.energyUseHistory.strategy_ids[i] = v
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
if(templateValue.value) {
|
||||
targetData.value.commonData.dems_device_points_uid.push(templateValue.value)
|
||||
targetData.value.commonData.energyUseHistory.strategy_ids.push(templateValue.value)
|
||||
templateValue.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = (i: number) => {
|
||||
targetData.value.commonData.dems_device_points_uid.splice(i, 1)
|
||||
targetData.value.commonData.energyUseHistory.strategy_ids.splice(i, 1)
|
||||
}
|
||||
|
||||
</script>
|
@ -0,0 +1,118 @@
|
||||
<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" />
|
||||
</n-space>
|
||||
</setting-item-box>
|
||||
<setting-item-box name="时间" :alone="true">
|
||||
<n-select v-model:value="pointHistory.dateType" :options="DateOptions" size="small"/>
|
||||
</setting-item-box>
|
||||
<setting-item-box name="统计方式" :alone="true">
|
||||
<n-select multiple v-model:value="pointHistory.methods" :options="MethodsOptions" 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
|
||||
:value="item.value"
|
||||
@update:value="(v: string) => handleChange(v, i)"
|
||||
placeholder="请输入测点ID"
|
||||
size="small"
|
||||
clearable
|
||||
/>
|
||||
<n-button @click="handleDelete(i)" circle size="tiny">
|
||||
<template #icon>
|
||||
<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">
|
||||
<template #icon>
|
||||
<n-icon><AddIcon /></n-icon>
|
||||
</template>
|
||||
</n-button>
|
||||
</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 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 { icon } from '@/plugins/icon'
|
||||
import { commonDataType, RequestConfigType, PointHistoryType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
import { selectTimeOptions } from '../index.d'
|
||||
|
||||
const { CloseIcon, AddIcon } = icon.ionicons5
|
||||
|
||||
const { targetData } = useTargetData() as { targetData: Ref<{ commonData: commonDataType, id: string, request: RequestConfigType }> }
|
||||
|
||||
// const commonData: Ref<commonDataType> = computed(() => targetData.value.commonData)
|
||||
const pointHistory: Ref<PointHistoryType> = computed(() => targetData.value.commonData.pointHistory)
|
||||
|
||||
type computeIdsItemType = {
|
||||
id: string,
|
||||
value: string
|
||||
}
|
||||
|
||||
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 => {
|
||||
return {
|
||||
id: nanoid(),
|
||||
value: item
|
||||
}
|
||||
})
|
||||
computeIds.splice(0, computeIds.length, ...arr)
|
||||
}, {
|
||||
deep: true,
|
||||
immediate: true
|
||||
})
|
||||
|
||||
const handleChange = (v: string, i: number) => {
|
||||
targetData.value.commonData.pointHistory.dems_device_points_uid[i] = v
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
if(templateValue.value) {
|
||||
targetData.value.commonData.pointHistory.dems_device_points_uid.push(templateValue.value)
|
||||
templateValue.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = (i: number) => {
|
||||
targetData.value.commonData.pointHistory.dems_device_points_uid.splice(i, 1)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
</style>
|
@ -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
|
||||
},
|
||||
]
|
||||
|
@ -1,6 +1,10 @@
|
||||
<template>
|
||||
<div class="go-chart-configurations-data" v-if="targetData && !targetData.chartConfig.conDataKey">
|
||||
<ChartDataPointHistory/>
|
||||
<setting-item-box name="数据源" :alone="true">
|
||||
<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"/>
|
||||
</div>
|
||||
<div v-if="targetData && targetData.chartConfig.conDataKey">
|
||||
<component :is="targetData.chartConfig.conDataKey" :customData="targetData.customData" :request="targetData.request"></component>
|
||||
@ -23,15 +27,18 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import ChartDataPointHistory from './components/ChartDataPointHistory.vue'
|
||||
import PointHistory from './components/PointHistory.vue'
|
||||
import EnergyUseHistory from './components/EnergyUseHistory.vue'
|
||||
import { computed } from 'vue'
|
||||
import { loadAsyncComponent } from '@/utils'
|
||||
import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
|
||||
import { useTargetData } from '../hooks/useTargetData.hook'
|
||||
import { selectTypeOptions, selectTimeOptions } from '@/views/chart/ContentConfigurations/components/ChartData/index.d'
|
||||
import { sourceOptions, selectTimeOptions } from './index.d'
|
||||
import { CurrentSourceEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||
|
||||
// const ChartDataStatic = loadAsyncComponent(() => import('./components/ChartDataStatic/index.vue'))
|
||||
|
||||
const { targetData } = useTargetData()
|
||||
console.log(targetData)
|
||||
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user