fix: pk comment
This commit is contained in:
@@ -12,6 +12,18 @@ export function getList(data) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取PK赛参与人
|
||||||
|
* @param { pkId: string, chooseItemId: string, pageNo: number, pageSize: number } data
|
||||||
|
*/
|
||||||
|
export function getParticipantList(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/pk/participant',
|
||||||
|
method: 'get',
|
||||||
|
params: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成PK赛
|
* 生成PK赛
|
||||||
* @param {topicId: string, leftItemId: string, rightItemId: string} data
|
* @param {topicId: string, leftItemId: string, rightItemId: string} data
|
||||||
@@ -23,3 +35,53 @@ export function generate(data) {
|
|||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取PK赛评论列表
|
||||||
|
* @param { pageNo: number, pageSize: number, pkId: string, status?: number, rootCommentId?: string, orderBy?: string } data
|
||||||
|
*/
|
||||||
|
export function getCommentList(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/pk/comment/list',
|
||||||
|
method: 'get',
|
||||||
|
params: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PK赛 评论/回复
|
||||||
|
* @param { userId: string, pkId: string, content: string, parentCommentId?: string, replyToCommentId?: string } data
|
||||||
|
* @param { parentCommentId: string } data 评论回复必传
|
||||||
|
* @param { replyToCommentId: string } data 回复必传
|
||||||
|
*/
|
||||||
|
export function comment(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/pk/comment',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PK赛 评论 点赞
|
||||||
|
* @param { userId: string, commentId: string } data
|
||||||
|
*/
|
||||||
|
export function like(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/pk/comment/like',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PK赛 评论 禁用/启用
|
||||||
|
* @param { id: string, enable: boolean } data
|
||||||
|
*/
|
||||||
|
export function toggleEnable(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/pk/comment/toggle',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -110,10 +110,10 @@ export const asyncRoutes = [
|
|||||||
meta: { title: 'PK赛列表', icon: 'setting' },
|
meta: { title: 'PK赛列表', icon: 'setting' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'pkRecord',
|
path: 'pkComment',
|
||||||
name: 'PkRecord',
|
name: 'PkComment',
|
||||||
component: () => import('@/views/rating/pk/record/index'),
|
component: () => import('@/views/rating/pk/comment/index'),
|
||||||
meta: { title: 'PK赛记录', icon: 'setting' },
|
meta: { title: 'pK赛评论', icon: 'setting' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
233
src/views/rating/pk/comment/components/CommentReplyList.vue
Normal file
233
src/views/rating/pk/comment/components/CommentReplyList.vue
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" :visible.sync="dialogVisible" width="900px" @close="close">
|
||||||
|
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
|
||||||
|
<el-table-column align="center" fixed="left" label="操作" width="120">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="text" @click="handleLike(row)">点赞</el-button>
|
||||||
|
<el-button type="text" @click="handleReply(row)">回复</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="left" label="回复内容" min-width="250">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="comment-content-cell">
|
||||||
|
<div v-if="row.replyToUser" class="reply-target">回复 @{{ row.replyToUser.nickname || '未知用户' }}:</div>
|
||||||
|
<div class="content-text">{{ row.content }}</div>
|
||||||
|
<div class="comment-meta">
|
||||||
|
<span class="meta-item">
|
||||||
|
<i class="el-icon-thumb" />
|
||||||
|
{{ row.likeCount || 0 }}
|
||||||
|
</span>
|
||||||
|
<el-tag v-if="row.status === 2" size="mini" style="margin-left: 8px" type="success">已展示</el-tag>
|
||||||
|
<el-tag v-else size="mini" style="margin-left: 8px" type="info">隐藏/待审</el-tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="left" label="用户信息" min-width="180">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div v-if="row.user" class="user-info-cell">
|
||||||
|
<el-image
|
||||||
|
v-if="row.user.avatar"
|
||||||
|
class="user-avatar"
|
||||||
|
:preview-src-list="[row.user.avatar]"
|
||||||
|
:src="getThumbUrl(row.user.avatar)"
|
||||||
|
/>
|
||||||
|
<div v-else class="user-avatar-placeholder"><i class="el-icon-user" /></div>
|
||||||
|
<div class="user-details">
|
||||||
|
<div class="user-nickname">
|
||||||
|
{{ row.user.nickname || '未知用户' }}
|
||||||
|
<el-tag v-if="row.user.isRobot" size="mini" style="margin-left: 4px" type="info">机器人</el-tag>
|
||||||
|
<el-tag v-else size="mini" style="margin-left: 4px" type="success">真人</el-tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="user-details">
|
||||||
|
<div class="user-id">{{ row.userId }}</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="状态切换" width="80">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-switch v-model="row.enable" :active-value="true" :inactive-value="false" @change="handleToggleStatus(row)" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="时间" prop="createdAt" width="160">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatTime(row.createdAt) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
:current-page="queryForm.pageNo"
|
||||||
|
:layout="layout"
|
||||||
|
:page-size="queryForm.pageSize"
|
||||||
|
:total="total"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
/>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getCommentList, toggleEnable } from '@/api/rating/pk'
|
||||||
|
import { formatTime } from '@/utils'
|
||||||
|
import { getThumbUrl } from '@/utils/blessing'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'CommentReplyList',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
title: '回复列表',
|
||||||
|
dialogVisible: false,
|
||||||
|
list: [],
|
||||||
|
listLoading: false,
|
||||||
|
layout: 'total, prev, pager, next',
|
||||||
|
total: 0,
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
rootCommentId: '',
|
||||||
|
},
|
||||||
|
parentRow: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
formatTime,
|
||||||
|
getThumbUrl,
|
||||||
|
show(row) {
|
||||||
|
this.parentRow = row
|
||||||
|
this.title = `回复列表`
|
||||||
|
this.dialogVisible = true
|
||||||
|
this.queryForm.rootCommentId = row.id
|
||||||
|
this.queryForm.pageNo = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.dialogVisible = false
|
||||||
|
this.list = []
|
||||||
|
},
|
||||||
|
handleSizeChange(val) {
|
||||||
|
this.queryForm.pageSize = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleCurrentChange(val) {
|
||||||
|
this.queryForm.pageNo = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
async fetchData() {
|
||||||
|
this.listLoading = true
|
||||||
|
try {
|
||||||
|
const { data } = await getCommentList(this.queryForm)
|
||||||
|
this.list = data.list || []
|
||||||
|
this.total = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.listLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleLike(row) {
|
||||||
|
this.$emit('like', row)
|
||||||
|
},
|
||||||
|
handleReply(row) {
|
||||||
|
// 传递当前行作为被回复对象,同时传递根评论ID
|
||||||
|
this.$emit('reply', row, this.queryForm.rootCommentId)
|
||||||
|
},
|
||||||
|
async handleToggleStatus(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await toggleEnable({ id: row.id, enable: row.enable })
|
||||||
|
this.$baseMessage(msg || '状态切换成功', 'success')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
row.enable = !row.enable
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.comment-content-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply-target {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #409eff;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #303133;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item i {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info-cell {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-avatar,
|
||||||
|
.user-avatar-placeholder {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 8px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-avatar-placeholder {
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-details {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-nickname {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #303133;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-id {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
194
src/views/rating/pk/comment/components/PkCommentEdit.vue
Normal file
194
src/views/rating/pk/comment/components/PkCommentEdit.vue
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px" @close="close">
|
||||||
|
<el-form ref="form" label-width="100px" :model="form" :rules="rules">
|
||||||
|
<el-form-item label="参与机器人" prop="userId">
|
||||||
|
<el-select v-model="form.userId" v-loadmore="loadMoreRobots" filterable placeholder="请选择参与评论的机器人" style="width: 100%">
|
||||||
|
<el-option v-for="item in robotList" :key="item.id" :label="item.nickname || item.id" :value="item.id">
|
||||||
|
<div style="display: flex; align-items: center">
|
||||||
|
<el-image
|
||||||
|
v-if="item.avatar"
|
||||||
|
:src="getThumbUrl(item.avatar)"
|
||||||
|
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
|
||||||
|
/>
|
||||||
|
<span>{{ item.nickname || '未知用户' }}</span>
|
||||||
|
</div>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item v-if="!isReply" label="PK赛" prop="pkId">
|
||||||
|
<el-select v-model="form.pkId" v-loadmore="loadMorePks" filterable placeholder="请选择PK赛" style="width: 100%">
|
||||||
|
<el-option v-for="item in pkList" :key="item.id" :label="getPkLabel(item)" :value="item.id" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="评论内容" prop="content">
|
||||||
|
<el-input v-model="form.content" maxlength="500" :placeholder="contentPlaceholder" :rows="4" show-word-limit type="textarea" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="close">取 消</el-button>
|
||||||
|
<el-button :loading="saving" type="primary" @click="save">确 定</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getListBase as getRobotList } from '@/api/system/robot'
|
||||||
|
import { getList as getPkList, comment } from '@/api/rating/pk'
|
||||||
|
import { getThumbUrl } from '@/utils/blessing'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PkCommentEdit',
|
||||||
|
directives: {
|
||||||
|
loadmore: {
|
||||||
|
bind(el, binding) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
|
||||||
|
if (SELECTWRAP_DOM) {
|
||||||
|
SELECTWRAP_DOM.addEventListener('scroll', function () {
|
||||||
|
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 2
|
||||||
|
if (condition) {
|
||||||
|
binding.value()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
title: '立即评论',
|
||||||
|
dialogFormVisible: false,
|
||||||
|
saving: false,
|
||||||
|
isReply: false,
|
||||||
|
contentPlaceholder: '请输入您的评论文字',
|
||||||
|
form: {
|
||||||
|
userId: '',
|
||||||
|
pkId: '',
|
||||||
|
content: '',
|
||||||
|
parentCommentId: '',
|
||||||
|
replyToCommentId: '',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
userId: [{ required: true, trigger: 'change', message: '请选择机器人' }],
|
||||||
|
pkId: [{ required: true, trigger: 'change', message: '请选择PK赛' }],
|
||||||
|
content: [{ required: true, trigger: 'blur', message: '请输入评论内容' }],
|
||||||
|
},
|
||||||
|
|
||||||
|
// 机器人列表
|
||||||
|
robotList: [],
|
||||||
|
robotQuery: { pageNo: 1, pageSize: 20, appId: '6a0d7dbe4c5de50f2ba66475' },
|
||||||
|
robotTotal: 0,
|
||||||
|
fetchingRobots: false,
|
||||||
|
|
||||||
|
// PK列表
|
||||||
|
pkList: [],
|
||||||
|
pkQuery: { pageNo: 1, pageSize: 20 },
|
||||||
|
pkTotal: 0,
|
||||||
|
fetchingPks: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getThumbUrl,
|
||||||
|
getPkLabel(item) {
|
||||||
|
if (!item) return ''
|
||||||
|
const left = item.leftItem ? item.leftItem.name : '未知'
|
||||||
|
const right = item.rightItem ? item.rightItem.name : '未知'
|
||||||
|
return `[${item.topic ? item.topic.title : '未知主题'}] ${left} vs ${right}`
|
||||||
|
},
|
||||||
|
showEdit(replyToRow = null, parentCommentId = null) {
|
||||||
|
this.dialogFormVisible = true
|
||||||
|
this.form = this.$options.data().form
|
||||||
|
|
||||||
|
if (replyToRow) {
|
||||||
|
this.isReply = true
|
||||||
|
this.title = '回复评论'
|
||||||
|
this.contentPlaceholder = `回复 @${replyToRow.user ? replyToRow.user.nickname : '未知用户'}:`
|
||||||
|
this.form.pkId = replyToRow.pkId
|
||||||
|
this.form.parentCommentId = parentCommentId || replyToRow.id
|
||||||
|
this.form.replyToCommentId = replyToRow.id
|
||||||
|
} else {
|
||||||
|
this.isReply = false
|
||||||
|
this.title = '立即评论'
|
||||||
|
this.contentPlaceholder = '请输入您的评论文字'
|
||||||
|
this.pkList = []
|
||||||
|
this.pkQuery.pageNo = 1
|
||||||
|
this.pkTotal = 0
|
||||||
|
this.fetchPkList()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.robotList = []
|
||||||
|
this.robotQuery.pageNo = 1
|
||||||
|
this.robotTotal = 0
|
||||||
|
this.fetchRobotList()
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$refs['form'].resetFields()
|
||||||
|
this.dialogFormVisible = false
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- 机器人列表加载 --
|
||||||
|
async fetchRobotList() {
|
||||||
|
if (this.fetchingRobots) return
|
||||||
|
this.fetchingRobots = true
|
||||||
|
try {
|
||||||
|
const { data } = await getRobotList(this.robotQuery)
|
||||||
|
this.robotList = this.robotList.concat(data.list || [])
|
||||||
|
this.robotTotal = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.fetchingRobots = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadMoreRobots() {
|
||||||
|
if (this.robotList.length >= this.robotTotal || this.fetchingRobots) return
|
||||||
|
this.robotQuery.pageNo += 1
|
||||||
|
this.fetchRobotList()
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- PK 列表加载 --
|
||||||
|
async fetchPkList() {
|
||||||
|
if (this.fetchingPks) return
|
||||||
|
this.fetchingPks = true
|
||||||
|
try {
|
||||||
|
const { data } = await getPkList(this.pkQuery)
|
||||||
|
this.pkList = this.pkList.concat(data.list || [])
|
||||||
|
this.pkTotal = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.fetchingPks = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadMorePks() {
|
||||||
|
if (this.pkList.length >= this.pkTotal || this.fetchingPks) return
|
||||||
|
this.pkQuery.pageNo += 1
|
||||||
|
this.fetchPkList()
|
||||||
|
},
|
||||||
|
|
||||||
|
save() {
|
||||||
|
this.$refs['form'].validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.saving = true
|
||||||
|
try {
|
||||||
|
const { msg } = await comment(this.form)
|
||||||
|
this.$baseMessage(msg || (this.isReply ? '回复成功' : '评论成功'), 'success')
|
||||||
|
this.close()
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.saving = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
134
src/views/rating/pk/comment/components/PkCommentLikeEdit.vue
Normal file
134
src/views/rating/pk/comment/components/PkCommentLikeEdit.vue
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px" @close="close">
|
||||||
|
<el-form ref="form" label-width="80px" :model="form" :rules="rules">
|
||||||
|
<el-form-item label="点赞用户" prop="userId">
|
||||||
|
<el-select v-model="form.userId" v-loadmore="loadMoreRobots" filterable placeholder="请选择执行点赞的机器人" style="width: 100%">
|
||||||
|
<el-option v-for="item in robotList" :key="item.id" :label="item.nickname || item.id" :value="item.id">
|
||||||
|
<div style="display: flex; align-items: center">
|
||||||
|
<el-image
|
||||||
|
v-if="item.avatar"
|
||||||
|
:src="getThumbUrl(item.avatar)"
|
||||||
|
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
|
||||||
|
/>
|
||||||
|
<span>{{ item.nickname || '未知用户' }}</span>
|
||||||
|
</div>
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button @click="close">取 消</el-button>
|
||||||
|
<el-button :loading="saving" type="primary" @click="save">确 定</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getListBase as getRobotList } from '@/api/system/robot'
|
||||||
|
import { like } from '@/api/rating/pk'
|
||||||
|
import { getThumbUrl } from '@/utils/blessing'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PkCommentLikeEdit',
|
||||||
|
directives: {
|
||||||
|
loadmore: {
|
||||||
|
bind(el, binding) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
|
||||||
|
if (SELECTWRAP_DOM) {
|
||||||
|
SELECTWRAP_DOM.addEventListener('scroll', function () {
|
||||||
|
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 2
|
||||||
|
if (condition) {
|
||||||
|
binding.value()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
title: '选择机器人点赞',
|
||||||
|
dialogFormVisible: false,
|
||||||
|
saving: false,
|
||||||
|
form: {
|
||||||
|
commentId: '',
|
||||||
|
userId: '',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
userId: [{ required: true, trigger: 'change', message: '请选择执行点赞的机器人' }],
|
||||||
|
},
|
||||||
|
|
||||||
|
// 机器人下拉列表状态
|
||||||
|
robotList: [],
|
||||||
|
robotQuery: {
|
||||||
|
appId: '6a0d7dbe4c5de50f2ba66475',
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 20,
|
||||||
|
commentId: '',
|
||||||
|
},
|
||||||
|
robotTotal: 0,
|
||||||
|
fetchingRobots: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getThumbUrl,
|
||||||
|
showEdit(row) {
|
||||||
|
this.title = '选择机器人点赞'
|
||||||
|
this.dialogFormVisible = true
|
||||||
|
this.form = this.$options.data().form
|
||||||
|
this.form.commentId = row.id
|
||||||
|
|
||||||
|
// 重置列表并加载第一页
|
||||||
|
this.robotList = []
|
||||||
|
this.robotQuery.pageNo = 1
|
||||||
|
this.robotQuery.commentId = row.id
|
||||||
|
this.robotTotal = 0
|
||||||
|
this.fetchRobotList()
|
||||||
|
},
|
||||||
|
close() {
|
||||||
|
this.$refs['form'].resetFields()
|
||||||
|
this.dialogFormVisible = false
|
||||||
|
},
|
||||||
|
async fetchRobotList() {
|
||||||
|
if (this.fetchingRobots) return
|
||||||
|
this.fetchingRobots = true
|
||||||
|
try {
|
||||||
|
const { data } = await getRobotList(this.robotQuery)
|
||||||
|
this.robotList = this.robotList.concat(data.list || [])
|
||||||
|
this.robotTotal = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.fetchingRobots = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadMoreRobots() {
|
||||||
|
if (this.robotList.length >= this.robotTotal || this.fetchingRobots) return
|
||||||
|
this.robotQuery.pageNo += 1
|
||||||
|
this.fetchRobotList()
|
||||||
|
},
|
||||||
|
save() {
|
||||||
|
this.$refs['form'].validate(async (valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.saving = true
|
||||||
|
try {
|
||||||
|
const { msg } = await like(this.form)
|
||||||
|
this.$baseMessage(msg || '点赞成功', 'success')
|
||||||
|
this.close()
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.saving = false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
376
src/views/rating/pk/comment/index.vue
Normal file
376
src/views/rating/pk/comment/index.vue
Normal file
@@ -0,0 +1,376 @@
|
|||||||
|
<template>
|
||||||
|
<div class="rating-pk-comment-container">
|
||||||
|
<vab-query-form>
|
||||||
|
<vab-query-form-left-panel :span="24">
|
||||||
|
<el-form :inline="true" :model="queryForm" @submit.native.prevent>
|
||||||
|
<el-form-item>
|
||||||
|
<el-select
|
||||||
|
v-model="queryForm.pkId"
|
||||||
|
v-loadmore="loadMorePks"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择PK赛"
|
||||||
|
style="width: 250px"
|
||||||
|
@change="handleFilterChange"
|
||||||
|
>
|
||||||
|
<el-option v-for="item in pkList" :key="item.id" :label="getPkLabel(item)" :value="item.id" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item>
|
||||||
|
<el-select v-model="queryForm.status" clearable placeholder="评论状态" @change="handleFilterChange">
|
||||||
|
<el-option label="待审/隐藏" :value="1" />
|
||||||
|
<el-option label="已展示" :value="2" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item>
|
||||||
|
<el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button icon="el-icon-edit" type="success" @click="handleCommentNow">立即评论</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</vab-query-form-left-panel>
|
||||||
|
</vab-query-form>
|
||||||
|
|
||||||
|
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
|
||||||
|
<el-table-column align="center" fixed="left" label="操作" width="160">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-button type="text" @click="handleLike(row)">点赞</el-button>
|
||||||
|
<el-button type="text" @click="handleReply(row)">回复</el-button>
|
||||||
|
<el-button v-if="row.replyCount > 0" type="text" @click="handleViewReplies(row)">查看回复</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="left" label="评论内容" min-width="250">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="comment-content-cell">
|
||||||
|
<div class="content-text">{{ row.content }}</div>
|
||||||
|
<div class="comment-meta">
|
||||||
|
<span class="meta-item">
|
||||||
|
<i class="el-icon-thumb" />
|
||||||
|
{{ row.likeCount || 0 }}
|
||||||
|
</span>
|
||||||
|
<span class="meta-item">
|
||||||
|
<i class="el-icon-chat-dot-square" />
|
||||||
|
{{ row.replyCount || 0 }}
|
||||||
|
</span>
|
||||||
|
<el-tag v-if="row.status === 2" size="mini" style="margin-left: 8px" type="success">已展示</el-tag>
|
||||||
|
<el-tag v-else size="mini" style="margin-left: 8px" type="info">隐藏/待审</el-tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="left" label="PK赛目标" min-width="250">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div v-if="row.pk" class="target-info-cell">
|
||||||
|
<div class="topic-title">[{{ row.pk.topic ? row.pk.topic.title : '未知主题' }}]</div>
|
||||||
|
<div class="item-info">
|
||||||
|
<span>{{ row.pk.leftItem ? row.pk.leftItem.name : '未知' }}</span>
|
||||||
|
<span style="margin: 0 8px; color: #f56c6c; font-weight: bold">VS</span>
|
||||||
|
<span>{{ row.pk.rightItem ? row.pk.rightItem.name : '未知' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else>{{ row.pkId }}</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="left" label="用户信息" min-width="200">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div v-if="row.user" class="user-info-cell">
|
||||||
|
<el-image
|
||||||
|
v-if="row.user.avatar"
|
||||||
|
class="user-avatar"
|
||||||
|
:preview-src-list="[row.user.avatar]"
|
||||||
|
:src="getThumbUrl(row.user.avatar)"
|
||||||
|
/>
|
||||||
|
<div v-else class="user-avatar-placeholder"><i class="el-icon-user" /></div>
|
||||||
|
<div class="user-details">
|
||||||
|
<div class="user-nickname">
|
||||||
|
{{ row.user.nickname || '未知用户' }}
|
||||||
|
<el-tag v-if="row.user.isRobot" size="mini" style="margin-left: 4px" type="info">机器人</el-tag>
|
||||||
|
<el-tag v-else size="mini" style="margin-left: 4px" type="success">真人</el-tag>
|
||||||
|
</div>
|
||||||
|
<div class="user-id">{{ row.user.id }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else class="user-details">
|
||||||
|
<div class="user-id">{{ row.userId }}</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="状态切换" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-switch v-model="row.enable" :active-value="true" :inactive-value="false" @change="handleToggleStatus(row)" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="评论时间" prop="createdAt" width="160">
|
||||||
|
<template #default="{ row }">
|
||||||
|
{{ formatTime(row.createdAt) }}
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
:current-page="queryForm.pageNo"
|
||||||
|
:layout="layout"
|
||||||
|
:page-size="queryForm.pageSize"
|
||||||
|
:total="total"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<pk-comment-edit ref="commentEdit" @fetch-data="fetchData" />
|
||||||
|
<pk-comment-like-edit ref="likeEdit" @fetch-data="fetchData" />
|
||||||
|
<comment-reply-list ref="replyList" @like="handleLikeFromList" @reply="handleReplyFromList" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getCommentList, toggleEnable, getList as getPkList } from '@/api/rating/pk'
|
||||||
|
import { formatTime } from '@/utils'
|
||||||
|
import { getThumbUrl } from '@/utils/blessing'
|
||||||
|
import PkCommentEdit from './components/PkCommentEdit'
|
||||||
|
import PkCommentLikeEdit from './components/PkCommentLikeEdit'
|
||||||
|
import CommentReplyList from './components/CommentReplyList'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PkComment',
|
||||||
|
components: { PkCommentEdit, PkCommentLikeEdit, CommentReplyList },
|
||||||
|
directives: {
|
||||||
|
loadmore: {
|
||||||
|
bind(el, binding) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
|
||||||
|
if (SELECTWRAP_DOM) {
|
||||||
|
SELECTWRAP_DOM.addEventListener('scroll', function () {
|
||||||
|
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight + 2
|
||||||
|
if (condition) {
|
||||||
|
binding.value()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
listLoading: true,
|
||||||
|
layout: 'total, sizes, prev, pager, next, jumper',
|
||||||
|
total: 0,
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
pkId: '',
|
||||||
|
status: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
// PK下拉列表状态
|
||||||
|
pkList: [],
|
||||||
|
pkQuery: { pageNo: 1, pageSize: 20 },
|
||||||
|
pkTotal: 0,
|
||||||
|
fetchingPks: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchPkList()
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
formatTime,
|
||||||
|
getThumbUrl,
|
||||||
|
getPkLabel(item) {
|
||||||
|
if (!item) return ''
|
||||||
|
const left = item.leftItem ? item.leftItem.name : '未知'
|
||||||
|
const right = item.rightItem ? item.rightItem.name : '未知'
|
||||||
|
return `[${item.topic ? item.topic.title : '未知主题'}] ${left} vs ${right}`
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- PK 列表加载 --
|
||||||
|
async fetchPkList() {
|
||||||
|
if (this.fetchingPks) return
|
||||||
|
this.fetchingPks = true
|
||||||
|
try {
|
||||||
|
const { data } = await getPkList(this.pkQuery)
|
||||||
|
this.pkList = this.pkList.concat(data.list || [])
|
||||||
|
this.pkTotal = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.fetchingPks = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
loadMorePks() {
|
||||||
|
if (this.pkList.length >= this.pkTotal || this.fetchingPks) return
|
||||||
|
this.pkQuery.pageNo += 1
|
||||||
|
this.fetchPkList()
|
||||||
|
},
|
||||||
|
|
||||||
|
handleFilterChange() {
|
||||||
|
this.queryForm.pageNo = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleSizeChange(val) {
|
||||||
|
this.queryForm.pageSize = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleCurrentChange(val) {
|
||||||
|
this.queryForm.pageNo = val
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
queryData() {
|
||||||
|
this.queryForm.pageNo = 1
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
async fetchData() {
|
||||||
|
this.listLoading = true
|
||||||
|
try {
|
||||||
|
const params = { ...this.queryForm }
|
||||||
|
if (params.pkId === '') delete params.pkId
|
||||||
|
if (params.status === '') delete params.status
|
||||||
|
|
||||||
|
const { data } = await getCommentList(params)
|
||||||
|
this.list = data.list || []
|
||||||
|
this.total = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.listLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleCommentNow() {
|
||||||
|
this.$refs['commentEdit'].showEdit()
|
||||||
|
},
|
||||||
|
handleLike(row) {
|
||||||
|
this.$refs['likeEdit'].showEdit(row)
|
||||||
|
},
|
||||||
|
handleReply(row) {
|
||||||
|
this.$refs['commentEdit'].showEdit(row)
|
||||||
|
},
|
||||||
|
handleViewReplies(row) {
|
||||||
|
this.$refs['replyList'].show(row)
|
||||||
|
},
|
||||||
|
async handleToggleStatus(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await toggleEnable({ id: row.id, enable: row.enable })
|
||||||
|
this.$baseMessage(msg || '状态切换成功', 'success')
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
row.enable = !row.enable
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 子组件触发的方法
|
||||||
|
handleReplyFromList(row, parentCommentId) {
|
||||||
|
this.$refs['commentEdit'].showEdit(row, parentCommentId)
|
||||||
|
},
|
||||||
|
handleLikeFromList(row) {
|
||||||
|
this.$refs['likeEdit'].showEdit(row)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.rating-pk-comment-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-content-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-text {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #303133;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment-meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item i {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.target-info-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-title {
|
||||||
|
font-size: 13px;
|
||||||
|
color: #909399;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.item-info {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-info-cell {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-avatar,
|
||||||
|
.user-avatar-placeholder {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 12px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-avatar-placeholder {
|
||||||
|
background-color: #f0f2f5;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-details {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-nickname {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #303133;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user-id {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user