增加设备测试按钮
This commit is contained in:
@@ -63,6 +63,7 @@
|
|||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button size="small" @click="editDevice(scope.row)">编辑</el-button>
|
<el-button size="small" @click="editDevice(scope.row)">编辑</el-button>
|
||||||
<el-button size="small" type="danger" @click="deleteDevice(scope.row)">删除</el-button>
|
<el-button size="small" type="danger" @click="deleteDevice(scope.row)">删除</el-button>
|
||||||
|
<el-button size="small" @click="handleTestDevice(scope.row)" :disabled="isTestButtonDisabled(scope.row)">测试</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -82,6 +83,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import { Refresh } from '@element-plus/icons-vue';
|
import { Refresh } from '@element-plus/icons-vue';
|
||||||
import deviceService from '../../services/deviceService.js';
|
import deviceService from '../../services/deviceService.js';
|
||||||
|
import { DeviceApi } from '../../api/device.js';
|
||||||
|
import { DeviceTemplateApi } from '../../api/deviceTemplate.js';
|
||||||
import DeviceForm from '../../components/DeviceForm.vue';
|
import DeviceForm from '../../components/DeviceForm.vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -95,6 +98,7 @@ export default {
|
|||||||
tableData: [], // 树形表格数据
|
tableData: [], // 树形表格数据
|
||||||
originalTableData: [], // 存储原始未排序的树形数据
|
originalTableData: [], // 存储原始未排序的树形数据
|
||||||
allDevices: [], // 存储所有设备用于构建树形结构
|
allDevices: [], // 存储所有设备用于构建树形结构
|
||||||
|
deviceTemplates: [], // 存储所有设备模板
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
saving: false,
|
saving: false,
|
||||||
@@ -113,12 +117,14 @@ export default {
|
|||||||
this.error = null;
|
this.error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await deviceService.getDevices();
|
const [deviceData, templateData] = await Promise.all([
|
||||||
// Default sort by ID ascending
|
deviceService.getDevices(),
|
||||||
data.sort((a, b) => a.id - b.id);
|
DeviceTemplateApi.getDeviceTemplates()
|
||||||
this.allDevices = data;
|
]);
|
||||||
this.tableData = this.buildTreeData(data);
|
this.allDevices = deviceData;
|
||||||
|
this.tableData = this.buildTreeData(deviceData);
|
||||||
this.originalTableData = [...this.tableData]; // 保存原始顺序
|
this.originalTableData = [...this.tableData]; // 保存原始顺序
|
||||||
|
this.deviceTemplates = templateData.data; // 存储设备模板
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.error = err.message || '未知错误';
|
this.error = err.message || '未知错误';
|
||||||
console.error('加载设备列表失败:', err);
|
console.error('加载设备列表失败:', err);
|
||||||
@@ -236,6 +242,53 @@ export default {
|
|||||||
return 'is-device-row';
|
return 'is-device-row';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
},
|
||||||
|
|
||||||
|
isTestButtonDisabled(device) {
|
||||||
|
// 区域主控禁用
|
||||||
|
if (device.type !== 'device') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找设备模板
|
||||||
|
const deviceTemplate = this.deviceTemplates.find(template => template.id === device.device_template_id);
|
||||||
|
|
||||||
|
// 如果找不到设备模板,也禁用
|
||||||
|
if (!deviceTemplate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果设备模板类型不是'传感器',则禁用
|
||||||
|
if (deviceTemplate.category !== '传感器') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false; // 否则启用
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleTestDevice(device) {
|
||||||
|
if (device.type !== 'device') {
|
||||||
|
this.$message.warning('暂不支持非传感器类的测试');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const deviceTemplate = this.deviceTemplates.find(template => template.id === device.device_template_id);
|
||||||
|
|
||||||
|
if (!deviceTemplate) {
|
||||||
|
this.$message.error('无法获取设备模板信息,请刷新重试');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceTemplate.category === '传感器') {
|
||||||
|
try {
|
||||||
|
await DeviceApi.manualControl(device.id, {});
|
||||||
|
this.$message.success('测试请求已发送,请前往传感器数据页面查看结果');
|
||||||
|
} catch (error) {
|
||||||
|
this.$message.error('发送测试请求失败: ' + (error.message || '未知错误'));
|
||||||
|
}
|
||||||
|
} else if (deviceTemplate.category === '执行器') {
|
||||||
|
this.$message.warning('暂不支持非传感器类的测试');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user