Commit c4ef059ccd95b9685e2a2b88991d85a20a1cf305

Authored by ww
1 parent 1281e6e8

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

@@ -13,6 +13,8 @@ import { queryDeviceProfileBy } from '/@/api/device/deviceManager'; @@ -13,6 +13,8 @@ import { queryDeviceProfileBy } from '/@/api/device/deviceManager';
13 import { getModelServices } from '/@/api/device/modelOfMatter'; 13 import { getModelServices } from '/@/api/device/modelOfMatter';
14 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; 14 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
15 import useCommonFun from '../hooks/useCommonFun'; 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 const { useByProductGetAttribute } = useCommonFun(); 19 const { useByProductGetAttribute } = useCommonFun();
18 export type TOption = { 20 export type TOption = {
@@ -443,6 +445,12 @@ export const actionSchema: FormSchema[] = [ @@ -443,6 +445,12 @@ export const actionSchema: FormSchema[] = [
443 ifShow: ({ values }) => isDeviceOut(values.outTarget), 445 ifShow: ({ values }) => isDeviceOut(values.outTarget),
444 }, 446 },
445 { 447 {
  448 + field: 'transportType',
  449 + label: '',
  450 + component: 'Input',
  451 + show: false,
  452 + },
  453 + {
446 field: 'deviceProfileId', 454 field: 'deviceProfileId',
447 label: '', 455 label: '',
448 component: 'ApiSelect', 456 component: 'ApiSelect',
@@ -459,8 +467,28 @@ export const actionSchema: FormSchema[] = [ @@ -459,8 +467,28 @@ export const actionSchema: FormSchema[] = [
459 labelField: 'name', 467 labelField: 'name',
460 valueField: 'id', 468 valueField: 'id',
461 getPopupContainer: () => document.body, 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,7 +156,7 @@ export const genActionData = (actionData) => {
156 clearRule, 156 clearRule,
157 } 157 }
158 : { 158 : {
159 - ...doContext, 159 + params: doContext,
160 alarmLevel: outTarget === 'MSG_NOTIFY' ? alarm_level : undefined, 160 alarmLevel: outTarget === 'MSG_NOTIFY' ? alarm_level : undefined,
161 }, 161 },
162 }, 162 },
@@ -39,8 +39,15 @@ @@ -39,8 +39,15 @@
39 </template> 39 </template>
40 </a-select> 40 </a-select>
41 </template> 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 <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> 51 <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div>
45 <a-button style="margin: -5px 0" type="text" @click="handlePremitter">格式化</a-button> 52 <a-button style="margin: -5px 0" type="text" @click="handlePremitter">格式化</a-button>
46 <Tooltip 53 <Tooltip
@@ -88,11 +95,13 @@ @@ -88,11 +95,13 @@
88 <script lang="ts"> 95 <script lang="ts">
89 import { defineComponent } from 'vue'; 96 import { defineComponent } from 'vue';
90 import { isNumber } from '/@/utils/is'; 97 import { isNumber } from '/@/utils/is';
  98 + import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const';
91 export default defineComponent({ 99 export default defineComponent({
92 components: { 100 components: {
93 VNodes: (_, { attrs }) => { 101 VNodes: (_, { attrs }) => {
94 return attrs.vnodes; 102 return attrs.vnodes;
95 }, 103 },
  104 + Input,
96 }, 105 },
97 inheritAttrs: false, 106 inheritAttrs: false,
98 }); 107 });
@@ -101,7 +110,7 @@ @@ -101,7 +110,7 @@
101 import { ref, onMounted, nextTick, unref, computed, provide } from 'vue'; 110 import { ref, onMounted, nextTick, unref, computed, provide } from 'vue';
102 import { CollapseContainer } from '/@/components/Container/index'; 111 import { CollapseContainer } from '/@/components/Container/index';
103 import { BasicForm, useForm } from '/@/components/Form/index'; 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 import { Icon } from '/@/components/Icon'; 114 import { Icon } from '/@/components/Icon';
106 import { actionSchema, CommandTypeEnum } from '../config/config.data'; 115 import { actionSchema, CommandTypeEnum } from '../config/config.data';
107 import jsoneditor from 'jsoneditor'; 116 import jsoneditor from 'jsoneditor';
@@ -260,13 +269,14 @@ @@ -260,13 +269,14 @@
260 //ft-add-2022-11-22 269 //ft-add-2022-11-22
261 //TODO-fengtao-设备验证 270 //TODO-fengtao-设备验证
262 const value = getFieldsValue(); 271 const value = getFieldsValue();
  272 + const isTCPTransportType = value.transportType === TransportTypeEnum.TCP;
263 const doContext = unref(jsonInstance)?.get() || {}; 273 const doContext = unref(jsonInstance)?.get() || {};
264 const serviceInputValue = Reflect.get(value, 'serviceInputValue'); 274 const serviceInputValue = Reflect.get(value, 'serviceInputValue');
265 275
266 return { 276 return {
267 ...value, 277 ...value,
268 ...(Number(value.commandType) === CommandTypeEnum.CUSTOM 278 ...(Number(value.commandType) === CommandTypeEnum.CUSTOM
269 - ? { doContext } 279 + ? { doContext: isTCPTransportType ? value.doContext : doContext }
270 : { doContext: serviceInputValue }), 280 : { doContext: serviceInputValue }),
271 clearRule, 281 clearRule,
272 }; 282 };
@@ -280,7 +290,9 @@ @@ -280,7 +290,9 @@
280 ...(isNumber(fieldsValue.commandType) 290 ...(isNumber(fieldsValue.commandType)
281 ? { commandType: String(fieldsValue.commandType) } 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 //ft-add 298 //ft-add