| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- /**
- * 设备管理相关API
- */
- import {
- http,
- Method
- } from '@/utils/request.js';
- import storage from "@/utils/storage.js";
- const request = http.request;
- const userInfo = storage.getUserInfo()
- /**
- * 获取设备概览数据
- * @param {string} fieldId - 地块ID,可选
- * @returns {Promise} 设备概览数据
- */
- export function fetchDeviceOverview(fieldId) {
- const params = {};
- console.log("userInfo请求:",userInfo);
- if (userInfo.userId) params.userId = userInfo.userId;
- if (fieldId) params.fieldId = fieldId;
-
- return http.request({
- url: 'uniapp/device/overview',
- method: Method.POST,
- data: params
- });
- }
- /**
- * 根据设备类型获取设备列表
- * @param {string} type - 设备类型(monitor-监控设备,sensor-采集设备,control-控制设备,irrigation-灌溉设备,tractor-农机设备)
- * @param {Object} params - 查询参数
- * @returns {Promise} 设备列表
- */
- export function fetchDevicesByType(params) {
- if (userInfo.userId) params.userId = userInfo.userId;
- return http.request({
- url: `uniapp/device/typeList`,
- method: Method.POST,
- data: params
- });
- }
- /**
- * 获取所有设备列表
- * @param {Object} params - 查询参数
- * @param {number} params.pageNum - 页码
- * @param {number} params.pageSize - 每页数量
- * @param {string} params.deviceName - 设备名称,可选
- * @param {string} params.deviceTypeId - 设备类型ID,可选
- * @param {number} params.status - 设备状态,可选
- * @returns {Promise} 设备列表
- */
- export function fetchDeviceList(params = {}) {
- return http.request({
- url: 'uniapp/device/list',
- method: Method.GET,
- params: params
- });
- }
- /**
- * 获取设备详情
- * @param {number} id - 设备ID
- * @returns {Promise} 设备详情
- */
- export function getDeviceDetail(id) {
- return http.request({
- url: `uniapp/device/${id}`,
- method: Method.GET
- });
- }
- /**
- * 获取设备采集器详情(包含气象/土壤数据和告警信息)
- * @param {number} id - 设备编码
- * @param {string} code - 设备编码,可选,用于判断设备类型
- * @returns {Promise} 设备详情数据
- */
- export function getDeviceCollectorDetail(deviceId, code) {
- return http.request({
- url: `uniapp/device/collector/detail/${deviceId}`,
- method: Method.GET,
- params: code ? { code } : {}
- });
- }
- /**
- * 添加设备
- * @param {Object} data - 设备信息
- * @returns {Promise} 添加结果
- */
- export function addDevice(data) {
- return http.request({
- url: 'uniapp/device',
- method: Method.POST,
- data: data
- });
- }
- /**
- * 更新设备信息
- * @param {Object} data - 设备信息
- * @returns {Promise} 更新结果
- */
- export function updateDevice(data) {
- return http.request({
- url: 'uniapp/device',
- method: Method.PUT,
- data: data
- });
- }
- /**
- * 删除设备
- * @param {number|number[]} ids - 设备ID或ID数组
- * @returns {Promise} 删除结果
- */
- export function deleteDevice(ids) {
- const idStr = Array.isArray(ids) ? ids.join(',') : ids;
- return http.request({
- url: `uniapp/device/${idStr}`,
- method: Method.DELETE
- });
- }
- /**
- * 根据用户ID获取关联的设备列表
- * @param {Object} params - 查询参数
- * @returns {Promise} 设备列表
- */
- export function fetchUserDeviceList(params = {}) {
- const user = storage.getUserInfo();
- return http.request({
- url: 'uniapp/device/user/list',
- method: Method.GET,
- params: {
- ...params,
- userId: user.userId
- }
- });
- }
- /**
- * 根据地块ID获取设备列表
- * @param {string} fieldId - 地块ID
- * @param {Object} params - 其他查询参数
- * @returns {Promise} 设备列表
- */
- export function fetchFieldDeviceList(fieldId, params = {}) {
- return http.request({
- url: 'uniapp/device/list',
- method: Method.GET,
- params: {
- ...params,
- fieldId: fieldId
- }
- });
- }
- /**
- * 获取设备类型统计数据
- * @param {string} fieldId - 地块ID,可选
- * @returns {Promise} 设备类型统计数据
- */
- export function fetchDeviceTypeStats(fieldId) {
- const params = {};
- if (fieldId) params.fieldId = fieldId;
-
- return http.request({
- url: 'uniapp/device/stats/type',
- method: Method.GET,
- params: params
- });
- }
|