const STATE = {
    VALIDATING: 'validating', // 校验中
    SUCCESS: 'success', // 校验通过
    ERROR: 'error', // 校验不通过
    WARNING: 'warning' // 存在问题但通过校验
}
const RULE = {
    // 默认校验信息
    validInfo: {
        validateStatus: STATE.SUCCESS,
        help: ''
    },
    // 必填
    required: function(value) {
        if(!value) {
            this.validInfo.validateStatus = STATE.ERROR;
            this.validInfo.help = '不能为空';
        }else {
            this.validInfo.validateStatus = STATE.SUCCESS
        }
        return this.validInfo;
    },
    // 长度
    length: function(value, maxLen, minLen) {
        let str = value + '';
        if(maxLen < minLen) {
            return this.validInfo;
        }
        if(maxLen > 0) {
            if(str.length > maxLen) {
                this.validInfo.validateStatus = STATE.ERROR;
                this.validInfo.help = '长度不能大于' + maxLen;
            }
        }
        if(minLen >= 0) {
            if(str.length < minLen) {
                this.validInfo.validateStatus = STATE.ERROR;
                this.validInfo.help = '长度不能小于' + minLen;
            }
        }
        return this.validInfo;
    },
};

export default RULE;