Skip to content

Commit

Permalink
refactor: 🦄 对插槽判空
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed Jun 5, 2023
1 parent 2b95801 commit 9ba8685
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/models/param/slotsBox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Variables from '@/constants/vars';
import SliderVue from '@/components/slider/index.vue';
import { type Component, type VNode, h, type Slots } from 'vue';
import {
type Component,
type VNode,
h,
type Slots,
Comment,
isVNode
} from 'vue';
import { TableHeader } from './header';

export default class SlotsBox {
Expand Down Expand Up @@ -28,8 +35,12 @@ export default class SlotsBox {
return !!v.type?.name && !!v.type?.setup;
}

private static __isValidComponent(v: any): v is Component {
return !(isVNode(v) && v.type === Comment);
}

private setMultiColumn(col: VNode, column: TableHeader['columns'][0]) {
const s: () => any[] = (col.children as any)?.default;
const s: () => VNode[] = (col.children as any)?.default;

if (s) {
try {
Expand All @@ -38,6 +49,7 @@ export default class SlotsBox {
const type = (v.type as Component)?.name;
return (
type &&
SlotsBox.__isValidComponent(v) &&
SlotsBox.__isCustomComponent(v) &&
SlotsBox.__checkType(type, Variables.name.column)
);
Expand Down Expand Up @@ -87,6 +99,7 @@ export default class SlotsBox {
// 只接收自定义的两个组件
return (
type &&
SlotsBox.__isValidComponent(v) &&
SlotsBox.__isCustomComponent(v) &&
[Variables.name.column, Variables.name.slider]
.map(n => SlotsBox.__checkType(type, n))
Expand Down

0 comments on commit 9ba8685

Please sign in to comment.