vr-shopxo-uniapp/pages/plugins/video/components/comment-info.vue

301 lines
10 KiB
Vue
Raw Normal View History

2025-09-19 05:39:25 +00:00
<template>
2026-03-09 10:34:25 +00:00
<view class="flex-row align-s wh-auto ht-auto">
2026-02-11 06:36:09 +00:00
<image class="comment-avatar" :src="propComment.user.avatar" mode="aspectFill"></image>
2026-03-09 10:34:25 +00:00
<view class="comment-info flex-col jc-c" style="margin-left: 20rpx;" @tap="comment_reply">
<view class="flex-row jc-sb">
<text class="comment-user">{{ propComment.user.user_name_view }}</text>
<view class="pr" style="margin-left: 20rpx;">
2026-02-12 01:31:04 +00:00
<!-- 直接实现下拉菜单 -->
2026-03-10 10:01:33 +00:00
<view ref="commentOption" class="comment-option" @tap.stop="toggle_dropdown">
2026-03-09 10:34:25 +00:00
<u-icon propName="ellipsis" propColor="#999" propSize="28rpx"></u-icon>
2026-02-12 01:31:04 +00:00
</view>
<!-- 下拉菜单 -->
2026-03-10 09:14:01 +00:00
<!-- #ifdef APP-NVUE -->
<view v-if="drop_down_visible && dropdownOptions && Array.isArray(dropdownOptions)" class="dropdown-menu" :style="dropdownMenuStyle" @tap.stop>
<!-- #endif -->
<!-- #ifndef APP-NVUE -->
<view v-if="drop_down_visible && dropdownOptions && Array.isArray(dropdownOptions)" class="dropdown-menu" @tap.stop></view>
<!-- #endif -->
2026-03-10 10:01:33 +00:00
<view v-for="(item, index) in dropdownOptions.filter(item => (propComment.is_can_delete == 1 && item.type == 'delete') || (propComment.is_can_report == 1 && item.type == 'report'))" :key="index" class="dropdown-item" :data-value="item" @tap.stop="handle_dropdown_item_click">
<text style="font-size: 28rpx;color: #666;">{{ item.label }}</text>
2026-02-12 01:31:04 +00:00
</view>
</view>
</view>
2026-02-11 09:26:37 +00:00
</view>
2026-03-09 10:34:25 +00:00
<text v-if="!isEmpty(propComment.reply_comments_text)" class="comment-reply-text">{{ propComment.reply_comments_text}}</text>
<text class="comment-text">{{ propComment.content }}</text>
2026-02-12 07:54:51 +00:00
<!-- <view class="comment-images flex-row align-c gap-5"> -->
<template v-if="!isEmpty(propComment.images)">
<image :src="propComment.images" :data-image="propComment.images" @tap="upload_show_event" mode="aspectFill" class="comment-images"></image>
</template>
<!-- </view> -->
2026-03-09 10:34:25 +00:00
<view class="comment-operation flex-row align-c jc-sb">
<view class="comment-operation-left flex-row align-c">
<text class="comment-time">{{ propComment.add_time }}</text>
<text class="comment-reply flex-row align-c gap-5" style="margin-left: 20rpx;">{{ propReplyContent || $t('common.reply') }}({{ propComment.comments_count }})</text>
2025-09-19 05:39:25 +00:00
</view>
2026-03-09 10:34:25 +00:00
<view class="comment-operation-right flex-row align-c" style="margin-left: 20rpx;" @tap.stop="comment_like">
<u-icon propName="givealike-o-fine" :propColor="propComment.is_give_thumbs == 0 ? '#000' : '#F4B73F'" propSize="28rpx"></u-icon>
<text class="comment-like-num" style="margin-left: 10rpx;">{{ propComment.give_thumbs_count || 0 }}</text>
2025-09-19 05:39:25 +00:00
</view>
</view>
<slot name="sub-comment"></slot>
</view>
</view>
</template>
<script>
2026-02-12 05:43:14 +00:00
const app = getApp();
2026-03-06 03:16:01 +00:00
//#ifdef APP-NVUE
2026-03-06 07:25:09 +00:00
import i18n from '@/locale/index.js';
2026-03-10 10:01:33 +00:00
const dom = weex.requireModule('dom');
// nvue页面在方法中使用时的处理
import { initVueI18n } from '@dcloudio/uni-i18n';
import en from '@/locale/en.json'
import zhHans from '@/locale/zh.json'
const messages = { en, 'zh-Hans': zhHans }
const { t } = initVueI18n(messages)
2026-03-06 03:16:01 +00:00
//#endif
2026-03-10 10:01:33 +00:00
import { isEmpty } from '@/common/js/common/common.js';
export default {
2026-03-06 07:25:09 +00:00
//#ifdef APP-NVUE
2026-03-10 10:01:33 +00:00
i18n,
2026-03-06 07:25:09 +00:00
//#endif
2025-09-19 05:39:25 +00:00
props: {
2025-09-22 07:20:50 +00:00
propComment: {
2025-09-19 05:39:25 +00:00
type: Object,
default: () => {
2026-03-10 10:01:33 +00:00
return {};
2025-09-19 05:39:25 +00:00
},
},
2025-09-22 07:20:50 +00:00
propId: {
2025-09-19 05:39:25 +00:00
type: [String, Number],
default: '',
},
2025-09-22 07:20:50 +00:00
propReplyContent: {
2025-09-19 05:39:25 +00:00
type: String,
default: ''
2026-02-12 01:55:15 +00:00
},
2026-02-12 02:03:43 +00:00
// 控制下拉菜单显示状态
2026-02-12 01:55:15 +00:00
propDropDownVisible: {
type: Boolean,
default: false
2025-09-19 05:39:25 +00:00
}
},
2026-02-12 01:31:04 +00:00
data() {
2026-03-10 10:01:33 +00:00
return {
2026-02-12 01:31:04 +00:00
// 下拉菜单选项数据
2026-03-10 09:14:01 +00:00
dropdownOptions: [],
// 下拉菜单位置信息
2026-03-10 10:01:33 +00:00
dropdownMenuTop: 0,
dropdownMenuLeft: 0
2026-02-12 01:31:04 +00:00
};
},
2026-03-10 09:03:39 +00:00
mounted() {
this.init();
},
2026-02-12 01:55:15 +00:00
computed: {
2026-03-10 10:01:33 +00:00
// 使用 computed 属性映射 props 状态
2026-02-12 01:55:15 +00:00
drop_down_visible() {
2026-03-10 10:01:33 +00:00
return this.propDropDownVisible;
2026-03-10 09:14:01 +00:00
},
// 下拉菜单样式
dropdownMenuStyle() {
2026-03-10 10:01:33 +00:00
return `top: ${this.dropdownMenuTop}px;`;
2026-02-12 01:55:15 +00:00
}
},
2026-03-10 10:01:33 +00:00
methods: {
2026-02-12 07:44:47 +00:00
isEmpty,
2026-03-10 09:03:39 +00:00
init() {
2026-03-10 10:01:33 +00:00
//#ifdef APP-NVUE
2026-03-10 09:03:39 +00:00
this.dropdownOptions = [
2026-03-10 10:01:33 +00:00
{ label: t('common_delete'), type: 'delete' },
{ label: t('common_complaint'), type: 'report' }
2026-03-10 09:03:39 +00:00
]
2026-03-10 10:01:33 +00:00
//#endif
//#ifndef APP-NVUE
this.dropdownOptions = [
{ label: $t('common.delete'), type: 'delete' },
{ label: $t('common.complaint'), type: 'report' }
]
//#endif
2026-03-10 09:03:39 +00:00
},
2025-09-22 01:26:18 +00:00
// 回复
2026-02-11 08:03:30 +00:00
comment_reply(e) {
2026-02-12 07:44:47 +00:00
this.$emit('comment_reply', this.propComment, e);
2025-09-19 05:39:25 +00:00
},
2025-09-22 01:26:18 +00:00
// 点赞
2026-02-11 08:03:30 +00:00
comment_like(e) {
2026-02-12 05:43:14 +00:00
if (!app.globalData.is_single_page_check()) {
2026-03-10 10:01:33 +00:00
return false;
2026-02-12 05:43:14 +00:00
}
2026-03-10 10:01:33 +00:00
var user= app.globalData.get_user_info(this, 'comment_like', e);
2026-02-12 05:43:14 +00:00
if (user != false) {
this.$emit('comment_like', this.propId, e);
}
2025-09-23 03:56:02 +00:00
},
// 上传图片预览
upload_show_event(e) {
2026-02-12 07:54:51 +00:00
const image = e?.currentTarget?.dataset?.image || '';
2025-09-23 03:56:02 +00:00
uni.previewImage({
2026-02-12 07:54:51 +00:00
current: 0,
urls: [image],
2025-09-23 03:56:02 +00:00
});
},
2026-02-12 01:31:04 +00:00
// 切换下拉菜单
2026-03-10 09:03:39 +00:00
toggle_dropdown(e) {
2026-03-10 09:14:01 +00:00
// 获取 comment-option 的位置信息
this.getDropdownPosition();
2026-02-12 01:55:15 +00:00
// 通知父组件切换当前组件的下拉菜单状态
2026-02-12 02:03:43 +00:00
this.$emit('toggle_dropdown', this.propId);
2026-03-10 09:03:39 +00:00
e.stopPropagation();
2026-02-12 01:31:04 +00:00
},
2026-03-10 09:14:01 +00:00
// 获取下拉菜单位置
getDropdownPosition() {
try {
// #ifdef APP-NVUE
2026-03-10 10:01:33 +00:00
// nvue 环境使用 dom 模块的 getComponentRect 方法
const commentOptionEl = this.$refs.commentOption;
2026-03-10 09:14:01 +00:00
if (commentOptionEl) {
dom.getComponentRect(commentOptionEl, (res) => {
if (res && res.size) {
const { top, left, width } = res.size;
// 计算菜单位置:在触发元素下方,右侧对齐
2026-03-10 10:01:33 +00:00
this.dropdownMenuTop = top + 20;
2026-03-10 09:14:01 +00:00
}
});
}
// #endif
} catch (error) {
2026-03-10 10:01:33 +00:00
console.error('获取下拉菜单位置失败:', error);
2026-03-10 09:14:01 +00:00
}
},
2026-03-10 10:01:33 +00:00
2026-02-12 01:31:04 +00:00
// 处理下拉菜单项点击
2026-02-12 01:41:10 +00:00
handle_dropdown_item_click(e) {
2026-02-12 05:43:14 +00:00
if (!app.globalData.is_single_page_check()) {
2026-03-10 10:01:33 +00:00
e.stopPropagation();
return false;
2026-02-12 05:43:14 +00:00
}
var user = app.globalData.get_user_info(this, 'comment_like', e);
if (user != false) {
const item = e.currentTarget.dataset.value || {};
this.$emit('dropdown_item_click', this.propId, item);
}
2026-03-10 10:01:33 +00:00
e.stopPropagation();
2026-02-12 01:31:04 +00:00
}
2025-09-19 05:39:25 +00:00
}
}
</script>
<style lang="scss" scoped>
.comment-avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
}
.comment-info {
flex: 1;
2025-09-23 03:56:02 +00:00
gap: 6rpx;
2025-09-19 05:39:25 +00:00
}
.comment-user {
font-size: 24rpx;
color: #999999;
line-height: 34rpx;
}
.comment-text {
font-size: 28rpx;
color: #333333;
line-height: 40rpx;
}
.comment-time {
font-size: 28rpx;
color: #999999;
line-height: 34rpx;
}
2025-09-19 08:24:52 +00:00
.comment-reply {
font-weight: blod;
font-size: 24rpx;
color: #666666;
line-height: 34rpx;
}
.comment-like-num {
font-size: 24rpx;
color: #999999;
line-height: 34rpx;
}
2025-09-23 03:56:02 +00:00
.comment-image {
width: 50rpx;
height: 50rpx;
}
2026-02-12 01:31:04 +00:00
/* 下拉菜单样式 */
.dropdown-menu {
2026-03-10 09:03:39 +00:00
/* #ifndef APP-NVUE */
2026-03-10 10:01:33 +00:00
position: absolute;
right: 0;
2026-03-10 09:03:39 +00:00
/* #endif */
/* #ifdef APP-NVUE */
position: fixed;
2026-03-10 10:01:33 +00:00
right: 30rpx;
2026-03-10 09:03:39 +00:00
/* #endif */
2026-02-12 01:31:04 +00:00
background: #ffffff;
border-radius: 8rpx;
box-shadow: 0 6rpx 16rpx 0 rgba(0, 0, 0, 0.15);
border: 1rpx solid #e5e5e5;
min-width: 160rpx;
z-index: 9999;
2026-03-10 10:01:33 +00:00
top: 100%;
2026-02-12 01:31:04 +00:00
margin-top: 8rpx;
padding: 10rpx 0;
}
.dropdown-item {
padding: 20rpx 30rpx;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
&:not(.dropdown-item-divided):active {
background-color: #f5f5f5;
}
&.dropdown-item-divided:not(:first-child)::before {
content: '';
position: absolute;
top: 0;
left: 30rpx;
right: 30rpx;
height: 1rpx;
background-color: #f0f0f0;
}
&:first-child {
border-radius: 8rpx 8rpx 0 0;
}
&:last-child {
border-radius: 0 0 8rpx 8rpx;
}
&:first-child:last-child {
border-radius: 8rpx;
}
}
2026-02-12 07:44:47 +00:00
.comment-reply-text {
color: #ccc;
padding: 0 10rpx;
}
2026-02-12 07:54:51 +00:00
.comment-operation {
margin-top: 10rpx;
}
.comment-images {
width: 80rpx;
height: 80rpx;
}
2025-09-19 05:39:25 +00:00
</style>