修改下拉框显示逻辑

master
于肖磊 2026-02-12 09:55:15 +08:00
parent b882f62bb5
commit da373bc72e
2 changed files with 75 additions and 28 deletions

View File

@ -54,11 +54,15 @@
propReplyContent: { propReplyContent: {
type: String, type: String,
default: '回复' default: '回复'
},
// props
propDropDownVisible: {
type: Boolean,
default: false
} }
}, },
data() { data() {
return { return {
drop_down_visible: false,
// //
dropdownOptions: [ dropdownOptions: [
{ label: '删除', type: 'delete' }, { label: '删除', type: 'delete' },
@ -66,6 +70,12 @@
] ]
}; };
}, },
computed: {
// 使computedprops
drop_down_visible() {
return this.propDropDownVisible;
}
},
methods: { methods: {
// //
comment_reply(e) { comment_reply(e) {
@ -84,41 +94,21 @@
}, },
// //
toggle_dropdown() { toggle_dropdown() {
this.drop_down_visible = !this.drop_down_visible; //
this.$emit('toggle-dropdown', this.propId);
//
if (this.drop_down_visible) {
//
setTimeout(() => {
uni.$on('global-click', this.handle_global_click);
}, 100);
} else {
uni.$off('global-click', this.handle_global_click);
}
},
//
handle_global_click() {
if (this.drop_down_visible) {
this.drop_down_visible = false;
uni.$off('global-click', this.handle_global_click);
}
}, },
// //
handle_dropdown_item_click(e) { handle_dropdown_item_click(e) {
const item = e.currentTarget.dataset.value || {}; const item = e.currentTarget.dataset.value || {};
console.log('点击:', item.label); console.log('点击:', item.label);
uni.showToast({ title: item.label, icon: 'none' }); uni.showToast({ title: item.label, icon: 'none' });
this.drop_down_visible = false; //
uni.$off('global-click', this.handle_global_click); this.$emit('close-dropdown', this.propId);
this.$emit('dropdown-item-click', { command: item.command, label: item.label }); this.$emit('dropdown-item-click', { command: item.command, label: item.label });
} }
}, },
mounted() { mounted() {
console.log('CommentInfo 组件已挂载'); console.log('CommentInfo 组件已挂载');
},
beforeDestroy() {
//
uni.$off('global-click', this.handle_global_click);
} }
} }
</script> </script>

View File

@ -97,12 +97,12 @@
<scroll-view class="comment-list" scroll-y show-scrollbar="false" @scrolltolower="handle_comment_to_lower_scroll" @scroll="handle_comment_scroll"> <scroll-view class="comment-list" scroll-y show-scrollbar="false" @scrolltolower="handle_comment_to_lower_scroll" @scroll="handle_comment_scroll">
<view class="comment-scroll"> <view class="comment-scroll">
<view class="comment-item flex-col" v-for="(comment_item, index) in active_comments" :key="index"> <view class="comment-item flex-col" v-for="(comment_item, index) in active_comments" :key="index">
<commentInfoComponent class="wh-auto ht-auto" :propComment="comment_item" :propId="comment_item.id" @comment_reply="comment_reply" @comment_like="comment_like"></commentInfoComponent> <commentInfoComponent class="wh-auto ht-auto" :propComment="comment_item" :propId="comment_item.id" :propDropDownVisible="active_dropdown_id === comment_item.id" @comment_reply="comment_reply" @comment_like="comment_like" @toggle-dropdown="handle_toggle_dropdown" @close-dropdown="handle_close_dropdown"></commentInfoComponent>
<!-- 子评论 --> <!-- 子评论 -->
<view class="sub-comment flex-col jc-c gap-10 mt-10"> <view class="sub-comment flex-col jc-c gap-10 mt-10">
<view v-if="comment_item.sub_comments && comment_item.sub_comments.length > 0 && comment_item.show_sub_comment" class="sub-comment-list flex-col jc-c"> <view v-if="comment_item.sub_comments && comment_item.sub_comments.length > 0 && comment_item.show_sub_comment" class="sub-comment-list flex-col jc-c">
<view class="sub-comment-item flex-row align-s gap-10" v-for="(sub_comment_item, sub_comment_index) in comment_item.sub_comments" :key="sub_comment_index"> <view class="sub-comment-item flex-row align-s gap-10" v-for="(sub_comment_item, sub_comment_index) in comment_item.sub_comments" :key="sub_comment_index">
<commentInfoComponent class="wh-auto ht-auto" :propComment="sub_comment_item" :propId="sub_comment_item.id" @comment_reply="comment_reply" @comment_like="comment_like"></commentInfoComponent> <commentInfoComponent class="wh-auto ht-auto" :propComment="sub_comment_item" :propId="sub_comment_item.id" :propDropDownVisible="active_dropdown_id === sub_comment_item.id" @comment_reply="comment_reply" @comment_like="comment_like" @toggle-dropdown="handle_toggle_dropdown" @close-dropdown="handle_close_dropdown"></commentInfoComponent>
</view> </view>
</view> </view>
<template v-if="comment_item.comments_count > 0"> <template v-if="comment_item.comments_count > 0">
@ -237,6 +237,8 @@
}, },
video_switch_debounce_timer: null, // video_switch_debounce_timer: null, //
video_cleanup_timer: null, // video_cleanup_timer: null, //
//
active_dropdown_id: null, // ID
} }
}, },
computed: { computed: {
@ -1218,7 +1220,62 @@
console.error('清理视频资源时出错:', error); console.error('清理视频资源时出错:', error);
} }
}, },
//
handle_toggle_dropdown(comment_id) {
//
if (this.active_dropdown_id === comment_id) {
this.active_dropdown_id = null;
} else {
this.active_dropdown_id = comment_id;
}
},
//
handle_close_dropdown(comment_id) {
if (this.active_dropdown_id === comment_id) {
this.active_dropdown_id = null;
}
},
//
handle_global_click(e) {
//
const target = e.target || e.srcElement;
// comment-optiondropdown-menu
let isInDropdown = false;
let currentElement = target;
while (currentElement && currentElement !== document) {
//
if (currentElement.classList &&
(currentElement.classList.contains('comment-option') ||
currentElement.classList.contains('dropdown-menu') ||
currentElement.closest('.comment-option') ||
currentElement.closest('.dropdown-menu'))) {
isInDropdown = true;
break;
}
currentElement = currentElement.parentNode;
}
//
if (!isInDropdown && this.active_dropdown_id !== null) {
this.active_dropdown_id = null;
}
},
},
mounted() {
//
document.addEventListener('click', this.handle_global_click);
//
document.addEventListener('touchstart', this.handle_global_click);
},
beforeDestroy() {
//
document.removeEventListener('click', this.handle_global_click);
document.removeEventListener('touchstart', this.handle_global_click);
} }
}; };
</script> </script>