Commit 09ae380c5a7afc4bf3e2d3db2746786d8f55538c

Authored by ww
1 parent 44fc42cf

fix: 修复任务中心创建任务表单校验问题

... ... @@ -133,6 +133,7 @@
133 133 } = props.schema;
134 134
135 135 if (isFunction(dynamicRules)) {
  136 + console.log(dynamicRules(unref(getValues)));
136 137 return dynamicRules(unref(getValues)) as ValidationRule[];
137 138 }
138 139
... ...
1 1 import { TaskTargetEnum, TaskTargetNameEnum, TaskTypeEnum, TaskTypeNameEnum } from '../../config';
2 2 import { findDictItemByCode } from '/@/api/system/dict';
3   -import { FormSchema, useComponentRegister } from '/@/components/Form';
  3 +import { FormSchema, Rule, useComponentRegister } from '/@/components/Form';
4 4 import {
5 5 DevicePicker,
6 6 validateDevicePicker,
... ... @@ -211,14 +211,18 @@ export const formSchemas: FormSchema[] = [
211 211 field: FormFieldsEnum.RPC_COMMAND,
212 212 component: 'PollCommandInput',
213 213 label: '自定义数据流',
214   - rules: [{ required: true, message: '请输入自定义数据流' }],
215   - dynamicRules: ({ model }) =>
216   - model[FormFieldsEnum.PUSH_WAY] === PushWayEnum.MQTT ? JSONEditorValidator() : [],
  214 + dynamicRules: ({ model }) => {
  215 + const rules: Rule[] = [{ required: true, message: '请输入自定义数据流' }];
  216 + return model[FormFieldsEnum.PUSH_WAY] === PushWayEnum.MQTT
  217 + ? [...rules, ...JSONEditorValidator()]
  218 + : rules;
  219 + },
217 220 ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_CONTENT_TYPE] === TaskTypeEnum.CUSTOM,
218 221 valueField: 'value',
219 222 changeEvent: 'update:value',
220   - componentProps: ({ formModel }) => {
  223 + componentProps: ({ formModel, formActionType }) => {
221 224 const pushMode = Reflect.get(formModel, FormFieldsEnum.PUSH_WAY);
  225 + formActionType?.clearValidate(FormFieldsEnum.RPC_COMMAND);
222 226 return {
223 227 inputProps: {
224 228 placeholder: '请输入自定义数据流',
... ... @@ -232,7 +236,9 @@ export const formSchemas: FormSchema[] = [
232 236 component: 'PollCommandInput',
233 237 label: 'ModbusRTU轮询',
234 238 rules: [{ required: true, message: '请输入Modbus RTU 轮询指令' }],
235   - ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_CONTENT_TYPE] === TaskTypeEnum.MODBUS_RTU,
  239 + ifShow: ({ model }) =>
  240 + model[FormFieldsEnum.EXECUTE_CONTENT_TYPE] === TaskTypeEnum.MODBUS_RTU &&
  241 + model[FormFieldsEnum.PUSH_WAY] === PushWayEnum.TCP,
236 242 valueField: 'value',
237 243 changeEvent: 'update:value',
238 244 componentProps: () => {
... ... @@ -345,6 +351,7 @@ export const formSchemas: FormSchema[] = [
345 351 field: FormFieldsEnum.EXECUTE_TIME_INTERVAL,
346 352 label: '间隔时间',
347 353 component: 'InputNumber',
  354 + rules: [{ required: true, message: '请输入间隔时间', type: 'number' }],
348 355 ifShow: ({ model }) => model[FormFieldsEnum.EXECUTE_TIME_TYPE] === ExecuteTimeTypeEnum.POLL,
349 356 componentProps: ({ formModel }) => {
350 357 const unit = formModel[FormFieldsEnum.POLL_UNIT];
... ...