import moment from 'moment'; import { request } from 'umi'; //获取项目列表 export async function getProjectList( params: any, ): Promise { const response = await request(`/api/v2/project`, { params: params, }); let nowDate = new Date(); (response.data.list || []).map((item: Api.IProject) => { let type; if (!item.EndDate) { type = 2; } else { type = nowDate >= new Date(item.EndDate) ? 2 : 1; } item.type = type; }); return response; } export async function getDeviceRealData(params: any) { return request(`/api/v1/jinke-cloud/device/current-data`, { method: 'POST', body: params, }); } export async function getDeviceRealDataByTime(params: any) { return request(`/api/v1/jinke-cloud/db/device/history-data`, { method: 'GET', params, }); } export async function queryFormCell( projectId: string | number, formName: string, ) { const res = await request( `/api/v1/api/v1/runtime_form/cell/to/chart/${projectId}/${formName}`, ); return res; } const CACHE: any = {}; // 查询图表对应的表单数据-最新数据 export async function queryFormCurrentData(params: any) { const { projectId, formName, titles } = params; if (!CACHE[formName]) { const resCell = await queryFormCell(projectId, formName); CACHE[formName] = resCell.data || []; } let cells = titles.map((t: string) => { let cell = CACHE[formName].find((item: any) => item.title == t); return cell; }); const { data } = await request( `/api/v1/runtime_form/chart/current/${projectId}/${formName}`, ); return cells.map((item: any) => ({ key: item.cell_key, value: data[item.cell_key], title: item.title, })); } export async function queryFormHistoryData2(params: any) { const { data } = await request(`/api/v1/jinke-cloud/db/device/form-chart`, { method: 'POST', body: params, }); return Object.keys(data).map((key) => { let [tableName, title] = key.split('|'); let dataValue = data[key]; return { name: title, data: dataValue.map((item: any) => ({ htime: moment(item.time).format('YYYY-MM-DD HH:mm:ss'), val: item.key, })), }; }); }