Commit 9d9622cde1824f0e6842838ff9117e4f9ea40d1a

Authored by liuhanchen
1 parent d497786e

feat: 优化表格条件渲染

Showing 1 changed file with 6 additions and 2 deletions   Show diff stats
packages/table/editor.vue
@@ -108,6 +108,9 @@ function editorRender(h, context, item) { @@ -108,6 +108,9 @@ function editorRender(h, context, item) {
108 const contentProps = context.props || {}; 108 const contentProps = context.props || {};
109 return function(scope) { 109 return function(scope) {
110 const value = get(scope.row, item.prop); 110 const value = get(scope.row, item.prop);
  111 + if (item.if === false) {
  112 + return cellRender(h, context, item)(scope);
  113 + }
111 if (item.if && typeof item.if === 'function') { 114 if (item.if && typeof item.if === 'function') {
112 const showEditor = item.if({ item, value, index: scope.$index, ...scope }); 115 const showEditor = item.if({ item, value, index: scope.$index, ...scope });
113 if (!showEditor) { 116 if (!showEditor) {
@@ -118,7 +121,7 @@ function editorRender(h, context, item) { @@ -118,7 +121,7 @@ function editorRender(h, context, item) {
118 // 默认 121 // 默认
119 const setValue = val => { 122 const setValue = val => {
120 if (get(contentProps, 'editor.force') === true) { 123 if (get(contentProps, 'editor.force') === true) {
121 - vnode.componentInstance.$set(scope.row, item.prop, val); 124 + if (vnode.componentInstance) vnode.componentInstance.$set(scope.row, item.prop, val);
122 } else { 125 } else {
123 scope.row[item.prop] = val; 126 scope.row[item.prop] = val;
124 } 127 }
@@ -136,7 +139,7 @@ function editorRender(h, context, item) { @@ -136,7 +139,7 @@ function editorRender(h, context, item) {
136 const bindProp = path[0]; 139 const bindProp = path[0];
137 const propValue = cloneDeep(scope.row); 140 const propValue = cloneDeep(scope.row);
138 set(propValue, item.prop, val); 141 set(propValue, item.prop, val);
139 - vnode.componentInstance.$set(scope.row, bindProp, propValue[bindProp]); 142 + if (vnode.componentInstance) vnode.componentInstance.$set(scope.row, bindProp, propValue[bindProp]);
140 } else { 143 } else {
141 setValue(val); 144 setValue(val);
142 } 145 }
@@ -256,6 +259,7 @@ export default { @@ -256,6 +259,7 @@ export default {
256 <style lang="scss"> 259 <style lang="scss">
257 .z-table-editor { 260 .z-table-editor {
258 .column-editor { 261 .column-editor {
  262 + padding: 0;
259 .cell { 263 .cell {
260 padding: 2px; 264 padding: 2px;
261 .el-form-item { 265 .el-form-item {