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 99 const contentProps = context.props || {};
100 100 return function(scope) {
101 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 108 let vnode = {};
103 109 // 默认
104 110 const setValue = val => {
... ... @@ -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 156 const editorProps = get(contentProps, 'editor') || {};
144 157 // 生成虚拟节点
145 158 vnode = h(item.is, {
146   - attrs: item.attrs,
  159 + attrs: itemAttrs,
147 160 props: { ...editorProps, ...itemProps, value },
148 161 on: { input: inputEvent, blur: blurEvent },
149 162 });
... ...