Commit 168791ada39167267dd3b52b5bdd5efb786fc5d5

Authored by ww
1 parent 54d6888a

fix: 设备列表根据设备传输协议不同,命令下发方式区分

... ... @@ -179,6 +179,11 @@ export interface DeviceRecord {
179 179 profileId: string;
180 180 alias?: string;
181 181 brand?: string;
  182 + deviceProfile: {
  183 + default: boolean;
  184 + name: string;
  185 + transportType: string;
  186 + };
182 187 }
183 188
184 189 export interface DeviceModelOfMatterAttrs {
... ...
... ... @@ -714,62 +714,67 @@ export const TokenSchemas: FormSchema[] = [
714 714 },
715 715 ];
716 716
717   -export const CommandSchemas: FormSchema[] = [
718   - {
719   - field: 'commandType',
720   - component: 'RadioGroup',
721   - label: '下发类型',
722   - colProps: {
723   - span: 8,
724   - },
725   - defaultValue: 'OneWay',
726   - componentProps: {
727   - options: [
728   - {
729   - label: '单向',
730   - value: 'OneWay',
731   - },
732   - {
733   - label: '双向',
734   - value: 'TwoWay',
735   - },
736   - ],
737   - },
738   - },
739   - {
740   - field: 'valueType',
741   - label: '命令类型',
742   - component: 'RadioGroup',
743   - defaultValue: 'json',
744   - componentProps: () => {
745   - return {
  717 +export const CommandSchemas = (transportType: TransportTypeEnum): FormSchema[] => {
  718 + return [
  719 + {
  720 + field: 'commandType',
  721 + component: 'RadioGroup',
  722 + label: '下发类型',
  723 + colProps: {
  724 + span: 8,
  725 + },
  726 + defaultValue: 'OneWay',
  727 + componentProps: {
746 728 options: [
747   - { label: 'JSON', value: 'json' },
748   - { label: '字符串', value: 'string' },
  729 + {
  730 + label: '单向',
  731 + value: 'OneWay',
  732 + },
  733 + {
  734 + label: '双向',
  735 + value: 'TwoWay',
  736 + },
749 737 ],
750   - };
  738 + },
751 739 },
752   - },
753   - {
754   - field: 'commandText',
755   - label: '请输入命令内容',
756   - ifShow: ({ model }) => {
757   - return model['valueType'] === 'string';
  740 + {
  741 + field: 'valueType',
  742 + label: '命令类型',
  743 + component: 'RadioGroup',
  744 + defaultValue: transportType === TransportTypeEnum.TCP ? 'string' : 'json',
  745 + componentProps: () => {
  746 + const options: Record<'label' | 'value', string>[] = [];
  747 + if (transportType === TransportTypeEnum.TCP) {
  748 + options.push({ label: '字符串', value: 'string' });
  749 + } else {
  750 + options.push({ label: 'JSON', value: 'json' });
  751 + }
  752 + return {
  753 + options,
  754 + };
  755 + },
758 756 },
759   - component: 'InputTextArea',
760   - componentProps: {
761   - autosize: {
762   - minRows: 6,
  757 + {
  758 + field: 'commandText',
  759 + label: '请输入命令内容',
  760 + ifShow: ({ model }) => {
  761 + return model['valueType'] === 'string';
  762 + },
  763 + component: 'InputTextArea',
  764 + componentProps: {
  765 + autosize: {
  766 + minRows: 6,
  767 + },
763 768 },
764 769 },
765   - },
766   - {
767   - field: 'commandValue',
768   - label: '请输入命令内容',
769   - slot: 'commandSlot',
770   - component: 'InputTextArea',
771   - show: ({ model }) => {
772   - return model['valueType'] === 'json';
  770 + {
  771 + field: 'commandValue',
  772 + label: '请输入命令内容',
  773 + slot: 'commandSlot',
  774 + component: 'InputTextArea',
  775 + show: ({ model }) => {
  776 + return model['valueType'] === 'json';
  777 + },
773 778 },
774   - },
775   -];
  779 + ];
  780 +};
... ...
... ... @@ -30,6 +30,8 @@
30 30 import 'jsoneditor/dist/jsoneditor.min.css';
31 31 import { QuestionCircleOutlined } from '@ant-design/icons-vue';
32 32 import { Tooltip } from 'ant-design-vue';
  33 + import { DeviceRecord } from '/@/api/device/model/deviceModel';
  34 + import { TransportTypeEnum } from '../../../profiles/components/TransportDescript/const';
33 35
34 36 interface CommandParams {
35 37 additionalInfo: Recordable;
... ... @@ -43,7 +45,7 @@
43 45 components: { BasicForm, Button, QuestionCircleOutlined, Tooltip },
44 46 props: {
45 47 deviceDetail: {
46   - type: Object,
  48 + type: Object as PropType<DeviceRecord>,
47 49 required: true,
48 50 },
49 51 },
... ... @@ -52,9 +54,12 @@
52 54 const { createMessage } = useMessage();
53 55 const jsonData = ref<CommandParams>({} as unknown as CommandParams);
54 56 const disable = ref(false);
  57 +
55 58 const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({
56 59 labelWidth: 100,
57   - schemas: CommandSchemas,
  60 + schemas: CommandSchemas(
  61 + props.deviceDetail.deviceProfile.transportType as TransportTypeEnum
  62 + ),
58 63 labelAlign: 'right',
59 64 showSubmitButton: false,
60 65 showResetButton: false,
... ...