Commit e71f783da776d8336da7e554ade4002613cf181f

Authored by ww
1 parent d702b232

perf: tcp产品创建物模型时,只可创建布尔、浮点、整型、字符串结构的物模型

... ... @@ -111,6 +111,19 @@ export const formSchemas = ({
111 111 api: async (params: Recordable) => {
112 112 try {
113 113 const record = await findDictItemByCode(params);
  114 +
  115 + if (isTcp) {
  116 + // TCP 产品 属性可创建范围
  117 + return record.filter((item) =>
  118 + [
  119 + DataTypeEnum.BOOL,
  120 + DataTypeEnum.NUMBER_DOUBLE,
  121 + DataTypeEnum.NUMBER_INT,
  122 + DataTypeEnum.STRING,
  123 + ].includes(item.itemValue as DataTypeEnum)
  124 + );
  125 + }
  126 +
114 127 return hasStructForm
115 128 ? record.filter((item) => item.itemValue !== DataTypeEnum.STRUCT)
116 129 : record;
... ...
  1 +import { StructJSON } from '/@/api/device/model/modelOfMatterModel';
1 2 import { FormSchema } from '/@/components/Form';
  3 +import { validateTCPCustomCommand } from '/@/components/Form/src/externalCompns/components/ThingsModelForm';
  4 +import { DataTypeEnum } from '/@/enums/objectModelEnum';
2 5
3 6 const InsertString = (t, c, n) => {
4 7 const r: string | number[] = [];
... ... @@ -127,21 +130,33 @@ const SingleToHexBatch = (t) => {
127 130 return r.join('\r\n');
128 131 };
129 132
130   -const formSchemasConfig = (schemas, actionType): FormSchema[] => {
131   - const { identifier, functionName } = schemas;
  133 +const formSchemasConfig = (schemas: StructJSON, actionType: string): FormSchema[] => {
  134 + const { identifier, functionName, dataType } = schemas;
  135 +
  136 + if (dataType?.type === DataTypeEnum.STRING) {
  137 + return [
  138 + {
  139 + field: identifier,
  140 + label: functionName!,
  141 + component: 'Input',
  142 + rules: [{ required: true, validator: validateTCPCustomCommand }],
  143 + componentProps: {
  144 + placeholder: `请输入${functionName}`,
  145 + },
  146 + },
  147 + ];
  148 + }
  149 +
132 150 if (actionType == '06') {
133 151 return [
134 152 {
135 153 field: identifier,
136   - label: functionName,
  154 + label: functionName!,
137 155 component: 'InputNumber',
138 156 rules: [{ required: true, message: '请输入正数' }],
139 157 componentProps: {
140 158 min: 0,
141   - formatter: (e) => {
142   - const value = `${e}`.replace('-', '').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
143   - return value;
144   - },
  159 + precision: 2,
145 160 placeholder: `请输入正数`,
146 161 },
147 162 },
... ... @@ -150,7 +165,7 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => {
150 165 return [
151 166 {
152 167 field: identifier,
153   - label: functionName,
  168 + label: functionName!,
154 169 component: 'InputNumber',
155 170 rules: [{ required: true, message: '请输入值' }],
156 171 componentProps: {
... ... @@ -165,13 +180,12 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => {
165 180 return [
166 181 {
167 182 field: identifier,
168   - label: functionName,
  183 + label: functionName!,
169 184 component: 'InputNumber',
170 185 rules: [{ required: true, message: '请输入值' }],
171 186 componentProps: {
172 187 placeholder: `请输入数字`,
173   - formatter: (e) =>
174   - `${e}`.replace(/\B(?=(\d{3})+(?!\d))/g, '').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3'),
  188 + precision: 2,
175 189 },
176 190 },
177 191 ];
... ...
... ... @@ -35,6 +35,7 @@
35 35 const zoomFactorValue = ref<number>(1); //缩放因子
36 36 const isShowMultiply = ref<Boolean>(false); // 只有tcp --> int和double类型才相乘缩放因子
37 37 const deviceTransportType = ref<string>();
  38 + const objectDataType = ref<DataTypeEnum>();
38 39
39 40 const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => {
40 41 const { record } = params;
... ... @@ -48,6 +49,7 @@
48 49 zoomFactorValue.value = zoomFactor ? Number(zoomFactor) : 1;
49 50 isShowMultiply.value = type == 'INT' || type == 'DOUBLE' ? true : false;
50 51 deviceTransportType.value = transportType;
  52 + objectDataType.value = type;
51 53
52 54 let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON];
53 55
... ... @@ -136,7 +138,12 @@
136 138
137 139 const sendValue = ref({});
138 140 //判断tcp类型 标识符是自定义还是ModBus
139   - if (unref(isShowModBUS)) {
  141 + if (unref(objectDataType) === DataTypeEnum.STRING) {
  142 + const flag = await validate();
  143 + if (!flag) return;
  144 + const value = getFieldsValue()[unref(formField)];
  145 + sendValue.value = value;
  146 + } else if (unref(isShowModBUS)) {
140 147 if (!unref(isShowActionType)) {
141 148 createMessage.warning('当前物模型扩展描述没有填写');
142 149 return;
... ...