mes-web/src/views/device/DeviceConfigList.vue
@@ -4,10 +4,13 @@
    <div class="search-section">
      <el-form :model="searchForm" :inline="true" class="search-form">
        <el-form-item label="设备类型">
          <el-select v-model="searchForm.deviceType" placeholder="选择设备类型" clearable>
            <el-option label="上大车" value="上大车" />
            <el-option label="大理片" value="大理片" />
            <el-option label="玻璃存储" value="玻璃存储" />
          <el-select v-model="searchForm.deviceType" placeholder="选择设备类型" clearable :loading="deviceTypesLoading">
            <el-option
              v-for="type in deviceTypes"
              :key="type"
              :label="type"
              :value="type"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="设备状态">
@@ -76,7 +79,7 @@
        </el-table-column>
        <el-table-column prop="plcIp" label="PLC IP" width="130" />
        <el-table-column prop="plcType" label="PLC类型" width="100" />
        <el-table-column prop="moduleName" label="模块名称" min-width="120" />
        <el-table-column prop="moduleName" label="模块名称" min-width="60" />
        <el-table-column prop="isPrimary" label="主控设备" width="100" align="center">
          <template #default="scope">
            <el-tag v-if="scope.row.isPrimary" type="success" size="small">主控</el-tag>
@@ -104,12 +107,12 @@
            {{ formatDateTime(scope.row.lastHeartbeat) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
        <el-table-column label="操作" width="300" fixed="right">
          <template #default="scope">
            <el-button type="primary" size="small" @click="editDevice(scope.row)">
              编辑
            </el-button>
            <el-button type="warning" size="small" :loading="plcOperationLoading" @click="handleSinglePlcRequest(scope.row)">
            <el-button type="warning" size="small" :loading="plcOperationLoading" @click.stop="handleSinglePlcRequest(scope.row, $event)">
              PLC请求
            </el-button>
            <el-button type="success" size="small" @click="healthCheck(scope.row)">
@@ -165,6 +168,10 @@
const selectedDevices = ref([])
const plcOperationLoading = ref(false)
// 设备类型列表
const deviceTypes = ref([])
const deviceTypesLoading = ref(false)
// 搜索表单
const searchForm = reactive({
  deviceType: '',
@@ -183,6 +190,37 @@
const emit = defineEmits(['device-selected', 'refresh-statistics'])
// 方法定义
// 加载设备类型列表
const loadDeviceTypes = async () => {
  if (deviceTypes.value.length > 0) {
    // 如果已经加载过,不再重复加载
    return
  }
  // 所有支持的设备类型(确保包含所有有配置组件的类型)
  const supportedTypes = ['大车设备', '大理片笼', '卧转立扫码设备', '卧转立设备']
  try {
    deviceTypesLoading.value = true
    const res = await deviceConfigApi.getDeviceTypes()
    if (res?.data && Array.isArray(res.data)) {
      // 合并数据库中的类型和支持的类型,去重并排序
      const dbTypes = res.data
      const allTypes = [...new Set([...supportedTypes, ...dbTypes])].sort()
      deviceTypes.value = allTypes
    } else {
      // 如果API返回失败,使用默认类型
      deviceTypes.value = supportedTypes
      console.warn('获取设备类型列表失败,使用默认类型')
    }
  } catch (error) {
    console.error('加载设备类型列表失败:', error)
    // 失败时使用默认类型
    deviceTypes.value = supportedTypes
  } finally {
    deviceTypesLoading.value = false
  }
}
const loadDeviceList = async () => {
  try {
    tableLoading.value = true
@@ -190,8 +228,8 @@
      pageNum: pagination.page,
      pageSize: pagination.size,
      deviceType: searchForm.deviceType || undefined,
      status: searchForm.deviceStatus || undefined,
      deviceCode: searchForm.keyword || undefined
      deviceStatus: searchForm.deviceStatus || undefined,
      keyword: searchForm.keyword?.trim() || undefined
    }
    
    const response = await deviceConfigApi.getList(params)
@@ -284,9 +322,24 @@
  }
}
const handleSinglePlcRequest = (row) => executePlcOperation([row.id || row.deviceId], 'request')
const handleSinglePlcReport = (row) => executePlcOperation([row.id || row.deviceId], 'report')
const handleSinglePlcReset = (row) => executePlcOperation([row.id || row.deviceId], 'reset')
const handleSinglePlcRequest = (row, event) => {
  if (event) {
    event.stopPropagation()
  }
  executePlcOperation([row.id || row.deviceId], 'request')
}
const handleSinglePlcReport = (row, event) => {
  if (event) {
    event.stopPropagation()
  }
  executePlcOperation([row.id || row.deviceId], 'report')
}
const handleSinglePlcReset = (row, event) => {
  if (event) {
    event.stopPropagation()
  }
  executePlcOperation([row.id || row.deviceId], 'reset')
}
const batchPlcRequest = () => executePlcOperation(getSelectedDeviceIds(), 'request')
const batchPlcReport = () => executePlcOperation(getSelectedDeviceIds(), 'report')
@@ -438,9 +491,9 @@
// 工具函数
const getDeviceTypeTag = (type) => {
  const typeMap = {
    '上大车': 'primary',
    '大理片': 'success',
    '玻璃存储': 'warning'
    '大车设备': 'primary',
    '大理片笼': 'success',
    '卧式缓存': 'warning'
  }
  return typeMap[type] || 'info'
}
@@ -481,6 +534,7 @@
// 组件挂载时加载数据
onMounted(() => {
  loadDeviceTypes()
  loadDeviceList()
})
</script>