Commit 49f38d3ef0d2925ed07e94304adcd06382ec7dd5

Authored by xp.Huang
2 parents 444d7d51 ed6c8d17

Merge branch 'fix/attribute-distribution' into 'main_dev'

fix: 修改物模型属性下发

See merge request yunteng/thingskit-front!782
... ... @@ -17,7 +17,7 @@
17 17 defineEmits(['register']);
18 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 21 schemas: [],
22 22 showActionButtonGroup: false,
23 23 layout: 'vertical',
... ... @@ -28,7 +28,8 @@
28 28 const keys = ref<string[]>([]);
29 29
30 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 33 const formField = ref('');
33 34
34 35 const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => {
... ... @@ -45,6 +46,14 @@
45 46 if (type === DataTypeEnum.IS_STRUCT) {
46 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 57 if (codeType == TaskTypeEnum.MODBUS) {
49 58 isShowModBUS.value = true;
50 59 modBUSForm.value = {
... ... @@ -59,9 +68,6 @@
59 68 } else {
60 69 isShowModBUS.value = false;
61 70 const formSchemas = genForm(schemas);
62   - keys.value = schemas.map((item) => {
63   - return item.identifier!;
64   - });
65 71 setProps({ schemas: formSchemas });
66 72 }
67 73
... ... @@ -85,15 +91,25 @@
85 91 try {
86 92 loading.value = true;
87 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 100 const sendValue = ref({});
  101 + //判断tcp类型 标识符是自定义还是ModBus
89 102 if (unref(isShowModBUS)) {
90   - //判断tcp类型 标识符是自定义还是ModBus
91 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 114 sendValue.value = await genModbusCommand(unref(modBUSForm));
99 115 } else {
... ...