Showing
13 changed files
with
439 additions
and
153 deletions
src/views/task/center/components/ControlGroup/componentMap.ts
deleted
100644 → 0
1 | -import { Component } from 'vue'; | |
2 | -import { ComponentType } from './type'; | |
3 | - | |
4 | -const componentMap = new Map<ComponentType, Component>(); | |
5 | - | |
6 | -export function add(compName: ComponentType, component: Component) { | |
7 | - componentMap.set(compName, component); | |
8 | -} | |
9 | - | |
10 | -export function del(compName: ComponentType) { | |
11 | - componentMap.delete(compName); | |
12 | -} | |
13 | - | |
14 | -export { componentMap }; |
src/views/task/center/components/ControlGroup/help.ts
deleted
100644 → 0
1 | -import type { ComponentType } from './type'; | |
2 | -import { tryOnUnmounted } from '@vueuse/core'; | |
3 | -import { add, del } from './componentMap'; | |
4 | -import type { Component } from 'vue'; | |
5 | - | |
6 | -export function useComponentRegister(compName: ComponentType, comp: Component) { | |
7 | - add(compName, comp); | |
8 | - tryOnUnmounted(() => { | |
9 | - del(compName); | |
10 | - }); | |
11 | -} |
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { BasicForm, FormSchema, useForm } from '/@/components/Form'; |
3 | 3 | import { ComponentType, ColEx } from '/@/components/Form/src/types/index'; |
4 | + import { computed } from '@vue/reactivity'; | |
5 | + import { isFunction } from '/@/utils/is'; | |
6 | + import { unref } from 'vue'; | |
7 | + import { watch } from 'vue'; | |
8 | + import { nextTick } from 'vue'; | |
9 | + import { ref } from 'vue'; | |
10 | + import { onMounted } from 'vue'; | |
4 | 11 | |
5 | - withDefaults( | |
12 | + interface ValueItemType { | |
13 | + value: any; | |
14 | + } | |
15 | + | |
16 | + enum FormFieldsEnum { | |
17 | + TOTAL_CONTROL = 'totalControl', | |
18 | + } | |
19 | + | |
20 | + enum EmitEventEnum { | |
21 | + UPDATE_VALUE = 'update:value', | |
22 | + } | |
23 | + | |
24 | + const emit = defineEmits<{ | |
25 | + (event: EmitEventEnum.UPDATE_VALUE, value: ValueItemType[]): void; | |
26 | + }>(); | |
27 | + | |
28 | + const props = withDefaults( | |
6 | 29 | defineProps<{ |
30 | + value: ValueItemType[]; | |
31 | + length?: number; | |
7 | 32 | component?: ComponentType; |
8 | 33 | itemColProps?: Partial<ColEx>; |
34 | + itemLabel?: (index: number) => string; | |
35 | + itemProps?: (index: number) => FormSchema; | |
36 | + showTotalControl?: boolean; | |
37 | + totalControlProps?: FormSchema; | |
9 | 38 | }>(), |
10 | 39 | { |
40 | + value: () => [], | |
41 | + length: 0, | |
11 | 42 | component: 'Switch', |
43 | + itemLabel: (index: number) => `#${index}`, | |
44 | + itemProps: () => ({} as unknown as FormSchema), | |
12 | 45 | itemColProps: () => ({ span: 12 } as Partial<ColEx>), |
46 | + showTotalControl: true, | |
47 | + totalControlProps: () => ({} as unknown as FormSchema), | |
13 | 48 | } |
14 | 49 | ); |
15 | 50 | |
16 | - const [registerForm, {}] = useForm({ | |
51 | + const getProps = computed(() => { | |
52 | + return props; | |
53 | + }); | |
54 | + | |
55 | + const batchSetValue = (value: any): ValueItemType[] => { | |
56 | + const { length } = unref(getProps); | |
57 | + return Array.from({ length }, () => ({ value })); | |
58 | + }; | |
59 | + | |
60 | + const getTotalControlItem = computed(() => { | |
61 | + const { totalControlProps, component, showTotalControl } = unref(getProps); | |
62 | + return { | |
63 | + ...totalControlProps, | |
64 | + field: FormFieldsEnum.TOTAL_CONTROL, | |
65 | + component, | |
66 | + ifShow: showTotalControl, | |
67 | + componentProps: { | |
68 | + onChange(value: any) { | |
69 | + handleUpdateValue(batchSetValue(value)); | |
70 | + }, | |
71 | + }, | |
72 | + } as FormSchema; | |
73 | + }); | |
74 | + | |
75 | + const getSchemas = computed(() => { | |
76 | + const { itemProps, itemLabel, length, component } = unref(getProps); | |
77 | + let label = isFunction(itemLabel) ? itemLabel : (index: number) => `#${index}`; | |
78 | + let _itemProps = isFunction(itemProps) ? itemProps : () => ({}); | |
79 | + const schemas = Array.from( | |
80 | + { length }, | |
81 | + (_item, index) => | |
82 | + ({ | |
83 | + ..._itemProps(index), | |
84 | + label: label(index), | |
85 | + field: index.toString(), | |
86 | + component, | |
87 | + componentProps: { | |
88 | + onChange: async () => { | |
89 | + await nextTick(); | |
90 | + handleUpdateValue(); | |
91 | + }, | |
92 | + }, | |
93 | + } as FormSchema) | |
94 | + ); | |
95 | + | |
96 | + length && schemas.unshift(unref(getTotalControlItem)); | |
97 | + | |
98 | + return schemas; | |
99 | + }); | |
100 | + | |
101 | + const [registerForm, { getFieldsValue, setProps, setFieldsValue }] = useForm({ | |
17 | 102 | showActionButtonGroup: false, |
18 | - schemas: Array.from({ length: 3 }).map((_item, index) => { | |
19 | - return { | |
20 | - field: index.toString(), | |
21 | - label: index.toString(), | |
22 | - component: 'Switch', | |
23 | - } as FormSchema; | |
24 | - }), | |
103 | + schemas: unref(getSchemas), | |
25 | 104 | // baseColProps, |
105 | + baseColProps: props.itemColProps, | |
106 | + }); | |
107 | + | |
108 | + const handleUpdateValue = (value?: ValueItemType[]) => { | |
109 | + if (value) { | |
110 | + emit(EmitEventEnum.UPDATE_VALUE, value); | |
111 | + return; | |
112 | + } | |
113 | + const allValue = getFieldsValue(); | |
114 | + const sortKeyList = Array.from({ length: unref(getProps).length }, (_v, key) => key); | |
115 | + const res = sortKeyList.map((item) => ({ value: allValue[item] } as ValueItemType)); | |
116 | + | |
117 | + emit(EmitEventEnum.UPDATE_VALUE, res); | |
118 | + }; | |
119 | + | |
120 | + const transformValue = (value: ValueItemType[]) => { | |
121 | + const { length } = unref(getProps); | |
122 | + if (value.length !== length) { | |
123 | + value = Array.from( | |
124 | + { length: unref(getProps).length }, | |
125 | + () => ({ value: null } as ValueItemType) | |
126 | + ); | |
127 | + } | |
128 | + return value.reduce((prev, next, index) => ({ ...prev, [index]: next.value }), {}); | |
129 | + }; | |
130 | + | |
131 | + const initialized = ref(false); | |
132 | + | |
133 | + watch( | |
134 | + () => props.value, | |
135 | + async (target) => { | |
136 | + if (target) { | |
137 | + let flag = unref(initialized); | |
138 | + if (!flag) { | |
139 | + await nextTick(); | |
140 | + } | |
141 | + const value = transformValue(target); | |
142 | + setFieldsValue(value); | |
143 | + | |
144 | + if (!flag) { | |
145 | + handleUpdateValue(); | |
146 | + } | |
147 | + } | |
148 | + }, | |
149 | + { | |
150 | + immediate: true, | |
151 | + } | |
152 | + ); | |
153 | + | |
154 | + watch( | |
155 | + () => [props.length, props.component], | |
156 | + (target) => { | |
157 | + if (target !== undefined || target !== null) { | |
158 | + setProps({ | |
159 | + schemas: unref(getSchemas), | |
160 | + }); | |
161 | + handleUpdateValue(); | |
162 | + } | |
163 | + } | |
164 | + ); | |
165 | + | |
166 | + onMounted(() => { | |
167 | + initialized.value = true; | |
26 | 168 | }); |
27 | 169 | </script> |
28 | 170 | |
29 | 171 | <template> |
30 | - <BasicForm @register="registerForm" /> | |
172 | + <BasicForm class="control-group-form" @register="registerForm" /> | |
31 | 173 | </template> |
174 | + | |
175 | +<style lang="less" scoped> | |
176 | + .control-group-form { | |
177 | + :deep(.ant-form-item-label) { | |
178 | + font-weight: 700; | |
179 | + } | |
180 | + } | |
181 | +</style> | ... | ... |
src/views/task/center/components/ControlGroup/type.ts
deleted
100644 → 0
1 | -export type ComponentType = ''; |
src/views/task/center/components/CustomInput/config.ts
deleted
100644 → 0
1 | -import { findDictItemByCode } from '/@/api/system/dict'; | |
2 | -import { FormSchema, useComponentRegister } from '/@/components/Form'; | |
3 | -import { DictEnum } from '/@/enums/dictEnum'; | |
4 | -import RegisterAddressInput from './RegisterAddressInput.vue'; | |
5 | -import { createPickerSearch } from '/@/utils/pickerSearch'; | |
6 | -import { ControlGroup } from '../ControlGroup'; | |
7 | - | |
8 | -export enum FormFieldsEnum { | |
9 | - ADDRESS = 'address', | |
10 | - FUNCTION_CODE = 'functionCode', | |
11 | - START_REGISTER_ADDRESS = 'startRegisterAddress', | |
12 | - REGISTER_NUMBER = 'registerNumber', | |
13 | - DATA_VALID = 'dataValid', | |
14 | -} | |
15 | - | |
16 | -useComponentRegister('RegisterAddressInput', RegisterAddressInput); | |
17 | -useComponentRegister('ControlGroup', ControlGroup); | |
18 | - | |
19 | -export const formSchemas: FormSchema[] = [ | |
20 | - { | |
21 | - field: FormFieldsEnum.ADDRESS, | |
22 | - component: 'ApiSelect', | |
23 | - label: '从机地址', | |
24 | - componentProps: () => { | |
25 | - return { | |
26 | - api: async (params: Recordable) => { | |
27 | - try { | |
28 | - const result = await findDictItemByCode(params); | |
29 | - return result.map((item, index) => ({ | |
30 | - ...item, | |
31 | - itemText: `${index + 1} - ${item.itemText}`, | |
32 | - })); | |
33 | - } catch (error) { | |
34 | - return []; | |
35 | - } | |
36 | - }, | |
37 | - params: { | |
38 | - dictCode: DictEnum.SLAVE_ADDRESS, | |
39 | - }, | |
40 | - labelField: 'itemText', | |
41 | - valueField: 'itemValue', | |
42 | - ...createPickerSearch(), | |
43 | - getPopupContainer: () => document.body, | |
44 | - }; | |
45 | - }, | |
46 | - }, | |
47 | - { | |
48 | - field: FormFieldsEnum.FUNCTION_CODE, | |
49 | - component: 'ApiSelect', | |
50 | - label: '功能码', | |
51 | - componentProps: () => { | |
52 | - return { | |
53 | - api: findDictItemByCode, | |
54 | - params: { | |
55 | - dictCode: DictEnum.FUNCTION_CODE, | |
56 | - }, | |
57 | - labelField: 'itemText', | |
58 | - valueField: 'itemValue', | |
59 | - getPopupContainer: () => document.body, | |
60 | - }; | |
61 | - }, | |
62 | - }, | |
63 | - { | |
64 | - field: FormFieldsEnum.START_REGISTER_ADDRESS, | |
65 | - label: '起始寄存器地址', | |
66 | - component: 'RegisterAddressInput', | |
67 | - valueField: 'value', | |
68 | - changeEvent: 'update:value', | |
69 | - }, | |
70 | - { | |
71 | - field: FormFieldsEnum.REGISTER_NUMBER, | |
72 | - label: '寄存器个数', | |
73 | - component: 'InputNumber', | |
74 | - componentProps: { | |
75 | - min: 1, | |
76 | - max: 64, | |
77 | - step: 1, | |
78 | - }, | |
79 | - }, | |
80 | - { | |
81 | - field: FormFieldsEnum.DATA_VALID, | |
82 | - label: '数据校验', | |
83 | - component: 'ApiSelect', | |
84 | - colProps: { span: 24 }, | |
85 | - componentProps: () => { | |
86 | - return { | |
87 | - api: findDictItemByCode, | |
88 | - params: { | |
89 | - dictCode: DictEnum.DATA_VALIDATE, | |
90 | - }, | |
91 | - labelField: 'itemText', | |
92 | - valueField: 'itemValue', | |
93 | - getPopupContainer: () => document.body, | |
94 | - }; | |
95 | - }, | |
96 | - }, | |
97 | - // { | |
98 | - // field: 'test', | |
99 | - // label: '住', | |
100 | - // component: 'ControlGroup', | |
101 | - // }, | |
102 | -]; |
... | ... | @@ -6,7 +6,7 @@ import { |
6 | 6 | validateDevicePicker, |
7 | 7 | FormFieldsEnum as DeviceCascadePickerFieldsEnum, |
8 | 8 | } from '../DevicePicker'; |
9 | -import { CustomInput, ModeEnum } from '../CustomInput'; | |
9 | +import { PollCommandInput, ModeEnum } from '../PollCommandInput'; | |
10 | 10 | import { DeviceProfileModel } from '/@/api/device/model/deviceModel'; |
11 | 11 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
12 | 12 | import { getDeviceProfile } from '/@/api/alarm/position'; |
... | ... | @@ -15,7 +15,7 @@ import { TimeUnitEnum, TimeUnitNameEnum } from '/@/enums/toolEnum'; |
15 | 15 | import { createPickerSearch } from '/@/utils/pickerSearch'; |
16 | 16 | |
17 | 17 | useComponentRegister('DevicePicker', DevicePicker); |
18 | -useComponentRegister('CustomInput', CustomInput); | |
18 | +useComponentRegister('PollCommandInput', PollCommandInput); | |
19 | 19 | |
20 | 20 | export enum FormFieldsEnum { |
21 | 21 | // 任务名称 |
... | ... | @@ -208,7 +208,7 @@ export const formSchemas: FormSchema[] = [ |
208 | 208 | }, |
209 | 209 | { |
210 | 210 | field: FormFieldsEnum.RPC_COMMAND, |
211 | - component: 'CustomInput', | |
211 | + component: 'PollCommandInput', | |
212 | 212 | label: '自定义数据流', |
213 | 213 | rules: [{ required: true, message: '请输入自定义数据流' }], |
214 | 214 | dynamicRules: ({ model }) => |
... | ... | @@ -228,7 +228,7 @@ export const formSchemas: FormSchema[] = [ |
228 | 228 | }, |
229 | 229 | { |
230 | 230 | field: FormFieldsEnum.RPC_COMMAND, |
231 | - component: 'CustomInput', | |
231 | + component: 'PollCommandInput', | |
232 | 232 | label: 'ModbusRTU轮询', |
233 | 233 | rules: [{ required: true, message: '请输入Modbus RTU 轮询指令' }], |
234 | 234 | ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_CONTENT_TYPE] === TaskTypeEnum.MODBUS_RTU, | ... | ... |
src/views/task/center/components/PollCommandInput/CreateTCPCommandModal.vue
renamed from
src/views/task/center/components/CustomInput/CreateTCPCommandModal.vue
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | |
11 | 11 | const [registerModal] = useModal(); |
12 | 12 | |
13 | - const [registerForm, {}] = useForm({ | |
13 | + const [registerForm, { getFieldsValue }] = useForm({ | |
14 | 14 | schemas: formSchemas, |
15 | 15 | showActionButtonGroup: false, |
16 | 16 | rowProps: { gutter: 10 }, |
... | ... | @@ -19,7 +19,10 @@ |
19 | 19 | |
20 | 20 | const commandValue = ref(''); |
21 | 21 | |
22 | - const handleGetValue = async () => {}; | |
22 | + const handleGetValue = async () => { | |
23 | + const value = getFieldsValue(); | |
24 | + console.log(value); | |
25 | + }; | |
23 | 26 | |
24 | 27 | const handleOk = () => { |
25 | 28 | emit('update:value', unref(commandValue)); | ... | ... |
src/views/task/center/components/PollCommandInput/RegisterAddressInput.vue
renamed from
src/views/task/center/components/CustomInput/RegisterAddressInput.vue
... | ... | @@ -14,9 +14,16 @@ |
14 | 14 | |
15 | 15 | const DEC_MAX_VALUE = parseInt('0xffff', 16); |
16 | 16 | |
17 | - const props = defineProps<{ | |
18 | - value?: string; | |
19 | - }>(); | |
17 | + const props = withDefaults( | |
18 | + defineProps<{ | |
19 | + value?: string; | |
20 | + inputProps?: Recordable; | |
21 | + }>(), | |
22 | + { | |
23 | + value: '0', | |
24 | + inputProps: () => ({}), | |
25 | + } | |
26 | + ); | |
20 | 27 | |
21 | 28 | const addressTypeOptions = [ |
22 | 29 | { label: AddressTypeEnum.DEC, value: AddressTypeEnum.DEC }, |
... | ... | @@ -52,7 +59,6 @@ |
52 | 59 | () => props.value, |
53 | 60 | (targetValue) => { |
54 | 61 | inputValue.value = targetValue || 0; |
55 | - console.log(`inputValue: ${unref(inputValue)}`); | |
56 | 62 | } |
57 | 63 | ); |
58 | 64 | </script> |
... | ... | @@ -63,7 +69,7 @@ |
63 | 69 | v-model:value="type" |
64 | 70 | :options="addressTypeOptions" |
65 | 71 | @change="handleChange" |
66 | - class="bg-gray-200" | |
72 | + class="bg-gray-200 max-w-20" | |
67 | 73 | /> |
68 | 74 | <InputNumber |
69 | 75 | v-if="type === AddressTypeEnum.DEC" |
... | ... | @@ -71,6 +77,7 @@ |
71 | 77 | :step="1" |
72 | 78 | class="flex-1" |
73 | 79 | @change="handleEmit" |
80 | + v-bind="inputProps" | |
74 | 81 | /> |
75 | 82 | <Input v-if="type === AddressTypeEnum.HEX" v-model:value="inputValue" /> |
76 | 83 | <div class="text-center h-8 leading-8 px-2 bg-gray-200 cursor-pointer rounded-1 w-20"> | ... | ... |
1 | +import { findDictItemByCode } from '/@/api/system/dict'; | |
2 | +import { FormSchema, useComponentRegister } from '/@/components/Form'; | |
3 | +import { DictEnum } from '/@/enums/dictEnum'; | |
4 | +import RegisterAddressInput from './RegisterAddressInput.vue'; | |
5 | +import { createPickerSearch } from '/@/utils/pickerSearch'; | |
6 | +import { ControlGroup } from '../ControlGroup'; | |
7 | + | |
8 | +export enum FormFieldsEnum { | |
9 | + ADDRESS = 'address', | |
10 | + FUNCTION_CODE = 'functionCode', | |
11 | + START_REGISTER_ADDRESS = 'startRegisterAddress', | |
12 | + DATA_VALID = 'dataValid', | |
13 | + // 线圈个数 | |
14 | + COIL_NUMBER = 'coilNumber', | |
15 | + // 寄存器个数 | |
16 | + REGISTER_NUMBER = 'registerNumber', | |
17 | + // 线圈值 | |
18 | + COIL_VALUE = 'coilValue', | |
19 | + // 寄存器值 | |
20 | + REGISTER_VALUE = 'registerValue', | |
21 | + // 线圈组值 | |
22 | + COIL_VALUES = 'coilValues', | |
23 | + // 寄存器组值 | |
24 | + REGISTER_VALUES = 'registerValues', | |
25 | +} | |
26 | + | |
27 | +useComponentRegister('RegisterAddressInput', RegisterAddressInput); | |
28 | +useComponentRegister('ControlGroup', ControlGroup); | |
29 | + | |
30 | +enum FunctionCodeEnum { | |
31 | + // 读取线圈状态01 | |
32 | + READ_COIL_STATE_01 = '01', | |
33 | + // 读取输入状态02 | |
34 | + READ_INPUT_STATE_02 = '02', | |
35 | + // 读取保持寄存器 | |
36 | + READ_KEEP_REGISTER_03 = '03', | |
37 | + // 读取输入寄存器 | |
38 | + READ_INPUT_REGISTER_04 = '04', | |
39 | + // 写入耽搁线圈寄存器 | |
40 | + WRITE_SINGLE_COIL_REGISTER_05 = '05', | |
41 | + // 写入单个保持寄存器 | |
42 | + WRITE_SINGLE_KEEP_COIL_REGISTER_06 = '06', | |
43 | + // 写入多个线圈状态 | |
44 | + WRITE_MULTIPLE_COIL_STATE_15 = '15', | |
45 | + // 写入多个保持寄存器 | |
46 | + WRITE_MULTIPLE_KEEP_REGISTER_16 = '16', | |
47 | +} | |
48 | + | |
49 | +const showCoilNumber = (value: FunctionCodeEnum) => | |
50 | + [ | |
51 | + FunctionCodeEnum.READ_COIL_STATE_01, | |
52 | + FunctionCodeEnum.READ_INPUT_STATE_02, | |
53 | + FunctionCodeEnum.WRITE_MULTIPLE_COIL_STATE_15, | |
54 | + ].includes(value); | |
55 | + | |
56 | +const showRegisterNumber = (value: FunctionCodeEnum) => | |
57 | + [ | |
58 | + FunctionCodeEnum.READ_KEEP_REGISTER_03, | |
59 | + FunctionCodeEnum.READ_INPUT_REGISTER_04, | |
60 | + FunctionCodeEnum.WRITE_MULTIPLE_KEEP_REGISTER_16, | |
61 | + ].includes(value); | |
62 | + | |
63 | +const showCoilValue = (value: FunctionCodeEnum) => | |
64 | + [FunctionCodeEnum.WRITE_SINGLE_COIL_REGISTER_05].includes(value); | |
65 | + | |
66 | +const showRegisterValue = (value: FunctionCodeEnum) => | |
67 | + [FunctionCodeEnum.WRITE_SINGLE_KEEP_COIL_REGISTER_06].includes(value); | |
68 | + | |
69 | +const isWriteCoilGroup = (value: FunctionCodeEnum) => | |
70 | + [FunctionCodeEnum.WRITE_MULTIPLE_COIL_STATE_15].includes(value); | |
71 | + | |
72 | +const isWriteRegisterGroup = (value: FunctionCodeEnum) => | |
73 | + [FunctionCodeEnum.WRITE_MULTIPLE_KEEP_REGISTER_16].includes(value); | |
74 | + | |
75 | +export const formSchemas: FormSchema[] = [ | |
76 | + { | |
77 | + field: FormFieldsEnum.ADDRESS, | |
78 | + component: 'ApiSelect', | |
79 | + label: '从机地址', | |
80 | + rules: [{ required: true, message: '请选择从机地址' }], | |
81 | + defaultValue: '01', | |
82 | + componentProps: () => { | |
83 | + return { | |
84 | + api: async (params: Recordable) => { | |
85 | + try { | |
86 | + const result = await findDictItemByCode(params); | |
87 | + return result.map((item, index) => ({ | |
88 | + ...item, | |
89 | + itemText: `${index + 1} - ${item.itemText}`, | |
90 | + })); | |
91 | + } catch (error) { | |
92 | + return []; | |
93 | + } | |
94 | + }, | |
95 | + params: { | |
96 | + dictCode: DictEnum.SLAVE_ADDRESS, | |
97 | + }, | |
98 | + labelField: 'itemText', | |
99 | + valueField: 'itemValue', | |
100 | + ...createPickerSearch(), | |
101 | + getPopupContainer: () => document.body, | |
102 | + }; | |
103 | + }, | |
104 | + }, | |
105 | + { | |
106 | + field: FormFieldsEnum.FUNCTION_CODE, | |
107 | + component: 'ApiSelect', | |
108 | + label: '功能码', | |
109 | + defaultValue: '01', | |
110 | + rules: [{ required: true, message: '请选择功能码' }], | |
111 | + componentProps: () => { | |
112 | + return { | |
113 | + api: findDictItemByCode, | |
114 | + params: { | |
115 | + dictCode: DictEnum.FUNCTION_CODE, | |
116 | + }, | |
117 | + labelField: 'itemText', | |
118 | + valueField: 'itemValue', | |
119 | + getPopupContainer: () => document.body, | |
120 | + }; | |
121 | + }, | |
122 | + }, | |
123 | + { | |
124 | + field: FormFieldsEnum.START_REGISTER_ADDRESS, | |
125 | + label: '起始寄存器地址', | |
126 | + component: 'RegisterAddressInput', | |
127 | + valueField: 'value', | |
128 | + changeEvent: 'update:value', | |
129 | + defaultValue: '0', | |
130 | + }, | |
131 | + { | |
132 | + field: FormFieldsEnum.REGISTER_NUMBER, | |
133 | + label: '寄存器个数', | |
134 | + component: 'InputNumber', | |
135 | + ifShow: ({ model }) => showRegisterNumber(model[FormFieldsEnum.FUNCTION_CODE]), | |
136 | + defaultValue: 1, | |
137 | + rules: [{ required: true, message: '请输入寄存器个数' }], | |
138 | + componentProps: { | |
139 | + min: 1, | |
140 | + max: 64, | |
141 | + step: 1, | |
142 | + placeholder: '请输入寄存器个数', | |
143 | + }, | |
144 | + }, | |
145 | + { | |
146 | + field: FormFieldsEnum.COIL_NUMBER, | |
147 | + label: '线圈个数', | |
148 | + component: 'InputNumber', | |
149 | + ifShow: ({ model }) => showCoilNumber(model[FormFieldsEnum.FUNCTION_CODE]), | |
150 | + defaultValue: 1, | |
151 | + rules: [{ required: true, message: '请输入线圈个数' }], | |
152 | + componentProps: { | |
153 | + min: 1, | |
154 | + max: 64, | |
155 | + step: 1, | |
156 | + placeholder: '请输入线圈个数', | |
157 | + }, | |
158 | + }, | |
159 | + { | |
160 | + field: FormFieldsEnum.COIL_VALUE, | |
161 | + label: '线圈值', | |
162 | + component: 'RegisterAddressInput', | |
163 | + valueField: 'value', | |
164 | + changeEvent: 'update:value', | |
165 | + ifShow: ({ model }) => showCoilValue(model[FormFieldsEnum.FUNCTION_CODE]), | |
166 | + defaultValue: '0', | |
167 | + rules: [{ required: true, message: '请输入线圈值' }], | |
168 | + componentProps: { | |
169 | + placeholder: '请输入线圈值', | |
170 | + }, | |
171 | + }, | |
172 | + { | |
173 | + field: FormFieldsEnum.REGISTER_VALUE, | |
174 | + label: '寄存器值', | |
175 | + component: 'RegisterAddressInput', | |
176 | + valueField: 'value', | |
177 | + changeEvent: 'update:value', | |
178 | + ifShow: ({ model }) => showRegisterValue(model[FormFieldsEnum.FUNCTION_CODE]), | |
179 | + defaultValue: '0', | |
180 | + rules: [{ required: true, message: '请输入寄存器值' }], | |
181 | + componentProps: { | |
182 | + placeholder: '请输入寄存器值', | |
183 | + }, | |
184 | + }, | |
185 | + { | |
186 | + field: FormFieldsEnum.REGISTER_VALUES, | |
187 | + label: '', | |
188 | + component: 'ControlGroup', | |
189 | + colProps: { span: 24 }, | |
190 | + valueField: 'value', | |
191 | + changeEvent: 'update:value', | |
192 | + ifShow: ({ model }) => isWriteRegisterGroup(model[FormFieldsEnum.FUNCTION_CODE]), | |
193 | + componentProps: ({ formModel }) => { | |
194 | + const length = formModel[FormFieldsEnum.REGISTER_NUMBER]; | |
195 | + return { | |
196 | + length: length || 1, | |
197 | + itemColProps: { span: 12, style: { paddingRight: '10px' } }, | |
198 | + component: 'RegisterAddressInput', | |
199 | + itemLabel: (index: number) => `#${index} 寄存器值`, | |
200 | + showTotalControl: false, | |
201 | + itemProps: () => { | |
202 | + return { | |
203 | + defaultValue: '0', | |
204 | + } as FormSchema; | |
205 | + }, | |
206 | + }; | |
207 | + }, | |
208 | + }, | |
209 | + { | |
210 | + field: FormFieldsEnum.COIL_VALUES, | |
211 | + label: '', | |
212 | + component: 'ControlGroup', | |
213 | + colProps: { span: 24 }, | |
214 | + valueField: 'value', | |
215 | + changeEvent: 'update:value', | |
216 | + ifShow: ({ model }) => isWriteCoilGroup(model[FormFieldsEnum.FUNCTION_CODE]), | |
217 | + componentProps: ({ formModel }) => { | |
218 | + const length = formModel[FormFieldsEnum.COIL_NUMBER]; | |
219 | + return { | |
220 | + length: length || 1, | |
221 | + itemColProps: { span: 6 }, | |
222 | + itemLabel: (index: number) => `#${index} 线圈状态值`, | |
223 | + itemProps: (index: number) => { | |
224 | + return { | |
225 | + defaultValue: 0, | |
226 | + helpMessage: [`设置从起始地址偏移 ${index} 位的线圈开关量状态。`], | |
227 | + } as FormSchema; | |
228 | + }, | |
229 | + totalControlProps: { | |
230 | + label: '全开或全关', | |
231 | + helpMessage: ['将以下所有线圈的开关量状态全部置为 1 或 0,实现一键全开或全关.'], | |
232 | + colProps: { span: 24 }, | |
233 | + } as FormSchema, | |
234 | + }; | |
235 | + }, | |
236 | + }, | |
237 | + { | |
238 | + field: FormFieldsEnum.DATA_VALID, | |
239 | + label: '数据校验', | |
240 | + component: 'ApiSelect', | |
241 | + colProps: { span: 24 }, | |
242 | + rules: [{ required: true, message: '请选择数据校验方式' }], | |
243 | + componentProps: () => { | |
244 | + return { | |
245 | + api: findDictItemByCode, | |
246 | + params: { | |
247 | + dictCode: DictEnum.DATA_VALIDATE, | |
248 | + }, | |
249 | + labelField: 'itemText', | |
250 | + valueField: 'itemValue', | |
251 | + placeholder: '请选择数据校验方式', | |
252 | + getPopupContainer: () => document.body, | |
253 | + }; | |
254 | + }, | |
255 | + }, | |
256 | +]; | ... | ... |
src/views/task/center/components/PollCommandInput/index.ts
renamed from
src/views/task/center/components/CustomInput/index.ts
src/views/task/center/components/PollCommandInput/index.vue
renamed from
src/views/task/center/components/CustomInput/index.vue