|
|
|
|
@ -0,0 +1,424 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<div class="tableTop">
|
|
|
|
|
<div>
|
|
|
|
|
<el-input @input="handleSearch" suffix-icon="el-icon-search" style="width: 300px" placeholder="请输入搜索关键字" v-model="input" clearable></el-input>
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<el-button @click="handleAdd" type="primary">添加公告</el-button>
|
|
|
|
|
<el-button @click="handleDeleteMul" type="danger">批量删除</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- 表单 -->
|
|
|
|
|
<el-dialog title="公告信息" :visible.sync="dialogVisible" :before-close="handleClose">
|
|
|
|
|
<el-form align="left" ref="dialogForm" :rules="rules" :model="dialogForm" label-width="130px" style="margin-right: 150px">
|
|
|
|
|
<el-form-item label="公告标题" prop="notice_title">
|
|
|
|
|
<el-input v-model="dialogForm.notice_title" placeholder="请输入公告标题"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="公告内容" prop="notice_content">
|
|
|
|
|
<el-input
|
|
|
|
|
type="textarea"
|
|
|
|
|
:autosize="{ minRows: 2, maxRows: 4}"
|
|
|
|
|
placeholder="请输入内容"
|
|
|
|
|
v-model="dialogForm.notice_content">
|
|
|
|
|
</el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button @click="handleClose">取 消</el-button>
|
|
|
|
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</div>
|
|
|
|
|
<el-table
|
|
|
|
|
ref="multipleTable"
|
|
|
|
|
:data="tableData"
|
|
|
|
|
tooltip-effect="dark"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
@selection-change="handleSelectionChange">
|
|
|
|
|
<el-table-column type="selection" width="60"></el-table-column>
|
|
|
|
|
<el-table-column prop="notice_id" label="id" width="100"></el-table-column>
|
|
|
|
|
<el-table-column prop="notice_title" label="公告标题" width="200"></el-table-column>
|
|
|
|
|
<el-table-column label="公告内容" width="180">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button @click="handleDetail(scope.row)" type="text">查看公告详情</el-button>
|
|
|
|
|
<el-dialog
|
|
|
|
|
title="公告内容"
|
|
|
|
|
:visible.sync="noticeDialogVisible"
|
|
|
|
|
width="30%"
|
|
|
|
|
center>
|
|
|
|
|
<span>{{noticeDetail}}</span>
|
|
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
|
<el-button @click="noticeDialogVisible = false">关 闭</el-button>
|
|
|
|
|
</span>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column prop="notice_time" label="发布时间" sortable width="200"></el-table-column>
|
|
|
|
|
<el-table-column label="操作" >
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button @click="handleModify(scope.row)" type="primary" size="small" plain>修改</el-button>
|
|
|
|
|
<el-button @click="handleDelete(scope.row)" type="danger" size="small" plain>删除</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<el-pagination
|
|
|
|
|
background
|
|
|
|
|
:current-page="currentPage"
|
|
|
|
|
:page-size="pageSize"
|
|
|
|
|
layout="total, prev, pager, next, jumper"
|
|
|
|
|
:total="total"
|
|
|
|
|
:page-count="page_number"
|
|
|
|
|
style="margin-top: 30px"
|
|
|
|
|
@current-change="handleCurrentChange">
|
|
|
|
|
</el-pagination>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import Cookie from "js-cookie";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
//页面数据
|
|
|
|
|
tableData: [{
|
|
|
|
|
notice_id: 1,
|
|
|
|
|
notice_title: '',
|
|
|
|
|
notice_content: '',
|
|
|
|
|
notice_time: ''
|
|
|
|
|
}],
|
|
|
|
|
dialogForm:[{
|
|
|
|
|
notice_id: 1,
|
|
|
|
|
notice_title: '',
|
|
|
|
|
notice_content: '',
|
|
|
|
|
notice_time: ''
|
|
|
|
|
}],
|
|
|
|
|
//表单校验
|
|
|
|
|
rules:{
|
|
|
|
|
notice_title:[
|
|
|
|
|
{ required:true, trigger:'blur', message:'请输入标题'}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
//数据处理
|
|
|
|
|
multipleSelection: [],
|
|
|
|
|
input: '',
|
|
|
|
|
dialogVisible:false,//增加与修改表单
|
|
|
|
|
noticeDialogVisible:false,//查看公告详情表单
|
|
|
|
|
noticeDetail:'',
|
|
|
|
|
modelType:0, //0表示新增弹窗,1表示修改弹窗
|
|
|
|
|
//分页相关
|
|
|
|
|
currentPage:1,
|
|
|
|
|
pageSize:10,
|
|
|
|
|
page_number:1,//总页数
|
|
|
|
|
total:10,//总条数
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.currentPage=1;
|
|
|
|
|
this.fetchData();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
fetchData(){
|
|
|
|
|
//获取所有信息
|
|
|
|
|
const _this=this;
|
|
|
|
|
try {
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/list',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
page:_this.currentPage,
|
|
|
|
|
page_size:_this.pageSize
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200){
|
|
|
|
|
//查询所有信息成功
|
|
|
|
|
_this.tableData=response.data.data.notices;
|
|
|
|
|
_this.page_number=response.data.data.page_number;
|
|
|
|
|
_this.total=response.data.data.total;
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}catch (error){
|
|
|
|
|
this.$message.warning('页面加载出错,请重试!')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
//搜索
|
|
|
|
|
handleSearch(){
|
|
|
|
|
const _this = this
|
|
|
|
|
try {
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/query',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
page:_this.currentPage,
|
|
|
|
|
page_size:_this.pageSize,
|
|
|
|
|
notice_content:_this.input
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200){
|
|
|
|
|
//查询所有信息成功
|
|
|
|
|
_this.tableData=response.data.data.notices;
|
|
|
|
|
_this.page_number=response.data.data.page_number;
|
|
|
|
|
_this.total=response.data.data.total;
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}catch (error){
|
|
|
|
|
this.$message.warning('页面加载出错,请重试!')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
//分页
|
|
|
|
|
handleCurrentChange(page) {
|
|
|
|
|
this.currentPage = page;
|
|
|
|
|
this.fetchData();
|
|
|
|
|
},
|
|
|
|
|
//多选
|
|
|
|
|
handleSelectionChange(val) {
|
|
|
|
|
this.multipleSelection = val;
|
|
|
|
|
},
|
|
|
|
|
//表单相关
|
|
|
|
|
//添加
|
|
|
|
|
handleAdd(){
|
|
|
|
|
this.modelType = 0
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
},
|
|
|
|
|
//修改
|
|
|
|
|
handleModify(row){
|
|
|
|
|
const _this = this
|
|
|
|
|
this.modelType = 1
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/info',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
notice_id: row.notice_id
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200) {
|
|
|
|
|
//获取信息成功
|
|
|
|
|
_this.dialogForm = response.data.data
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.dialogVisible = true
|
|
|
|
|
},
|
|
|
|
|
//提交添加或修改的表单
|
|
|
|
|
submitForm(){ //提交表单
|
|
|
|
|
const _this=this;
|
|
|
|
|
this.$refs.dialogForm.validate((valid) =>{
|
|
|
|
|
if(valid){
|
|
|
|
|
if(_this.modelType===0){
|
|
|
|
|
//提交添加表单
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/add',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
notice_title:_this.dialogForm.notice_title,
|
|
|
|
|
notice_content:_this.dialogForm.notice_content
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200) {
|
|
|
|
|
//添加信息成功
|
|
|
|
|
_this.$message.success('添加成功!')
|
|
|
|
|
//再次获取数据以更新页面
|
|
|
|
|
_this.fetchData()
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if(_this.modelType===1){
|
|
|
|
|
//提交修改表单
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/modify',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
notice_id:_this.dialogForm.notice_id,
|
|
|
|
|
notice_title:_this.dialogForm.notice_title,
|
|
|
|
|
notice_content:_this.dialogForm.notice_content
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200) {
|
|
|
|
|
//修改信息成功
|
|
|
|
|
_this.$message.success('修改成功!')
|
|
|
|
|
//再次获取数据以更新页面
|
|
|
|
|
_this.handleSearch()
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//清空表单数据
|
|
|
|
|
this.handleClose();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
//删除
|
|
|
|
|
handleDelete(row){
|
|
|
|
|
const _this = this;
|
|
|
|
|
this.$confirm('此操作将永久删除该公告, 是否继续?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
//确认删除
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/deletePer',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
notice_id:row.notice_id
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200) {
|
|
|
|
|
//删除成功
|
|
|
|
|
_this.handleSearch()
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("页面加载出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.$message({type: 'success', message: '删除成功!'});
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.$message({type: 'info', message: '已取消删除'});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
handleDeleteMul(){
|
|
|
|
|
const _this = this
|
|
|
|
|
if(_this.multipleSelection.length===0)
|
|
|
|
|
this.$message({type: 'warning', message: '请选择公告'});
|
|
|
|
|
else{
|
|
|
|
|
let ids = []
|
|
|
|
|
for (let i=0; i<_this.multipleSelection.length; i++){
|
|
|
|
|
ids[i] = _this.multipleSelection[i].notice_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.$confirm('此操作将永久删除公告信息, 是否继续?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
|
|
|
|
//确认删除
|
|
|
|
|
axios({
|
|
|
|
|
method: 'post',
|
|
|
|
|
url: 'http://localhost:8181/notice/deleteMul',
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: Cookie.get('token'),
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
data:{
|
|
|
|
|
notice_ids:ids
|
|
|
|
|
}
|
|
|
|
|
}).then(function (response){
|
|
|
|
|
if (response.data.code===200) {
|
|
|
|
|
//删除成功
|
|
|
|
|
_this.handleSearch()
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===401){
|
|
|
|
|
_this.$message.warning('身份验证失败,请重新登录!')
|
|
|
|
|
}
|
|
|
|
|
if (response.data.code===403){
|
|
|
|
|
const message = response.data.msg;
|
|
|
|
|
this.$alert("任务出错,具体原因如下:\n"+message, '页面加载失败', {
|
|
|
|
|
confirmButtonText: '确定'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.$message({type: 'success', message: '批量删除成功!'});
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
this.$message({type: 'info', message: '已取消删除'});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
//dialog弹窗关闭时触发该方法
|
|
|
|
|
handleClose(){
|
|
|
|
|
this.$refs.dialogForm.resetFields()
|
|
|
|
|
//重置表单
|
|
|
|
|
this.dialogForm.notice_id = 1;
|
|
|
|
|
this.dialogForm.notice_title='';
|
|
|
|
|
this.dialogForm.notice_content='';
|
|
|
|
|
|
|
|
|
|
this.dialogVisible = false;
|
|
|
|
|
},
|
|
|
|
|
handleDetail(row){
|
|
|
|
|
this.noticeDialogVisible=true
|
|
|
|
|
this.noticeDetail = row.notice_content
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style>
|
|
|
|
|
.tableTop{
|
|
|
|
|
width: 1200px;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin: 10px 0 20px 50px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|