|
|
@@ -0,0 +1,262 @@
|
|
|
+<template>
|
|
|
+ <a-card :bordered="false">
|
|
|
+ <div class="table-page-search-wrapper">
|
|
|
+ <a-form layout="inline">
|
|
|
+ <a-row :gutter="48">
|
|
|
+ <a-col :md="6" :sm="24">
|
|
|
+ <a-form-item label="标题">
|
|
|
+ <a-input v-model="queryParam.title" placeholder="请输入标题"/>
|
|
|
+ </a-form-item>
|
|
|
+ </a-col>
|
|
|
+ <a-col :md="5" :sm="24">
|
|
|
+ <a-form-item label="类型">
|
|
|
+ <a-select v-model="queryParam.type" placeholder="请选择" allowClear>
|
|
|
+ <a-select-option :value="1">文字公告</a-select-option>
|
|
|
+ <a-select-option :value="2">文件资料</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ </a-col>
|
|
|
+ <a-col :md="5" :sm="24">
|
|
|
+ <a-form-item label="状态">
|
|
|
+ <a-select v-model="queryParam.status" placeholder="请选择" allowClear>
|
|
|
+ <a-select-option :value="0">草稿</a-select-option>
|
|
|
+ <a-select-option :value="1">已发布</a-select-option>
|
|
|
+ <a-select-option :value="2">已下架</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ </a-col>
|
|
|
+ <a-col :md="8" :sm="24">
|
|
|
+ <span class="table-page-search-submitButtons">
|
|
|
+ <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
|
|
|
+ <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
|
|
|
+ </span>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ </a-form>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="table-operator">
|
|
|
+ <a-button v-if="$auth('announcement-add')" type="primary" icon="plus" @click="$refs.baseModal.base()">新增</a-button>
|
|
|
+ <a-dropdown v-if="selectedRowKeys.length > 0 && $auth('announcement-del')">
|
|
|
+ <a-menu slot="overlay">
|
|
|
+ <a-menu-item key="1" @click="batchDelete()">
|
|
|
+ <a-icon type="delete"/>批量删除
|
|
|
+ </a-menu-item>
|
|
|
+ </a-menu>
|
|
|
+ <a-button style="margin-left: 8px">批量操作 <a-icon type="down"/></a-button>
|
|
|
+ </a-dropdown>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <s-table
|
|
|
+ ref="table"
|
|
|
+ size="default"
|
|
|
+ rowKey="id"
|
|
|
+ :columns="columns"
|
|
|
+ :data="loadData"
|
|
|
+ :alert="options.alert"
|
|
|
+ :rowSelection="options.rowSelection"
|
|
|
+ :scroll="{ x: 1250 }"
|
|
|
+ showPagination="auto"
|
|
|
+ >
|
|
|
+ <span slot="topFlag" slot-scope="text">
|
|
|
+ <a-tag v-if="text === 1" color="red">置顶</a-tag>
|
|
|
+ <span v-else>—</span>
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <span slot="showSwitch" slot-scope="record">
|
|
|
+ <template v-if="record.status === 0">
|
|
|
+ <span style="color:#999;">未发布</span>
|
|
|
+ </template>
|
|
|
+ <a-switch
|
|
|
+ v-else
|
|
|
+ :checked="record.status === 1"
|
|
|
+ :loading="record._switchLoading"
|
|
|
+ :disabled="!$auth('announcement-publish')"
|
|
|
+ checked-children="显示"
|
|
|
+ un-checked-children="下架"
|
|
|
+ @change="checked => handleToggle(checked, record)"
|
|
|
+ />
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <span slot="action" slot-scope="record">
|
|
|
+ <template>
|
|
|
+ <a v-if="$auth('announcement-edit')" @click="handleEdit(record)">编辑</a>
|
|
|
+ <a-divider v-if="record.status === 0 && $auth('announcement-publish')" type="vertical"/>
|
|
|
+ <a v-if="record.status === 0 && $auth('announcement-publish')" @click="handlePublish(record)">发布</a>
|
|
|
+ <a-divider v-if="$auth('announcement-del')" type="vertical"/>
|
|
|
+ <a-popconfirm v-if="$auth('announcement-del')" title="确定删除该公告?" @confirm="handleDelete(record)">
|
|
|
+ <a>删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ </template>
|
|
|
+ </span>
|
|
|
+ </s-table>
|
|
|
+
|
|
|
+ <base-form ref="baseModal" @ok="handleOk"/>
|
|
|
+ </a-card>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { STable } from '@/components'
|
|
|
+import BaseForm from './modules/BaseForm'
|
|
|
+import {
|
|
|
+ getAnnouncementPage,
|
|
|
+ deleteAnnouncement,
|
|
|
+ deleteAnnouncements,
|
|
|
+ publishAnnouncement,
|
|
|
+ hideAnnouncement,
|
|
|
+ showAnnouncement
|
|
|
+} from '@/api/upms/announcement'
|
|
|
+
|
|
|
+const typeMap = { 1: '文字公告', 2: '文件资料' }
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'Announcement',
|
|
|
+ components: { STable, BaseForm },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ queryParam: {},
|
|
|
+ columns: [
|
|
|
+ {
|
|
|
+ title: '序号',
|
|
|
+ dataIndex: 'index',
|
|
|
+ width: 60,
|
|
|
+ align: 'center',
|
|
|
+ customRender: (text, record, index) => {
|
|
|
+ return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '标题',
|
|
|
+ dataIndex: 'title',
|
|
|
+ width: 260,
|
|
|
+ customRender: (text) => this.BaseTool.Table.customRenderWidthDefault(this, text)
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '类型',
|
|
|
+ dataIndex: 'type',
|
|
|
+ width: 100,
|
|
|
+ align: 'center',
|
|
|
+ customRender: (text) => typeMap[text] || '—'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '显示/下架',
|
|
|
+ key: 'showSwitch',
|
|
|
+ width: 110,
|
|
|
+ align: 'center',
|
|
|
+ scopedSlots: { customRender: 'showSwitch' }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '置顶',
|
|
|
+ dataIndex: 'topFlag',
|
|
|
+ width: 80,
|
|
|
+ align: 'center',
|
|
|
+ scopedSlots: { customRender: 'topFlag' }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '发布时间',
|
|
|
+ dataIndex: 'publishTime',
|
|
|
+ width: 160,
|
|
|
+ align: 'center',
|
|
|
+ customRender: (text) => text || '—'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '有效期至',
|
|
|
+ dataIndex: 'expireTime',
|
|
|
+ width: 160,
|
|
|
+ align: 'center',
|
|
|
+ customRender: (text) => text || '长期有效'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '发布人',
|
|
|
+ dataIndex: 'createdUserName',
|
|
|
+ width: 100,
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ key: 'action',
|
|
|
+ width: 160,
|
|
|
+ align: 'center',
|
|
|
+ scopedSlots: { customRender: 'action' }
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ loadData: parameter => {
|
|
|
+ parameter = { ...parameter, ...this.queryParam }
|
|
|
+ return getAnnouncementPage(parameter).then(res => res.data)
|
|
|
+ },
|
|
|
+ selectedRowKeys: [],
|
|
|
+ selectedRows: [],
|
|
|
+ options: {
|
|
|
+ alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
|
|
|
+ rowSelection: {
|
|
|
+ selectedRowKeys: this.selectedRowKeys,
|
|
|
+ onChange: this.onSelectChange
|
|
|
+ }
|
|
|
+ },
|
|
|
+ optionAlertShow: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ handleEdit (record) {
|
|
|
+ this.$refs.baseModal.base(record)
|
|
|
+ },
|
|
|
+ handlePublish (record) {
|
|
|
+ publishAnnouncement({ id: record.id }).then(() => {
|
|
|
+ this.$message.success('发布成功')
|
|
|
+ this.handleOk()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleToggle (checked, record) {
|
|
|
+ if (!checked) {
|
|
|
+ // 下架
|
|
|
+ record._switchLoading = true
|
|
|
+ hideAnnouncement({ id: record.id }).then(() => {
|
|
|
+ this.$message.success('已下架')
|
|
|
+ this.handleOk()
|
|
|
+ }).finally(() => {
|
|
|
+ record._switchLoading = false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 显示:从下架恢复用 show,其他情况用 publish
|
|
|
+ record._switchLoading = true
|
|
|
+ const req = record.status === 2 ? showAnnouncement({ id: record.id }) : publishAnnouncement({ id: record.id })
|
|
|
+ req.then(() => {
|
|
|
+ this.$message.success('已恢复显示')
|
|
|
+ this.handleOk()
|
|
|
+ }).finally(() => {
|
|
|
+ record._switchLoading = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleDelete (record) {
|
|
|
+ deleteAnnouncement({ id: record.id }).then(() => {
|
|
|
+ this.$message.success('删除成功')
|
|
|
+ this.handleOk()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ batchDelete () {
|
|
|
+ if (this.selectedRowKeys.length <= 0) {
|
|
|
+ this.$message.info('请选择要删除的记录')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const ids = this.selectedRows.map(item => item.id)
|
|
|
+ deleteAnnouncements(ids).then(() => {
|
|
|
+ this.$message.success('批量删除成功')
|
|
|
+ this.$refs.table.clearSelected()
|
|
|
+ this.handleOk()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ handleOk () {
|
|
|
+ this.$refs.table.refresh()
|
|
|
+ },
|
|
|
+ onSelectChange (selectedRowKeys, selectedRows) {
|
|
|
+ this.selectedRowKeys = selectedRowKeys
|
|
|
+ this.selectedRows = selectedRows
|
|
|
+ },
|
|
|
+ resetSearchForm () {
|
|
|
+ this.queryParam = {}
|
|
|
+ this.$refs.table.refresh(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|