Commit 4e01d6efe132a80985e07a5204818075e77bdb22

Authored by liuhanchen
1 parent 4661b90e

feat: 新增表单配置项条件函数

Showing 1 changed file with 15 additions and 2 deletions   Show diff stats
packages/table/editor.vue
@@ -99,6 +99,12 @@ function editorRender(h, context, item) { @@ -99,6 +99,12 @@ function editorRender(h, context, item) {
99 const contentProps = context.props || {}; 99 const contentProps = context.props || {};
100 return function(scope) { 100 return function(scope) {
101 const value = get(scope.row, item.prop); 101 const value = get(scope.row, item.prop);
  102 + if (item.if && typeof item.if === 'function') {
  103 + const showEditor = item.if({ item, value, index: scope.$index, ...scope });
  104 + if (!showEditor) {
  105 + return cellRender(h, context, item)(scope);
  106 + }
  107 + }
102 let vnode = {}; 108 let vnode = {};
103 // 默认 109 // 默认
104 const setValue = val => { 110 const setValue = val => {
@@ -138,12 +144,19 @@ function editorRender(h, context, item) { @@ -138,12 +144,19 @@ function editorRender(h, context, item) {
138 } 144 }
139 }; 145 };
140 // 编辑表单项配置 146 // 编辑表单项配置
141 - const itemProps = item.props || {}; 147 + let itemProps = item.props || {};
  148 + if (typeof item.props === 'function') {
  149 + itemProps = item.props({ item, value, index: scope.$index, ...scope, onInput: inputEvent });
  150 + }
  151 + let itemAttrs = item.attrs || {};
  152 + if (typeof item.attrs === 'function') {
  153 + itemAttrs = item.attrs({ item, value, index: scope.$index, ...scope, onInput: inputEvent });
  154 + }
142 // 编辑器统一配置 155 // 编辑器统一配置
143 const editorProps = get(contentProps, 'editor') || {}; 156 const editorProps = get(contentProps, 'editor') || {};
144 // 生成虚拟节点 157 // 生成虚拟节点
145 vnode = h(item.is, { 158 vnode = h(item.is, {
146 - attrs: item.attrs, 159 + attrs: itemAttrs,
147 props: { ...editorProps, ...itemProps, value }, 160 props: { ...editorProps, ...itemProps, value },
148 on: { input: inputEvent, blur: blurEvent }, 161 on: { input: inputEvent, blur: blurEvent },
149 }); 162 });