Compare commits
5 Commits
a457b9713c
...
9c6467176c
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c6467176c | |||
| fdc568753c | |||
| a3e9465b88 | |||
| 96c36f9ce1 | |||
| c68dff6123 |
@@ -1,5 +1,7 @@
|
|||||||
import http from '../utils/http';
|
import http from '../utils/http';
|
||||||
|
|
||||||
|
// --- Device API Functions ---
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统中所有设备的列表
|
* 获取系统中所有设备的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
@@ -54,3 +56,72 @@ export const deleteDevice = (id) => {
|
|||||||
export const manualControlDevice = (id, manualControlData) => {
|
export const manualControlDevice = (id, manualControlData) => {
|
||||||
return http.post(`/api/v1/devices/manual-control/${id}`, manualControlData);
|
return http.post(`/api/v1/devices/manual-control/${id}`, manualControlData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// --- AreaController API Functions ---
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统中所有区域主控的列表
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const getAreaControllers = () => {
|
||||||
|
return http.get('/api/v1/area-controllers');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新区域主控
|
||||||
|
* @param {object} areaControllerData - 区域主控信息
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const createAreaController = (areaControllerData) => {
|
||||||
|
return http.post('/api/v1/area-controllers', areaControllerData);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID获取单个区域主控的详细信息
|
||||||
|
* @param {string} id - 区域主控ID
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const getAreaControllerById = (id) => {
|
||||||
|
return http.get(`/api/v1/area-controllers/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID更新一个已存在的区域主控信息
|
||||||
|
* @param {string} id - 区域主控ID
|
||||||
|
* @param {object} areaControllerData - 要更新的区域主控信息
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const updateAreaController = (id, areaControllerData) => {
|
||||||
|
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除一个区域主控
|
||||||
|
* @param {string} id - 区域主控ID
|
||||||
|
* @returns {Promise<*>}
|
||||||
|
*/
|
||||||
|
export const deleteAreaController = (id) => {
|
||||||
|
return http.delete(`/api/v1/area-controllers/${id}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// --- API Wrappers ---
|
||||||
|
|
||||||
|
// AreaControllerApi 封装
|
||||||
|
export const AreaControllerApi = {
|
||||||
|
list: getAreaControllers,
|
||||||
|
create: createAreaController,
|
||||||
|
getById: getAreaControllerById,
|
||||||
|
update: updateAreaController,
|
||||||
|
delete: deleteAreaController
|
||||||
|
};
|
||||||
|
|
||||||
|
// DeviceApi 封装
|
||||||
|
export const DeviceApi = {
|
||||||
|
list: getDevices,
|
||||||
|
create: createDevice,
|
||||||
|
getById: getDeviceById,
|
||||||
|
update: updateDevice,
|
||||||
|
delete: deleteDevice
|
||||||
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import http from '../utils/http';
|
|||||||
* 获取系统中所有设备模板的列表
|
* 获取系统中所有设备模板的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const getDeviceTemplates = () => {
|
const getDeviceTemplates = () => {
|
||||||
return http.get('/api/v1/device-templates');
|
return http.get('/api/v1/device-templates');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ export const getDeviceTemplates = () => {
|
|||||||
* @param {object} deviceTemplateData - 设备模板信息,对应 dto.CreateDeviceTemplateRequest
|
* @param {object} deviceTemplateData - 设备模板信息,对应 dto.CreateDeviceTemplateRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const createDeviceTemplate = (deviceTemplateData) => {
|
const createDeviceTemplate = (deviceTemplateData) => {
|
||||||
return http.post('/api/v1/device-templates', deviceTemplateData);
|
return http.post('/api/v1/device-templates', deviceTemplateData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ export const createDeviceTemplate = (deviceTemplateData) => {
|
|||||||
* @param {string} id - 设备模板ID
|
* @param {string} id - 设备模板ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const getDeviceTemplateById = (id) => {
|
const getDeviceTemplateById = (id) => {
|
||||||
return http.get(`/api/v1/device-templates/${id}`);
|
return http.get(`/api/v1/device-templates/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ export const getDeviceTemplateById = (id) => {
|
|||||||
* @param {object} deviceTemplateData - 要更新的设备模板信息,对应 dto.UpdateDeviceTemplateRequest
|
* @param {object} deviceTemplateData - 要更新的设备模板信息,对应 dto.UpdateDeviceTemplateRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const updateDeviceTemplate = (id, deviceTemplateData) => {
|
const updateDeviceTemplate = (id, deviceTemplateData) => {
|
||||||
return http.put(`/api/v1/device-templates/${id}`, deviceTemplateData);
|
return http.put(`/api/v1/device-templates/${id}`, deviceTemplateData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,6 +41,14 @@ export const updateDeviceTemplate = (id, deviceTemplateData) => {
|
|||||||
* @param {string} id - 设备模板ID
|
* @param {string} id - 设备模板ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const deleteDeviceTemplate = (id) => {
|
const deleteDeviceTemplate = (id) => {
|
||||||
return http.delete(`/api/v1/device-templates/${id}`);
|
return http.delete(`/api/v1/device-templates/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const DeviceTemplateApi = {
|
||||||
|
getDeviceTemplates,
|
||||||
|
createDeviceTemplate,
|
||||||
|
getDeviceTemplateById,
|
||||||
|
updateDeviceTemplate,
|
||||||
|
deleteDeviceTemplate,
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { AreaControllerApi, DeviceApi } from './device.js';
|
import { AreaControllerApi, DeviceApi } from './device.js';
|
||||||
import PlanApi from './plan.js';
|
import { PlanApi } from './plan.js';
|
||||||
import UserApi from './user.js';
|
import { UserApi } from './user.js';
|
||||||
import DeviceTemplateApi from './deviceTemplate.js'; // 导入设备模板API
|
import { DeviceTemplateApi } from './deviceTemplate.js'; // 导入设备模板API
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API客户端
|
* API客户端
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import http from '../utils/http';
|
|||||||
* 获取所有计划的列表
|
* 获取所有计划的列表
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const getPlans = () => {
|
const getPlans = () => {
|
||||||
return http.get('/api/v1/plans');
|
return http.get('/api/v1/plans');
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ export const getPlans = () => {
|
|||||||
* @param {object} planData - 计划信息,对应 dto.CreatePlanRequest
|
* @param {object} planData - 计划信息,对应 dto.CreatePlanRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const createPlan = (planData) => {
|
const createPlan = (planData) => {
|
||||||
return http.post('/api/v1/plans', planData);
|
return http.post('/api/v1/plans', planData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ export const createPlan = (planData) => {
|
|||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const getPlanById = (id) => {
|
const getPlanById = (id) => {
|
||||||
return http.get(`/api/v1/plans/${id}`);
|
return http.get(`/api/v1/plans/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ export const getPlanById = (id) => {
|
|||||||
* @param {object} planData - 更新后的计划信息,对应 dto.UpdatePlanRequest
|
* @param {object} planData - 更新后的计划信息,对应 dto.UpdatePlanRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const updatePlan = (id, planData) => {
|
const updatePlan = (id, planData) => {
|
||||||
return http.put(`/api/v1/plans/${id}`, planData);
|
return http.put(`/api/v1/plans/${id}`, planData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export const updatePlan = (id, planData) => {
|
|||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const deletePlan = (id) => {
|
const deletePlan = (id) => {
|
||||||
return http.delete(`/api/v1/plans/${id}`);
|
return http.delete(`/api/v1/plans/${id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ export const deletePlan = (id) => {
|
|||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const startPlan = (id) => {
|
const startPlan = (id) => {
|
||||||
return http.post(`/api/v1/plans/${id}/start`);
|
return http.post(`/api/v1/plans/${id}/start`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,6 +59,16 @@ export const startPlan = (id) => {
|
|||||||
* @param {number} id - 计划ID
|
* @param {number} id - 计划ID
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const stopPlan = (id) => {
|
const stopPlan = (id) => {
|
||||||
return http.post(`/api/v1/plans/${id}/stop`);
|
return http.post(`/api/v1/plans/${id}/stop`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const PlanApi = {
|
||||||
|
getPlans,
|
||||||
|
createPlan,
|
||||||
|
getPlanById,
|
||||||
|
updatePlan,
|
||||||
|
deletePlan,
|
||||||
|
startPlan,
|
||||||
|
stopPlan,
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import http from '../utils/http';
|
|||||||
* @param {object} userData - 用户信息,对应 dto.CreateUserRequest
|
* @param {object} userData - 用户信息,对应 dto.CreateUserRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const createUser = (userData) => {
|
const createUser = (userData) => {
|
||||||
return http.post('/api/v1/users', userData);
|
return http.post('/api/v1/users', userData);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export const createUser = (userData) => {
|
|||||||
* @param {object} credentials - 登录凭证,对应 dto.LoginRequest
|
* @param {object} credentials - 登录凭证,对应 dto.LoginRequest
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const login = (credentials) => {
|
const login = (credentials) => {
|
||||||
return http.post('/api/v1/users/login', credentials);
|
return http.post('/api/v1/users/login', credentials);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,6 +24,12 @@ export const login = (credentials) => {
|
|||||||
* @param {object} params - 查询参数
|
* @param {object} params - 查询参数
|
||||||
* @returns {Promise<*>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
export const getUserHistory = (id, params) => {
|
const getUserHistory = (id, params) => {
|
||||||
return http.get(`/api/v1/users/${id}/history`, { params });
|
return http.get(`/api/v1/users/${id}/history`, { params });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const UserApi = {
|
||||||
|
createUser,
|
||||||
|
login,
|
||||||
|
getUserHistory,
|
||||||
|
};
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ export default {
|
|||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.plans.get(this.planId);
|
const response = await apiClient.plans.getPlanById(this.planId);
|
||||||
this.plan = {
|
this.plan = {
|
||||||
...response.data,
|
...response.data,
|
||||||
sub_plans: response.data.sub_plans || [],
|
sub_plans: response.data.sub_plans || [],
|
||||||
@@ -320,7 +320,7 @@ export default {
|
|||||||
delete submitData.status;
|
delete submitData.status;
|
||||||
|
|
||||||
console.log("PlanDetail: Submitting data", submitData);
|
console.log("PlanDetail: Submitting data", submitData);
|
||||||
await apiClient.plans.update(this.planId, submitData);
|
await apiClient.plans.updatePlan(this.planId, submitData);
|
||||||
ElMessage.success('计划内容已保存');
|
ElMessage.success('计划内容已保存');
|
||||||
this.isEditingContent = false;
|
this.isEditingContent = false;
|
||||||
this.fetchPlan();
|
this.fetchPlan();
|
||||||
@@ -355,7 +355,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async fetchAvailablePlans() {
|
async fetchAvailablePlans() {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.plans.list();
|
const response = await apiClient.plans.getPlans(); // 更正此处
|
||||||
this.availablePlans = response.data.plans.filter(p =>
|
this.availablePlans = response.data.plans.filter(p =>
|
||||||
p.id !== this.planId
|
p.id !== this.planId
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ export default {
|
|||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.plans.list();
|
const response = await apiClient.plans.getPlans(); // 更正此处
|
||||||
let fetchedPlans = response.data?.plans || [];
|
let fetchedPlans = response.data?.plans || [];
|
||||||
// Default sort by ID ascending
|
// Default sort by ID ascending
|
||||||
fetchedPlans.sort((a, b) => a.id - b.id);
|
fetchedPlans.sort((a, b) => a.id - b.id);
|
||||||
@@ -262,7 +262,7 @@ export default {
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
});
|
});
|
||||||
|
|
||||||
await apiClient.plans.delete(plan.id);
|
await apiClient.plans.deletePlan(plan.id);
|
||||||
this.$message.success('删除成功');
|
this.$message.success('删除成功');
|
||||||
await this.loadPlans();
|
await this.loadPlans();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -275,7 +275,7 @@ export default {
|
|||||||
async startPlan(plan) {
|
async startPlan(plan) {
|
||||||
try {
|
try {
|
||||||
this.startingPlanId = plan.id;
|
this.startingPlanId = plan.id;
|
||||||
await apiClient.plans.start(plan.id);
|
await apiClient.plans.startPlan(plan.id);
|
||||||
this.$message.success('计划启动成功');
|
this.$message.success('计划启动成功');
|
||||||
await this.loadPlans();
|
await this.loadPlans();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -288,7 +288,7 @@ export default {
|
|||||||
async stopPlan(plan) {
|
async stopPlan(plan) {
|
||||||
try {
|
try {
|
||||||
this.stoppingPlanId = plan.id;
|
this.stoppingPlanId = plan.id;
|
||||||
await apiClient.plans.stop(plan.id);
|
await apiClient.plans.stopPlan(plan.id);
|
||||||
this.$message.success('计划停止成功');
|
this.$message.success('计划停止成功');
|
||||||
await this.loadPlans();
|
await this.loadPlans();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -303,7 +303,7 @@ export default {
|
|||||||
try {
|
try {
|
||||||
if (this.isEdit) {
|
if (this.isEdit) {
|
||||||
// 编辑计划
|
// 编辑计划
|
||||||
await apiClient.plans.update(planData.id, planData);
|
await apiClient.plans.updatePlan(planData.id, planData);
|
||||||
this.$message.success('计划更新成功');
|
this.$message.success('计划更新成功');
|
||||||
} else {
|
} else {
|
||||||
// 添加新计划
|
// 添加新计划
|
||||||
@@ -312,7 +312,7 @@ export default {
|
|||||||
content_type: 'tasks' // 默认使用任务类型
|
content_type: 'tasks' // 默认使用任务类型
|
||||||
};
|
};
|
||||||
|
|
||||||
await apiClient.plans.create(planRequest);
|
await apiClient.plans.createPlan(planRequest);
|
||||||
this.$message.success('计划添加成功');
|
this.$message.success('计划添加成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {AreaControllerApi, DeviceApi} from '../api/device.js';
|
import { AreaControllerApi, DeviceApi } from '../api/device.js';
|
||||||
|
|
||||||
class DeviceService {
|
class DeviceService {
|
||||||
/**
|
/**
|
||||||
@@ -7,22 +7,26 @@ class DeviceService {
|
|||||||
*/
|
*/
|
||||||
async getDevices() {
|
async getDevices() {
|
||||||
try {
|
try {
|
||||||
|
// 1. 并行发起两个独立的API请求:一个获取区域主控,一个获取普通设备
|
||||||
const [areaControllersResponse, devicesResponse] = await Promise.all([
|
const [areaControllersResponse, devicesResponse] = await Promise.all([
|
||||||
AreaControllerApi.list(),
|
AreaControllerApi.list(), // 调用 GET /api/v1/area-controllers
|
||||||
DeviceApi.list()
|
DeviceApi.list() // 调用 GET /api/v1/devices
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// 2. 处理区域主控数据,并添加前端所需的'type'标识
|
||||||
const areaControllers = (areaControllersResponse.data || []).map(controller => ({
|
const areaControllers = (areaControllersResponse.data || []).map(controller => ({
|
||||||
...controller,
|
...controller,
|
||||||
type: 'area_controller' // 添加类型标识
|
type: 'area_controller'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// 3. 处理普通设备数据,并添加'type'和'parent_id'以构建树形结构
|
||||||
const devices = (devicesResponse.data || []).map(device => ({
|
const devices = (devicesResponse.data || []).map(device => ({
|
||||||
...device,
|
...device,
|
||||||
type: 'device', // 添加类型标识
|
type: 'device',
|
||||||
parent_id: device.area_controller_id // 适配前端树形结构
|
parent_id: device.area_controller_id
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// 4. 合并两份数据,形成完整的列表,返回给UI组件
|
||||||
return [...areaControllers, ...devices];
|
return [...areaControllers, ...devices];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取设备列表失败:', error);
|
console.error('获取设备列表失败:', error);
|
||||||
@@ -32,17 +36,16 @@ class DeviceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新设备或区域主控
|
* 创建新设备或区域主控
|
||||||
* @param {Object} deviceData 设备或区域主控信息,包含type字段
|
* @param {Object} data - 设备或区域主控信息,包含type字段
|
||||||
* @returns {Promise<Object>} 创建结果
|
* @returns {Promise<Object>} 创建结果
|
||||||
*/
|
*/
|
||||||
async createDevice(deviceData) {
|
async createDevice(data) {
|
||||||
try {
|
try {
|
||||||
if (deviceData.type === 'area_controller') {
|
if (data.type === 'area_controller') {
|
||||||
const response = await AreaControllerApi.create(deviceData);
|
const response = await AreaControllerApi.create(data);
|
||||||
return {...response.data, type: 'area_controller'};
|
return {...response.data, type: 'area_controller'};
|
||||||
} else {
|
} else {
|
||||||
// 默认创建普通设备
|
const response = await DeviceApi.create(data);
|
||||||
const response = await DeviceApi.create(deviceData);
|
|
||||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -53,17 +56,17 @@ class DeviceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备或区域主控详情
|
* 获取设备或区域主控详情
|
||||||
* @param {number} id ID
|
* @param {number} id - ID
|
||||||
* @param {string} type 类型 ('area_controller' 或 'device')
|
* @param {string} type - 类型 ('area_controller' 或 'device')
|
||||||
* @returns {Promise<Object>} 详情
|
* @returns {Promise<Object>} 详情
|
||||||
*/
|
*/
|
||||||
async getDevice(id, type) {
|
async getDevice(id, type) {
|
||||||
try {
|
try {
|
||||||
if (type === 'area_controller') {
|
if (type === 'area_controller') {
|
||||||
const response = await AreaControllerApi.get(id);
|
const response = await AreaControllerApi.getById(id);
|
||||||
return {...response.data, type: 'area_controller'};
|
return {...response.data, type: 'area_controller'};
|
||||||
} else {
|
} else {
|
||||||
const response = await DeviceApi.get(id);
|
const response = await DeviceApi.getById(id);
|
||||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -74,17 +77,17 @@ class DeviceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备或区域主控信息
|
* 更新设备或区域主控信息
|
||||||
* @param {number} id ID
|
* @param {number} id - ID
|
||||||
* @param {Object} deviceData 更新的设备或区域主控信息,包含type字段
|
* @param {Object} data - 更新的设备或区域主控信息,包含type字段
|
||||||
* @returns {Promise<Object>} 更新后的信息
|
* @returns {Promise<Object>} 更新后的信息
|
||||||
*/
|
*/
|
||||||
async updateDevice(id, deviceData) {
|
async updateDevice(id, data) {
|
||||||
try {
|
try {
|
||||||
if (deviceData.type === 'area_controller') {
|
if (data.type === 'area_controller') {
|
||||||
const response = await AreaControllerApi.update(id, deviceData);
|
const response = await AreaControllerApi.update(id, data);
|
||||||
return {...response.data, type: 'area_controller'};
|
return {...response.data, type: 'area_controller'};
|
||||||
} else {
|
} else {
|
||||||
const response = await DeviceApi.update(id, deviceData);
|
const response = await DeviceApi.update(id, data);
|
||||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -95,7 +98,7 @@ class DeviceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除设备或区域主控
|
* 删除设备或区域主控
|
||||||
* @param {Object} device 包含id和type属性的设备或区域主控对象
|
* @param {Object} device - 包含id和type属性的设备或区域主控对象
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async deleteDevice(device) {
|
async deleteDevice(device) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class DeviceTemplateService {
|
|||||||
*/
|
*/
|
||||||
async getDeviceTemplates() {
|
async getDeviceTemplates() {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.deviceTemplates.list();
|
const response = await apiClient.deviceTemplates.getDeviceTemplates(); // 更正此处
|
||||||
return response || [];
|
return response || [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取设备模板列表失败:', error);
|
console.error('获取设备模板列表失败:', error);
|
||||||
@@ -22,7 +22,7 @@ class DeviceTemplateService {
|
|||||||
*/
|
*/
|
||||||
async createDeviceTemplate(deviceTemplateData) {
|
async createDeviceTemplate(deviceTemplateData) {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.deviceTemplates.create(deviceTemplateData);
|
const response = await apiClient.deviceTemplates.createDeviceTemplate(deviceTemplateData);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('创建设备模板失败:', error);
|
console.error('创建设备模板失败:', error);
|
||||||
@@ -37,7 +37,7 @@ class DeviceTemplateService {
|
|||||||
*/
|
*/
|
||||||
async getDeviceTemplate(id) {
|
async getDeviceTemplate(id) {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.deviceTemplates.get(id);
|
const response = await apiClient.deviceTemplates.getDeviceTemplateById(id);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取设备模板详情失败:', error);
|
console.error('获取设备模板详情失败:', error);
|
||||||
@@ -53,7 +53,7 @@ class DeviceTemplateService {
|
|||||||
*/
|
*/
|
||||||
async updateDeviceTemplate(id, deviceTemplateData) {
|
async updateDeviceTemplate(id, deviceTemplateData) {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.deviceTemplates.update(id, deviceTemplateData);
|
const response = await apiClient.deviceTemplates.updateDeviceTemplate(id, deviceTemplateData);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('更新设备模板失败:', error);
|
console.error('更新设备模板失败:', error);
|
||||||
@@ -68,7 +68,7 @@ class DeviceTemplateService {
|
|||||||
*/
|
*/
|
||||||
async deleteDeviceTemplate(id) {
|
async deleteDeviceTemplate(id) {
|
||||||
try {
|
try {
|
||||||
await apiClient.deviceTemplates.delete(id);
|
await apiClient.deviceTemplates.deleteDeviceTemplate(id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('删除设备模板失败:', error);
|
console.error('删除设备模板失败:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user