Commit 09ae380c5a7afc4bf3e2d3db2746786d8f55538c

Authored by ww
1 parent 44fc42cf

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

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