Newer
Older
operation_web / src / util / initRules.js
@田松 田松 on 11 Jan 2021 885 bytes +++配置管理-项目管理
export default (fieldList) => {
  const obj = {}
  // 循环字段列表
  for (const item of fieldList) {
    let type = item.type === 'select' || item.type === 'cascader' || item.type === 'treeselect' ? '选择' : (item.type === 'avatar' ? '上传' : '输入')
    let method = item.type === 'select' || item.type === 'cascader' || item.type === 'avatar' ? 'change' : 'blur'
    if (item.required) {
      if (item.validator) {
        obj[item.value] = {
          required: item.required,
          validator: item.validator,
          trigger: method
        }
      } else {
        obj[item.value] = {
          required: item.required,
          message: '请' + type + item.label,
          trigger: method
        }
      }
    } else if (item.validator) {
      obj[item.value] = {
        validator: item.validator,
        trigger: method
      }
    }
  }
  return obj
}