You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
7.5 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

<template>
<div>
<el-card shadow="never" class="search-card">
<FormSearch
:fields="searchFormFields"
:loading="loading"
:show-create="false"
:show-delete="true"
:disabled-delete="selectedRow.length === 0"
:default-search="search"
@onSearch="onSearch"
@onCreate="onCreate"
@onDelete="batchDelete"
/>
</el-card>
<el-card shadow="never" class="mgt-20px">
<TableList
:loading="loading"
:table-data="reports"
:fields="tableListFields"
:show-actions="true"
:show-view="false"
:show-edit="true"
:show-delete="true"
:show-select="true"
@selectRow="selectRow"
@editRow="editRow"
@deleteRow="deleteRow"
/>
</el-card>
<el-card shadow="never" class="mgt-20px">
<div class="text-right">
<el-pagination
background
:current-page="search.page"
:page-sizes="[10, 20, 50, 100]"
:page-size="search.size"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handlePageChange"
>
</el-pagination>
</div>
</el-card>
<el-dialog
:close-on-click-modal="false"
:title="report.id ? '编辑举报' : '新增举报'"
:visible.sync="formReportVisible"
width="640px"
>
<FormReport
ref="reportForm"
:init-report="report"
:is-admin="true"
@success="formReportSuccess"
/>
</el-dialog>
</div>
</template>
<script>
import { listReport, deleteReport } from '~/api/report'
import { reportOptions } from '~/utils/enum'
import { parseQueryIntArray, genLinkHTML } from '~/utils/utils'
import TableList from '~/components/TableList.vue'
import FormSearch from '~/components/FormSearch.vue'
import FormReport from '~/components/FormReport.vue'
import { mapGetters } from 'vuex'
export default {
components: { TableList, FormSearch, FormReport },
layout: 'admin',
data() {
return {
loading: false,
formReportVisible: false,
search: {
wd: '',
page: 1,
status: [],
size: 10,
},
reports: [],
reportOptions,
total: 0,
searchFormFields: [],
tableListFields: [],
selectedRow: [],
report: { id: 0 },
}
},
head() {
return {
title: `举报管理 - ${this.settings.system.sitename}`,
}
},
computed: {
...mapGetters('setting', ['settings']),
},
async created() {
this.initSearchForm()
this.initTableListFields()
},
watch: {
'$route.query': {
handler() {
this.search = {
...this.search,
...this.$route.query,
page: parseInt(this.$route.query.page) || 1,
size: parseInt(this.$route.query.size) || 10,
...parseQueryIntArray(this.$route.query, ['status']),
}
this.listReport()
},
immediate: true,
},
},
methods: {
async listReport() {
this.loading = true
const res = await listReport(this.search)
if (res.status === 200) {
let reports = res.data.report || []
reports.map((item) => {
item.username_html = genLinkHTML(
item.username,
`/user/${item.user_id}`
)
item.document_title_html = genLinkHTML(
item.document_title,
`/document/${item.document_id}`
)
})
this.reports = reports
this.total = res.data.total
} else {
this.$message.error(res.data.message)
}
this.loading = false
},
handleSizeChange(val) {
this.search.size = val
this.$router.push({
query: this.search,
})
},
handlePageChange(val) {
this.search.page = val
this.$router.push({
query: this.search,
})
},
onSearch(search) {
this.search = { ...this.search, ...search, page: 1 }
if (
location.pathname + location.search ===
        this.$router.resolve({
          query: this.search,
        }).href
) {
this.listReport()
} else {
this.$router.push({
query: this.search,
})
}
},
onCreate() {
this.report = { id: 0 }
this.formReportVisible = true
this.$nextTick(() => {
this.$refs.reportForm.reset()
})
},
async editRow(row) {
this.report = row
this.formReportVisible = true
},
formReportSuccess() {
this.formReportVisible = false
this.listReport()
},
batchDelete() {
this.$confirm(
`您确定要删除选中的【${this.selectedRow.length}条】举报吗?删除之后不可恢复!`,
'',
{
confirmButtonText: '',
cancelButtonText: '',
type: 'warning',
}
)
.then(async () => {
const ids = this.selectedRow.map((item) => item.id)
const res = await deleteReport({ id: ids })
if (res.status === 200) {
this.$message.success('')
this.listReport()
} else {
this.$message.error(res.data.message)
}
})
.catch(() => {})
},
deleteRow(row) {
this.$confirm(
`您确定要删除对文档【${row.document_title}】的举报吗?删除之后不可恢复!`,
'',
{
confirmButtonText: '',
cancelButtonText: '',
type: 'warning',
}
)
.then(async () => {
const res = await deleteReport({ id: row.id })
if (res.status === 200) {
this.$message.success('')
this.listReport()
} else {
this.$message.error(res.data.message)
}
})
.catch(() => {})
},
selectRow(rows) {
this.selectedRow = rows
},
initSearchForm() {
this.searchFormFields = [
{
type: 'text',
label: '',
name: 'wd',
placeholder: '',
},
{
type: 'select',
label: '',
name: 'status',
placeholder: '',
multiple: true,
options: [
{ label: '', value: 1 },
{ label: '', value: 0 },
],
},
]
},
initTableListFields() {
const reasonEnum = {}
this.reportOptions.forEach((item) => {
reasonEnum[item.value] = item
})
this.tableListFields = [
{ prop: 'id', label: 'ID', width: 80, type: 'number', fixed: 'left' },
{
prop: 'status',
label: '',
width: 100,
type: 'bool',
fixed: 'left',
},
{
prop: 'document_title_html',
label: '',
minWidth: 150,
fixed: 'left',
type: 'html',
},
{
prop: 'reason',
label: '',
width: 80,
type: 'enum',
enum: reasonEnum,
},
{
prop: 'username_html',
label: '',
width: 100,
type: 'html',
},
{ prop: 'remark', label: '', minWidth: 150 },
{ prop: 'created_at', label: '', width: 160, type: 'datetime' },
{ prop: 'updated_at', label: '', width: 160, type: 'datetime' },
]
},
},
}
</script>
<style></style>