修改校验逻辑

点击查看代码
const invalidRows = selectedRows
  .map(row => {
    const invalidFields = requiredFields
      .map(field => {
        const value = row[field.key];

        if (!value) {
          return `${field.label}(未填写)`;
        }

        if (field.key === 'dataOwner' && typeof value === 'string') {
          const trimmed = value.trim();
          if (/[,;;、]/.test(trimmed)) {
            return `${field.label}(只能选择一位,对接人过多)`;
          }
          const atCount = (trimmed.match(/@/g) || []).length;
          if (atCount > 1) {
            return `${field.label}(只能选择一位,对接人过多)`;
          }
        }

        return null;
      })
      .filter(Boolean);

    return invalidFields.length > 0 ? { row, invalidFields } : null;
  })
  .filter(Boolean);

组装提示
if (invalidRows.length > 0) {
  const errorMsg = invalidRows
    .map(item => {
      const { row, invalidFields } = item;
      return `台帐编号:${row.taskId} 的以下字段有问题: ${invalidFields.join('、')}`;
    })
    .join('\n\n');

  Modal.error({
    title: '存在未填写或格式错误的字段',
    content: <div style={{ maxHeight: 400, overflow: 'auto', whiteSpace: 'pre-line' }}>{errorMsg}</div>,
  });
  return reject(new Error('存在未填写或格式错误的字段'));
}
posted @ 2025-12-15 23:58  牛久安  阅读(0)  评论(0)    收藏  举报