修bug
This commit is contained in:
@@ -118,7 +118,6 @@ export default {
|
||||
data.sort((a, b) => a.id - b.id);
|
||||
this.allDevices = data;
|
||||
this.tableData = this.buildTreeData(data);
|
||||
console.log('Final tableData:', this.tableData); // 添加这行日志
|
||||
this.originalTableData = [...this.tableData]; // 保存原始顺序
|
||||
} catch (err) {
|
||||
this.error = err.message || '未知错误';
|
||||
|
||||
@@ -104,8 +104,9 @@ export default {
|
||||
this.loading = true;
|
||||
this.error = null;
|
||||
try {
|
||||
const data = await deviceTemplateService.getDeviceTemplates();
|
||||
this.tableData = data;
|
||||
const response = await deviceTemplateService.getDeviceTemplates();
|
||||
// 确保只将数组部分赋值给 tableData
|
||||
this.tableData = response.data || [];
|
||||
} catch (err) {
|
||||
this.error = err.message || '未知错误';
|
||||
console.error('加载设备模板列表失败:', err);
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
import { AreaControllerApi, DeviceApi } from '../api/device.js';
|
||||
import {AreaControllerApi, DeviceApi} from '../api/device.js';
|
||||
|
||||
class DeviceService {
|
||||
/**
|
||||
* 获取所有设备和区域主控的列表,并将其合并为树形结构所需的数据
|
||||
* @returns {Promise<Array>} 合并后的设备列表
|
||||
*/
|
||||
async getDevices() {
|
||||
try {
|
||||
const [areaControllersResponse, devicesResponse] = await Promise.all([
|
||||
AreaControllerApi.list(),
|
||||
DeviceApi.list()
|
||||
]);
|
||||
/**
|
||||
* 获取所有设备和区域主控的列表,并将其合并为树形结构所需的数据
|
||||
* @returns {Promise<Array>} 合并后的设备列表
|
||||
*/
|
||||
async getDevices() {
|
||||
try {
|
||||
const [areaControllersResponse, devicesResponse] = await Promise.all([
|
||||
AreaControllerApi.list(),
|
||||
DeviceApi.list()
|
||||
]);
|
||||
|
||||
const areaControllers = (areaControllersResponse.data || []).map(controller => ({
|
||||
...controller,
|
||||
type: 'area_controller' // 添加类型标识
|
||||
}));
|
||||
const areaControllers = (areaControllersResponse.data || []).map(controller => ({
|
||||
...controller,
|
||||
type: 'area_controller' // 添加类型标识
|
||||
}));
|
||||
|
||||
const devices = (devicesResponse.data || []).map(device => ({
|
||||
...device,
|
||||
type: 'device', // 添加类型标识
|
||||
parent_id: device.area_controller_id // 适配前端树形结构
|
||||
}));
|
||||
const devices = (devicesResponse.data || []).map(device => ({
|
||||
...device,
|
||||
type: 'device', // 添加类型标识
|
||||
parent_id: device.area_controller_id // 适配前端树形结构
|
||||
}));
|
||||
|
||||
return [...areaControllers, ...devices];
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
throw error;
|
||||
return [...areaControllers, ...devices];
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新设备或区域主控
|
||||
* @param {Object} deviceData 设备或区域主控信息,包含type字段
|
||||
* @returns {Promise<Object>} 创建结果
|
||||
*/
|
||||
async createDevice(deviceData) {
|
||||
try {
|
||||
if (deviceData.type === 'area_controller') {
|
||||
const response = await AreaControllerApi.create(deviceData);
|
||||
return { ...response.data, type: 'area_controller' };
|
||||
} else {
|
||||
// 默认创建普通设备
|
||||
const response = await DeviceApi.create(deviceData);
|
||||
return { ...response.data, type: 'device', parent_id: response.data.area_controller_id };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建设备失败:', error);
|
||||
throw error;
|
||||
/**
|
||||
* 创建新设备或区域主控
|
||||
* @param {Object} deviceData 设备或区域主控信息,包含type字段
|
||||
* @returns {Promise<Object>} 创建结果
|
||||
*/
|
||||
async createDevice(deviceData) {
|
||||
try {
|
||||
if (deviceData.type === 'area_controller') {
|
||||
const response = await AreaControllerApi.create(deviceData);
|
||||
return {...response.data, type: 'area_controller'};
|
||||
} else {
|
||||
// 默认创建普通设备
|
||||
const response = await DeviceApi.create(deviceData);
|
||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建设备失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备或区域主控详情
|
||||
* @param {number} id ID
|
||||
* @param {string} type 类型 ('area_controller' 或 'device')
|
||||
* @returns {Promise<Object>} 详情
|
||||
*/
|
||||
async getDevice(id, type) {
|
||||
try {
|
||||
if (type === 'area_controller') {
|
||||
const response = await AreaControllerApi.get(id);
|
||||
return { ...response.data, type: 'area_controller' };
|
||||
} else {
|
||||
const response = await DeviceApi.get(id);
|
||||
return { ...response.data, type: 'device', parent_id: response.data.area_controller_id };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备详情失败:', error);
|
||||
throw error;
|
||||
/**
|
||||
* 获取设备或区域主控详情
|
||||
* @param {number} id ID
|
||||
* @param {string} type 类型 ('area_controller' 或 'device')
|
||||
* @returns {Promise<Object>} 详情
|
||||
*/
|
||||
async getDevice(id, type) {
|
||||
try {
|
||||
if (type === 'area_controller') {
|
||||
const response = await AreaControllerApi.get(id);
|
||||
return {...response.data, type: 'area_controller'};
|
||||
} else {
|
||||
const response = await DeviceApi.get(id);
|
||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备详情失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设备或区域主控信息
|
||||
* @param {number} id ID
|
||||
* @param {Object} deviceData 更新的设备或区域主控信息,包含type字段
|
||||
* @returns {Promise<Object>} 更新后的信息
|
||||
*/
|
||||
async updateDevice(id, deviceData) {
|
||||
try {
|
||||
if (deviceData.type === 'area_controller') {
|
||||
const response = await AreaControllerApi.update(id, deviceData);
|
||||
return { ...response.data, type: 'area_controller' };
|
||||
} else {
|
||||
const response = await DeviceApi.update(id, deviceData);
|
||||
return { ...response.data, type: 'device', parent_id: response.data.area_controller_id };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新设备失败:', error);
|
||||
throw error;
|
||||
/**
|
||||
* 更新设备或区域主控信息
|
||||
* @param {number} id ID
|
||||
* @param {Object} deviceData 更新的设备或区域主控信息,包含type字段
|
||||
* @returns {Promise<Object>} 更新后的信息
|
||||
*/
|
||||
async updateDevice(id, deviceData) {
|
||||
try {
|
||||
if (deviceData.type === 'area_controller') {
|
||||
const response = await AreaControllerApi.update(id, deviceData);
|
||||
return {...response.data, type: 'area_controller'};
|
||||
} else {
|
||||
const response = await DeviceApi.update(id, deviceData);
|
||||
return {...response.data, type: 'device', parent_id: response.data.area_controller_id};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新设备失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备或区域主控
|
||||
* @param {Object} device 包含id和type属性的设备或区域主控对象
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async deleteDevice(device) {
|
||||
try {
|
||||
if (device.type === 'area_controller') {
|
||||
await AreaControllerApi.delete(device.id);
|
||||
} else {
|
||||
await DeviceApi.delete(device.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除设备失败:', error);
|
||||
throw error;
|
||||
/**
|
||||
* 删除设备或区域主控
|
||||
* @param {Object} device 包含id和type属性的设备或区域主控对象
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async deleteDevice(device) {
|
||||
try {
|
||||
if (device.type === 'area_controller') {
|
||||
await AreaControllerApi.delete(device.id);
|
||||
} else {
|
||||
await DeviceApi.delete(device.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('删除设备失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 导出设备服务实例
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const { VueLoaderPlugin } = require('vue-loader');
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const webpack = require('webpack'); // 引入 webpack 模块
|
||||
|
||||
module.exports = (env, argv) => {
|
||||
const isDevelopment = argv.mode === 'development';
|
||||
@@ -38,6 +39,12 @@ module.exports = (env, argv) => {
|
||||
new HtmlWebpackPlugin({
|
||||
template: './index.html',
|
||||
filename: 'index.html'
|
||||
}),
|
||||
// 添加 Vue 特性标志的定义
|
||||
new webpack.DefinePlugin({
|
||||
__VUE_OPTIONS_API__: JSON.stringify(true),
|
||||
__VUE_PROD_DEVTOOLS__: JSON.stringify(isDevelopment),
|
||||
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(isDevelopment)
|
||||
})
|
||||
],
|
||||
devServer: {
|
||||
|
||||
Reference in New Issue
Block a user