123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template>
- <view>
- <fs-cell-group full border :radius="false">
- <fs-cell align="top" v-for="(item, index) in list" :key="item.id">
- <template #title>
- <fs-avatar :src="item[keyMap.avatar]"></fs-avatar>
- </template>
- <template #value>
- <view class="fs-comment-hd">
- <view class="fs-comment-hd-item fs-comment-hd-title">{{ item[keyMap.name] }}</view>
- <view class="fs-comment-hd-item">{{ item[keyMap.time] }}</view>
- </view>
- <view class="fs-comment-content">{{ item[keyMap.content] }}</view>
- <view class="fs-comment-reply">
- <view class="fs-comment-reply-item" @click="handleLike(item)" v-if="showLike">
- <fs-icon type="icon-like" :color="item[keyMap.isLike] ? 'red' : ''"></fs-icon>
- <view v-if="!item[keyMap.isLike]">点赞</view>
- </view>
- <view class="fs-comment-reply-item" @click="initInput(item)">
- <fs-icon type="icon-comment"></fs-icon>
- 回复
- </view>
- </view>
- <view class="fs-comment-reply-box">
- <fs-cell-group border bgColor="transparent" full>
- <fs-cell align="top" v-for="reply in item[keyMap.replyList]" :key="reply.id">
- <template #title>
- <fs-avatar :src="reply[keyMap.avatar]"></fs-avatar>
- </template>
- <template #value>
- <view class="fs-comment-hd fs-comment-hd-title">
- <view class="fs-comment-hd-item">{{ reply[keyMap.name] }}</view>
- <view class="fs-comment-hd-item">{{ reply[keyMap.time] }}</view>
- </view>
- <view class="fs-comment-content">{{ reply[keyMap.content] }}</view>
- <view class="fs-comment-reply">
- <view class="fs-comment-reply-item" @click="handleLike(reply)" v-if="showLike">
- <fs-icon type="icon-like" :color="reply[keyMap.isLike] ? 'red' : ''"></fs-icon>
- <view v-if="!reply[keyMap.isLike]">点赞</view>
- </view>
- <view class="fs-comment-reply-item" @click="initInput(reply)">
- <fs-icon type="icon-comment"></fs-icon>
- 回复
- </view>
- </view>
- </template>
- </fs-cell>
- </fs-cell-group>
- </view>
- </template>
- </fs-cell>
- </fs-cell-group>
- <view class="fs-comment-input-box" v-if="showInput">
- <input
- type="text"
- class="fs-comment-input"
- placeholder="回复..."
- v-model="replyValue"
- :focus="focus"
- @confirm="handleConfirm"
- />
- <view class="fs-comment-button" @click="handleConfirm">发送</view>
- <!-- :style="{backgroundColor: replyValue ? '#08bf65' : '#f7f7f7',color: replyValue ? '#fff' : '#cecece'}" -->
- </view>
- </view>
- </template>
- <script>
- /**
- * 评论组件
- * @description 评论组件
- * @property {Array} list 手风琴效果
- * @property {Boolean} showLike 激活项name
- * @property {Object} keyMap 箭头位置
- * @event {Function} like 点赞事件
- * @event {Function} reply 发送事件
- */
- export default {
- name: 'fs-comment'
- }
- </script>
- <script setup>
- import { ref, nextTick } from 'vue'
- const props = defineProps({
- list: {
- type: Array,
- default() {
- return []
- }
- },
- showLike: Boolean,
- keyMap: {
- type: Object,
- default() {
- return {
- avatar: 'avatar',
- name: 'name',
- time: 'time',
- content: 'content',
- replyList: 'children',
- isLike: 'isLike'
- }
- }
- }
- })
- const emits = defineEmits(['like', 'reply'])
- let focus = ref(false)
- let showInput = ref(false)
- let reply = ref(null)
- let replyValue = ref('')
- const initInput = item => {
- showInput.value = true
- focus.value = true
- reply.value = item
- replyValue.value = ''
- }
- const handleBlur = () => {
- nextTick(() => {
- showInput.value = false
- focus.value = false
- })
- }
- const handleConfirm = () => {
- if (replyValue.value) {
- emits('reply', reply.value)
- }
- showInput.value = false
- focus.value = false
- }
- const handleLike = item => {
- item[props.keyMap.isLike] = !item[props.keyMap.isLike]
- emits('like', item)
- }
- </script>
- <style lang="scss">
- .fs-comment {
- font-size: 14px;
- &-hd {
- display: flex;
- &-title {
- color: #222;
- }
- &-item {
- padding-right: 30rpx;
- position: relative;
- margin-bottom: 10rpx;
- & + & {
- padding-left: 30rpx;
- &::before {
- position: absolute;
- left: 0;
- top: 50%;
- transform: translateY(-50%);
- width: 2rpx;
- height: 24rpx;
- background-color: #d9d9d9;
- content: '';
- }
- }
- }
- }
- &-content {
- font-size: 14px;
- }
- &-reply-box {
- background-color: #f7f8fa;
- margin-top: 10rpx;
- border-radius: var(--radius);
- overflow: hidden;
- }
- &-reply {
- display: flex;
- font-size: 14px;
- margin-top: 10rpx;
- align-items: center;
- &-item {
- display: flex;
- align-items: center;
- margin-right: 30rpx;
- }
- }
- &-input-box {
- height: 110rpx;
- position: fixed;
- display: flex;
- left: 0;
- right: 0;
- bottom: 0;
- padding: 20rpx;
- border-top: 1rpx solid #eaeaea;
- background-color: #fff;
- align-items: center;
- z-index: 10;
- }
- &-input {
- height: 100%;
- margin-right: 20rpx;
- flex: 1;
- background-color: #fff;
- border-radius: 8rpx;
- padding-left: 20rpx;
- }
- &-button {
- height: 100%;
- padding: 10rpx 20rpx;
- border-radius: 8rpx;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- background-color: #08bf65;
- color: #fff;
- }
- }
- </style>
|