大屏编辑器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

268 lines
5.4 KiB

import { http } from "@/api/http";
import { ModuleTypeEnum, RequestHttpEnum } from "@/enums/httpEnum";
import { ProjectDetail } from "@/api/path/project";
import { getLocalStorage, httpErrorHandle } from "@/utils";
import { RequestDataSourceConfig } from '@/store/modules/chartEditStore/chartEditStore.d'
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
}
]
}
}
/*
*
*/
export const fetchDataSite = async (data: object) => {
try {
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-site`)
} catch {
httpErrorHandle()
}
}
/*
*
* @param data {
* siteId // 站点
* }
*/
export const fetchDataDevice = async (data: object) => {
try {
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-entity`,data)
} catch {
httpErrorHandle()
}
}
/*
*
* @param data {
* siteId // 站点
* entityId // 设备
* }
*/
export const fetchDataPoint = async (data: object) => {
try {
return await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-point`, data)
} catch {
httpErrorHandle()
}
}
// {
// "queryType": 2,
// "site": "53",
// "width": "1d",
// "tenantId": 169,
// "interval":"1h",
// "points":[]
// }
/*
*
* @param params {
* queryType = 2
* siteId // 站点
* entityId // 设备
* width = 1d
* tenantId
* interval
* points = []
* }
*/
export async function test (){
// const params = {
// "queryType": 1,
// "site": 56,
// "with": 30,
// "deviceSn": 454,
// "points": [
// 4,
// 7
// ],
// "tenantId": 169
// }
const params = {
"queryType": 2,
"site": 56,
"with": "6h",
"interval": "20m",
"points": [],
"tenantId": 169
}
try {
return await http(RequestHttpEnum.POST)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-by-iot`, params)
} catch {
httpErrorHandle()
}
}
function getPointParams(requestSource:RequestDataSourceConfig) {
let params:any = {
queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType],
site: requestSource.station,
with: requestSource.recentTimeRange,
deviceSn: requestSource.device.split('|')[0],
deviceType: requestSource.device.split('|')[1],
points: requestSource.points,
tenantId: getToken()
}
return params
}
function getEarningParams(requestSource:RequestDataSourceConfig){
let params: any = {
queryType: SelectDataSourceTypeAPIObj[requestSource.dataSourceType],
site:requestSource.station,
with: requestSource.recentTimeRange,
interval: '20m',
points: [],
tenantId: getToken()
}
return params
}
export const fetchDataByIot = async (requestSource:RequestDataSourceConfig) => {
let params:any = {}
if(requestSource.dataSourceType === 'point') {
params = getPointParams(requestSource)
} else if(requestSource.dataSourceType === 'earning') {
params = getEarningParams(requestSource)
}
try {
return await http(RequestHttpEnum.POST)<ProjectDetail>(`${ModuleTypeEnum.DATA}/get-by-iot`, params)
// await specialCustomizeHttp({
// url: `${ModuleTypeEnum.DATA}/get-by-iot`,
// method: 'POST',
// params
// })
} catch {
httpErrorHandle()
}
}
function getToken() {
const info = getLocalStorage(StorageEnum.GO_SYSTEM_STORE)
return info ? info[SystemStoreEnum.TENANT_INFO]['tenantId'] : undefined
}