Showing
5 changed files
with
88 additions
and
9 deletions
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | inputData?: StructJSON[]; | 12 | inputData?: StructJSON[]; |
13 | formProps?: FormProps; | 13 | formProps?: FormProps; |
14 | value?: Recordable; | 14 | value?: Recordable; |
15 | + required?: boolean; | ||
15 | }>(), | 16 | }>(), |
16 | { | 17 | { |
17 | inputData: () => [] as StructJSON[], | 18 | inputData: () => [] as StructJSON[], |
@@ -62,6 +63,10 @@ | @@ -62,6 +63,10 @@ | ||
62 | component: 'InputNumber', | 63 | component: 'InputNumber', |
63 | rules: [ | 64 | rules: [ |
64 | { | 65 | { |
66 | + required: props.required, | ||
67 | + message: `${functionName}是必填项`, | ||
68 | + }, | ||
69 | + { | ||
65 | type: 'number', | 70 | type: 'number', |
66 | trigger: 'change', | 71 | trigger: 'change', |
67 | validator: (_rule, value) => { | 72 | validator: (_rule, value) => { |
@@ -100,6 +105,10 @@ | @@ -100,6 +105,10 @@ | ||
100 | component: 'Input', | 105 | component: 'Input', |
101 | rules: [ | 106 | rules: [ |
102 | { | 107 | { |
108 | + required: props.required, | ||
109 | + message: `${functionName}是必填项`, | ||
110 | + }, | ||
111 | + { | ||
103 | type: 'string', | 112 | type: 'string', |
104 | trigger: 'change', | 113 | trigger: 'change', |
105 | validator: (_rule, value) => { | 114 | validator: (_rule, value) => { |
@@ -125,6 +134,12 @@ | @@ -125,6 +134,12 @@ | ||
125 | field: identifier, | 134 | field: identifier, |
126 | label: functionName, | 135 | label: functionName, |
127 | component: 'Select', | 136 | component: 'Select', |
137 | + rules: [ | ||
138 | + { | ||
139 | + required: props.required, | ||
140 | + message: `${functionName}是必填项`, | ||
141 | + }, | ||
142 | + ], | ||
128 | componentProps: { | 143 | componentProps: { |
129 | options: [ | 144 | options: [ |
130 | { label: `${boolClose}-0`, value: 0 }, | 145 | { label: `${boolClose}-0`, value: 0 }, |
@@ -142,6 +157,12 @@ | @@ -142,6 +157,12 @@ | ||
142 | field: identifier, | 157 | field: identifier, |
143 | label: functionName, | 158 | label: functionName, |
144 | component: 'InputTextArea', | 159 | component: 'InputTextArea', |
160 | + rules: [ | ||
161 | + { | ||
162 | + required: props.required, | ||
163 | + message: `${functionName}是必填项`, | ||
164 | + }, | ||
165 | + ], | ||
145 | componentProps: { | 166 | componentProps: { |
146 | onChange: (value: InputEvent) => { | 167 | onChange: (value: InputEvent) => { |
147 | syncValue(identifier, (value.target as HTMLInputElement).value); | 168 | syncValue(identifier, (value.target as HTMLInputElement).value); |
@@ -867,7 +867,7 @@ export const CommandSchemas = ( | @@ -867,7 +867,7 @@ export const CommandSchemas = ( | ||
867 | return []; | 867 | return []; |
868 | } | 868 | } |
869 | }, | 869 | }, |
870 | - valueField: 'id', | 870 | + valueField: 'identifier', |
871 | labelField: 'functionName', | 871 | labelField: 'functionName', |
872 | getPopupContainer: () => document.body, | 872 | getPopupContainer: () => document.body, |
873 | onChange(value: string, options: ModelOfMatterParams) { | 873 | onChange(value: string, options: ModelOfMatterParams) { |
@@ -77,6 +77,9 @@ | @@ -77,6 +77,9 @@ | ||
77 | ? field[CommandFieldsEnum.TCP_SERVICE] | 77 | ? field[CommandFieldsEnum.TCP_SERVICE] |
78 | : field[CommandFieldsEnum.MODEL_INPUT]; | 78 | : field[CommandFieldsEnum.MODEL_INPUT]; |
79 | command.additionalInfo = { cmdType: 1 }; | 79 | command.additionalInfo = { cmdType: 1 }; |
80 | + command.params = { | ||
81 | + [field[CommandFieldsEnum.SERVICE]]: command.params, | ||
82 | + }; | ||
80 | } | 83 | } |
81 | 84 | ||
82 | commandIssuanceApi( | 85 | commandIssuanceApi( |
@@ -17,6 +17,7 @@ import { DeviceProfileModel } from '/@/api/device/model/deviceModel'; | @@ -17,6 +17,7 @@ import { DeviceProfileModel } from '/@/api/device/model/deviceModel'; | ||
17 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | 17 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
18 | import { useComponentRegister } from '/@/components/Form'; | 18 | import { useComponentRegister } from '/@/components/Form'; |
19 | import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect'; | 19 | import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect'; |
20 | +import { isArray } from '/@/utils/is'; | ||
20 | 21 | ||
21 | useComponentRegister('OrgTreeSelect', OrgTreeSelect); | 22 | useComponentRegister('OrgTreeSelect', OrgTreeSelect); |
22 | 23 | ||
@@ -597,7 +598,21 @@ export const actionSchema: FormSchema[] = [ | @@ -597,7 +598,21 @@ export const actionSchema: FormSchema[] = [ | ||
597 | ifShow: ({ values }) => | 598 | ifShow: ({ values }) => |
598 | isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType), | 599 | isDeviceOut(values.outTarget) && isPartOrAll(values.device) && isDefine(values.commandType), |
599 | }, | 600 | }, |
600 | - //新增代码2022-11-23 | 601 | + { |
602 | + field: 'serviceIdentifier', | ||
603 | + label: '', | ||
604 | + component: 'Input', | ||
605 | + show: false, | ||
606 | + }, | ||
607 | + { | ||
608 | + field: 'thingsModelKeys', | ||
609 | + label: '', | ||
610 | + show: false, | ||
611 | + component: 'Select', | ||
612 | + componentProps: { | ||
613 | + mode: 'multiple', | ||
614 | + }, | ||
615 | + }, | ||
601 | { | 616 | { |
602 | field: 'thingsModelId', | 617 | field: 'thingsModelId', |
603 | label: '', | 618 | label: '', |
@@ -626,7 +641,14 @@ export const actionSchema: FormSchema[] = [ | @@ -626,7 +641,14 @@ export const actionSchema: FormSchema[] = [ | ||
626 | inputData: selected?.functionJson.inputData, | 641 | inputData: selected?.functionJson.inputData, |
627 | }, | 642 | }, |
628 | }); | 643 | }); |
629 | - selected && setFieldsValue({ callType: selected.callType }); | 644 | + selected && |
645 | + setFieldsValue({ | ||
646 | + callType: selected.callType, | ||
647 | + serviceIdentifier: selected?.identifier, | ||
648 | + thingsModelKeys: isArray(selected?.functionJson?.inputData) | ||
649 | + ? selected?.functionJson?.inputData.map((item) => item.identifier) | ||
650 | + : [], | ||
651 | + }); | ||
630 | return record; | 652 | return record; |
631 | } catch (error) { | 653 | } catch (error) { |
632 | console.error(error); | 654 | console.error(error); |
@@ -642,7 +664,14 @@ export const actionSchema: FormSchema[] = [ | @@ -642,7 +664,14 @@ export const actionSchema: FormSchema[] = [ | ||
642 | onChange: (_, options: ModelOfMatterParams) => { | 664 | onChange: (_, options: ModelOfMatterParams) => { |
643 | if (options) { | 665 | if (options) { |
644 | // setFieldsValue({ doContext: { ...options.functionJson, callType: options.callType } }); | 666 | // setFieldsValue({ doContext: { ...options.functionJson, callType: options.callType } }); |
645 | - const record = { callType: options.callType }; | 667 | + // if ( ) |
668 | + const record = { | ||
669 | + callType: options.callType, | ||
670 | + serviceIdentifier: options.identifier, | ||
671 | + thingsModelKeys: isArray(options?.functionJson?.inputData) | ||
672 | + ? options?.functionJson?.inputData.map((item) => item.identifier) | ||
673 | + : [], | ||
674 | + }; | ||
646 | transportType === TransportTypeEnum.TCP | 675 | transportType === TransportTypeEnum.TCP |
647 | ? Object.assign(record, { | 676 | ? Object.assign(record, { |
648 | tcpServiceCommand: options.functionJson?.inputData?.[0]?.serviceCommand, | 677 | tcpServiceCommand: options.functionJson?.inputData?.[0]?.serviceCommand, |
@@ -655,6 +684,8 @@ export const actionSchema: FormSchema[] = [ | @@ -655,6 +684,8 @@ export const actionSchema: FormSchema[] = [ | ||
655 | }); | 684 | }); |
656 | 685 | ||
657 | setFieldsValue(record); | 686 | setFieldsValue(record); |
687 | + } else { | ||
688 | + setFieldsValue({ serviceIdentifier: null }); | ||
658 | } | 689 | } |
659 | }, | 690 | }, |
660 | }; | 691 | }; |
@@ -94,7 +94,7 @@ | @@ -94,7 +94,7 @@ | ||
94 | 94 | ||
95 | <script lang="ts"> | 95 | <script lang="ts"> |
96 | import { defineComponent } from 'vue'; | 96 | import { defineComponent } from 'vue'; |
97 | - import { isNumber, isObject, isString } from '/@/utils/is'; | 97 | + import { isNullOrUnDef, isNumber, isObject, isString } from '/@/utils/is'; |
98 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | 98 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
99 | export default defineComponent({ | 99 | export default defineComponent({ |
100 | components: { | 100 | components: { |
@@ -110,7 +110,7 @@ | @@ -110,7 +110,7 @@ | ||
110 | import { ref, onMounted, nextTick, unref, computed, provide } from 'vue'; | 110 | import { ref, onMounted, nextTick, unref, computed, provide } from 'vue'; |
111 | import { CollapseContainer } from '/@/components/Container/index'; | 111 | import { CollapseContainer } from '/@/components/Container/index'; |
112 | import { BasicForm, useForm } from '/@/components/Form/index'; | 112 | import { BasicForm, useForm } from '/@/components/Form/index'; |
113 | - import { Tooltip, Select, Checkbox, Card, Input } from 'ant-design-vue'; | 113 | + import { Tooltip, Select, Checkbox, Card, Input, message } from 'ant-design-vue'; |
114 | import { Icon } from '/@/components/Icon'; | 114 | import { Icon } from '/@/components/Icon'; |
115 | import { actionSchema, CommandTypeEnum } from '../config/config.data'; | 115 | import { actionSchema, CommandTypeEnum } from '../config/config.data'; |
116 | import jsoneditor from 'jsoneditor'; | 116 | import jsoneditor from 'jsoneditor'; |
@@ -272,11 +272,31 @@ | @@ -272,11 +272,31 @@ | ||
272 | const isTCPTransportType = value.transportType === TransportTypeEnum.TCP; | 272 | const isTCPTransportType = value.transportType === TransportTypeEnum.TCP; |
273 | const doContext = unref(jsonInstance)?.get() || {}; | 273 | const doContext = unref(jsonInstance)?.get() || {}; |
274 | const serviceInputValue = Reflect.get(value, 'serviceInputValue'); | 274 | const serviceInputValue = Reflect.get(value, 'serviceInputValue'); |
275 | + | ||
276 | + const getServiceIdentifier = Reflect.get(value, 'serviceIdentifier'); | ||
277 | + | ||
278 | + const isCustomCommand = Number(value.commandType) === CommandTypeEnum.CUSTOM; | ||
279 | + | ||
280 | + const thingsModelKeys = Reflect.get(value, 'thingsModelKeys'); | ||
281 | + | ||
282 | + if (!isCustomCommand) { | ||
283 | + for (const key of thingsModelKeys) { | ||
284 | + if (isNullOrUnDef(serviceInputValue[key]) || '') { | ||
285 | + message.warning('服务命令为必填项'); | ||
286 | + throw ''; | ||
287 | + } | ||
288 | + } | ||
289 | + } | ||
290 | + | ||
275 | return { | 291 | return { |
276 | ...value, | 292 | ...value, |
277 | - ...(Number(value.commandType) === CommandTypeEnum.CUSTOM | 293 | + ...(isCustomCommand |
278 | ? { doContext: isTCPTransportType ? value.doContext : doContext } | 294 | ? { doContext: isTCPTransportType ? value.doContext : doContext } |
279 | - : { doContext: isTCPTransportType ? value.tcpServiceCommand : serviceInputValue }), | 295 | + : { |
296 | + doContext: isTCPTransportType | ||
297 | + ? value.serviceIdentifier | ||
298 | + : { [getServiceIdentifier]: serviceInputValue }, | ||
299 | + }), | ||
280 | clearRule, | 300 | clearRule, |
281 | }; | 301 | }; |
282 | }; | 302 | }; |
@@ -284,6 +304,8 @@ | @@ -284,6 +304,8 @@ | ||
284 | const setFieldsFormValueFun = (fieldsValue) => { | 304 | const setFieldsFormValueFun = (fieldsValue) => { |
285 | const doContext = Reflect.get(fieldsValue, 'doContext'); | 305 | const doContext = Reflect.get(fieldsValue, 'doContext'); |
286 | const commandType = Reflect.get(fieldsValue, 'commandType'); | 306 | const commandType = Reflect.get(fieldsValue, 'commandType'); |
307 | + const getServiceIdentifier = Object.keys(doContext?.params || {})[0]; | ||
308 | + | ||
287 | setFieldsValue({ | 309 | setFieldsValue({ |
288 | ...fieldsValue, | 310 | ...fieldsValue, |
289 | ...(isNumber(fieldsValue.commandType) | 311 | ...(isNumber(fieldsValue.commandType) |
@@ -291,7 +313,9 @@ | @@ -291,7 +313,9 @@ | ||
291 | : {}), | 313 | : {}), |
292 | ...(commandType === CommandTypeEnum.SERVICE | 314 | ...(commandType === CommandTypeEnum.SERVICE |
293 | ? { | 315 | ? { |
294 | - serviceInputValue: isObject(doContext.params) ? doContext.params : {}, | 316 | + serviceInputValue: isObject(doContext.params) |
317 | + ? doContext?.params?.[getServiceIdentifier] || {} | ||
318 | + : {}, | ||
295 | tcpServiceCommand: isString(doContext.params) ? doContext.params : '', | 319 | tcpServiceCommand: isString(doContext.params) ? doContext.params : '', |
296 | } | 320 | } |
297 | : { doContext: doContext.params }), | 321 | : { doContext: doContext.params }), |