Commit 49f38d3ef0d2925ed07e94304adcd06382ec7dd5
Merge branch 'fix/attribute-distribution' into 'main_dev'
fix: 修改物模型属性下发 See merge request yunteng/thingskit-front!782
Showing
1 changed file
with
27 additions
and
11 deletions
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | defineEmits(['register']); | 17 | defineEmits(['register']); |
18 | const props = defineProps<{ deviceId: string; deviceName: string }>(); | 18 | const props = defineProps<{ deviceId: string; deviceName: string }>(); |
19 | 19 | ||
20 | - const [registerForm, { setProps, getFieldsValue, resetFields }] = useForm({ | 20 | + const [registerForm, { setProps, getFieldsValue, resetFields, validate }] = useForm({ |
21 | schemas: [], | 21 | schemas: [], |
22 | showActionButtonGroup: false, | 22 | showActionButtonGroup: false, |
23 | layout: 'vertical', | 23 | layout: 'vertical', |
@@ -28,7 +28,8 @@ | @@ -28,7 +28,8 @@ | ||
28 | const keys = ref<string[]>([]); | 28 | const keys = ref<string[]>([]); |
29 | 29 | ||
30 | const modBUSForm = ref<any>({}); | 30 | const modBUSForm = ref<any>({}); |
31 | - const isShowModBUS = ref<Boolean>(false); | 31 | + const isShowModBUS = ref<Boolean>(false); //用于判断标识符类型是否时自定义还是modBUS |
32 | + const isShowActionType = ref<Boolean>(true); //判断设备属性标识符为modBus时没有填写扩展描述 | ||
32 | const formField = ref(''); | 33 | const formField = ref(''); |
33 | 34 | ||
34 | const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => { | 35 | const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => { |
@@ -45,6 +46,14 @@ | @@ -45,6 +46,14 @@ | ||
45 | if (type === DataTypeEnum.IS_STRUCT) { | 46 | if (type === DataTypeEnum.IS_STRUCT) { |
46 | schemas = dataType?.specs as StructJSON[]; | 47 | schemas = dataType?.specs as StructJSON[]; |
47 | } | 48 | } |
49 | + | ||
50 | + keys.value = schemas.map((item) => { | ||
51 | + return item.identifier!; | ||
52 | + }); | ||
53 | + isShowActionType.value = actionType ? true : false; //判断modBUS类型时 物模型是否填写扩展描述 | ||
54 | + | ||
55 | + //是modBUS类型的就用另外的表单 | ||
56 | + //判断是否是modBus的下发命令 | ||
48 | if (codeType == TaskTypeEnum.MODBUS) { | 57 | if (codeType == TaskTypeEnum.MODBUS) { |
49 | isShowModBUS.value = true; | 58 | isShowModBUS.value = true; |
50 | modBUSForm.value = { | 59 | modBUSForm.value = { |
@@ -59,9 +68,6 @@ | @@ -59,9 +68,6 @@ | ||
59 | } else { | 68 | } else { |
60 | isShowModBUS.value = false; | 69 | isShowModBUS.value = false; |
61 | const formSchemas = genForm(schemas); | 70 | const formSchemas = genForm(schemas); |
62 | - keys.value = schemas.map((item) => { | ||
63 | - return item.identifier!; | ||
64 | - }); | ||
65 | setProps({ schemas: formSchemas }); | 71 | setProps({ schemas: formSchemas }); |
66 | } | 72 | } |
67 | 73 | ||
@@ -85,15 +91,25 @@ | @@ -85,15 +91,25 @@ | ||
85 | try { | 91 | try { |
86 | loading.value = true; | 92 | loading.value = true; |
87 | if (!props.deviceId) return; | 93 | if (!props.deviceId) return; |
94 | + if (!unref(isShowActionType)) { | ||
95 | + createMessage.warning('当前物模型扩展描述没有填写'); | ||
96 | + return; | ||
97 | + } | ||
98 | + const flag = await validate(); | ||
99 | + if (!flag) return; | ||
88 | const sendValue = ref({}); | 100 | const sendValue = ref({}); |
101 | + //判断tcp类型 标识符是自定义还是ModBus | ||
89 | if (unref(isShowModBUS)) { | 102 | if (unref(isShowModBUS)) { |
90 | - //判断tcp类型 标识符是自定义还是ModBus | ||
91 | const oldValue = getFieldsValue()[unref(formField)]; | 103 | const oldValue = getFieldsValue()[unref(formField)]; |
92 | - const newValue = getArray(SingleToHex(oldValue)); | ||
93 | - | ||
94 | - modBUSForm.value.registerValues = | ||
95 | - unref(modBUSForm).method != '16' ? [newValue[0]] : newValue; | ||
96 | - modBUSForm.value.registerNumber = unref(modBUSForm).method != '16' ? 1 : 2; | 104 | + modBUSForm.value.registerValues = [oldValue]; |
105 | + modBUSForm.value.registerNumber = 1; | ||
106 | + | ||
107 | + if (unref(modBUSForm).method == '16') { | ||
108 | + const newValue = getArray(SingleToHex(oldValue)); | ||
109 | + modBUSForm.value.registerValues = newValue; | ||
110 | + modBUSForm.value.registerNumber = 2; | ||
111 | + modBUSForm.value.method = '10'; | ||
112 | + } | ||
97 | 113 | ||
98 | sendValue.value = await genModbusCommand(unref(modBUSForm)); | 114 | sendValue.value = await genModbusCommand(unref(modBUSForm)); |
99 | } else { | 115 | } else { |