1
|
|
-import { FormSchema, useComponentRegister } from '/@/components/Form';
|
|
1
|
+import { FormProps, FormSchema, useComponentRegister } from '/@/components/Form';
|
2
|
2
|
import { findDictItemByCode } from '/@/api/system/dict';
|
3
|
3
|
import { deviceProfile, getGatewayDevice } from '/@/api/device/deviceManager';
|
4
|
4
|
import { TransportTypeEnum } from '../../profiles/components/TransportDescript/const';
|
5
|
5
|
import { JSONEditorValidator } from '/@/components/CodeEditor/src/JSONEditor';
|
6
|
6
|
import { JSONEditor } from '/@/components/CodeEditor';
|
7
|
7
|
import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
|
|
8
|
+import { getModelServices } from '/@/api/device/modelOfMatter';
|
|
9
|
+import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
|
|
10
|
+import { toRaw, unref } from 'vue';
|
|
11
|
+import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/components/ObjectModelValidateForm/ObjectModelValidateForm.vue';
|
|
12
|
+import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum';
|
8
|
13
|
useComponentRegister('JSONEditor', JSONEditor);
|
|
14
|
+useComponentRegister('ObjectModelValidateForm', ObjectModelValidateForm);
|
9
|
15
|
|
10
|
16
|
export enum TypeEnum {
|
11
|
17
|
IS_GATEWAY = 'GATEWAY',
|
...
|
...
|
@@ -711,37 +717,87 @@ export const TokenSchemas: FormSchema[] = [ |
711
|
717
|
},
|
712
|
718
|
];
|
713
|
719
|
|
714
|
|
-export const CommandSchemas = (transportType: TransportTypeEnum): FormSchema[] => {
|
|
720
|
+export enum ValueType {
|
|
721
|
+ JSON = 'json',
|
|
722
|
+ STRING = 'string',
|
|
723
|
+}
|
|
724
|
+
|
|
725
|
+export enum CommandFieldsEnum {
|
|
726
|
+ COMMAND_TYPE = 'commandType',
|
|
727
|
+ VALUE_TYPE = 'valueType',
|
|
728
|
+ COMMAND_TEXT = 'commandText',
|
|
729
|
+ COMAND_VALUE = 'commandValue',
|
|
730
|
+ SERVICE = 'service',
|
|
731
|
+ SERVICE_TYPE = 'service_type',
|
|
732
|
+ TCP_SERVICE = 'tcpService',
|
|
733
|
+ MODEL_INPUT = 'modelInput',
|
|
734
|
+ CUSTOM_TYPE = 'customType',
|
|
735
|
+}
|
|
736
|
+
|
|
737
|
+export enum CommandType {
|
|
738
|
+ CUSTOM = 'custom',
|
|
739
|
+ SERVICE = 'service',
|
|
740
|
+}
|
|
741
|
+
|
|
742
|
+export const CommandSchemas = (
|
|
743
|
+ transportType: TransportTypeEnum,
|
|
744
|
+ deviceProfileId: string
|
|
745
|
+): FormSchema[] => {
|
715
|
746
|
return [
|
716
|
747
|
{
|
717
|
|
- field: 'commandType',
|
|
748
|
+ field: CommandFieldsEnum.COMMAND_TYPE,
|
718
|
749
|
component: 'RadioGroup',
|
719
|
750
|
label: '下发类型',
|
720
|
|
- defaultValue: 'OneWay',
|
|
751
|
+ defaultValue: CommandType.CUSTOM,
|
|
752
|
+ componentProps: ({ formActionType }) => {
|
|
753
|
+ const { setFieldsValue } = formActionType;
|
|
754
|
+ return {
|
|
755
|
+ options: [
|
|
756
|
+ { label: '自定义', value: CommandType.CUSTOM },
|
|
757
|
+ { label: '服务', value: CommandType.SERVICE },
|
|
758
|
+ ],
|
|
759
|
+ onChange() {
|
|
760
|
+ setFieldsValue({
|
|
761
|
+ [CommandFieldsEnum.SERVICE]: null,
|
|
762
|
+ [CommandFieldsEnum.MODEL_INPUT]: null,
|
|
763
|
+ [CommandFieldsEnum.COMAND_VALUE]: null,
|
|
764
|
+ [CommandFieldsEnum.COMMAND_TEXT]: null,
|
|
765
|
+ });
|
|
766
|
+ },
|
|
767
|
+ };
|
|
768
|
+ },
|
|
769
|
+ },
|
|
770
|
+ {
|
|
771
|
+ field: CommandFieldsEnum.CUSTOM_TYPE,
|
|
772
|
+ component: 'RadioGroup',
|
|
773
|
+ label: '单向/双向',
|
|
774
|
+ defaultValue: CommandDeliveryWayEnum.ONE_WAY,
|
|
775
|
+ ifShow: ({ model }) => model[CommandFieldsEnum.COMMAND_TYPE] === CommandType.CUSTOM,
|
721
|
776
|
componentProps: {
|
722
|
777
|
options: [
|
723
|
778
|
{
|
724
|
779
|
label: '单向',
|
725
|
|
- value: 'OneWay',
|
|
780
|
+ value: CommandDeliveryWayEnum.ONE_WAY,
|
726
|
781
|
},
|
727
|
782
|
{
|
728
|
783
|
label: '双向',
|
729
|
|
- value: 'TwoWay',
|
|
784
|
+ value: CommandDeliveryWayEnum.TWO_WAY,
|
730
|
785
|
},
|
731
|
786
|
],
|
732
|
787
|
},
|
733
|
788
|
},
|
734
|
789
|
{
|
735
|
|
- field: 'valueType',
|
|
790
|
+ field: CommandFieldsEnum.VALUE_TYPE,
|
736
|
791
|
label: '命令类型',
|
737
|
792
|
component: 'RadioGroup',
|
738
|
|
- defaultValue: transportType === TransportTypeEnum.TCP ? 'string' : 'json',
|
|
793
|
+ ifShow: ({ model }) => model[CommandFieldsEnum.COMMAND_TYPE] === CommandType.CUSTOM,
|
|
794
|
+ defaultValue: transportType === TransportTypeEnum.TCP ? ValueType.STRING : ValueType.JSON,
|
739
|
795
|
componentProps: () => {
|
740
|
796
|
const options: Record<'label' | 'value', string>[] = [];
|
741
|
797
|
if (transportType === TransportTypeEnum.TCP) {
|
742
|
|
- options.push({ label: '字符串', value: 'string' });
|
|
798
|
+ options.push({ label: '字符串', value: ValueType.STRING });
|
743
|
799
|
} else {
|
744
|
|
- options.push({ label: 'JSON', value: 'json' });
|
|
800
|
+ options.push({ label: 'JSON', value: ValueType.JSON });
|
745
|
801
|
}
|
746
|
802
|
return {
|
747
|
803
|
options,
|
...
|
...
|
@@ -749,18 +805,18 @@ export const CommandSchemas = (transportType: TransportTypeEnum): FormSchema[] = |
749
|
805
|
},
|
750
|
806
|
},
|
751
|
807
|
{
|
752
|
|
- field: 'commandText',
|
753
|
|
- label: '请输入命令内容',
|
754
|
|
- ifShow: ({ model }) => {
|
755
|
|
- return model['valueType'] === 'string';
|
756
|
|
- },
|
|
808
|
+ field: CommandFieldsEnum.COMMAND_TEXT,
|
|
809
|
+ label: '命令',
|
|
810
|
+ ifShow: ({ model }) =>
|
|
811
|
+ model[CommandFieldsEnum.VALUE_TYPE] === ValueType.STRING &&
|
|
812
|
+ model[CommandFieldsEnum.COMMAND_TYPE] === CommandType.CUSTOM,
|
757
|
813
|
component: 'InputTextArea',
|
758
|
814
|
componentProps: {
|
759
|
815
|
autoSize: {
|
760
|
|
- minRows: 6,
|
|
816
|
+ minRows: 3,
|
761
|
817
|
},
|
|
818
|
+ placeholder: '请输入命令内容',
|
762
|
819
|
},
|
763
|
|
- colProps: { span: 20 },
|
764
|
820
|
dynamicRules: () => {
|
765
|
821
|
return [
|
766
|
822
|
{
|
...
|
...
|
@@ -778,19 +834,97 @@ export const CommandSchemas = (transportType: TransportTypeEnum): FormSchema[] = |
778
|
834
|
},
|
779
|
835
|
},
|
780
|
836
|
{
|
781
|
|
- field: 'commandValue',
|
782
|
|
- label: '请输入命令内容',
|
|
837
|
+ field: CommandFieldsEnum.COMAND_VALUE,
|
|
838
|
+ label: '命令',
|
783
|
839
|
component: 'JSONEditor',
|
784
|
840
|
colProps: { span: 20 },
|
785
|
841
|
changeEvent: 'update:value',
|
786
|
842
|
valueField: 'value',
|
787
|
843
|
rules: [...JSONEditorValidator()],
|
788
|
|
- ifShow: ({ model }) => {
|
789
|
|
- return model['valueType'] === 'json';
|
790
|
|
- },
|
|
844
|
+ ifShow: ({ model }) =>
|
|
845
|
+ model[CommandFieldsEnum.VALUE_TYPE] === ValueType.JSON &&
|
|
846
|
+ model[CommandFieldsEnum.COMMAND_TYPE] === CommandType.CUSTOM,
|
|
847
|
+
|
791
|
848
|
componentProps: {
|
792
|
849
|
height: 250,
|
793
|
850
|
},
|
794
|
851
|
},
|
|
852
|
+ {
|
|
853
|
+ field: CommandFieldsEnum.SERVICE,
|
|
854
|
+ label: '服务',
|
|
855
|
+ component: 'ApiSelect',
|
|
856
|
+ ifShow: ({ model }) => model[CommandFieldsEnum.COMMAND_TYPE] !== CommandType.CUSTOM,
|
|
857
|
+ rules: [{ required: true, message: '请选择服务' }],
|
|
858
|
+ componentProps: ({ formActionType }) => {
|
|
859
|
+ const { setFieldsValue, updateSchema } = formActionType;
|
|
860
|
+ return {
|
|
861
|
+ api: async () => {
|
|
862
|
+ try {
|
|
863
|
+ const result = await getModelServices({ deviceProfileId });
|
|
864
|
+ return result || [];
|
|
865
|
+ } catch (error) {
|
|
866
|
+ console.error(error);
|
|
867
|
+ return [];
|
|
868
|
+ }
|
|
869
|
+ },
|
|
870
|
+ valueField: 'id',
|
|
871
|
+ labelField: 'functionName',
|
|
872
|
+ getPopupContainer: () => document.body,
|
|
873
|
+ onChange(value: string, options: ModelOfMatterParams) {
|
|
874
|
+ if (!value) return;
|
|
875
|
+
|
|
876
|
+ const setValues = {
|
|
877
|
+ [CommandFieldsEnum.CUSTOM_TYPE]:
|
|
878
|
+ options.callType === ServiceCallTypeEnum.ASYNC
|
|
879
|
+ ? CommandDeliveryWayEnum.TWO_WAY
|
|
880
|
+ : CommandDeliveryWayEnum.ONE_WAY,
|
|
881
|
+ [CommandFieldsEnum.MODEL_INPUT]: null,
|
|
882
|
+ };
|
|
883
|
+
|
|
884
|
+ if (transportType !== TransportTypeEnum.TCP) {
|
|
885
|
+ updateSchema({
|
|
886
|
+ field: CommandFieldsEnum.MODEL_INPUT,
|
|
887
|
+ componentProps: {
|
|
888
|
+ inputData: toRaw(unref(options.functionJson.inputData)),
|
|
889
|
+ },
|
|
890
|
+ });
|
|
891
|
+ } else {
|
|
892
|
+ Object.assign(setValues, {
|
|
893
|
+ [CommandFieldsEnum.TCP_SERVICE]:
|
|
894
|
+ options.functionJson?.inputData?.[0]?.serviceCommand,
|
|
895
|
+ });
|
|
896
|
+ }
|
|
897
|
+
|
|
898
|
+ setFieldsValue(setValues);
|
|
899
|
+ },
|
|
900
|
+ };
|
|
901
|
+ },
|
|
902
|
+ },
|
|
903
|
+ {
|
|
904
|
+ field: CommandFieldsEnum.TCP_SERVICE,
|
|
905
|
+ component: 'Input',
|
|
906
|
+ label: '命令',
|
|
907
|
+ dynamicDisabled: true,
|
|
908
|
+ ifShow: ({ model }) =>
|
|
909
|
+ model[CommandFieldsEnum.SERVICE] &&
|
|
910
|
+ transportType === TransportTypeEnum.TCP &&
|
|
911
|
+ model[CommandFieldsEnum.COMMAND_TYPE] !== CommandType.CUSTOM,
|
|
912
|
+ },
|
|
913
|
+ {
|
|
914
|
+ field: CommandFieldsEnum.MODEL_INPUT,
|
|
915
|
+ component: 'ObjectModelValidateForm',
|
|
916
|
+ label: '输入参数',
|
|
917
|
+ changeEvent: 'update:value',
|
|
918
|
+ valueField: 'value',
|
|
919
|
+ ifShow: ({ model }) =>
|
|
920
|
+ model[CommandFieldsEnum.SERVICE] &&
|
|
921
|
+ transportType !== TransportTypeEnum.TCP &&
|
|
922
|
+ model[CommandFieldsEnum.COMMAND_TYPE] !== CommandType.CUSTOM,
|
|
923
|
+ componentProps: {
|
|
924
|
+ formProps: {
|
|
925
|
+ wrapperCol: { span: 24 },
|
|
926
|
+ } as FormProps,
|
|
927
|
+ },
|
|
928
|
+ },
|
795
|
929
|
];
|
796
|
930
|
}; |
...
|
...
|
|