project.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import moment from 'moment';
  2. import { request } from 'umi';
  3. //获取项目列表
  4. export async function getProjectList(
  5. params: any,
  6. ): Promise<Api.IResponseStructure> {
  7. const response = await request(`/api/v2/project`, {
  8. params: params,
  9. });
  10. let nowDate = new Date();
  11. (response.data.list || []).map((item: Api.IProject) => {
  12. let type;
  13. if (!item.EndDate) {
  14. type = 2;
  15. } else {
  16. type = nowDate >= new Date(item.EndDate) ? 2 : 1;
  17. }
  18. item.type = type;
  19. });
  20. return response;
  21. }
  22. export async function getDeviceRealData(params: any) {
  23. return request(`/api/v1/jinke-cloud/device/current-data`, {
  24. method: 'POST',
  25. body: params,
  26. });
  27. }
  28. export async function getDeviceRealDataByTime(params: any) {
  29. return request(`/api/v1/jinke-cloud/db/device/history-data`, {
  30. method: 'GET',
  31. params,
  32. });
  33. }
  34. export async function queryFormCell(
  35. projectId: string | number,
  36. formName: string,
  37. ) {
  38. const res = await request(
  39. `/api/v1/api/v1/runtime_form/cell/to/chart/${projectId}/${formName}`,
  40. );
  41. return res;
  42. }
  43. const CACHE: any = {};
  44. // 查询图表对应的表单数据-最新数据
  45. export async function queryFormCurrentData(params: any) {
  46. const { projectId, formName, titles } = params;
  47. if (!CACHE[formName]) {
  48. const resCell = await queryFormCell(projectId, formName);
  49. CACHE[formName] = resCell.data || [];
  50. }
  51. let cells = titles.map((t: string) => {
  52. let cell = CACHE[formName].find((item: any) => item.title == t);
  53. return cell;
  54. });
  55. const { data } = await request(
  56. `/api/v1/runtime_form/chart/current/${projectId}/${formName}`,
  57. );
  58. return cells.map((item: any) => ({
  59. key: item.cell_key,
  60. value: data[item.cell_key],
  61. title: item.title,
  62. }));
  63. }
  64. export async function queryFormHistoryData2(params: any) {
  65. const { data } = await request(`/api/v1/jinke-cloud/db/device/form-chart`, {
  66. method: 'POST',
  67. body: params,
  68. });
  69. return Object.keys(data).map((key) => {
  70. let [tableName, title] = key.split('|');
  71. let dataValue = data[key];
  72. return {
  73. name: title,
  74. data: dataValue.map((item: any) => ({
  75. htime: moment(item.time).format('YYYY-MM-DD HH:mm:ss'),
  76. val: item.key,
  77. })),
  78. };
  79. });
  80. }