feat: add community post categories and channels
This commit is contained in:
@@ -25,6 +25,21 @@ export function communityPostSetHot(params: any) {
|
||||
return request.post({ url: '/community.communityPost/setHot', params })
|
||||
}
|
||||
|
||||
// 帖子设推荐
|
||||
export function communityPostSetRecommend(params: any) {
|
||||
return request.post({ url: '/community.communityPost/setRecommend', params })
|
||||
}
|
||||
|
||||
// 帖子设话题
|
||||
export function communityPostSetTopic(params: any) {
|
||||
return request.post({ url: '/community.communityPost/setTopic', params })
|
||||
}
|
||||
|
||||
// 帖子设置分类
|
||||
export function communityPostSetCategory(params: any) {
|
||||
return request.post({ url: '/community.communityPost/setCategory', params })
|
||||
}
|
||||
|
||||
// 删除帖子
|
||||
export function communityPostDelete(params: any) {
|
||||
return request.post({ url: '/community.communityPost/delete', params })
|
||||
@@ -60,6 +75,36 @@ export function communityTagDetail(params: any) {
|
||||
return request.get({ url: '/community.communityTag/detail', params })
|
||||
}
|
||||
|
||||
// 帖子分类列表
|
||||
export function communityCategoryLists(params?: any) {
|
||||
return request.get({ url: '/community.communityCategory/lists', params })
|
||||
}
|
||||
|
||||
// 全部帖子分类
|
||||
export function communityCategoryAll(params?: any) {
|
||||
return request.get({ url: '/community.communityCategory/all', params })
|
||||
}
|
||||
|
||||
// 帖子分类详情
|
||||
export function communityCategoryDetail(params: any) {
|
||||
return request.get({ url: '/community.communityCategory/detail', params })
|
||||
}
|
||||
|
||||
// 新增帖子分类
|
||||
export function communityCategoryAdd(params: any) {
|
||||
return request.post({ url: '/community.communityCategory/add', params })
|
||||
}
|
||||
|
||||
// 编辑帖子分类
|
||||
export function communityCategoryEdit(params: any) {
|
||||
return request.post({ url: '/community.communityCategory/edit', params })
|
||||
}
|
||||
|
||||
// 删除帖子分类
|
||||
export function communityCategoryDelete(params: any) {
|
||||
return request.post({ url: '/community.communityCategory/delete', params })
|
||||
}
|
||||
|
||||
// 评论列表
|
||||
export function communityCommentLists(params?: any) {
|
||||
return request.get({ url: '/community.communityComment/lists', params })
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<template>
|
||||
<div class="community-category">
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
|
||||
<el-form-item class="w-[280px]" label="分类名称">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="输入分类名称"
|
||||
clearable
|
||||
@keyup.enter="resetPage"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[220px]" label="分类状态">
|
||||
<el-select v-model="queryParams.status" clearable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||
<el-button @click="resetParams">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="!border-none mt-4" shadow="never">
|
||||
<el-button
|
||||
v-perms="['community.communityCategory/add']"
|
||||
type="primary"
|
||||
class="mb-4"
|
||||
@click="handleAdd"
|
||||
>
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增分类
|
||||
</el-button>
|
||||
|
||||
<el-table size="large" v-loading="pager.loading" :data="pager.lists">
|
||||
<el-table-column label="ID" prop="id" min-width="60" />
|
||||
<el-table-column label="分类名称" prop="name" min-width="140" />
|
||||
<el-table-column label="图标" min-width="80">
|
||||
<template #default="{ row }">
|
||||
<el-avatar v-if="row.icon" :src="row.icon" :size="36" shape="square" />
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="帖子数" prop="post_count" min-width="80" />
|
||||
<el-table-column label="排序" prop="sort" min-width="80" />
|
||||
<el-table-column label="状态" min-width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.status === 1" type="success">启用</el-tag>
|
||||
<el-tag v-else type="danger">禁用</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="150" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['community.communityCategory/edit']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['community.communityCategory/delete']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="showEdit" :title="editData.id ? '编辑分类' : '新增分类'" width="500px">
|
||||
<el-form ref="editFormRef" :model="editData" :rules="editRules" label-width="80px">
|
||||
<el-form-item label="分类名称" prop="name">
|
||||
<el-input v-model="editData.name" placeholder="请输入分类名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类图标" prop="icon">
|
||||
<div>
|
||||
<material-picker v-model="editData.icon" :limit="1" size="80px" />
|
||||
<div class="form-tips">建议上传正方形图标</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model="editData.sort" :min="0" :max="9999" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch v-model="editData.status" :active-value="1" :inactive-value="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showEdit = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="communityCategory">
|
||||
import {
|
||||
communityCategoryAdd,
|
||||
communityCategoryDelete,
|
||||
communityCategoryEdit,
|
||||
communityCategoryLists
|
||||
} from '@/api/community'
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import feedback from '@/utils/feedback'
|
||||
import type { FormInstance } from 'element-plus'
|
||||
|
||||
const queryParams = reactive({
|
||||
name: '',
|
||||
status: ''
|
||||
})
|
||||
|
||||
const { pager, getLists, resetPage, resetParams } = usePaging({
|
||||
fetchFun: communityCategoryLists,
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
const showEdit = ref(false)
|
||||
const editFormRef = ref<FormInstance>()
|
||||
const editData = reactive({
|
||||
id: 0,
|
||||
name: '',
|
||||
icon: '',
|
||||
sort: 0,
|
||||
status: 1
|
||||
})
|
||||
|
||||
const editRules = {
|
||||
name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const handleAdd = () => {
|
||||
Object.assign(editData, { id: 0, name: '', icon: '', sort: 0, status: 1 })
|
||||
showEdit.value = true
|
||||
}
|
||||
|
||||
const handleEdit = (row: any) => {
|
||||
Object.assign(editData, {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
icon: row.icon || '',
|
||||
sort: row.sort,
|
||||
status: row.status
|
||||
})
|
||||
showEdit.value = true
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await editFormRef.value?.validate()
|
||||
if (editData.id) {
|
||||
await communityCategoryEdit(editData)
|
||||
} else {
|
||||
await communityCategoryAdd(editData)
|
||||
}
|
||||
showEdit.value = false
|
||||
getLists()
|
||||
}
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await feedback.confirm('确定要删除该分类?')
|
||||
await communityCategoryDelete({ id })
|
||||
getLists()
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
@@ -17,6 +17,35 @@
|
||||
<el-option label="赛事分析" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[240px]" label="帖子分类">
|
||||
<el-select v-model="queryParams.category_id" clearable filterable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="未分类" :value="0" />
|
||||
<el-option v-for="item in categoryList" :key="item.id"
|
||||
:label="item.status === 1 ? item.name : `${item.name}(禁用)`" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[200px]" label="推荐">
|
||||
<el-select v-model="queryParams.is_recommend" clearable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="是" :value="1" />
|
||||
<el-option label="否" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[200px]" label="热门">
|
||||
<el-select v-model="queryParams.is_hot" clearable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="是" :value="1" />
|
||||
<el-option label="否" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item class="w-[200px]" label="话题">
|
||||
<el-select v-model="queryParams.is_topic" clearable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="是" :value="1" />
|
||||
<el-option label="否" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||
<el-button @click="resetParams">重置</el-button>
|
||||
@@ -42,6 +71,17 @@
|
||||
<el-tag v-else>普通</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="分类" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<el-select v-perms="['community.communityPost/setCategory']" v-model="row.category_id"
|
||||
filterable @change="handleSetCategory($event, row.id)">
|
||||
<el-option label="未分类" :value="0" />
|
||||
<el-option v-for="item in categoryList" :key="item.id"
|
||||
:label="item.status === 1 ? item.name : `${item.name}(禁用)`" :value="item.id"
|
||||
:disabled="item.status !== 1" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="付费" min-width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.is_paid" type="danger">{{ row.price_points }}积分</el-tag>
|
||||
@@ -57,12 +97,24 @@
|
||||
:inactive-value="0" @change="handleSetTop($event, row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="推荐" min-width="70">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-perms="['community.communityPost/setRecommend']" v-model="row.is_recommend"
|
||||
:active-value="1" :inactive-value="0" @change="handleSetRecommend($event, row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="热门" min-width="70">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-perms="['community.communityPost/setHot']" v-model="row.is_hot" :active-value="1"
|
||||
:inactive-value="0" @change="handleSetHot($event, row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="话题" min-width="70">
|
||||
<template #default="{ row }">
|
||||
<el-switch v-perms="['community.communityPost/setTopic']" v-model="row.is_topic"
|
||||
:active-value="1" :inactive-value="0" @change="handleSetTopic($event, row.id)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" min-width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.status === 0" type="warning">待审核</el-tag>
|
||||
@@ -129,7 +181,10 @@
|
||||
<el-descriptions-item label="付费积分">{{ detailData.is_paid ? detailData.price_points + '积分' : '免费'
|
||||
}}</el-descriptions-item>
|
||||
<el-descriptions-item label="置顶">{{ detailData.is_top ? '是' : '否' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="分类">{{ detailData.category_name || '未分类' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="推荐">{{ detailData.is_recommend ? '是' : '否' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="热门">{{ detailData.is_hot ? '是' : '否' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="话题">{{ detailData.is_topic ? '是' : '否' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ detailData.update_time || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</div>
|
||||
@@ -146,6 +201,10 @@ import {
|
||||
communityPostStatus,
|
||||
communityPostSetTop,
|
||||
communityPostSetHot,
|
||||
communityPostSetRecommend,
|
||||
communityPostSetTopic,
|
||||
communityPostSetCategory,
|
||||
communityCategoryAll,
|
||||
communityPostDelete
|
||||
} from '@/api/community'
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
@@ -153,9 +212,15 @@ import feedback from '@/utils/feedback'
|
||||
|
||||
const queryParams = reactive({
|
||||
status: '',
|
||||
post_type: ''
|
||||
post_type: '',
|
||||
category_id: '',
|
||||
is_recommend: '',
|
||||
is_hot: '',
|
||||
is_topic: ''
|
||||
})
|
||||
|
||||
const categoryList = ref<any[]>([])
|
||||
|
||||
const { pager, getLists, resetPage, resetParams } = usePaging({
|
||||
fetchFun: communityPostLists,
|
||||
params: queryParams
|
||||
@@ -185,6 +250,33 @@ const handleSetHot = async (is_hot: any, id: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleSetRecommend = async (is_recommend: any, id: number) => {
|
||||
try {
|
||||
await communityPostSetRecommend({ id, is_recommend })
|
||||
getLists()
|
||||
} catch (error) {
|
||||
getLists()
|
||||
}
|
||||
}
|
||||
|
||||
const handleSetTopic = async (is_topic: any, id: number) => {
|
||||
try {
|
||||
await communityPostSetTopic({ id, is_topic })
|
||||
getLists()
|
||||
} catch (error) {
|
||||
getLists()
|
||||
}
|
||||
}
|
||||
|
||||
const handleSetCategory = async (category_id: any, id: number) => {
|
||||
try {
|
||||
await communityPostSetCategory({ id, category_id })
|
||||
getLists()
|
||||
} catch (error) {
|
||||
getLists()
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await feedback.confirm('确定要删除该帖子?')
|
||||
await communityPostDelete({ id })
|
||||
@@ -206,5 +298,15 @@ const handleDetail = async (id: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadCategories = async () => {
|
||||
try {
|
||||
const categories = await communityCategoryAll()
|
||||
categoryList.value = Array.isArray(categories) ? categories : []
|
||||
} catch {
|
||||
categoryList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
loadCategories()
|
||||
getLists()
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user