Commit 0a388f4c722780a7459434efbac8c493b69455e5

Authored by 刘汉宸
1 parent 2c8430c4

fix: 修复SchemaForm和SchemaTransfer传值

packages/schema-form/index.vue
@@ -4,14 +4,15 @@ @@ -4,14 +4,15 @@
4 <template v-if="item.is"> 4 <template v-if="item.is">
5 <z-form-item v-if="bindParam(item, 'if')" v-show="bindParam(item, 'show')" v-bind="bindItemProps(item)" :key="index"> 5 <z-form-item v-if="bindParam(item, 'if')" v-show="bindParam(item, 'show')" v-bind="bindItemProps(item)" :key="index">
6 <slot v-if="$scopedSlots[item.prop]" :name="item.prop" :value="get(model, item.prop)" :onInput="value => onComponentInput({ value, item })" v-bind="slotProps"> </slot> 6 <slot v-if="$scopedSlots[item.prop]" :name="item.prop" :value="get(model, item.prop)" :onInput="value => onComponentInput({ value, item })" v-bind="slotProps"> </slot>
7 - <item-render v-else :item="item" :value="get(model, item.prop)" :onInput="value => onComponentInput({ value, item })"></item-render> 7 + <item-render v-else :item="item" :value="get(model, item.prop)" :model="model" :onInput="value => onComponentInput({ value, item })"></item-render>
8 <slot :name="`label-${item.prop}`" slot="label" v-bind="slotProps"></slot> 8 <slot :name="`label-${item.prop}`" slot="label" v-bind="slotProps"></slot>
9 <slot :name="`error-${item.prop}`" slot="error" v-bind="slotProps"></slot> 9 <slot :name="`error-${item.prop}`" slot="error" v-bind="slotProps"></slot>
10 </z-form-item> 10 </z-form-item>
11 </template> 11 </template>
12 <template v-else> 12 <template v-else>
13 <z-form-item v-if="bindParam(item, 'if')" v-show="bindParam(item, 'show')" v-bind="bindItemProps(item)" :key="index" :value="get(model, item.prop)"> 13 <z-form-item v-if="bindParam(item, 'if')" v-show="bindParam(item, 'show')" v-bind="bindItemProps(item)" :key="index" :value="get(model, item.prop)">
14 - <slot :name="item.prop" :value="get(model, item.prop)" :onInput="value => onComponentInput({ value, item })" v-bind="slotProps"></slot> 14 + <slot v-if="$scopedSlots[item.prop]" :name="item.prop" :value="get(model, item.prop)" :onInput="value => onComponentInput({ value, item })" v-bind="slotProps"> </slot>
  15 + <item-render v-else :item="item" :value="get(model, item.prop)" :model="model" :onInput="value => onComponentInput({ value, item })"></item-render>
15 </z-form-item> 16 </z-form-item>
16 </template> 17 </template>
17 </template> 18 </template>
@@ -32,10 +33,9 @@ export default { @@ -32,10 +33,9 @@ export default {
32 render(h, context) { 33 render(h, context) {
33 const props = context.props; 34 const props = context.props;
34 const item = props.item || {}; 35 const item = props.item || {};
35 - let content = []; 36 + let content = props.value;
36 if (item.render && typeof item.render === 'function') { 37 if (item.render && typeof item.render === 'function') {
37 - console.log('render');  
38 - content = item.render(props.value, h); 38 + content = [item.render(props.value, props.model, h)];
39 } 39 }
40 if (item.children) { 40 if (item.children) {
41 if (Array.isArray(item.children)) { 41 if (Array.isArray(item.children)) {
@@ -58,7 +58,11 @@ export default { @@ -58,7 +58,11 @@ export default {
58 result[current] = item[current]; 58 result[current] = item[current];
59 return result; 59 return result;
60 }, {}); 60 }, {});
61 - return h(item.is, { props: _props, on: _on, ...otherAttrs }, content); 61 + if (item.is) {
  62 + return h(item.is, { props: _props, on: _on, ...otherAttrs }, content);
  63 + } else {
  64 + return content;
  65 + }
62 }, 66 },
63 }, 67 },
64 }, 68 },
@@ -89,7 +93,7 @@ export default { @@ -89,7 +93,7 @@ export default {
89 return this.size || (this.$ELEMENT || {}).size; 93 return this.size || (this.$ELEMENT || {}).size;
90 }, 94 },
91 _schemaProps() { 95 _schemaProps() {
92 - return { size: this._size, ...(this.schema.props || {}) }; 96 + return { size: this._size, ...(this.schema.props || {}), ...this.$attrs };
93 }, 97 },
94 slotProps() { 98 slotProps() {
95 return { 99 return {
@@ -128,7 +132,7 @@ export default { @@ -128,7 +132,7 @@ export default {
128 return item[key]; 132 return item[key];
129 }, 133 },
130 bindItemProps(item) { 134 bindItemProps(item) {
131 - const { children, is, props, on, ...other } = item || {}; 135 + const { children, is, props, on, render, ...other } = item || {};
132 return Object.keys(other).reduce((result, current) => { 136 return Object.keys(other).reduce((result, current) => {
133 result = { ...result, [current]: this.bindParam(item, current, item[current]) }; 137 result = { ...result, [current]: this.bindParam(item, current, item[current]) };
134 return result; 138 return result;
packages/schema-transfer/index.vue
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 <div class="z-schema-transfer__content"> 35 <div class="z-schema-transfer__content">
36 <slot v-bind="_slotScope"> 36 <slot v-bind="_slotScope">
37 <z-schema-page 37 <z-schema-page
  38 + ref="schema-page"
38 :size="transferSize" 39 :size="transferSize"
39 :value-filter="valueFilter" 40 :value-filter="valueFilter"
40 :value-table="valueTable" 41 :value-table="valueTable"
@@ -69,7 +70,7 @@ @@ -69,7 +70,7 @@
69 </div> 70 </div>
70 <div class="z-schema-transfer__content"> 71 <div class="z-schema-transfer__content">
71 <slot name="selected" v-bind="_slotScope"> 72 <slot name="selected" v-bind="_slotScope">
72 - <z-schema-table :size="transferSize" :value="value" :schema="schemaRight" @input="onInput"> 73 + <z-schema-table ref="schema-table" :size="transferSize" :value="value" :schema="schemaRight" @input="onInput">
73 <template v-for="item in getSlotKeys('selected-', true)" #[item.name]="slotScope"> 74 <template v-for="item in getSlotKeys('selected-', true)" #[item.name]="slotScope">
74 <slot :name="item.slot" v-bind="{ ..._slotScope, ...slotScope }"></slot> 75 <slot :name="item.slot" v-bind="{ ..._slotScope, ...slotScope }"></slot>
75 </template> 76 </template>
@@ -209,6 +210,7 @@ export default { @@ -209,6 +210,7 @@ export default {
209 disabled: this.transferDisabled, 210 disabled: this.transferDisabled,
210 choose: this.onChoose, 211 choose: this.onChoose,
211 remove: this.onRemove, 212 remove: this.onRemove,
  213 + source: this.valueTable,
212 }; 214 };
213 return [...methods].reduce((result, current) => { 215 return [...methods].reduce((result, current) => {
214 result[current] = this[current]; 216 result[current] = this[current];
@@ -237,6 +239,11 @@ export default { @@ -237,6 +239,11 @@ export default {
237 } 239 }
238 return false; 240 return false;
239 }, 241 },
  242 + search() {
  243 + if (this.$refs['schema-page']) {
  244 + this.$refs['schema-page'].search();
  245 + }
  246 + },
240 deselect(value) { 247 deselect(value) {
241 return value.filter(item => !this.valueKeys.includes(item[this.valueKey])); 248 return value.filter(item => !this.valueKeys.includes(item[this.valueKey]));
242 }, 249 },