diff --git a/src/api/path/dataSource/index.ts b/src/api/path/dataSource/index.ts index 877c6de..dbccfed 100644 --- a/src/api/path/dataSource/index.ts +++ b/src/api/path/dataSource/index.ts @@ -7,121 +7,6 @@ import { StorageEnum } from "@/enums/storageEnum"; import { SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d' import { SelectDataSourceTypeAPIObj } from "@/enums/dataSourceEnum"; -const testData = { - "code": 0, - "msg": "", - "data": { - "dimensions": [ - "c_40136", - "c_40138", - "_ts" - ], - "source": [ - { - "c_40136": 24.93, - "c_40138": 11.31, - "_ts": 1753977600000 - }, - { - "c_40136": 24.94, - "c_40138": 11.31, - "_ts": 1753977720000 - }, - { - "c_40136": 24.94, - "c_40138": 11.31, - "_ts": 1753977840000 - }, - { - "c_40136": 24.95, - "c_40138": 11.31, - "_ts": 1753977960000 - }, - { - "c_40136": 24.96, - "c_40138": 11.31, - "_ts": 1753978080000 - }, - { - "c_40136": 24.97, - "c_40138": 11.31, - "_ts": 1753978200000 - }, - { - "c_40136": 24.98, - "c_40138": 11.31, - "_ts": 1753978320000 - }, - { - "c_40136": 24.99, - "c_40138": 11.31, - "_ts": 1753978440000 - }, - { - "c_40136": 25, - "c_40138": 11.31, - "_ts": 1753978560000 - }, - - - { - "c_40136": 27.45, - "c_40138": 11.51, - "_ts": 1754038560000 - }, - { - "c_40136": 27.45, - "c_40138": 11.51, - "_ts": 1754038680000 - }, - { - "c_40136": 27.45, - "c_40138": 11.52, - "_ts": 1754038800000 - }, - { - "c_40136": 27.45, - "c_40138": 11.52, - "_ts": 1754038920000 - }, - { - "c_40136": 27.45, - "c_40138": 11.52, - "_ts": 1754039040000 - }, - { - "c_40136": 27.45, - "c_40138": 11.53, - "_ts": 1754039160000 - }, - { - "c_40136": 27.45, - "c_40138": 11.53, - "_ts": 1754039280000 - }, - { - "c_40136": 27.45, - "c_40138": 11.54, - "_ts": 1754039400000 - }, - { - "c_40136": 27.45, - "c_40138": 11.54, - "_ts": 1754039520000 - }, - { - "c_40136": 27.45, - "c_40138": 11.55, - "_ts": 1754039640000 - }, - { - "c_40136": 27.45, - "c_40138": 11.55, - "_ts": 1754039760000 - } - ] -} -} /* * 获取站点 */ @@ -215,11 +100,11 @@ export async function test (){ } } -function getPointParams(requestSource:RequestDataSourceConfig) { +function getPointParams(requestSource: RequestDataSourceConfig) { let params:any = { queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType], site: requestSource.station, - with: requestSource.recentTimeRange, + width: requestSource.recentTimeRange, deviceSn: requestSource.device.split('|')[0], deviceType: requestSource.device.split('|')[1], points: requestSource.points, @@ -229,11 +114,11 @@ function getPointParams(requestSource:RequestDataSourceConfig) { return params } -function getEarningParams(requestSource:RequestDataSourceConfig){ +function getEarningParams(requestSource: RequestDataSourceConfig) { let params: any = { queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType], - site:requestSource.station, - with: requestSource.recentTimeRange, + site: requestSource.station, + width: requestSource.recentTimeRange, interval: '20m', points: [], tenantId: getToken() @@ -242,7 +127,8 @@ function getEarningParams(requestSource:RequestDataSourceConfig){ return params } -export const fetchDataByIot = async (requestSource:RequestDataSourceConfig) => { +export const fetchDataByIot = async (requestSource: RequestDataSourceConfig) => { + if (!requestSource.station) return let params:any = {} if(requestSource.dataSourceType === 'point') { params = getPointParams(requestSource) @@ -251,14 +137,34 @@ export const fetchDataByIot = async (requestSource:RequestDataSourceConfig) => { } try { - return await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.DATA}/get-by-iot`, params) + const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.DATA}/get-by-iot`, params) as any + let keyMap: any = [] + if (requestSource.dataSourceType === 'point') { + keyMap = Object.fromEntries( + requestSource.pointsInfo.map(p => [p.columnName, p.nameCn]) + ) + } else if(requestSource.dataSourceType === 'earning'){ + keyMap = { + 'sum(earning)': '收益' + } + } + res.data.dimensions = res.data.dimensions.map((key:string) => keyMap[key] || key) + res.data.source = res.data.source.map((item:any) => { + const newItem: Record = {} + for (const key in item) { + newItem[keyMap[key] || key] = item[key] + } + return newItem + }) ?? [] + + return res // await specialCustomizeHttp({ // url: `${ModuleTypeEnum.DATA}/get-by-iot`, // method: 'POST', // params // }) } catch { - httpErrorHandle() + // httpErrorHandle() } } diff --git a/src/api/path/infra.api.ts b/src/api/path/infra.api.ts index ee85c21..b0486b8 100644 --- a/src/api/path/infra.api.ts +++ b/src/api/path/infra.api.ts @@ -4,6 +4,7 @@ import { RequestHttpEnum, ModuleTypeEnum, ContentTypeEnum } from '@/enums/httpEn // * 上传文件 export const uploadFile = async (data: object) => { + console.log('uploadFile',data) try { const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.INFRA}/file/upload`, data, ContentTypeEnum.FORM_DATA) return res diff --git a/src/api/path/project.api.ts b/src/api/path/project.api.ts index b04272d..a047b3b 100644 --- a/src/api/path/project.api.ts +++ b/src/api/path/project.api.ts @@ -38,6 +38,7 @@ export const fetchProjectApi = async (data: object) => { // * 保存项目 export const saveProjectApi = async (data: object) => { + console.log('saveProjectApi') try { const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/update`, data) return res @@ -48,6 +49,7 @@ export const saveProjectApi = async (data: object) => { // * 修改项目基础信息 export const updateProjectApi = async (data: object) => { + console.log('updateProjectApi') try { const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/update`, data) return res @@ -68,6 +70,7 @@ export const deleteProjectApi = async (data: object) => { // * 修改发布状态 [0 已发布, 1 未发布] export const changeProjectReleaseApi = async (data: object) => { + console.log('changeProjectReleaseApi') try { const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/update`, data) return res diff --git a/src/enums/dataSourceEnum.ts b/src/enums/dataSourceEnum.ts index 2f1a3d7..75c1875 100644 --- a/src/enums/dataSourceEnum.ts +++ b/src/enums/dataSourceEnum.ts @@ -24,7 +24,7 @@ export const SelectDataSourceTypeAPIObj = { /** - * @description: 点位时间范围 + * @description: 收益时间范围 */ export enum EarningTimeRangeEnum { @@ -40,7 +40,7 @@ export enum EarningTimeRangeEnum { } /** - * @description: 点位时间范围名称 + * @description: 收益时间范围名称 */ export const EarningTimeRangeNameObj = { [EarningTimeRangeEnum.LAST_6h]: '最近6小时', @@ -57,11 +57,15 @@ export const EarningTimeRangeNameObj = { /** - * @description: 收益时间范围 + * @description: 点位时间范围 */ export enum PointsTimeRangeEnum { - // 收益 + LAST_3d = '3d', + LAST_2d= '2d', + LAST_1d= '1d', + LAST_12h= '12h', + LAST_6h= '6h', LAST_30= '30m', LAST_25= '25m', LAST_20 = '20m', @@ -72,9 +76,14 @@ export enum PointsTimeRangeEnum { } /** - * @description: // 收益时间范围名称 + * @description: // 点位时间范围名称 */ export const PointsTimeRangeNameObj = { + [PointsTimeRangeEnum.LAST_3d]: '最近3天', + [PointsTimeRangeEnum.LAST_2d]: '最近2天', + [PointsTimeRangeEnum.LAST_1d]: '最近1天', + [PointsTimeRangeEnum.LAST_12h]: '最近12小时', + [PointsTimeRangeEnum.LAST_6h]: '最近6小时', [PointsTimeRangeEnum.LAST_30]: '最近30分钟', [PointsTimeRangeEnum.LAST_25]: '最近25分钟', [PointsTimeRangeEnum.LAST_20]: '最近20分钟', diff --git a/src/packages/public/publicConfig.ts b/src/packages/public/publicConfig.ts index b6253a4..889fe8d 100644 --- a/src/packages/public/publicConfig.ts +++ b/src/packages/public/publicConfig.ts @@ -52,7 +52,8 @@ export const requestDataSourceConfig: RequestDataSourceConfig = { station: '', device: '', points: [], - recentTimeRange: PointsTimeRangeEnum.LAST_20, + pointsInfo: [], + recentTimeRange: PointsTimeRangeEnum.LAST_6h, requestInterval: 5, requestIntervalUnit: RequestHttpIntervalEnum.SECOND, } diff --git a/src/store/modules/chartEditStore/chartEditStore.d.ts b/src/store/modules/chartEditStore/chartEditStore.d.ts index 8d7b283..3843dd2 100644 --- a/src/store/modules/chartEditStore/chartEditStore.d.ts +++ b/src/store/modules/chartEditStore/chartEditStore.d.ts @@ -242,9 +242,10 @@ export interface RequestConfigType extends RequestPublicConfigType { export interface RequestDataSourceConfig { dataSourceType: DataSourceTypeEnum station: string, - device: Array[any], - points: Array[any], - recentTimeRange: number, + device: string, + points: Array, + pointsInfo: Array, + recentTimeRange: string, requestInterval: number, requestIntervalUnit: RequestHttpIntervalEnum, } diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue index a019f31..9c4b5a6 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue @@ -89,18 +89,37 @@ v-show="targetDataSourceRequest.dataSourceType == 'point'" > + + + - - - - - - - - - + @@ -124,10 +143,10 @@ const props = defineProps<{ const selectRecentTimeRangeOptions = computed(() => { console.log('computed') if (props.targetDataSourceRequest!.dataSourceType === 'point') { - props.targetDataSourceRequest!.recentTimeRange = selectPointsTimeRangeOptions[0].value + // props.targetDataSourceRequest!.recentTimeRange = selectPointsTimeRangeOptions[0].value return selectPointsTimeRangeOptions } else if(props.targetDataSourceRequest!.dataSourceType === 'earning') { - props.targetDataSourceRequest!.recentTimeRange = selectEarningTimeRangeOptions[0].value + // props.targetDataSourceRequest!.recentTimeRange = selectEarningTimeRangeOptions[0].value return selectEarningTimeRangeOptions } return [] @@ -151,6 +170,8 @@ watch(() => props.targetDataSourceRequest.station, (val) => { function handleStationChange() { props.targetDataSourceRequest.device = '' + props.targetDataSourceRequest.points = [] + pointList.value = [] } const deviceList = ref([]) @@ -170,9 +191,11 @@ async function loadDevicesData() { window['$message'].error('设备列表数据获取失败!') } } - -watch(() => props.targetDataSourceRequest.device, (val) => { - val && loadPointsData() +watch(() => props.targetDataSourceRequest.device, async (val) => { + if (val && !deviceList.value.length) { + await loadDevicesData() + } + val && await loadPointsData() },{ immediate: true, }) @@ -183,10 +206,13 @@ function handleDeviceChange () { const pointList = ref([]) -async function loadPointsData(){ +const loadingPoints = ref(false) +async function loadPointsData() { + loadingPoints.value = true const curDeviceSn = props.targetDataSourceRequest.device.split('|')[0] ?? '' const findDeviceId = deviceList.value.find((device: any) => device.sn === curDeviceSn).id if (!findDeviceId) { + loadingPoints.value = false pointList.value = [] return } @@ -199,6 +225,22 @@ async function loadPointsData(){ } else { window['$message'].error('点位列表数据获取失败!') } + loadingPoints.value = false +} + +function handlePointsUpdate(newVal:string[], currentVal:any) { + if (newVal.length > 6 && currentVal.actionType !== "uncheck") return; + props.targetDataSourceRequest.points = newVal + props.targetDataSourceRequest.pointsInfo = pointList.value.filter((point: any) => + newVal.includes(point.columnName)).map((point: any) => ({ + id: point.id, + addr: point.addr, + columnName:point.columnName, + nameCn:point.nameCn, + permission:point.permission, + unit:point.unit, + })) + console.log(props.targetDataSourceRequest.pointsInfo) } onMounted(()=>{ diff --git a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/index.vue b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/index.vue index 30152c3..dccabe3 100644 --- a/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/index.vue +++ b/src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/index.vue @@ -11,7 +11,10 @@ -