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