From 4bf8d1e300c28f405402582dd32fde4245d9ed47 Mon Sep 17 00:00:00 2001 From: Gahotx <53534938+Gahotx@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:11:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8DCollaps?= =?UTF-8?q?e=E6=8A=98=E5=8F=A0=E9=9D=A2=E6=9D=BF=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E6=BA=A2=E5=87=BA=E9=97=AE=E9=A2=98=20(#710)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/wd-collapse-item/types.ts | 5 +++ .../wd-collapse-item/wd-collapse-item.vue | 33 +++++++------------ .../components/wd-collapse/wd-collapse.vue | 1 + 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts b/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts index c796c7c5..e2056b9c 100644 --- a/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts @@ -31,6 +31,11 @@ export type CollapseItemExpose = { * @returns boolean */ getExpanded: () => boolean + /** + * 更新展开状态 + * @returns Promise + */ + updateExpand: () => Promise } export type CollapseItemInstance = ComponentPublicInstance diff --git a/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue b/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue index e0d63144..47d8bb8a 100644 --- a/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue +++ b/src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue @@ -74,25 +74,11 @@ const selected = computed(() => { } }) -watch( - () => selected.value, - () => { - if (!inited.value) { - return - } - updateExpend() - }, - { - deep: true, - immediate: true - } -) - onMounted(() => { - updateExpend() + updateExpand() }) -function updateExpend() { +function updateExpand() { return getRect(`#${collapseId.value}`, false, proxy).then((rect) => { const { height: rectHeight } = rect height.value = isDef(rectHeight) ? Number(rectHeight) : '' @@ -136,16 +122,16 @@ function handleClick() { } if (isPromise(response)) { response.then(() => { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) }) } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } else { - collapse && collapse.toggle(name, !expanded.value) + handleChangeExpand(name) } } @@ -153,7 +139,12 @@ function getExpanded() { return expanded.value } -defineExpose({ getExpanded }) +function handleChangeExpand(name: string) { + updateExpand() + collapse && collapse.toggle(name, !expanded.value) +} + +defineExpose({ getExpanded, updateExpand })