|
@@ -1,37 +1,44 @@
|
|
|
<!-- -->
|
|
|
<template>
|
|
|
<div class="aside-item right-item">
|
|
|
- <div class="comment-content">
|
|
|
+ <div class="comment-content" ref="slider" v-if="slideHeigt" :style="`height:${slideHeigt - 84}px;`">
|
|
|
<div class="comment-header"><span>评论</span></div>
|
|
|
<div class="comment-msg">
|
|
|
- <div class="comment-item">
|
|
|
- <div class="avatar-box"></div>
|
|
|
+ <div class="comment-item" v-for="(i, index) in commentList">
|
|
|
+ <div class="avatar-box" :style="i.head ? `background-image:url(${i.head});` : `background-image:url(${emptyAvatar});`"></div>
|
|
|
<div class="comment-box">
|
|
|
- <div class="view-top">
|
|
|
- <span class="user-name">用户名称</span>
|
|
|
- <i class="iconfont icon-del"></i>
|
|
|
+ <div class="view-box view-top">
|
|
|
+ <span class="user-name">{{ i.nickName }}</span>
|
|
|
+ <i class="iconfont icon-del" v-if="i.userId == userId" @click="delComment({ commentId: i.commentId, index })"></i>
|
|
|
</div>
|
|
|
- <div class="view-middle">
|
|
|
- <span class="comment-text">这个地方的油漆没有干</span>
|
|
|
+ <div class="view-box view-middle">
|
|
|
+ <span class="comment-text">{{ i.content }}</span>
|
|
|
</div>
|
|
|
- <div class="view-bottom">
|
|
|
- <span class="comment-time">2022-11-28</span>
|
|
|
- <span class="reply-btn" @click="handlerReply">回复</span>
|
|
|
+ <div class="view-box view-bottom">
|
|
|
+ <span class="comment-time">{{ i.createTime }}</span>
|
|
|
+ <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, nickName: i.nickName }, index)">回复</span>
|
|
|
</div>
|
|
|
- <div class="reply-content">
|
|
|
- <div class="reply-item">
|
|
|
- <div class="avatar-box"></div>
|
|
|
+ <div class="reply-content" v-if="i.children">
|
|
|
+ <div class="reply-item" v-for="(j, j_index) in i.children">
|
|
|
+ <div class="avatar-box" :style="j.head ? `background-image:url(${j.head});` : `background-image:url(${emptyAvatar});`"></div>
|
|
|
<div class="reply-box">
|
|
|
- <div class="view-top">
|
|
|
- <span class="user-name">用户名称</span>
|
|
|
- <i class="iconfont icon-del"></i>
|
|
|
+ <div class="view-box view-top">
|
|
|
+ <span class="user-name">{{ j.nickName }}</span>
|
|
|
+ <i class="iconfont icon-del" v-if="j.userId == userId" @click="delComment({ commentId: j.commentId, index: j_index, parentIndex: index })"></i>
|
|
|
</div>
|
|
|
- <div class="view-middle">
|
|
|
- <span class="reply-text">回复<span class="reply-tips">@用户A</span>这个地方的油漆没有干</span>
|
|
|
+ <div class="view-box view-middle">
|
|
|
+ <span class="reply-text"
|
|
|
+ ><span v-if="j.replyId"
|
|
|
+ >回复<span class="reply-tips">@{{ j.replyNickName }}</span></span
|
|
|
+ >
|
|
|
+ {{ j.content }}</span
|
|
|
+ >
|
|
|
</div>
|
|
|
- <div class="view-bottom">
|
|
|
- <span class="reply-time">2022-11-28</span>
|
|
|
- <span class="reply-btn">回复</span>
|
|
|
+ <div class="view-box view-bottom">
|
|
|
+ <span class="reply-time">{{ j.createTime }}</span>
|
|
|
+ <span class="reply-btn" @click="handlerReply({ parentId: i.commentId, replyId: j.commentId, parentUserId: j.userId, nickName: i.nickName }, j_index)"
|
|
|
+ >回复</span
|
|
|
+ >
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -39,72 +46,101 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <div class="empty-box" v-if="!commentList.length">
|
|
|
+ <div class="pic"></div>
|
|
|
+ <div>暂无评论</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
+
|
|
|
<div class="input-content">
|
|
|
<div class="input-box"><input ref="input$" @input="handlerInput" v-model="inputText" :placeholder="placeholderText" type="text" /></div>
|
|
|
<div class="send-btn" @click="hanlderSubmit">发布</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <Toast v-if="showTips" type="warn" :content="showTips" :close="() => (showTips = null)" />
|
|
|
+ <Toast v-if="showTips" :type="tipsType" :content="showTips" :close="() => (showTips = null)" />
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, onMounted, onBeforeUnmount, computed, inject, nextTick } from 'vue'
|
|
|
+import { ref, onMounted, onBeforeUnmount, computed, inject, nextTick, defineProps } from 'vue'
|
|
|
import Toast from '@/components/dialog/Toast'
|
|
|
import { http } from '@/utils/request'
|
|
|
+import avatar from '@/assets/img/avatar@2x.png'
|
|
|
+const props = defineProps({
|
|
|
+ slideHeigt: Number,
|
|
|
+})
|
|
|
+const emptyAvatar = ref(avatar)
|
|
|
const notify = inject('notify')
|
|
|
console.log(notify.value)
|
|
|
const emits = defineEmits(['action'])
|
|
|
const input$ = ref(null)
|
|
|
const inputText = ref('')
|
|
|
-const placeholderText = ref('')
|
|
|
-const replyStatus = ref(false)
|
|
|
-
|
|
|
+const placeholderText = ref('发一条评论吧')
|
|
|
+const replyInfo = ref(null)
|
|
|
+const tipsType = ref('warn')
|
|
|
const showTips = ref(null)
|
|
|
-const handlerReply = () => {
|
|
|
+const slider = ref(null)
|
|
|
+
|
|
|
+const handlerReply = (data, index) => {
|
|
|
inputText.value = ''
|
|
|
- placeholderText.value = '@用户名称'
|
|
|
- replyStatus.value = true
|
|
|
+ placeholderText.value = '@' + data.nickName
|
|
|
+ delete data.nickName
|
|
|
+ replyInfo.value = data
|
|
|
+
|
|
|
+ console.log(replyInfo.value)
|
|
|
}
|
|
|
|
|
|
const handlerInput = () => {
|
|
|
// console.log(inputText.value.length)
|
|
|
- if (replyStatus.value && inputText.value.length) {
|
|
|
- // console.log(1)
|
|
|
- }
|
|
|
+ // if (replyInfo.value && inputText.value.length) {
|
|
|
+ // // console.log(1)
|
|
|
+ // }
|
|
|
}
|
|
|
let parentId = null
|
|
|
let commentId = null
|
|
|
-let userId = localStorage.getItem('userId')
|
|
|
-
|
|
|
+const userId = ref(localStorage.getItem('userId') - 0)
|
|
|
+const commentList = ref([])
|
|
|
const hanlderSubmit = () => {
|
|
|
if (inputText.value == '') {
|
|
|
+ tipsType.value = 'warn'
|
|
|
showTips.value = '请输入内容'
|
|
|
return
|
|
|
}
|
|
|
- if (replyStatus.value) {
|
|
|
- } else {
|
|
|
- }
|
|
|
|
|
|
let params = {
|
|
|
- commentId: commentId,
|
|
|
markingId: notify.value.id,
|
|
|
content: inputText.value,
|
|
|
- userId: userId,
|
|
|
+ userId: userId.value,
|
|
|
parentId: parentId,
|
|
|
}
|
|
|
|
|
|
- // if (!params.commentId) {
|
|
|
- // delete params.commentId
|
|
|
- // }
|
|
|
- // if (!params.parentId) {
|
|
|
- // delete params.parentId
|
|
|
- // }
|
|
|
+ if (replyInfo.value) {
|
|
|
+ for (let key in replyInfo.value) {
|
|
|
+ if (replyInfo.value[key]) {
|
|
|
+ params[key] = replyInfo.value[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
console.log(params)
|
|
|
http.post(`smart-site/comment/reply`, params).then(response => {
|
|
|
console.log(response)
|
|
|
if (response.success) {
|
|
|
+ getAllComments()
|
|
|
+
|
|
|
+ // if (replyInfo.value) {
|
|
|
+ // } else {
|
|
|
+ // // slider.value.
|
|
|
+ // slider.value.scrollTo({
|
|
|
+ // top: 0,
|
|
|
+ // behavior: 'smooth',
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+
|
|
|
+ replyInfo.value = null
|
|
|
+ inputText.value = ''
|
|
|
+ placeholderText.value = '发一条评论吧'
|
|
|
} else {
|
|
|
+ tipsType.value = 'error'
|
|
|
showTips.value = response.message
|
|
|
}
|
|
|
})
|
|
@@ -118,11 +154,33 @@ const onClose = () => {
|
|
|
}
|
|
|
notify.value = null
|
|
|
}
|
|
|
-onMounted(() => {
|
|
|
+const getAllComments = () => {
|
|
|
http.post(`smart-site/comment/tree/all`, { markingId: notify.value.id }).then(response => {
|
|
|
- // console.log(response)
|
|
|
+ if (response.success) {
|
|
|
+ commentList.value = response.data
|
|
|
+ } else {
|
|
|
+ }
|
|
|
})
|
|
|
+}
|
|
|
|
|
|
+const delComment = data => {
|
|
|
+ http.post(`smart-site/comment/del`, { commentId: data.commentId }).then(response => {
|
|
|
+ if (response.success) {
|
|
|
+ if (!data.parentIndex) {
|
|
|
+ commentList.value.splice(data.index, 1)
|
|
|
+ } else {
|
|
|
+ commentList.value[data.parentIndex].children.splice(data.index, 1)
|
|
|
+ }
|
|
|
+ tipsType.value = 'success'
|
|
|
+ showTips.value = '删除成功'
|
|
|
+ } else {
|
|
|
+ tipsType.value = 'error'
|
|
|
+ showTips.value = response.message
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+onMounted(() => {
|
|
|
+ getAllComments()
|
|
|
if (window.kankan) {
|
|
|
window.kankan.TagManager.focusTag(notify.value.sid, {
|
|
|
direction: 'left',
|
|
@@ -140,9 +198,9 @@ onMounted(() => {
|
|
|
nextTick(() => {
|
|
|
input$.value.addEventListener('keydown', function (e) {
|
|
|
if (e.keyCode == 8) {
|
|
|
- if (replyStatus.value && !inputText.value.length) {
|
|
|
- replyStatus.value = false
|
|
|
- placeholderText.value = ''
|
|
|
+ if (replyInfo.value && !inputText.value.length) {
|
|
|
+ replyInfo.value = null
|
|
|
+ placeholderText.value = '发一条评论吧'
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -153,10 +211,10 @@ onBeforeUnmount(() => {})
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
.aside-item {
|
|
|
- padding: 20px;
|
|
|
+ padding: 20px 0 20px 20px;
|
|
|
box-sizing: border-box;
|
|
|
line-height: 28px;
|
|
|
-
|
|
|
+ flex: 1;
|
|
|
&.right-item {
|
|
|
position: relative;
|
|
|
.input-content {
|
|
@@ -194,7 +252,31 @@ onBeforeUnmount(() => {})
|
|
|
cursor: pointer;
|
|
|
}
|
|
|
}
|
|
|
+ .empty-box {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ flex-flow: column;
|
|
|
+ position: absolute;
|
|
|
+ top: 50%;
|
|
|
+ left: 50%;
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
+ .pic {
|
|
|
+ width: 134px;
|
|
|
+ height: 134px;
|
|
|
+ background: url('~@/assets/img/pic_bg.png') no-repeat;
|
|
|
+ background-size: 100% 100%;
|
|
|
+ }
|
|
|
+ div {
|
|
|
+ margin-top: 5px;
|
|
|
+ color: #999;
|
|
|
+ }
|
|
|
+ }
|
|
|
.comment-content {
|
|
|
+ // height: calc(100% - 54px);
|
|
|
+ overflow-y: auto;
|
|
|
+ padding: 0 20px 0 0;
|
|
|
+ position: relative;
|
|
|
.comment-header {
|
|
|
font-size: 16px;
|
|
|
font-weight: bold;
|
|
@@ -210,12 +292,14 @@ onBeforeUnmount(() => {})
|
|
|
width: 24px;
|
|
|
height: 24px;
|
|
|
border-radius: 50%;
|
|
|
- background: #f2f2f2;
|
|
|
margin-right: 6px;
|
|
|
+ background-size: 100% 100%;
|
|
|
+
|
|
|
+ background-repeat: no-repeat;
|
|
|
}
|
|
|
.comment-box {
|
|
|
flex: 1;
|
|
|
- > div {
|
|
|
+ > div.view-box {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: space-between;
|
|
@@ -258,8 +342,10 @@ onBeforeUnmount(() => {})
|
|
|
width: 24px;
|
|
|
height: 24px;
|
|
|
border-radius: 50%;
|
|
|
- background: #f2f2f2;
|
|
|
margin-right: 6px;
|
|
|
+ background-size: 100% 100%;
|
|
|
+
|
|
|
+ background-repeat: no-repeat;
|
|
|
}
|
|
|
.reply-box {
|
|
|
flex: 1;
|