✨(component): select / tab slots 解析逻辑优化
This commit is contained in:
parent
753ef0fab2
commit
e2b14f9fd4
@ -108,4 +108,4 @@ export const transformPlacement = (
|
|||||||
}` as DropdownPlacement;
|
}` as DropdownPlacement;
|
||||||
}
|
}
|
||||||
return placement;
|
return placement;
|
||||||
};
|
};
|
||||||
|
@ -26,7 +26,7 @@ import LayTagInput from "../tagInput/index.vue";
|
|||||||
import LayDropdown from "../dropdown/index.vue";
|
import LayDropdown from "../dropdown/index.vue";
|
||||||
import LaySelectOption, { SelectOptionProps } from "../selectOption/index.vue";
|
import LaySelectOption, { SelectOptionProps } from "../selectOption/index.vue";
|
||||||
import { SelectSize } from "./interface";
|
import { SelectSize } from "./interface";
|
||||||
import { ShapeFlags } from "../dropdown/util";
|
import { isArrayChildren } from "src/utils";
|
||||||
|
|
||||||
export interface SelectProps {
|
export interface SelectProps {
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -76,7 +76,7 @@ var timer: any;
|
|||||||
|
|
||||||
const getOption = (nodes: VNode[], newOptions: any[]) => {
|
const getOption = (nodes: VNode[], newOptions: any[]) => {
|
||||||
nodes?.map((item) => {
|
nodes?.map((item) => {
|
||||||
if (item && item.shapeFlag && item.shapeFlag == ShapeFlags.ARRAY_CHILDREN) {
|
if (isArrayChildren(item, item.children)) {
|
||||||
getOption(item.children as VNode[], newOptions);
|
getOption(item.children as VNode[], newOptions);
|
||||||
} else {
|
} else {
|
||||||
if ((item.type as Component).name == LaySelectOption.name) {
|
if ((item.type as Component).name == LaySelectOption.name) {
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
} from "vue";
|
} from "vue";
|
||||||
import { useResizeObserver } from "@vueuse/core";
|
import { useResizeObserver } from "@vueuse/core";
|
||||||
import { TabData, TabInjectKey, TabPosition } from "./interface";
|
import { TabData, TabInjectKey, TabPosition } from "./interface";
|
||||||
import { ShapeFlags } from "../dropdown/util";
|
import { isArrayChildren } from "src/utils";
|
||||||
|
|
||||||
export interface TabProps {
|
export interface TabProps {
|
||||||
type?: string;
|
type?: string;
|
||||||
@ -47,7 +47,7 @@ const childrens: Ref<VNode[]> = ref([]);
|
|||||||
|
|
||||||
const setItemInstanceBySlot = function (nodes: VNode[]) {
|
const setItemInstanceBySlot = function (nodes: VNode[]) {
|
||||||
nodes?.map((item) => {
|
nodes?.map((item) => {
|
||||||
if (item && item.shapeFlag && item.shapeFlag == ShapeFlags.ARRAY_CHILDREN) {
|
if (isArrayChildren(item, item.children)) {
|
||||||
setItemInstanceBySlot(item.children as VNode[]);
|
setItemInstanceBySlot(item.children as VNode[]);
|
||||||
} else {
|
} else {
|
||||||
if ((item.type as Component).name == tabItem.name) {
|
if ((item.type as Component).name == tabItem.name) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export * from "./domUtil";
|
export * from "./domUtil";
|
||||||
export * from "./withInstall";
|
export * from "./withInstall";
|
||||||
export * from "./arrayUtil";
|
export * from "./arrayUtil";
|
||||||
export * from "./vueUtil";
|
export * from "./vueUtil";
|
||||||
|
@ -18,10 +18,16 @@ export const isElement = (vn: VNode) => {
|
|||||||
return Boolean(vn && vn.shapeFlag & ShapeFlags.ELEMENT);
|
return Boolean(vn && vn.shapeFlag & ShapeFlags.ELEMENT);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isComponent = (vn: VNode, type?: VNodeTypes): type is Component => {
|
export const isComponent = (
|
||||||
|
vn: VNode,
|
||||||
|
type?: VNodeTypes
|
||||||
|
): type is Component => {
|
||||||
return Boolean(vn && vn.shapeFlag & ShapeFlags.COMPONENT);
|
return Boolean(vn && vn.shapeFlag & ShapeFlags.COMPONENT);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isArrayChildren = (vn: VNode, children: VNode["children"]): children is VNode[] => {
|
export const isArrayChildren = (
|
||||||
|
vn: VNode,
|
||||||
|
children: VNode["children"]
|
||||||
|
): children is VNode[] => {
|
||||||
return Boolean(vn && vn.shapeFlag & ShapeFlags.ARRAY_CHILDREN);
|
return Boolean(vn && vn.shapeFlag & ShapeFlags.ARRAY_CHILDREN);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user