Commit 0a388f4c722780a7459434efbac8c493b69455e5

Authored by 刘汉宸
1 parent 2c8430c4

fix: 修复SchemaForm和SchemaTransfer传值

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