fix: rating
This commit is contained in:
@@ -12,3 +12,43 @@ export function getList(data) {
|
||||
params: data,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换话题分类状态
|
||||
* @param {*} id
|
||||
* @param {*} enable
|
||||
* @returns
|
||||
*/
|
||||
export function toggleEnable(id, enable) {
|
||||
return request({
|
||||
url: `/management/api/rating/topic_category/toggle/${id}`,
|
||||
method: 'patch',
|
||||
data: { enable },
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动话题分类
|
||||
* @param {*} id
|
||||
* @param {*} to
|
||||
* @returns
|
||||
*/
|
||||
export function moveTo(id, to) {
|
||||
return request({
|
||||
url: `/management/api/rating/topic_category/move_to/${id}`,
|
||||
method: 'patch',
|
||||
data: { to },
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 编辑话题分类
|
||||
* @param {*} id
|
||||
* @returns
|
||||
*/
|
||||
export function doEdit(id, data) {
|
||||
return request({
|
||||
url: `/management/api/rating/topic_category/${id}`,
|
||||
method: 'put',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -79,6 +79,12 @@ export const asyncRoutes = [
|
||||
component: () => import('@/views/rating/topicCommentRecord/index'),
|
||||
meta: { title: '用户评论记录' },
|
||||
},
|
||||
{
|
||||
path: 'topic-category',
|
||||
name: 'RatingTopicCategoryIndex',
|
||||
component: () => import('@/views/rating/topicCategory/index'),
|
||||
meta: { title: '评分话题分类' },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<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="title">
|
||||
<el-input v-model.trim="form.title" placeholder="请输入分类名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model="form.sort" :min="0" placeholder="数字越大越靠前" />
|
||||
</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 { doEdit } from '@/api/rating/topicCategory'
|
||||
|
||||
export default {
|
||||
name: 'TopicCategoryEdit',
|
||||
data() {
|
||||
return {
|
||||
title: '编辑话题分类',
|
||||
dialogFormVisible: false,
|
||||
saving: false,
|
||||
form: {
|
||||
title: '',
|
||||
sort: 0,
|
||||
},
|
||||
rules: {
|
||||
title: [{ required: true, trigger: 'blur', message: '请输入分类名称' }],
|
||||
},
|
||||
id: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showEdit(row) {
|
||||
if (!row) {
|
||||
// 当前接口似乎只提供了编辑,如果需要新增可在此扩展
|
||||
this.title = '添加话题分类'
|
||||
this.id = ''
|
||||
this.form = this.$options.data().form
|
||||
} else {
|
||||
this.title = '编辑话题分类'
|
||||
this.id = row.id
|
||||
this.form = {
|
||||
title: row.title || '',
|
||||
sort: row.sort || 0,
|
||||
}
|
||||
}
|
||||
this.dialogFormVisible = true
|
||||
},
|
||||
close() {
|
||||
this.$refs['form'].resetFields()
|
||||
this.form = this.$options.data().form
|
||||
this.id = ''
|
||||
this.saving = false
|
||||
this.dialogFormVisible = false
|
||||
},
|
||||
save() {
|
||||
this.$refs['form'].validate(async (valid) => {
|
||||
if (valid) {
|
||||
this.saving = true
|
||||
try {
|
||||
if (this.id) {
|
||||
const { msg } = await doEdit(this.id, this.form)
|
||||
this.$baseMessage(msg || '编辑成功', 'success')
|
||||
}
|
||||
this.$emit('fetch-data')
|
||||
this.close()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.saving = false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
141
src/views/rating/topicCategory/index.vue
Normal file
141
src/views/rating/topicCategory/index.vue
Normal file
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div class="topic-category-container">
|
||||
<vab-query-form>
|
||||
<vab-query-form-right-panel :span="24">
|
||||
<el-form :inline="true" :model="queryForm" @submit.native.prevent>
|
||||
<el-form-item>
|
||||
<el-input v-model.trim="queryForm.keyword" clearable placeholder="请输入分类名称" />
|
||||
</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" prop="title" width="100" />
|
||||
<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-column align="center" label="操作" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-button type="text" @click="handleEdit(row)">编辑</el-button>
|
||||
</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-category-edit ref="edit" @fetch-data="fetchData" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getList, toggleEnable, moveTo } from '@/api/rating/topicCategory'
|
||||
import { formatTime } from '@/utils'
|
||||
import TopicCategoryEdit from './components/TopicCategoryEdit'
|
||||
|
||||
export default {
|
||||
name: 'RatingTopicCategoryIndex',
|
||||
components: { TopicCategoryEdit },
|
||||
data() {
|
||||
return {
|
||||
list: [],
|
||||
listLoading: true,
|
||||
layout: 'total, sizes, prev, pager, next, jumper',
|
||||
total: 0,
|
||||
elementLoadingText: '正在加载...',
|
||||
queryForm: {
|
||||
pageNo: 1,
|
||||
pageSize: 20,
|
||||
keyword: '',
|
||||
},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.fetchData()
|
||||
},
|
||||
methods: {
|
||||
formatTime,
|
||||
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 { data } = await getList(this.queryForm)
|
||||
this.list = data.list
|
||||
this.total = data.totalCount
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
this.listLoading = false
|
||||
}
|
||||
},
|
||||
handleEdit(row) {
|
||||
this.$refs['edit'].showEdit(row)
|
||||
},
|
||||
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-category-container {
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user