feat: rating

This commit is contained in:
zzc
2026-06-10 01:38:55 +08:00
parent 993b5f8eef
commit d44f88b124
6 changed files with 598 additions and 0 deletions

25
src/api/rating/pk.js Normal file
View File

@@ -0,0 +1,25 @@
import request from '@/utils/request'
/**
* 获取PK赛列表
* @param {pageNo: number, pageSize: number, topicId?: string, itemId?: string} data
*/
export function getList(data) {
return request({
url: 'management/api/rating/pk/list',
method: 'get',
params: data,
})
}
/**
* 生成PK赛
* @param {topicId: string, leftItemId: string, rightItemId: string} data
*/
export function generate(data) {
return request({
url: 'management/api/rating/pk/generate',
method: 'post',
data,
})
}

View File

@@ -85,6 +85,32 @@ export const asyncRoutes = [
component: () => import('@/views/rating/topicCategory/index'),
meta: { title: '评分话题分类' },
},
{
path: 'pk',
component: EmptyLayout,
alwaysShow: true,
redirect: 'noRedirect',
name: 'PkIndex',
meta: {
title: 'PK赛',
icon: 'clover',
permissions: ['admin'],
},
children: [
{
path: 'list',
name: 'List',
component: () => import('@/views/rating/pk/list/index'),
meta: { title: 'PK赛列表', icon: 'setting' },
},
{
path: 'pkRecord',
name: 'PkRecord',
component: () => import('@/views/rating/pk/record/index'),
meta: { title: 'PK赛记录', icon: 'setting' },
},
],
},
{
path: 'topic-review',
name: 'RatingTopicReviewIndex',

View File

@@ -27,6 +27,7 @@ export const eventTypeMap = {
export const appMap = {
'69665538a49b8ae3be50fe5d': '新春祝福',
'6a0d7dbe4c5de50f2ba66475': '夯拉评',
}
export const userMap = {

View File

@@ -0,0 +1,210 @@
<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="topicId">
<el-select
v-model="form.topicId"
v-loadmore="loadMoreTopics"
filterable
placeholder="请选择评价主题"
style="width: 100%"
@change="handleTopicChange"
>
<el-option v-for="item in topicList" :key="item.id" :label="item.title" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="评价项" prop="itemIds">
<el-select
v-model="form.itemIds"
v-loadmore="loadMoreItems"
:disabled="!form.topicId"
filterable
multiple
:multiple-limit="2"
placeholder="请选择两个评价项进行PK"
style="width: 100%"
>
<el-option v-for="item in itemList" :key="item.id" :label="item.name" :value="item.id">
<div style="display: flex; align-items: center">
<el-image
v-if="item.avatarUrl"
:src="getThumbUrl(item.avatarUrl)"
style="width: 24px; height: 24px; border-radius: 50%; margin-right: 10px"
/>
<span>{{ item.name }}</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 { getList as getTopicList } from '@/api/rating/topic'
import { getList as getItemList } from '@/api/rating/topicItem'
import { generate } from '@/api/rating/pk'
import { getThumbUrl } from '@/utils/blessing'
export default {
name: 'PkGenerate',
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() {
const validateItemIds = (rule, value, callback) => {
if (!value || value.length !== 2) {
callback(new Error('请必须选择两个评价项进行PK'))
} else {
callback()
}
}
return {
title: '生成PK赛',
dialogFormVisible: false,
saving: false,
form: {
topicId: '',
itemIds: [],
},
rules: {
topicId: [{ required: true, trigger: 'change', message: '请选择评价主题' }],
itemIds: [{ required: true, trigger: 'change', validator: validateItemIds }],
},
topicList: [],
topicQuery: {
pageNo: 1,
pageSize: 20,
},
topicTotal: 0,
fetchingTopics: false,
itemList: [],
itemQuery: {
pageNo: 1,
pageSize: 20,
topicId: '',
},
itemTotal: 0,
fetchingItems: false,
}
},
methods: {
getThumbUrl,
showEdit() {
this.title = '生成PK赛'
this.form = this.$options.data().form
this.dialogFormVisible = true
this.topicQuery.pageNo = 1
this.topicList = []
this.topicTotal = 0
this.fetchTopicList()
},
close() {
this.$refs['form'].resetFields()
this.form = this.$options.data().form
this.itemList = []
this.dialogFormVisible = false
},
// -- Topic 列表加载 --
async fetchTopicList() {
if (this.fetchingTopics) return
this.fetchingTopics = true
try {
const { data } = await getTopicList(this.topicQuery)
this.topicList = this.topicList.concat(data.list || [])
this.topicTotal = data.totalCount || 0
} catch (error) {
console.error(error)
} finally {
this.fetchingTopics = false
}
},
loadMoreTopics() {
if (this.topicList.length >= this.topicTotal || this.fetchingTopics) return
this.topicQuery.pageNo += 1
this.fetchTopicList()
},
// -- Item 列表加载 --
async fetchItemList() {
if (this.fetchingItems || !this.itemQuery.topicId) return
this.fetchingItems = true
try {
const { data } = await getItemList(this.itemQuery)
this.itemList = this.itemList.concat(data.list || [])
this.itemTotal = data.totalCount || 0
} catch (error) {
console.error(error)
} finally {
this.fetchingItems = false
}
},
loadMoreItems() {
if (this.itemList.length >= this.itemTotal || this.fetchingItems) return
this.itemQuery.pageNo += 1
this.fetchItemList()
},
handleTopicChange(val) {
this.form.itemIds = []
this.itemList = []
this.itemQuery.pageNo = 1
this.itemTotal = 0
if (val) {
this.itemQuery.topicId = val
this.fetchItemList()
} else {
this.itemQuery.topicId = ''
}
},
save() {
this.$refs['form'].validate(async (valid) => {
if (valid) {
this.saving = true
try {
const payload = {
topicId: this.form.topicId,
leftItemId: this.form.itemIds[0],
rightItemId: this.form.itemIds[1],
}
const { msg } = await generate(payload)
this.$baseMessage(msg || '生成PK赛成功', 'success')
this.close()
this.$emit('fetch-data')
} catch (error) {
console.error(error)
} finally {
this.saving = false
}
} else {
return false
}
})
},
},
}
</script>

View File

@@ -0,0 +1,336 @@
<template>
<div class="rating-pk-list-container">
<vab-query-form>
<vab-query-form-left-panel :span="12">
<el-button icon="el-icon-magic-stick" type="primary" @click="handleGenerate">生成PK</el-button>
</vab-query-form-left-panel>
<vab-query-form-right-panel :span="12">
<el-form :inline="true" :model="queryForm" @submit.native.prevent>
<el-form-item>
<el-select
v-model="queryForm.topicId"
v-loadmore="loadMoreTopics"
clearable
filterable
placeholder="请选择评价主题"
@change="handleTopicFilterChange"
>
<el-option v-for="item in topicList" :key="item.id" :label="item.title" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item>
<el-select
v-model="queryForm.itemId"
v-loadmore="loadMoreItems"
clearable
:disabled="!queryForm.topicId"
filterable
placeholder="请选择评价项"
>
<el-option v-for="item in itemList" :key="item.id" :label="item.name" :value="item.id" />
</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>
</vab-query-form-right-panel>
</vab-query-form>
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
<el-table-column align="center" label="所属主题" min-width="150" width="150">
<template #default="{ row }">
{{ row.topicTitle ? row.topicTitle : '-' }}
</template>
</el-table-column>
<el-table-column align="center" label="PK 双方" min-width="400" width="400">
<template #default="{ row }">
<div class="pk-sides">
<div class="pk-item pk-left">
<el-image v-if="row.leftItemName && row.leftItemAvatar" class="pk-avatar" :src="getThumbUrl(row.leftItemAvatar)" />
<span class="pk-name">{{ row.leftItemName ? row.leftItemName : '-' }}</span>
<div class="pk-stats">
<span class="pk-vote">{{ row.leftVoteCount || 0 }} </span>
<span class="pk-rate">({{ calculateRate(row.leftVoteCount, row.voteCount) }})</span>
</div>
</div>
<div class="pk-vs-wrapper">
<div class="pk-vs">VS</div>
<div class="pk-total-vote">总票数: {{ row.voteCount || 0 }}</div>
</div>
<div class="pk-item pk-right">
<el-image v-if="row.rightItemName && row.rightItemAvatar" class="pk-avatar" :src="getThumbUrl(row.rightItemAvatar)" />
<span class="pk-name">{{ row.rightItemName ? row.rightItemName : '-' }}</span>
<div class="pk-stats">
<span class="pk-vote">{{ row.rightVoteCount || 0 }} </span>
<span class="pk-rate">({{ calculateRate(row.rightVoteCount, row.voteCount) }})</span>
</div>
</div>
</div>
</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-generate ref="generate" @fetch-data="fetchData" />
</div>
</template>
<script>
import { getList } from '@/api/rating/pk'
import { getList as getTopicList } from '@/api/rating/topic'
import { getList as getItemList } from '@/api/rating/topicItem'
import { formatTime } from '@/utils'
import { getThumbUrl } from '@/utils/blessing'
import PkGenerate from './components/PkGenerate'
export default {
name: 'RatingPkListIndex',
components: { PkGenerate },
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,
topicId: '',
itemId: '',
},
topicList: [],
topicQuery: {
pageNo: 1,
pageSize: 20,
},
topicTotal: 0,
fetchingTopics: false,
itemList: [],
itemQuery: {
pageNo: 1,
pageSize: 20,
topicId: '',
},
itemTotal: 0,
fetchingItems: false,
}
},
created() {
this.fetchData()
this.fetchTopicList()
},
methods: {
formatTime,
getThumbUrl,
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 = {
pageNo: this.queryForm.pageNo,
pageSize: this.queryForm.pageSize,
}
if (this.queryForm.topicId) params.topicId = this.queryForm.topicId
if (this.queryForm.itemId) params.itemId = this.queryForm.itemId
const { data } = await getList(params)
this.list = data.list
this.total = data.totalCount
} catch (error) {
console.error(error)
} finally {
this.listLoading = false
}
},
handleGenerate() {
this.$refs['generate'].showEdit()
},
// -- Topic 列表加载 --
async fetchTopicList() {
if (this.fetchingTopics) return
this.fetchingTopics = true
try {
const { data } = await getTopicList(this.topicQuery)
this.topicList = this.topicList.concat(data.list || [])
this.topicTotal = data.totalCount || 0
} catch (error) {
console.error(error)
} finally {
this.fetchingTopics = false
}
},
loadMoreTopics() {
if (this.topicList.length >= this.topicTotal || this.fetchingTopics) return
this.topicQuery.pageNo += 1
this.fetchTopicList()
},
// -- Item 列表加载 --
async fetchItemList() {
if (this.fetchingItems || !this.itemQuery.topicId) return
this.fetchingItems = true
try {
const { data } = await getItemList(this.itemQuery)
this.itemList = this.itemList.concat(data.list || [])
this.itemTotal = data.totalCount || 0
} catch (error) {
console.error(error)
} finally {
this.fetchingItems = false
}
},
loadMoreItems() {
if (this.itemList.length >= this.itemTotal || this.fetchingItems) return
this.itemQuery.pageNo += 1
this.fetchItemList()
},
handleTopicFilterChange(val) {
this.queryForm.itemId = ''
this.itemList = []
this.itemQuery.pageNo = 1
this.itemTotal = 0
if (val) {
this.itemQuery.topicId = val
this.fetchItemList()
} else {
this.itemQuery.topicId = ''
}
this.queryData()
},
calculateRate(count, total) {
if (!total || total === 0) return '0%'
const rate = ((count || 0) / total) * 100
return `${rate.toFixed(1)}%`
},
},
}
</script>
<style scoped>
.rating-pk-list-container {
padding: 20px;
}
.pk-sides {
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
}
.pk-item {
display: flex;
flex-direction: column;
align-items: center;
width: 120px;
}
.pk-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
margin-bottom: 5px;
}
.pk-name {
font-size: 13px;
color: #303133;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
margin-bottom: 4px;
}
.pk-stats {
display: flex;
flex-direction: column;
align-items: center;
font-size: 12px;
}
.pk-vote {
color: #409eff;
font-weight: bold;
}
.pk-rate {
color: #909399;
}
.pk-vs-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-width: 80px;
}
.pk-vs {
font-size: 18px;
font-weight: bold;
color: #f56c6c;
font-style: italic;
margin-bottom: 4px;
}
.pk-total-vote {
font-size: 12px;
color: #909399;
background-color: #f4f4f5;
padding: 2px 6px;
border-radius: 10px;
}
</style>

View File