| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <template>
- <div>
- <div class="toolbar">
- <el-select v-model="statusFilter" placeholder="审核状态" @change="loadData">
- <el-option label="全部" value="" />
- <el-option label="待审核" value="pending" />
- <el-option label="已通过" value="approved" />
- <el-option label="已拒绝" value="rejected" />
- </el-select>
- <el-input v-model="keyword" placeholder="搜索标题..." prefix-icon="el-icon-search" clearable @keyup.enter.native="handleSearch" @clear="handleSearch" style="width:200px" />
- <el-button size="small" @click="loadData" :loading="loading">刷新</el-button>
- </div>
- <el-table :data="list" v-loading="loading" border stripe>
- <el-table-column prop="id" label="ID" width="60" />
- <el-table-column prop="title" label="标题" min-width="200" show-overflow-tooltip />
- <el-table-column label="审核状态" width="100">
- <template slot-scope="{ row }">
- <el-tag :type="statusType(row.auditStatus)">{{ statusLabel(row.auditStatus) }}</el-tag>
- </template>
- </el-table-column>
- <el-table-column prop="auditReason" label="原因" width="160" show-overflow-tooltip />
- <el-table-column label="操作" width="180" fixed="right">
- <template slot-scope="{ row }">
- <template v-if="row.auditStatus === 'pending'">
- <el-button size="mini" type="success" @click="handleAudit(row, 'approved')">通过</el-button>
- <el-button size="mini" type="danger" @click="showReject(row)">拒绝</el-button>
- </template>
- <span v-else class="no-op">—</span>
- </template>
- </el-table-column>
- </el-table>
- <el-dialog title="驳回原因" :visible.sync="rejectDialogVisible" width="400px">
- <el-input v-model="rejectReason" type="textarea" :rows="3" placeholder="请输入驳回原因" />
- <span slot="footer">
- <el-button @click="rejectDialogVisible = false">取消</el-button>
- <el-button type="danger" @click="confirmReject">确认驳回</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import { adminArticleList, adminArticleAudit } from '@/api/article'
- export default {
- data() {
- return {
- list: [], loading: false, keyword: '', statusFilter: 'pending',
- rejectDialogVisible: false, rejectTarget: null, rejectReason: ''
- }
- },
- mounted() { this.loadData() },
- methods: {
- statusType(s) { return { pending: 'warning', approved: 'success', rejected: 'danger' }[s] || 'info' },
- statusLabel(s) { return { pending: '待审核', approved: '已通过', rejected: '已拒绝' }[s] || s },
- handleSearch() { this.loadData() },
- async loadData() {
- this.loading = true
- try {
- const res = await adminArticleList({
- auditStatus: this.statusFilter || undefined,
- keyword: this.keyword || undefined, page: 1, size: 50
- })
- this.list = res.data && res.data.records || []
- } catch (e) { this.$message.error('加载失败')
- } finally { this.loading = false }
- },
- async handleAudit(row, auditStatus) {
- try {
- await adminArticleAudit({ id: row.id, auditStatus, auditReason: auditStatus === 'rejected' ? this.rejectReason : '' })
- this.$message.success('审核完成')
- this.rejectDialogVisible = false
- this.loadData()
- } catch (e) { this.$message.error('操作失败') }
- },
- showReject(row) { this.rejectTarget = row; this.rejectReason = ''; this.rejectDialogVisible = true },
- confirmReject() {
- if (!this.rejectReason) return this.$message.warning('请填写驳回原因')
- this.handleAudit(this.rejectTarget, 'rejected')
- }
- }
- }
- </script>
- <style scoped>
- .toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
- .no-op { color: #ccc; }
- </style>
|