Commit 6c8c663414182a343191f74b4a167bf751ef7d89

Authored by ww
1 parent bdebc0d0

fix: only gateway subdevice disabled service and events panel on model of matter

... ... @@ -24,16 +24,8 @@
24 24 :size="size"
25 25 >
26 26 <TabPane :key="FunctionType.PROPERTIES" tab="属性" />
27   - <TabPane
28   - :key="FunctionType.SERVICE"
29   - :disabled="$props.record.transportType === 'TCP'"
30   - tab="服务"
31   - />
32   - <TabPane
33   - :key="FunctionType.EVENTS"
34   - tab="事件"
35   - :disabled="$props.record.transportType === 'TCP'"
36   - />
  27 + <TabPane :key="FunctionType.SERVICE" :disabled="isTCPGatewaySubDevice" tab="服务" />
  28 + <TabPane :key="FunctionType.EVENTS" tab="事件" :disabled="isTCPGatewaySubDevice" />
37 29 </Tabs>
38 30 <Attribute v-if="activeKey === FunctionType.PROPERTIES" ref="AttrRef" />
39 31 <Service
... ... @@ -51,7 +43,7 @@
51 43 </div>
52 44 </template>
53 45 <script lang="ts" setup>
54   - import { ref, unref, nextTick } from 'vue';
  46 + import { ref, unref, nextTick, computed } from 'vue';
55 47 import { BasicModal, useModalInner } from '/@/components/Modal';
56 48 import { Tabs, TabPane, Typography, TypographyParagraph } from 'ant-design-vue';
57 49 import Attribute from './cpns/Attribute.vue';
... ... @@ -59,7 +51,7 @@
59 51 import Events from './cpns/Events.vue';
60 52 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
61 53 import { createModel, updateModel } from '/@/api/device/modelOfMatter';
62   - import { DeviceRecord } from '/@/api/device/model/deviceModel';
  54 + import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
63 55 import { useMessage } from '/@/hooks/web/useMessage';
64 56 import { OpenModelMode, OpenModelOfMatterModelParams } from './types/index';
65 57 import { FunctionType } from './cpns/config';
... ... @@ -70,6 +62,12 @@
70 62 record: DeviceRecord;
71 63 }>();
72 64
  65 + const isTCPGatewaySubDevice = computed(() => {
  66 + const { record } = props;
  67 + const { deviceType, transportType } = record;
  68 + return deviceType === DeviceTypeEnum.SENSOR && transportType === 'TCP';
  69 + });
  70 +
73 71 const blockContent = `属性一般是设备的运行状态,如当前温度等;服务是设备可被调用的方法,支持定义参数,如执行某项任务;事件则是设备上报的
74 72 通知,如告警,需要被及时处理。`;
75 73 const activeKey = ref<FunctionType>(FunctionType.PROPERTIES);
... ... @@ -155,6 +153,7 @@
155 153 closeModal();
156 154 emit('success');
157 155 } catch (error) {
  156 + throw Error(error);
158 157 } finally {
159 158 setModalProps({ loading: false, okButtonProps: { loading: false } });
160 159 }
... ...
... ... @@ -28,7 +28,10 @@
28 28 //回显数据
29 29 const setFormData = (record: ModelOfMatterParams) => {
30 30 const { functionJson = {}, functionName, identifier, remark, callType } = record;
31   - const { inputData, outputData, serviceCommand } = functionJson;
  31 + const { inputData = [], outputData } = functionJson;
  32 + const { serviceCommand } =
  33 + (inputData.at(0) as unknown as { serviceCommand: string }) ||
  34 + ({} as { serviceCommand: string });
32 35 const value = {
33 36 functionName,
34 37 identifier,
... ... @@ -48,8 +51,8 @@
48 51 functionName,
49 52 remark,
50 53 identifier,
51   - inputData: _inputData,
52   - outputData: _outputData,
  54 + inputData: _inputData = [],
  55 + outputData: _outputData = [],
53 56 serviceCommand,
54 57 callType,
55 58 } = _values;
... ... @@ -71,7 +74,7 @@
71 74 functionJson: {
72 75 inputData,
73 76 outputData,
74   - serviceCommand,
  77 + ...(serviceCommand ? { inputData: [{ serviceCommand }] } : {}),
75 78 },
76 79 } as ModelOfMatterParams;
77 80
... ...
... ... @@ -113,6 +113,15 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => {
113 113 },
114 114 },
115 115 {
  116 + field: FormField.SERVICE_COMMAND,
  117 + label: '输入参数',
  118 + component: 'Input',
  119 + ifShow: tcpDeviceFlag,
  120 + componentProps: {
  121 + placeholder: '请输入ASCII或HEX服务命令',
  122 + },
  123 + },
  124 + {
116 125 field: FormField.INPUT_PARAM,
117 126 label: '输入参数',
118 127 component: 'StructForm',
... ... @@ -127,19 +136,9 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => {
127 136 component: 'StructForm',
128 137 valueField: 'value',
129 138 changeEvent: 'update:value',
130   - ifShow: !tcpDeviceFlag,
131 139 colProps: { span: 24 },
132 140 },
133 141 {
134   - field: FormField.SERVICE_COMMAND,
135   - label: '服务命令',
136   - component: 'Input',
137   - ifShow: tcpDeviceFlag,
138   - componentProps: {
139   - placeholder: '请输入服务命令',
140   - },
141   - },
142   - {
143 142 field: FormField.REFARK,
144 143 label: '备注',
145 144 component: 'InputTextArea',
... ...