Skip to content

Commit

Permalink
fix: 🐛 修复DropMenu第一次通过open()而非用户点击打开时展开菜单定位错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zybzzc committed Oct 18, 2024
1 parent 31353ce commit f38e51c
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {
</script>

<script lang="ts" setup>
import { getCurrentInstance, inject, onBeforeMount, ref, watch } from 'vue'
import { getCurrentInstance, inject, onBeforeMount, onMounted, ref, watch } from 'vue'
import { closeOther } from '../common/clickoutside'
import { type Queue, queueKey } from '../composables/useQueue'
import { getRect, uuid } from '../common/util'
Expand Down Expand Up @@ -68,6 +68,10 @@ onBeforeMount(() => {
windowHeight.value = uni.getSystemInfoSync().windowHeight
})
onMounted(() => {
updateOffset()
})
function noop(event: Event) {
event.preventDefault()
event.stopPropagation()
Expand Down Expand Up @@ -99,20 +103,26 @@ function toggle(child: any) {
}
}
/**
* 更新 offset
*/
async function updateOffset() {
const rect = await getRect(`#${dropMenuId.value}`, false, proxy)
if (!rect) return
const { top, bottom } = rect
if (props.direction === 'down') {
offset.value = Number(bottom)
} else {
offset.value = windowHeight.value - Number(top)
}
}
/**
* 控制菜单内容是否展开
*/
function fold(child: any) {
getRect(`#${dropMenuId.value}`, false, proxy).then((rect) => {
if (!rect) return
const { top, bottom } = rect
if (props.direction === 'down') {
offset.value = Number(bottom)
} else {
offset.value = windowHeight.value - Number(top)
}
child.$.exposed!.toggle()
})
async function fold(child: any) {
await updateOffset()
child.$.exposed!.toggle()
}
</script>

Expand Down

0 comments on commit f38e51c

Please sign in to comment.