| | |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="设备类型" prop="deviceType"> |
| | | <el-select v-model="deviceForm.deviceType" placeholder="选择设备类型" style="width: 100%;"> |
| | | <el-option label="大车设备" value="大车设备" /> |
| | | <el-option label="大理片笼" value="大理片笼" /> |
| | | <el-option label="卧转立扫码" value="卧转立扫码" /> |
| | | <el-option label="卧转立" value="卧转立" /> |
| | | <el-select v-model="deviceForm.deviceType" placeholder="选择设备类型" style="width: 100%;" :loading="deviceTypesLoading"> |
| | | <el-option |
| | | v-for="type in deviceTypes" |
| | | :key="type" |
| | | :label="type" |
| | | :value="type" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | |
| | |
| | | const testing = ref(false) |
| | | const testResult = ref(null) |
| | | |
| | | // 设备类型列表 |
| | | const deviceTypes = ref([]) |
| | | const deviceTypesLoading = ref(false) |
| | | |
| | | // 设备逻辑参数(根据设备类型动态显示) |
| | | const deviceLogicParams = reactive({}) |
| | | const deviceLogicParams = ref({}) |
| | | |
| | | const S7_PLC_TYPES = ['S1200', 'S1500'] |
| | | const MODBUS_PLC_TYPES = ['MODBUS'] |
| | |
| | | watch(() => props.modelValue, (newVal) => { |
| | | dialogVisible.value = newVal |
| | | if (newVal) { |
| | | // 加载设备类型列表 |
| | | loadDeviceTypes() |
| | | if (isEdit.value && props.deviceData) { |
| | | loadDeviceData(props.deviceData) |
| | | } else { |
| | |
| | | } |
| | | |
| | | if (value !== 'S7 Communication' && S7_PLC_TYPES.includes(deviceForm.plcType)) { |
| | | ElMessage.warning('S7系列PLC通常使用S7 Communication协议,请确认协议选择是否正确') |
| | | ElMessage.warning('S7系列PLC通常使用S7 Communication协议,请确认协议选择是否正确') |
| | | return |
| | | } |
| | | } |
| | | |
| | | if (value !== 'Modbus TCP' && MODBUS_PLC_TYPES.includes(deviceForm.plcType)) { |
| | | ElMessage.warning('Modbus 类型PLC通常使用 Modbus TCP 协议,请确认协议选择是否正确') |
| | |
| | | } |
| | | |
| | | // 方法定义 |
| | | // 加载设备类型列表 |
| | | 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 |
| | | ElMessage.warning('加载设备类型列表失败,使用默认类型') |
| | | } finally { |
| | | deviceTypesLoading.value = false |
| | | } |
| | | } |
| | | |
| | | const parseJsonSafe = (str, defaultValue = null) => { |
| | | if (!str) return defaultValue |
| | | try { |
| | |
| | | } |
| | | |
| | | // 加载设备逻辑参数 |
| | | const loadDeviceLogicParams = (deviceLogic, deviceType) => { |
| | | // 清空现有参数 |
| | | Object.keys(deviceLogicParams).forEach(key => { |
| | | delete deviceLogicParams[key] |
| | | }) |
| | | |
| | | // 根据设备类型加载对应的参数 |
| | | const loadDeviceLogicParams = (deviceLogic) => { |
| | | if (deviceLogic && Object.keys(deviceLogic).length > 0) { |
| | | Object.assign(deviceLogicParams, deviceLogic) |
| | | deviceLogicParams.value = { ...deviceLogic } |
| | | } else { |
| | | deviceLogicParams.value = {} |
| | | } |
| | | } |
| | | |
| | |
| | | deviceFormRef.value?.clearValidate() |
| | | |
| | | // 重置设备逻辑参数 |
| | | Object.keys(deviceLogicParams).forEach(key => { |
| | | delete deviceLogicParams[key] |
| | | }) |
| | | deviceLogicParams.value = {} |
| | | } |
| | | |
| | | const addConfigParam = () => { |
| | |
| | | } |
| | | |
| | | // 保存设备逻辑参数(直接使用deviceLogicParams,由各个配置组件管理) |
| | | if (deviceLogicParams && Object.keys(deviceLogicParams).length > 0) { |
| | | extraObj.deviceLogic = { ...deviceLogicParams } |
| | | if (deviceLogicParams.value && Object.keys(deviceLogicParams.value).length > 0) { |
| | | extraObj.deviceLogic = { ...deviceLogicParams.value } |
| | | } else { |
| | | delete extraObj.deviceLogic |
| | | } |
| | | |
| | | // 构建 configJson:将 configParams 数组转换为 JSON 字符串 |