Commit c4ef059ccd95b9685e2a2b88991d85a20a1cf305

Authored by ww
1 parent 1281e6e8

fix: DEFECT-1118 修复场景联动tcp设备下发指令为字符串

... ... @@ -13,6 +13,8 @@ import { queryDeviceProfileBy } from '/@/api/device/deviceManager';
13 13 import { getModelServices } from '/@/api/device/modelOfMatter';
14 14 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
15 15 import useCommonFun from '../hooks/useCommonFun';
  16 +import { DeviceProfileModel } from '/@/api/device/model/deviceModel';
  17 +import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
16 18
17 19 const { useByProductGetAttribute } = useCommonFun();
18 20 export type TOption = {
... ... @@ -443,6 +445,12 @@ export const actionSchema: FormSchema[] = [
443 445 ifShow: ({ values }) => isDeviceOut(values.outTarget),
444 446 },
445 447 {
  448 + field: 'transportType',
  449 + label: '',
  450 + component: 'Input',
  451 + show: false,
  452 + },
  453 + {
446 454 field: 'deviceProfileId',
447 455 label: '',
448 456 component: 'ApiSelect',
... ... @@ -459,8 +467,28 @@ export const actionSchema: FormSchema[] = [
459 467 labelField: 'name',
460 468 valueField: 'id',
461 469 getPopupContainer: () => document.body,
462   - onChange: () => {
463   - setFieldsValue({ thingsModelId: '', deviceId: [] });
  470 + onChange: (_value: string, options = {} as DeviceProfileModel) => {
  471 + const oldType = formModel['transportType'];
  472 +
  473 + const updateFlag =
  474 + oldType === TransportTypeEnum.TCP || options.transportType === TransportTypeEnum.TCP;
  475 +
  476 + setFieldsValue({
  477 + thingsModelId: '',
  478 + deviceId: [],
  479 + transportType: options.transportType,
  480 + ...(updateFlag ? { doContext: null } : {}),
  481 + });
  482 + },
  483 + onOptionsChange(options: DeviceProfileModel[]) {
  484 + const deviceProfileId = formModel['deviceProfileId'];
  485 + if (deviceProfileId) {
  486 + const index = options.findIndex(
  487 + (item) => (item as Recordable).value === deviceProfileId
  488 + );
  489 +
  490 + ~index && setFieldsValue({ transportType: options[index].transportType });
  491 + }
464 492 },
465 493 };
466 494 },
... ...
... ... @@ -156,7 +156,7 @@ export const genActionData = (actionData) => {
156 156 clearRule,
157 157 }
158 158 : {
159   - ...doContext,
  159 + params: doContext,
160 160 alarmLevel: outTarget === 'MSG_NOTIFY' ? alarm_level : undefined,
161 161 },
162 162 },
... ...
... ... @@ -39,8 +39,15 @@
39 39 </template>
40 40 </a-select>
41 41 </template>
42   - <template #doContext>
43   - <div class="flex" style="align-items: center">
  42 + <template #doContext="{ model, field }">
  43 + <div v-if="model['transportType'] === TransportTypeEnum.TCP">
  44 + <Input v-model:value="model[field]" placeholder="请输入自定义命令" />
  45 + </div>
  46 + <div
  47 + v-show="model['transportType'] !== TransportTypeEnum.TCP"
  48 + class="flex"
  49 + style="align-items: center"
  50 + >
44 51 <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div>
45 52 <a-button style="margin: -5px 0" type="text" @click="handlePremitter">格式化</a-button>
46 53 <Tooltip
... ... @@ -88,11 +95,13 @@
88 95 <script lang="ts">
89 96 import { defineComponent } from 'vue';
90 97 import { isNumber } from '/@/utils/is';
  98 + import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
91 99 export default defineComponent({
92 100 components: {
93 101 VNodes: (_, { attrs }) => {
94 102 return attrs.vnodes;
95 103 },
  104 + Input,
96 105 },
97 106 inheritAttrs: false,
98 107 });
... ... @@ -101,7 +110,7 @@
101 110 import { ref, onMounted, nextTick, unref, computed, provide } from 'vue';
102 111 import { CollapseContainer } from '/@/components/Container/index';
103 112 import { BasicForm, useForm } from '/@/components/Form/index';
104   - import { Tooltip, Select, Checkbox, Card } from 'ant-design-vue';
  113 + import { Tooltip, Select, Checkbox, Card, Input } from 'ant-design-vue';
105 114 import { Icon } from '/@/components/Icon';
106 115 import { actionSchema, CommandTypeEnum } from '../config/config.data';
107 116 import jsoneditor from 'jsoneditor';
... ... @@ -260,13 +269,14 @@
260 269 //ft-add-2022-11-22
261 270 //TODO-fengtao-设备验证
262 271 const value = getFieldsValue();
  272 + const isTCPTransportType = value.transportType === TransportTypeEnum.TCP;
263 273 const doContext = unref(jsonInstance)?.get() || {};
264 274 const serviceInputValue = Reflect.get(value, 'serviceInputValue');
265 275
266 276 return {
267 277 ...value,
268 278 ...(Number(value.commandType) === CommandTypeEnum.CUSTOM
269   - ? { doContext }
  279 + ? { doContext: isTCPTransportType ? value.doContext : doContext }
270 280 : { doContext: serviceInputValue }),
271 281 clearRule,
272 282 };
... ... @@ -280,7 +290,9 @@
280 290 ...(isNumber(fieldsValue.commandType)
281 291 ? { commandType: String(fieldsValue.commandType) }
282 292 : {}),
283   - serviceInputValue: commandType === CommandTypeEnum.SERVICE ? doContext.params || {} : {},
  293 + ...(commandType === CommandTypeEnum.SERVICE
  294 + ? { serviceInputValue: doContext.params || {} }
  295 + : { doContext: doContext.params }),
284 296 });
285 297 };
286 298 //ft-add
... ...