Commit 152f14b3699c004eab155e4e015f472b75ef3939

Authored by 刘汉宸
1 parent d0e13360

fix: 修复SchemaSelect插槽

Showing 1 changed file with 20 additions and 0 deletions   Show diff stats
packages/schema-select/index.vue
@@ -48,12 +48,18 @@ @@ -48,12 +48,18 @@
48 <cell-highlight v-if="highlight" :value="value" :keyword="query" :key="index"></cell-highlight> 48 <cell-highlight v-if="highlight" :value="value" :keyword="query" :key="index"></cell-highlight>
49 <template v-else>{{ value }}</template> 49 <template v-else>{{ value }}</template>
50 </template> 50 </template>
  51 + <template v-for="item in getSlotKeys('table-')" #[item.name]="slotScope">
  52 + <slot :name="item.slot" v-bind="slotScope"></slot>
  53 + </template>
51 </z-schema-page> 54 </z-schema-page>
52 <z-schema-table v-else ref="table" :value="options" :schema="selectTableSchema" :size="selectSize"> 55 <z-schema-table v-else ref="table" :value="options" :schema="selectTableSchema" :size="selectSize">
53 <template v-for="(item, index) in tableColumns" #[`cell-${item.prop}`]="{ value }"> 56 <template v-for="(item, index) in tableColumns" #[`cell-${item.prop}`]="{ value }">
54 <cell-highlight v-if="highlight" :value="value" :keyword="query" :key="index"></cell-highlight> 57 <cell-highlight v-if="highlight" :value="value" :keyword="query" :key="index"></cell-highlight>
55 <template v-else>{{ value }}</template> 58 <template v-else>{{ value }}</template>
56 </template> 59 </template>
  60 + <template v-for="item in getSlotKeys('table-', true)" #[item.name]="slotScope">
  61 + <slot :name="item.slot" v-bind="slotScope"></slot>
  62 + </template>
57 </z-schema-table> 63 </z-schema-table>
58 </div> 64 </div>
59 </el-popover> 65 </el-popover>
@@ -224,6 +230,9 @@ export default { @@ -224,6 +230,9 @@ export default {
224 } 230 }
225 return true; 231 return true;
226 }, 232 },
  233 + slotKeys() {
  234 + return Object.keys(this.$scopedSlots);
  235 + },
227 }, 236 },
228 watch: { 237 watch: {
229 value(val) { 238 value(val) {
@@ -234,6 +243,17 @@ export default { @@ -234,6 +243,17 @@ export default {
234 }, 243 },
235 }, 244 },
236 methods: { 245 methods: {
  246 + getSlotKeys(prefix, fixed) {
  247 + return this.slotKeys.reduce((result, current) => {
  248 + if (current.indexOf(prefix) === 0) {
  249 + result.push({
  250 + slot: current,
  251 + name: fixed ? current.substring(prefix.length) : current,
  252 + });
  253 + }
  254 + return result;
  255 + }, []);
  256 + },
237 // 手动设置当前value对应的label 257 // 手动设置当前value对应的label
238 setLabel(val) { 258 setLabel(val) {
239 this.currentLabel = val; 259 this.currentLabel = val;