Commit 28d586273876112ddaf39ecf78a2ddcb4114d6af

Authored by liuhanchen
1 parent 01950ddf

feat: 优化表头校验规则渲染

Showing 1 changed file with 22 additions and 15 deletions   Show diff stats
packages/table/editor.vue
@@ -7,19 +7,25 @@ function isItemRequired(context, config) { @@ -7,19 +7,25 @@ function isItemRequired(context, config) {
7 // 渲染函数配置 7 // 渲染函数配置
8 const contentProps = context.props || {}; 8 const contentProps = context.props || {};
9 // 编辑器统一配置 9 // 编辑器统一配置
10 - const editorConfig = contentProps.editor || {};  
11 - let result = false;  
12 - if (!editorConfig.items) { 10 + const editorProps = contentProps.editor || {};
  11 + const editorRules = editorProps.rules || {};
  12 + if (editorProps.validate !== true) {
13 return false; 13 return false;
14 } 14 }
15 - for (let item of editorConfig.items) {  
16 - if (item.prop === config.prop && item.rules) {  
17 - for (let rule of item.rules) {  
18 - if (rule.required) {  
19 - result = true;  
20 - break;  
21 - }  
22 - } 15 + // 判断校验规则
  16 + let rules = editorRules[config.prop] || [];
  17 + const match = editorProps.items.find(i => i.prop === config.prop);
  18 + if (match && match.rules) {
  19 + rules = match.rules;
  20 + }
  21 + if (rules.length === 0) {
  22 + return false;
  23 + }
  24 + let result = false;
  25 + for (let rule of rules) {
  26 + if (rule.required) {
  27 + result = true;
  28 + break;
23 } 29 }
24 } 30 }
25 return result; 31 return result;
@@ -72,7 +78,8 @@ function formItemRender(h, context, item, scope, children) { @@ -72,7 +78,8 @@ function formItemRender(h, context, item, scope, children) {
72 // 渲染函数配置 78 // 渲染函数配置
73 const contentProps = context.props || {}; 79 const contentProps = context.props || {};
74 // 编辑器统一配置 80 // 编辑器统一配置
75 - const editorProps = get(contentProps, 'editor.props') || {}; 81 + const editorProps = get(contentProps, 'editor') || {};
  82 + const editorRules = editorProps.rules || {};
76 let formItemProp = [editorProps.path].filter(i => i); 83 let formItemProp = [editorProps.path].filter(i => i);
77 formItemProp.push(scope.$index); 84 formItemProp.push(scope.$index);
78 formItemProp.push(item.prop); 85 formItemProp.push(item.prop);
@@ -80,7 +87,7 @@ function formItemRender(h, context, item, scope, children) { @@ -80,7 +87,7 @@ function formItemRender(h, context, item, scope, children) {
80 return h( 87 return h(
81 editorProps.formItem || 'el-form-item', 88 editorProps.formItem || 'el-form-item',
82 { 89 {
83 - props: { prop: formItemProp, rules: item.rules, 'inline-message': true }, 90 + props: { prop: formItemProp, rules: item.rules || editorRules[item.prop], 'inline-message': true },
84 }, 91 },
85 children, 92 children,
86 ); 93 );
@@ -95,7 +102,7 @@ function editorRender(h, context, item) { @@ -95,7 +102,7 @@ function editorRender(h, context, item) {
95 let vnode = {}; 102 let vnode = {};
96 // 默认 103 // 默认
97 const inputEvent = val => { 104 const inputEvent = val => {
98 - if (get(contentProps, 'editor.props.deep') === true) { 105 + if (get(contentProps, 'editor.deep') === true) {
99 if (item.prop.indexOf('.') > -1 || item.prop.indexOf('[') > -1) { 106 if (item.prop.indexOf('.') > -1 || item.prop.indexOf('[') > -1) {
100 let separator = ''; 107 let separator = '';
101 if (item.prop.indexOf('.') > -1) { 108 if (item.prop.indexOf('.') > -1) {
@@ -128,7 +135,7 @@ function editorRender(h, context, item) { @@ -128,7 +135,7 @@ function editorRender(h, context, item) {
128 // 编辑表单项配置 135 // 编辑表单项配置
129 const itemProps = item.props || {}; 136 const itemProps = item.props || {};
130 // 编辑器统一配置 137 // 编辑器统一配置
131 - const editorProps = get(contentProps, 'editor.props') || {}; 138 + const editorProps = get(contentProps, 'editor') || {};
132 // 生成虚拟节点 139 // 生成虚拟节点
133 vnode = h(item.is, { 140 vnode = h(item.is, {
134 attrs: item.attrs, 141 attrs: item.attrs,