diff --git a/packages/table/editor.vue b/packages/table/editor.vue index 5ea2d9e..bd33200 100644 --- a/packages/table/editor.vue +++ b/packages/table/editor.vue @@ -7,19 +7,25 @@ function isItemRequired(context, config) { // 渲染函数配置 const contentProps = context.props || {}; // 编辑器统一配置 - const editorConfig = contentProps.editor || {}; - let result = false; - if (!editorConfig.items) { + const editorProps = contentProps.editor || {}; + const editorRules = editorProps.rules || {}; + if (editorProps.validate !== true) { return false; } - for (let item of editorConfig.items) { - if (item.prop === config.prop && item.rules) { - for (let rule of item.rules) { - if (rule.required) { - result = true; - break; - } - } + // 判断校验规则 + let rules = editorRules[config.prop] || []; + const match = editorProps.items.find(i => i.prop === config.prop); + if (match && match.rules) { + rules = match.rules; + } + if (rules.length === 0) { + return false; + } + let result = false; + for (let rule of rules) { + if (rule.required) { + result = true; + break; } } return result; @@ -72,7 +78,8 @@ function formItemRender(h, context, item, scope, children) { // 渲染函数配置 const contentProps = context.props || {}; // 编辑器统一配置 - const editorProps = get(contentProps, 'editor.props') || {}; + const editorProps = get(contentProps, 'editor') || {}; + const editorRules = editorProps.rules || {}; let formItemProp = [editorProps.path].filter(i => i); formItemProp.push(scope.$index); formItemProp.push(item.prop); @@ -80,7 +87,7 @@ function formItemRender(h, context, item, scope, children) { return h( editorProps.formItem || 'el-form-item', { - props: { prop: formItemProp, rules: item.rules, 'inline-message': true }, + props: { prop: formItemProp, rules: item.rules || editorRules[item.prop], 'inline-message': true }, }, children, ); @@ -95,7 +102,7 @@ function editorRender(h, context, item) { let vnode = {}; // 默认 const inputEvent = val => { - if (get(contentProps, 'editor.props.deep') === true) { + if (get(contentProps, 'editor.deep') === true) { if (item.prop.indexOf('.') > -1 || item.prop.indexOf('[') > -1) { let separator = ''; if (item.prop.indexOf('.') > -1) { @@ -128,7 +135,7 @@ function editorRender(h, context, item) { // 编辑表单项配置 const itemProps = item.props || {}; // 编辑器统一配置 - const editorProps = get(contentProps, 'editor.props') || {}; + const editorProps = get(contentProps, 'editor') || {}; // 生成虚拟节点 vnode = h(item.is, { attrs: item.attrs, -- libgit2 0.21.0