|
@@ -8,7 +8,7 @@
|
|
|
<div class="avatar-box" :style="i.head ? `background-image:url(${i.head});` : `background-image:url(${emptyAvatar});`"></div>
|
|
|
<div class="comment-box">
|
|
|
<div class="view-box view-top">
|
|
|
- <span class="user-name">{{ i.nickName }}</span>
|
|
|
+ <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-box view-middle">
|
|
@@ -23,20 +23,20 @@
|
|
|
<div class="avatar-box" :style="j.head ? `background-image:url(${j.head});` : `background-image:url(${emptyAvatar});`"></div>
|
|
|
<div class="reply-box">
|
|
|
<div class="view-box view-top">
|
|
|
- <span class="user-name">{{ j.nickName }}</span>
|
|
|
+ <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-box view-middle">
|
|
|
<span class="reply-text"
|
|
|
><span v-if="j.replyId"
|
|
|
- >回复<span class="reply-tips">@{{ j.replyNickName }}</span></span
|
|
|
+ >回复<span class="reply-tips">@{{ j.replyNickName || '未知用户' }}</span></span
|
|
|
>
|
|
|
{{ j.content }}</span
|
|
|
>
|
|
|
</div>
|
|
|
<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 class="reply-btn" @click="handlerReply({ parentId: i.commentId, replyId: j.commentId, parentUserId: j.userId, nickName: j.nickName }, j_index)"
|
|
|
>回复</span
|
|
|
>
|
|
|
</div>
|
|
@@ -58,6 +58,12 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<Toast v-if="showTips" :type="tipsType" :content="showTips" :close="() => (showTips = null)" />
|
|
|
+
|
|
|
+ <ui-confirm v-if="delComfirm" @ok="handlerDel" @no="handlerDel">
|
|
|
+ <template #content>
|
|
|
+ <div>确定要删除吗?</div>
|
|
|
+ </template>
|
|
|
+ </ui-confirm>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
@@ -65,12 +71,14 @@ import { ref, onMounted, onBeforeUnmount, computed, inject, nextTick, defineProp
|
|
|
import Toast from '@/components/dialog/Toast'
|
|
|
import { http } from '@/utils/request'
|
|
|
import avatar from '@/assets/img/avatar@2x.png'
|
|
|
+import UiConfirm from '@/components/dialog/Confirm.vue'
|
|
|
const props = defineProps({
|
|
|
slideHeigt: Number,
|
|
|
})
|
|
|
+let canPut = true
|
|
|
+const delComfirm = ref(null)
|
|
|
const emptyAvatar = ref(avatar)
|
|
|
const notify = inject('notify')
|
|
|
-console.log(notify.value)
|
|
|
const emits = defineEmits(['action'])
|
|
|
const input$ = ref(null)
|
|
|
const inputText = ref('')
|
|
@@ -82,11 +90,11 @@ const slider = ref(null)
|
|
|
|
|
|
const handlerReply = (data, index) => {
|
|
|
inputText.value = ''
|
|
|
- placeholderText.value = '@' + data.nickName
|
|
|
+ let name = data.nickName ? data.nickName : '未知用户'
|
|
|
+ placeholderText.value = '@' + name
|
|
|
delete data.nickName
|
|
|
replyInfo.value = data
|
|
|
|
|
|
- console.log(replyInfo.value)
|
|
|
}
|
|
|
|
|
|
const handlerInput = () => {
|
|
@@ -121,29 +129,35 @@ const hanlderSubmit = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log(params)
|
|
|
- http.post(`smart-site/comment/reply`, params).then(response => {
|
|
|
- console.log(response)
|
|
|
- if (response.success) {
|
|
|
- getAllComments()
|
|
|
+ if (canPut) {
|
|
|
+ canPut = false
|
|
|
+ http.post(`smart-site/comment/reply`, params)
|
|
|
+ .then(response => {
|
|
|
+ if (response.success) {
|
|
|
+ getAllComments()
|
|
|
|
|
|
- // if (replyInfo.value) {
|
|
|
- // } else {
|
|
|
- // // slider.value.
|
|
|
- // slider.value.scrollTo({
|
|
|
- // top: 0,
|
|
|
- // behavior: 'smooth',
|
|
|
- // })
|
|
|
- // }
|
|
|
+ // 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
|
|
|
- }
|
|
|
- })
|
|
|
+ replyInfo.value = null
|
|
|
+ inputText.value = ''
|
|
|
+ placeholderText.value = '发一条评论吧'
|
|
|
+ } else {
|
|
|
+ tipsType.value = 'error'
|
|
|
+ showTips.value = response.message
|
|
|
+ }
|
|
|
+ canPut = true
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ canPut = true
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
const onClose = () => {
|
|
|
if (window.kankan) {
|
|
@@ -162,22 +176,35 @@ const getAllComments = () => {
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
-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)
|
|
|
+const handlerDel = status => {
|
|
|
+ if (status == 'ok') {
|
|
|
+ http.post(`smart-site/comment/del`, { commentId: delComfirm.value.commentId }).then(response => {
|
|
|
+ if (response.success) {
|
|
|
+ // if (!delComfirm.value.parentIndex) {
|
|
|
+ // commentList.value.splice(delComfirm.value.index, 1)
|
|
|
+ // } else {
|
|
|
+ // commentList.value[delComfirm.value.parentIndex].children.splice(delComfirm.value.index, 1)
|
|
|
+ // }
|
|
|
+ getAllComments()
|
|
|
+ if (replyInfo.value?.parentId == delComfirm.value.commentId) {
|
|
|
+ replyInfo.value = null
|
|
|
+ inputText.value = ''
|
|
|
+ placeholderText.value = '发一条评论吧'
|
|
|
+ }
|
|
|
+ tipsType.value = 'success'
|
|
|
+ showTips.value = '删除成功'
|
|
|
} else {
|
|
|
- commentList.value[data.parentIndex].children.splice(data.index, 1)
|
|
|
+ tipsType.value = 'error'
|
|
|
+ showTips.value = response.message
|
|
|
}
|
|
|
- tipsType.value = 'success'
|
|
|
- showTips.value = '删除成功'
|
|
|
- } else {
|
|
|
- tipsType.value = 'error'
|
|
|
- showTips.value = response.message
|
|
|
- }
|
|
|
- })
|
|
|
+ delComfirm.value = null
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ delComfirm.value = null
|
|
|
+ }
|
|
|
+}
|
|
|
+const delComment = data => {
|
|
|
+ delComfirm.value = data
|
|
|
}
|
|
|
onMounted(() => {
|
|
|
getAllComments()
|