| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import request from '@/utils/request/index.js'
- import {
- timeFormat
- } from '@/utils/utils.js'
- /**
- * 气象墒情模块
- */
- // 气象墒情数据请求父类函数
- const weatherRequest = async (url, data) => {
- const res = await request.post(`api/api_gateway?method=weather.weather.${url}`, data);
- return res?.data;
- }
- // 气象站、墒情站设备列表
- export const getWeatherDeviceList = (data) => weatherRequest('qxz_page', data);
- // 气象站、墒情站设备详情
- export const getWeatherDeviceDetail = async (params) => {
- const {
- dat,
- conf
- } = await weatherRequest('qxz_status', params);
- let result = [];
- for (let key in dat) {
- if (dat[key] && key != 'uptime') {
- console.log(dat[key]);
- const datArray = dat[key].split('#');
- const confArray = conf[key].split('#');
- result.push({
- el: key, // 通道
- markId: datArray[1], // 标识
- text: `${confArray[0]} ${confArray[1]}`, // 标题
- value: `${datArray[0]}`
- })
- }
- }
- return result;
- };
- /**
- * 气象站、墒情站历史数据
- * @param {*} params
- */
- export const getWeatherHistory = async (params) => {
- let {
- data,
- nums,
- conf,
- rainFall
- } = await weatherRequest('qxz_detail', params);
- let headers = [{
- text: '日期',
- value: 'date',
- }];
- // 组装数据头部列表
- for (let key in conf) {
- if (conf[key]) {
- let confArray = conf[key].split('#');
- headers.push({
- text: confArray[0] + confArray[1],
- value: key
- });
- }
- }
- let list = []; //历史列表数据 数据项格式 {date:日期,e1:'',e2:'',e3:'',e4:'',}
- for (let i = 0; i < data.length; i++) {
- let listItem = {
- date: timeFormat(data[i].time, 'yyyy-mm-dd hh:MM:ss')
- };
- for (let key in data[i].dat) {
- if (data[i].dat[key]) {
- let datArray = data[i].dat[key].split('#');
- listItem[key] = datArray[0]
- }
- }
- list.push(listItem);
- }
- return {
- headers: headers, //历史数据表头数据
- list: list, // 历史列表数据
- nums: nums, // 数据总数
- rainFall: rainFall, //气象设备是否具有日雨量累计因子,有返回1,无返回0
- }
- }
- // 气象站、墒情站折线图
- export const getWeatherChart = async (params) => {
- const {
- data,
- conf
- } = await weatherRequest('qxz_data_chart', params)
- if (!data) {
- return;
- }
- let times = []; // 时间数组
- // 下拉框数据
- let pickes = [];
- let charts = {};
- Object.keys(conf).forEach(key => {
- if (conf[key]) {
- pickes.push({
- text: conf[key].split('#').join(' '),
- value: key
- })
- charts[key] = []; //统计图
- }
- })
- // 处理统计图数据 格式:通道号:列表 {e1:list,e2:list,e3:list}
- // if(data.length = 10;)
- for (let i = 0; i < data.length; i++) {
- for (let key in charts) {
- let dat = data[i].dat[key];
- if (dat) {
- let num = dat.split('#')[0];
- charts[key].push(parseFloat(num));
- }
- }
- times.push(timeFormat(data[i].time, 'mm月dd日'));
- }
- return {
- times, // 日期列表
- pickes, // 下拉框列表
- charts, // 统计数据
- }
- };
- /**
- * 气象站、墒情站24小时数据
- * @param {*} data
- */
- export const getWeatherDayData = async (data) => {
- let res = await weatherRequest('qxz_day_data', data);
- return res;
- };
- // 气象站、墒情站预警
- export const getWeatherWarning = (data) => weatherRequest('qxz_warning', data);
|