feat: rating

This commit is contained in:
zzc
2026-06-14 23:11:04 +08:00
parent e032412adf
commit 2d84ee213c
4 changed files with 378 additions and 0 deletions

View 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,
})
}

View File

@@ -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',

View 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>

View 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>