weather.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import request from '@/utils/request/index.js'
  2. import {
  3. timeFormat
  4. } from '@/utils/utils.js'
  5. /**
  6. * 气象墒情模块
  7. */
  8. // 气象墒情数据请求父类函数
  9. const weatherRequest = async (url, data) => {
  10. const res = await request.post(`api/api_gateway?method=weather.weather.${url}`, data);
  11. return res?.data;
  12. }
  13. // 气象站、墒情站设备列表
  14. export const getWeatherDeviceList = (data) => weatherRequest('qxz_page', data);
  15. // 气象站、墒情站设备详情
  16. export const getWeatherDeviceDetail = async (params) => {
  17. const {
  18. dat,
  19. conf
  20. } = await weatherRequest('qxz_status', params);
  21. let result = [];
  22. for (let key in dat) {
  23. if (dat[key] && key != 'uptime') {
  24. console.log(dat[key]);
  25. const datArray = dat[key].split('#');
  26. const confArray = conf[key].split('#');
  27. result.push({
  28. el: key, // 通道
  29. markId: confArray[1], // 标识
  30. text: `${confArray[0]} ${confArray[1]}`, // 标题
  31. value: `${datArray[0]}`
  32. })
  33. }
  34. }
  35. return result;
  36. };
  37. /**
  38. * 气象站、墒情站历史数据
  39. * @param {*} params
  40. */
  41. export const getWeatherHistory = async (params) => {
  42. let {
  43. data,
  44. nums,
  45. conf,
  46. rainFall
  47. } = await weatherRequest('qxz_detail', params);
  48. let headers = [{
  49. text: '日期',
  50. value: 'date',
  51. }];
  52. // 组装数据头部列表
  53. for (let key in conf) {
  54. if (conf[key]) {
  55. let confArray = conf[key].split('#');
  56. headers.push({
  57. text: confArray[0] + confArray[1],
  58. value: key
  59. });
  60. }
  61. }
  62. let list = []; //历史列表数据 数据项格式 {date:日期,e1:'',e2:'',e3:'',e4:'',}
  63. for (let i = 0; i < data.length; i++) {
  64. let listItem = {
  65. date: timeFormat(data[i].time, 'yyyy-mm-dd hh:MM:ss')
  66. };
  67. for (let key in data[i].dat) {
  68. if (data[i].dat[key]) {
  69. let datArray = data[i].dat[key].split('#');
  70. listItem[key] = datArray[0]
  71. }
  72. }
  73. list.push(listItem);
  74. }
  75. return {
  76. headers: headers, //历史数据表头数据
  77. list: list, // 历史列表数据
  78. nums: nums, // 数据总数
  79. rainFall: rainFall, //气象设备是否具有日雨量累计因子,有返回1,无返回0
  80. }
  81. }
  82. // 气象站、墒情站折线图
  83. export const getWeatherChart = async (params) => {
  84. const {
  85. data,
  86. conf
  87. } = await weatherRequest('qxz_data_chart', params)
  88. if (!data) {
  89. return;
  90. }
  91. let times = []; // 时间数组
  92. // 下拉框数据
  93. let pickes = [];
  94. let charts = {};
  95. Object.keys(conf).forEach(key => {
  96. if (conf[key]) {
  97. pickes.push({
  98. text: conf[key].split('#').join(' '),
  99. value: key
  100. })
  101. charts[key] = []; //统计图
  102. }
  103. })
  104. // 处理统计图数据 格式:通道号:列表 {e1:list,e2:list,e3:list}
  105. // if(data.length = 10;)
  106. for (let i = 0; i < data.length; i++) {
  107. for (let key in charts) {
  108. let dat = data[i].dat[key];
  109. if (dat) {
  110. let num = dat.split('#')[0];
  111. charts[key].push(parseFloat(num));
  112. }
  113. }
  114. times.push(timeFormat(data[i].time, 'mm月dd日'));
  115. }
  116. return {
  117. times, // 日期列表
  118. pickes, // 下拉框列表
  119. charts, // 统计数据
  120. }
  121. };
  122. /**
  123. * 气象站、墒情站24小时数据
  124. * @param {*} data
  125. */
  126. export const getWeatherData = async (data) => {
  127. let res = await weatherRequest('qxz_day_data', data);
  128. return res;
  129. };
  130. // 气象站、墒情站预警
  131. export const getWeatherWarning = (data) => weatherRequest('qxz_warning', data);