ADD file via upload

main
pjhmizn49 1 year ago
parent f9a0190daf
commit e150203dd2

@ -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, //01
//
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>
Loading…
Cancel
Save