Commit e71f783da776d8336da7e554ade4002613cf181f

Authored by ww
1 parent d702b232

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

@@ -111,6 +111,19 @@ export const formSchemas = ({ @@ -111,6 +111,19 @@ export const formSchemas = ({
111 api: async (params: Recordable) => { 111 api: async (params: Recordable) => {
112 try { 112 try {
113 const record = await findDictItemByCode(params); 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 return hasStructForm 127 return hasStructForm
115 ? record.filter((item) => item.itemValue !== DataTypeEnum.STRUCT) 128 ? record.filter((item) => item.itemValue !== DataTypeEnum.STRUCT)
116 : record; 129 : record;
  1 +import { StructJSON } from '/@/api/device/model/modelOfMatterModel';
1 import { FormSchema } from '/@/components/Form'; 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 const InsertString = (t, c, n) => { 6 const InsertString = (t, c, n) => {
4 const r: string | number[] = []; 7 const r: string | number[] = [];
@@ -127,21 +130,33 @@ const SingleToHexBatch = (t) => { @@ -127,21 +130,33 @@ const SingleToHexBatch = (t) => {
127 return r.join('\r\n'); 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 if (actionType == '06') { 150 if (actionType == '06') {
133 return [ 151 return [
134 { 152 {
135 field: identifier, 153 field: identifier,
136 - label: functionName, 154 + label: functionName!,
137 component: 'InputNumber', 155 component: 'InputNumber',
138 rules: [{ required: true, message: '请输入正数' }], 156 rules: [{ required: true, message: '请输入正数' }],
139 componentProps: { 157 componentProps: {
140 min: 0, 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 placeholder: `请输入正数`, 160 placeholder: `请输入正数`,
146 }, 161 },
147 }, 162 },
@@ -150,7 +165,7 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => { @@ -150,7 +165,7 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => {
150 return [ 165 return [
151 { 166 {
152 field: identifier, 167 field: identifier,
153 - label: functionName, 168 + label: functionName!,
154 component: 'InputNumber', 169 component: 'InputNumber',
155 rules: [{ required: true, message: '请输入值' }], 170 rules: [{ required: true, message: '请输入值' }],
156 componentProps: { 171 componentProps: {
@@ -165,13 +180,12 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => { @@ -165,13 +180,12 @@ const formSchemasConfig = (schemas, actionType): FormSchema[] => {
165 return [ 180 return [
166 { 181 {
167 field: identifier, 182 field: identifier,
168 - label: functionName, 183 + label: functionName!,
169 component: 'InputNumber', 184 component: 'InputNumber',
170 rules: [{ required: true, message: '请输入值' }], 185 rules: [{ required: true, message: '请输入值' }],
171 componentProps: { 186 componentProps: {
172 placeholder: `请输入数字`, 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,6 +35,7 @@
35 const zoomFactorValue = ref<number>(1); //缩放因子 35 const zoomFactorValue = ref<number>(1); //缩放因子
36 const isShowMultiply = ref<Boolean>(false); // 只有tcp --> int和double类型才相乘缩放因子 36 const isShowMultiply = ref<Boolean>(false); // 只有tcp --> int和double类型才相乘缩放因子
37 const deviceTransportType = ref<string>(); 37 const deviceTransportType = ref<string>();
  38 + const objectDataType = ref<DataTypeEnum>();
38 39
39 const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => { 40 const [register] = useModalInner(async (params: ModalParamsType<DeviceModelOfMatterAttrs>) => {
40 const { record } = params; 41 const { record } = params;
@@ -48,6 +49,7 @@ @@ -48,6 +49,7 @@
48 zoomFactorValue.value = zoomFactor ? Number(zoomFactor) : 1; 49 zoomFactorValue.value = zoomFactor ? Number(zoomFactor) : 1;
49 isShowMultiply.value = type == 'INT' || type == 'DOUBLE' ? true : false; 50 isShowMultiply.value = type == 'INT' || type == 'DOUBLE' ? true : false;
50 deviceTransportType.value = transportType; 51 deviceTransportType.value = transportType;
  52 + objectDataType.value = type;
51 53
52 let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON]; 54 let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON];
53 55
@@ -136,7 +138,12 @@ @@ -136,7 +138,12 @@
136 138
137 const sendValue = ref({}); 139 const sendValue = ref({});
138 //判断tcp类型 标识符是自定义还是ModBus 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 if (!unref(isShowActionType)) { 147 if (!unref(isShowActionType)) {
141 createMessage.warning('当前物模型扩展描述没有填写'); 148 createMessage.warning('当前物模型扩展描述没有填写');
142 return; 149 return;