Compare commits
3 Commits
790a2658d5
...
2d84ee213c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d84ee213c | ||
|
|
e032412adf | ||
|
|
d44f88b124 |
25
src/api/rating/pk.js
Normal file
25
src/api/rating/pk.js
Normal 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,
|
||||||
|
})
|
||||||
|
}
|
||||||
67
src/api/rating/topicRecommend.js
Normal file
67
src/api/rating/topicRecommend.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取话题推荐列表
|
||||||
|
* @param {*} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function getList(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/topic_recommend/list',
|
||||||
|
method: 'get',
|
||||||
|
params: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加话题推荐
|
||||||
|
* @param {{ topicId: string }} data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function doAdd(data) {
|
||||||
|
return request({
|
||||||
|
url: 'management/api/rating/topic_recommend',
|
||||||
|
method: 'post',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切换话题推荐状态
|
||||||
|
* @param {*} id
|
||||||
|
* @param {*} enable
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function toggleEnable(id, enable) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/rating/topic_recommend/toggle/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
data: { enable },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动话题推荐
|
||||||
|
* @param {*} id
|
||||||
|
* @param {*} to
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function moveTo(id, to) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/rating/topic_recommend/move_to/${id}`,
|
||||||
|
method: 'patch',
|
||||||
|
data: { to },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 编辑话题推荐
|
||||||
|
* @param {*} id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function doEdit(id, data) {
|
||||||
|
return request({
|
||||||
|
url: `/management/api/rating/topic_recommend/${id}`,
|
||||||
|
method: 'put',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -61,6 +61,12 @@ export const asyncRoutes = [
|
|||||||
component: () => import('@/views/rating/topic/index'),
|
component: () => import('@/views/rating/topic/index'),
|
||||||
meta: { title: '评分话题' },
|
meta: { title: '评分话题' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'topic-recommend',
|
||||||
|
name: 'RatingTopicRecommendIndex',
|
||||||
|
component: () => import('@/views/rating/topicRecommend/index'),
|
||||||
|
meta: { title: '话题推荐' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'topic-item',
|
path: 'topic-item',
|
||||||
name: 'RatingTopicItemIndex',
|
name: 'RatingTopicItemIndex',
|
||||||
@@ -85,6 +91,32 @@ export const asyncRoutes = [
|
|||||||
component: () => import('@/views/rating/topicCategory/index'),
|
component: () => import('@/views/rating/topicCategory/index'),
|
||||||
meta: { title: '评分话题分类' },
|
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',
|
path: 'topic-review',
|
||||||
name: 'RatingTopicReviewIndex',
|
name: 'RatingTopicReviewIndex',
|
||||||
|
|||||||
210
src/views/rating/pk/list/components/PkGenerate.vue
Normal file
210
src/views/rating/pk/list/components/PkGenerate.vue
Normal 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>
|
||||||
336
src/views/rating/pk/list/index.vue
Normal file
336
src/views/rating/pk/list/index.vue
Normal 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>
|
||||||
0
src/views/rating/pk/record/index.vue
Normal file
0
src/views/rating/pk/record/index.vue
Normal file
143
src/views/rating/topicRecommend/components/TopicRecommendAdd.vue
Normal file
143
src/views/rating/topicRecommend/components/TopicRecommendAdd.vue
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog :title="title" :visible.sync="dialogFormVisible" width="560px" @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="请选择推荐话题"
|
||||||
|
:popper-append-to-body="false"
|
||||||
|
style="width: 100%"
|
||||||
|
>
|
||||||
|
<el-option v-for="item in topicList" :key="item.id" :label="item.title" :value="item.id">
|
||||||
|
<div class="topic-option">
|
||||||
|
<span class="topic-option-title">{{ item.title }}</span>
|
||||||
|
<el-tag v-if="item.status === 2" size="mini" type="success">已通过</el-tag>
|
||||||
|
<el-tag v-else-if="item.status === 1" size="mini" type="warning">审核中</el-tag>
|
||||||
|
<el-tag v-else-if="item.status === 3" size="mini" type="danger">已拒绝</el-tag>
|
||||||
|
<el-tag v-else-if="item.status === 4" size="mini" type="info">禁用</el-tag>
|
||||||
|
</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 { doAdd } from '@/api/rating/topicRecommend'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'TopicRecommendAdd',
|
||||||
|
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: {
|
||||||
|
topicId: '',
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
topicId: [{ required: true, trigger: 'change', message: '请选择推荐话题' }],
|
||||||
|
},
|
||||||
|
topicList: [],
|
||||||
|
topicQuery: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 20,
|
||||||
|
type: 'recommend',
|
||||||
|
},
|
||||||
|
topicTotal: 0,
|
||||||
|
fetchingTopics: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
showEdit() {
|
||||||
|
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.dialogFormVisible = false
|
||||||
|
this.saving = false
|
||||||
|
},
|
||||||
|
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()
|
||||||
|
},
|
||||||
|
save() {
|
||||||
|
this.$refs['form'].validate(async (valid) => {
|
||||||
|
if (!valid) return false
|
||||||
|
this.saving = true
|
||||||
|
try {
|
||||||
|
const { msg } = await doAdd(this.form)
|
||||||
|
this.$baseMessage(msg || '添加推荐成功', 'success')
|
||||||
|
this.$emit('fetch-data')
|
||||||
|
this.close()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.saving = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.topic-option {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-option-title {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
162
src/views/rating/topicRecommend/index.vue
Normal file
162
src/views/rating/topicRecommend/index.vue
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
<template>
|
||||||
|
<div class="topic-recommend-container">
|
||||||
|
<vab-query-form>
|
||||||
|
<vab-query-form-left-panel :span="12">
|
||||||
|
<el-button icon="el-icon-plus" type="primary" @click="handleAdd">添加推荐</el-button>
|
||||||
|
</vab-query-form-left-panel>
|
||||||
|
</vab-query-form>
|
||||||
|
|
||||||
|
<el-table v-loading="listLoading" :data="list" :element-loading-text="elementLoadingText">
|
||||||
|
<el-table-column align="left" label="推荐话题" min-width="220" width="220">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<div class="topic-cell">
|
||||||
|
<div class="topic-title">{{ row.topic ? row.topic.title : '-' }}</div>
|
||||||
|
<div class="topic-meta">
|
||||||
|
<span class="meta-label">Topic ID:</span>
|
||||||
|
<span>{{ row.topicId }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="话题状态" width="100">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag v-if="row.topic && row.topic.status === 1" type="warning">审核中</el-tag>
|
||||||
|
<el-tag v-else-if="row.topic && row.topic.status === 2" type="success">已通过</el-tag>
|
||||||
|
<el-tag v-else-if="row.topic && row.topic.status === 3" type="danger">已拒绝</el-tag>
|
||||||
|
<el-tag v-else-if="row.topic && row.topic.status === 4" type="info">禁用</el-tag>
|
||||||
|
<span v-else>-</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column align="center" label="排序" prop="sort" width="120">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-input v-model="row.sort" placeholder="排序" size="mini" @blur="handleMove(row)" @keyup.enter.native="handleMove(row)" />
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<el-pagination
|
||||||
|
background
|
||||||
|
:current-page="queryForm.pageNo"
|
||||||
|
:layout="layout"
|
||||||
|
:page-size="queryForm.pageSize"
|
||||||
|
:total="total"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<topic-recommend-add ref="add" @fetch-data="fetchData" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getList, toggleEnable, moveTo } from '@/api/rating/topicRecommend'
|
||||||
|
import TopicRecommendAdd from './components/TopicRecommendAdd'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'RatingTopicRecommendIndex',
|
||||||
|
components: { TopicRecommendAdd },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
list: [],
|
||||||
|
listLoading: true,
|
||||||
|
layout: 'total, sizes, prev, pager, next, jumper',
|
||||||
|
total: 0,
|
||||||
|
elementLoadingText: '正在加载...',
|
||||||
|
queryForm: {
|
||||||
|
pageNo: 1,
|
||||||
|
pageSize: 20,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleAdd() {
|
||||||
|
this.$refs['add'].showEdit()
|
||||||
|
},
|
||||||
|
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 getList(this.queryForm)
|
||||||
|
this.list = data.list || []
|
||||||
|
this.total = data.totalCount || 0
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
this.listLoading = false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleToggleStatus(row) {
|
||||||
|
try {
|
||||||
|
const { msg } = await toggleEnable(row.id, row.enable)
|
||||||
|
this.$baseMessage(msg || '状态切换成功', 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
row.enable = !row.enable
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleMove(row) {
|
||||||
|
const sortVal = Number(row.sort)
|
||||||
|
if (isNaN(sortVal)) {
|
||||||
|
this.$message.error('排序必须是数字')
|
||||||
|
this.fetchData()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { msg } = await moveTo(row.id, sortVal)
|
||||||
|
this.$baseMessage(msg || '移动成功', 'success')
|
||||||
|
this.fetchData()
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
this.fetchData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.topic-recommend-container {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-cell {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-title {
|
||||||
|
color: #303133;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topic-meta {
|
||||||
|
color: #909399;
|
||||||
|
font-size: 12px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-label {
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user