From 14042f9cd40b32674eee093a5e36712b469bf950 Mon Sep 17 00:00:00 2001 From: Tyh2001 <1469442737@qq.com> Date: Sat, 23 Dec 2023 18:57:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20select=20filter=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fighting-design/option/src/option.vue | 37 ++++++------ .../fighting-design/select/src/select.vue | 60 +++++++++++++------ start/src/App.vue | 17 +----- 3 files changed, 62 insertions(+), 52 deletions(-) diff --git a/packages/fighting-design/option/src/option.vue b/packages/fighting-design/option/src/option.vue index 8f07c5ecc4..50983567fa 100644 --- a/packages/fighting-design/option/src/option.vue +++ b/packages/fighting-design/option/src/option.vue @@ -21,24 +21,32 @@ /** 获取到 trigger 注入的依赖项 */ const triggerInject: TriggerProvide | null = inject(TRIGGER_CLOSE_KEY, null) + /** 获取插槽内容 */ + const slotLabel = computed((): string => { + if (!slot.default) { + return '' + } + + const _slot: VNodeNormalizedChildren | string = slot.default()[0].children + + return isString(_slot) ? _slot : '' + }) + /** 控制是否显示 */ - const isVisible = computed(() => { + const isVisible = computed((): boolean => { // 父组件没有依赖则不显示 if (!parentInject) { return false } + // 没有 filter 属性,则展示 if (!parentInject.filter) { return true } - const slotText: VNodeNormalizedChildren | string | undefined = - slot.default && slot.default()[0].children - - const label = isString(slotText) - ? slotText - : '' || prop.label.toString() || prop.value.toString() - + /** 获取到 label */ + const label = slotLabel.value || prop.label.toString() || prop.value.toString() + /** 获取到选中的项目 */ const currentItem = parentInject.childrenLabels.find(item => { return item.slot === label }) @@ -50,17 +58,6 @@ return true }) - /** 获取插槽内容 */ - const slotLabel = computed((): string => { - if (!slot.default) { - return '' - } - - const _slot: VNodeNormalizedChildren | string = slot.default()[0].children - - return isString(_slot) ? _slot : '' - }) - /** 标签选中状态 */ const labelActive = computed((): boolean => { /** 获取到 value 的值 */ @@ -161,11 +158,11 @@