Files
education/frontend/src/views/teachNotice/index.vue
T

438 lines
14 KiB
Vue

<template>
<div class="app-container teach-notice">
<!-- 查询条件区域 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
<el-form-item label="标题" prop="title">
<el-input
v-model="queryParams.title"
placeholder="请输入标题"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="公告类别">
<el-select
v-model="queryParams.category"
placeholder="请选择"
clearable
style="width: 160px"
>
<el-option
v-for="item in categoryOptions"
:key="item"
:label="item"
:value="item"
/>
</el-select>
</el-form-item>
<el-form-item label="发布日期">
<el-date-picker
v-model="queryParams.publishDateFrom"
type="date"
placeholder="从"
value-format="yyyy-MM-dd"
style="width: 140px"
/>
<span class="range-sep">-</span>
<el-date-picker
v-model="queryParams.publishDateTo"
type="date"
placeholder="到"
value-format="yyyy-MM-dd"
style="width: 140px"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<!-- 数据列表区域 -->
<div class="list-heading">
<div class="list-title">公告列表</div>
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增</el-button>
</div>
<el-table v-loading="loading" :data="noticeList" border :height="tableHeight">
<el-table-column label="序号" type="index" align="center" width="70" />
<el-table-column label="发布时间" align="center" width="165">
<template slot-scope="scope">{{ formatTime(scope.row.publishTime) }}</template>
</el-table-column>
<el-table-column label="标题" align="left" prop="title" min-width="300" :show-overflow-tooltip="true" />
<el-table-column label="公告状态" align="center" width="100">
<template slot-scope="scope">
<el-tag :type="statusTagType(scope.row.status)">{{ scope.row.status }}</el-tag>
</template>
</el-table-column>
<el-table-column label="公告类别" align="center" prop="category" width="110" />
<el-table-column label="优先级" align="center" prop="priority" width="80" />
<el-table-column label="阅读次数" align="center" prop="readCount" width="90" />
<el-table-column label="接收/已读" align="center" width="110">
<template slot-scope="scope">{{ scope.row.recipientCount }}/{{ scope.row.readerCount }}</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
width="300"
fixed="right"
class-name="small-padding fixed-width action-column"
>
<template slot-scope="scope">
<el-button
type="text"
size="mini"
icon="el-icon-view"
@click="handleView(scope.row)"
>详情</el-button>
<el-button
type="text"
size="mini"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
v-if="scope.row.status !== '已下架'"
type="text"
size="mini"
icon="el-icon-download"
@click="handleOffline(scope.row)"
>下架</el-button>
<el-button
type="text"
size="mini"
icon="el-icon-delete"
style="color: #f56c6c"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 新增/修改 对话框 -->
<el-dialog
:title="dialogTitle"
:visible="dialogVisible"
:close-on-click-modal="false"
width="600px"
@update:visible="handleDialogVisible"
>
<el-form ref="noticeForm" :model="form" :rules="rules" label-width="80px">
<el-form-item label="公告标题" prop="title">
<el-input v-model="form.title" placeholder="请输入公告标题" />
</el-form-item>
<el-form-item label="公告类别" prop="category">
<el-select v-model="form.category" placeholder="请选择公告类别" clearable>
<el-option v-for="item in categoryOptions" :key="item" :label="item" :value="item" />
</el-select>
</el-form-item>
<el-form-item label="公告正文" prop="content">
<el-input type="textarea" v-model="form.content" rows="8" placeholder="请输入公告正文" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" size="mini" @click="submitForm"> </el-button>
<el-button size="mini" @click="handleDialogVisible(false)"> </el-button>
</div>
</el-dialog>
<!-- 详情 对话框 -->
<el-dialog
title="公告详情"
:visible="viewVisible"
:close-on-click-modal="false"
width="600px"
@update:visible="handleViewVisible"
>
<div class="detail-body">
<div class="detail-row">
<span class="detail-label">公告标题</span>
<span class="detail-value">{{ viewForm.title }}</span>
</div>
<div class="detail-row">
<span class="detail-label">公告类别</span>
<span class="detail-value">{{ viewForm.category }}</span>
</div>
<div class="detail-row">
<span class="detail-label">公告状态</span>
<span class="detail-value">{{ viewForm.status }}</span>
</div>
<div class="detail-row">
<span class="detail-label">优先级</span>
<span class="detail-value">{{ viewForm.priority }}</span>
</div>
<div class="detail-row">
<span class="detail-label">发布时间</span>
<span class="detail-value">{{ viewForm.publishTime }}</span>
</div>
<div class="detail-row">
<span class="detail-label">阅读次数</span>
<span class="detail-value">{{ viewForm.readCount }}</span>
</div>
<div class="detail-row">
<span class="detail-label">接收/已读</span>
<span class="detail-value">{{ viewForm.recipientCount }}/{{ viewForm.readerCount }}</span>
</div>
<div class="detail-row">
<span class="detail-label">发布范围</span>
<span class="detail-value">{{ viewForm.scopeName }}</span>
</div>
<div class="detail-row">
<span class="detail-label">公告正文</span>
<span class="detail-value detail-content">{{ viewForm.content }}</span>
</div>
<div class="detail-row">
<span class="detail-label">备注</span>
<span class="detail-value">{{ viewForm.remark }}</span>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button size="mini" @click="handleViewVisible(false)"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listTeachNotice, getTeachNotice, addTeachNotice, updateTeachNotice, delTeachNotice } from "@/api/teachNotice"
export default {
name: "TeachNotice",
data() {
return {
loading: true,
tableHeight: window.innerHeight - 320,
total: 0,
noticeList: [],
categoryOptions: ['教学公告', '考试通知', '调课通知'],
queryParams: {
pageNum: 1,
pageSize: 10,
title: undefined,
category: undefined,
publishDateFrom: undefined,
publishDateTo: undefined
},
// 新增/修改 对话框
dialogVisible: false,
dialogTitle: '',
form: {},
rules: {
title: [{ required: true, message: "公告标题不能为空", trigger: "blur" }],
content: [{ required: true, message: "公告正文不能为空", trigger: "blur" }],
category: [{ required: true, message: "公告类别不能为空", trigger: "change" }]
},
// 详情 对话框
viewVisible: false,
viewForm: {}
}
},
created() {
this.getList()
},
methods: {
/** 查询列表 */
getList() {
this.loading = true
listTeachNotice(this.queryParams).then(response => {
const data = response.data || {}
this.noticeList = data.records || []
this.total = data.total || 0
this.loading = false
}).catch(() => {
this.noticeList = []
this.total = 0
this.loading = false
})
},
/** 时间格式化:yyyy-MM-dd HH:mm:ss */
formatTime(time) {
if (!time) return ''
const date = new Date(time)
if (isNaN(date.getTime())) return time
const pad = n => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
},
/** 状态标签颜色 */
statusTagType(status) {
if (status === '已发布') return 'success'
if (status === '已下架') return 'info'
return 'warning'
},
/** 查询按钮 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮 */
resetQuery() {
this.queryParams = {
pageNum: 1,
pageSize: 10,
title: undefined,
category: undefined,
publishDateFrom: undefined,
publishDateTo: undefined
}
this.handleQuery()
},
/** 新增 */
handleAdd() {
this.dialogTitle = '新增公告'
this.form = { title: undefined, content: undefined, category: undefined }
this.dialogVisible = true
this.$nextTick(() => {
this.$refs.noticeForm && this.$refs.noticeForm.clearValidate()
})
},
/** 修改 */
handleUpdate(row) {
getTeachNotice(row.id).then(response => {
const data = response.data || {}
this.form = {
id: data.id,
title: data.title,
content: data.content,
category: data.category
}
}).catch(() => {})
this.dialogTitle = '修改公告'
this.dialogVisible = true
},
/** 提交新增/修改 */
submitForm() {
this.$refs.noticeForm.validate(valid => {
if (!valid) return
const isAdd = !this.form.id
if (isAdd) {
addTeachNotice(this.form).then(() => {
this.$message.success("新增成功")
this.dialogVisible = false
this.getList()
}).catch(() => {})
} else {
updateTeachNotice(this.form).then(() => {
this.$message.success("修改成功")
this.dialogVisible = false
this.getList()
}).catch(() => {})
}
})
},
/** 下架 */
handleOffline(row) {
this.$confirm("确认下架该公告吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
updateTeachNotice({ id: row.id, status: '已下架' }).then(() => {
this.$message.success("下架成功")
this.getList()
}).catch(() => {})
}).catch(() => {})
},
/** 删除(级联删除:仅拟制/已下架可删,后端校验) */
handleDelete(row) {
this.$confirm("确认删除该公告吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(() => {
delTeachNotice(row.id).then(() => {
this.$message.success("删除成功")
this.getList()
}).catch(() => {})
}).catch(() => {})
},
/** 详情 */
handleView(row) {
getTeachNotice(row.id).then(response => {
this.viewForm = response.data || {}
this.viewVisible = true
}).catch(() => {})
},
/** 对话框关闭事件(Vue2 兼容) */
handleDialogVisible(val) {
this.dialogVisible = val
},
handleViewVisible(val) {
this.viewVisible = val
}
}
}
</script>
<style scoped lang="scss">
.teach-notice {
.range-sep {
margin: 0 8px;
color: #909399;
}
.list-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
.list-title {
font-size: 16px;
font-weight: 600;
color: #303133;
padding-left: 10px;
border-left: 4px solid var(--edu-green-primary);
}
::v-deep .action-column .cell {
white-space: nowrap;
}
.detail-body {
padding: 0 8px;
.detail-row {
display: flex;
padding: 6px 0;
font-size: 13px;
line-height: 1.6;
.detail-label {
flex-shrink: 0;
width: 90px;
color: #909399;
text-align: right;
margin-right: 12px;
}
.detail-value {
flex: 1;
color: #303133;
word-break: break-all;
}
.detail-content {
white-space: pre-wrap;
}
}
}
@media (max-width: 768px) {
.list-heading {
align-items: stretch;
flex-direction: column;
}
.list-heading .el-button {
width: 100%;
}
}
}
</style>