kindring преди 1 година
родител
ревизия
4aff52744e
променени са 4 файла, в които са добавени 63 реда и са изтрити 20 реда
  1. 1 1
      src/fieldCheck.ts
  2. 2 2
      src/formVerify.ts
  3. 28 10
      src/types/fieldCheck.d.ts
  4. 32 7
      src/types/formVerify.d.ts

+ 1 - 1
src/fieldCheck.ts

@@ -262,7 +262,7 @@ class FieldCheck{
 
     /**
      * 检查表单是否符合规则
-     * @param formObject 需要检验的表单项 字段:值
+     * @param {verifyForm} formObject 需要检验的表单项 字段:值
      * @param [isMustMatch] 是否强制要求匹配规则
      * @returns errMessage 错误码或错误信息
      */

+ 2 - 2
src/formVerify.ts

@@ -301,9 +301,9 @@ class FormVerify {
 
     /**
      * 验证当前的表单是否符合要求
-     * @param isMustMatch
+     * @param [isMustMatch] 是否必须全部匹配到验证规则
      */
-    public check (isMustMatch = false) : boolean {
+    public check (isMustMatch:boolean = false) : boolean {
         return this.checkForm(this.formData as formObject, isMustMatch);
     }
 

+ 28 - 10
src/types/fieldCheck.d.ts

@@ -2,10 +2,10 @@
 type errMessage = string | undefined;
 
 /**
- * 检测是否通过
- * code_pass 通过
- * code_notPass 不通过
- * code_notMatch 未匹配到规则
+ * 规则匹配结果
+ * @property code_pass 验证通过
+ * @property code_notPass 验证未通过
+ * @property code_notMatch 未匹配到规则
  */
 enum checkCode {
     code_pass = 1,
@@ -13,13 +13,21 @@ enum checkCode {
     code_notMatch = 3
 }
 
-/**
- * @description 验证字段
- * @param {Array<string | RegExp>} checkFields 用于匹配的字段字符或者正则
- */
 type checkFields = Array<string | RegExp>;
 
-
+/**
+ * 验证规则
+ * @property [type] 类型
+ * @property  [min] 最小值
+ * @property max 最大值
+ * @property length 长度
+ * @property regex 正则表达式
+ * @property message 错误信息
+ * @property require 是否必填
+ * @property minLength 最小长度
+ * @property maxLength 最大长度
+ * @property validator 自定义验证函数
+ */
 type checkRule = {
     type?: string;
     min?: number;
@@ -34,13 +42,23 @@ type checkRule = {
 }
 
 
-
+/**
+ * 规则项
+ * @property name 规则名称
+ * @property checkFields 验证匹配字段
+ * @property rules 验证规则
+ */
 type ruleItem = {
     name: string,
     checkFields: checkFields;
     rules: Array<validatorFunction | checkRule>;
 }
 
+/**
+ * 验证函数
+ * @param value 要验证的值
+ * @returns {string | null} 错误信息
+ */
 type validatorFunction = {
     (value: any): string | null
 }

+ 32 - 7
src/types/formVerify.d.ts

@@ -1,6 +1,10 @@
-
-
-
+/**
+ * 表单项 enum 值,用于下拉框
+ * @property key 枚举值
+ * @property value 枚举文本
+ * @property [disabled] 是否禁用
+ * @property [checkField] 依赖字段
+ */
 type formOption = {
     key: string;
     value: string;
@@ -8,12 +12,32 @@ type formOption = {
     checkField?: string;
 }
 
+/**
+ * 表单验证类配置
+ * @property [isMustMatchRule] 是否必须匹配规则 默认false
+ */
 type FormVerifyOption = {
     isMustMatchRule: boolean;
 }
 
+/**
+ * 表单数据
+ * @property [val] 字段值
+ * @property [msg] 提示信息
+ * @property [state] 状态
+ * @property [showText] 显示的文本
+ * @property [label] 标签
+ * @property [init] 初始值
+ * @property [options] 选项
+ * @property [depend] 依赖字段
+ * @property [reCheckField] 重新验证字段
+ * @property [disables] 禁用字段
+ * @property [any] 字段名
+ */
 type formItemData = {
+    // 字段值
     val?: string;
+    // 提示信息
     msg?: string;
     state?: number;
     showText?: string;
@@ -30,17 +54,18 @@ type formItemData = {
 /**
  * 表单数据对象
  * object 表单数据对象
+ * @property [key] k:v
  */
 type formObject = {
     [key: string]: formItemData;
 }
 
-type formOption= {
-    isMustMatchRule?: boolean;
-    [key: string]: any;
-}
 
 
+/**
+ * 要验证的数据值 {key: value}
+ */
 type verifyForm = {
+    // key: value
     [key: string]: any;
 }