修复 多个 下拉组件,切换 隐藏问题

This commit is contained in:
aihe 2024-05-08 19:08:32 +08:00
parent 2b23b4df51
commit 76c5387753

View File

@ -1,6 +1,6 @@
<template> <template>
<view class="" style="position: relative;"> <view @click.stop="handleRootClick" class="" style="position: relative;">
<view @click.stop="handleSelectSwitch"> <view @click="handleSelectSwitch">
<slot v-if="$slots.default"></slot> <slot v-if="$slots.default"></slot>
<default-select-input v-else :placeholder="placeholder" :show="show" :list="filDataList" :value="value" :isWhite="isWhite" :customStyle="customStyle"></default-select-input> <default-select-input v-else :placeholder="placeholder" :show="show" :list="filDataList" :value="value" :isWhite="isWhite" :customStyle="customStyle"></default-select-input>
</view> </view>
@ -40,6 +40,8 @@
drop: 'drop' drop: 'drop'
} }
const selectDropEventName = "selectDropEventName"
export default { export default {
computed: { computed: {
filDataList() { filDataList() {
@ -133,22 +135,31 @@
}, },
data() { data() {
return { return {
componentId: uni.$u.guid(20),
show: false, show: false,
modeEnum: Object.assign({}, modeEnum) modeEnum: Object.assign({}, modeEnum)
} }
}, },
created() { created() {
uni.$on(pageEventNames.globalClick, this.handleDocumentClick); uni.$on(pageEventNames.globalClick, this.handleDocumentClick);
uni.$on(selectDropEventName, this.listenSelectDrop);
}, },
unmounted() { unmounted() {
uni.$off(pageEventNames.globalClick, this.handleDocumentClick); uni.$off(pageEventNames.globalClick, this.handleDocumentClick);
uni.$off(selectDropEventName, this.listenSelectDrop);
}, },
methods: { methods: {
handleDocumentClick(){ handleDocumentClick(){
this.show = false this.show = false
}, },
listenSelectDrop(e) {
// 忽略当前组件发出的事件消息
if(e != this.componentId) {
this.show = false
}
},
handleSelectSwitch() { handleSelectSwitch() {
// this.$emit('update:show', !this.show) // this.$emit('update:show', !this.show)
this.show = !this.show this.show = !this.show
@ -162,6 +173,9 @@
}, },
onListChange(val){ onListChange(val){
this.$emit('update:resObject', val) this.$emit('update:resObject', val)
},
handleRootClick() {
uni.$emit(selectDropEventName, this.componentId)
} }
} }
} }