wupengfei
2025-04-11 29f11797c036e8b7f66ba0337b1aaa005eb508e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { EditorType } from '@/constants';
import _ from 'lodash';
 
export class FormValidator {
  /**
   * 验证表单input-number 不为0
   */
  static validatorNumberNotNull(rule: any, value: any, callback: any) {
    // eslint-disable-next-line eqeqeq
    if (!value) {
      return callback(new Error(rule.message));
    }
    callback();
  }
 
  static validatorRichEditor(rule: any, value: API.IntroInfo[], callback: any) {
    // eslint-disable-next-line eqeqeq
    const textEditorItem = value.filter((x) => x.type === EditorType.Text);
    if (textEditorItem.some((x) => !x.content)) {
      return callback(new Error(rule.message));
    }
    callback();
  }
  static validatorWeMap(rule: any, value: WeMapModel, callback: any) {
    // eslint-disable-next-line eqeqeq
    if (_.isEmpty(value) || Object.values(value).some((x) => !x)) {
      return callback(new Error(rule.message));
    }
    callback();
  }
}
 
export async function validateFormList(refs: any) {
  try {
    const validateList = Object.values(refs).map((x) => {
      const ref = x as any;
      if (Array.isArray(ref)) {
        return ref[0].validate();
      }
      return ref.validate();
    });
 
    let res = await Promise.allSettled(validateList);
    return res.every((x) => x.status === 'fulfilled');
  } catch (error) {}
}