Files
love-nav-vue/src/components/setting/notice/NoticeManage.vue
2023-12-28 22:55:04 +08:00

399 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="main" style="text-shadow: 0 0 20px var(--font-border);overflow: scroll">
<div class="HeadLine" style="margin-top:30px;margin-left:15px;">
<div class="HeadSquare" ></div>
<div class="TitleFont" style="color:var(--theme-color)"><i class="el-icon-s-grid"></i>通知管理</div>
</div>
<div class="base-style" style="margin-top:20px;font-family: SimHei;font-size:18px;font-weight:600;margin-left:20px">
<el-row>
<el-col :span="24">
<el-button @click="openAddCategoryFun()" type="primary" plain size="medium" round >创建通知</el-button>
</el-col>
<!-- <el-col :span="24" style="margin-top:20px">-->
<!-- <el-input-->
<!-- placeholder="请输入内容"-->
<!-- v-model="searchCate"-->
<!-- clearable-->
<!-- style="width:200px">-->
<!-- </el-input>-->
<!-- <el-button type="success" plain size="medium" round style="margin-left:10px">查询</el-button>-->
<!-- </el-col>-->
</el-row>
<el-table class="MyTable"
:data="List"
header-row-class-name="table_header_class"
border>
<el-table-column
align="center"
prop="id"
label="通知编号"
width="150">
</el-table-column>
<el-table-column
align="center"
prop="title"
label="通知标题"
width="180">
</el-table-column>
<el-table-column
align="center"
prop="content"
label="通知内容"
width="160">
</el-table-column>
<el-table-column
align="center"
prop="url"
label="通知URL"
width="100">
</el-table-column>
<el-table-column
align="center"
prop="createtime"
label="创建时间"
width="120">
</el-table-column>
<el-table-column
align="center"
prop="urlNumber"
label="包含网址数"
width="100">
</el-table-column>
<!-- <el-table-column align="center" key="status" prop="status" label="启用状态" width="90" >-->
<!-- <template slot-scope="scope">-->
<!-- <el-switch-->
<!-- v-model="scope.row.status"-->
<!-- :active-value="0"-->
<!-- :inactive-value="1"-->
<!-- active-color="#13ce66"-->
<!-- inactive-color="#ff4949"-->
<!-- disabled-->
<!-- >-->
<!-- </el-switch>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column align="center" key="needLogin" prop="needLogin" label="公开状态" width="90">-->
<!-- <template slot-scope="scope">-->
<!-- <el-switch-->
<!-- v-model="scope.row.needLogin"-->
<!-- :active-value="1"-->
<!-- :inactive-value="0"-->
<!-- active-color="#13ce66"-->
<!-- inactive-color="#ff4949"-->
<!-- disabled-->
<!-- >-->
<!-- </el-switch>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column-->
<!-- align="center"-->
<!-- prop="weigh"-->
<!-- label="权重"-->
<!-- width="80">-->
<!-- </el-table-column>-->
<el-table-column prop="date" label="操作" width="100">
<template slot-scope="scope">
<div class="ButtonBlock">
<img class="MyButton" @click="handleDelete(scope.row)"
src="../../../assets/img/DeleteButton.svg" style="width:60px">
</div>
</template>
</el-table-column>
</el-table>
<el-dialog title="新增公告" :visible.sync="openAddCategory" width="30%"
append-to-body
:close-on-click-modal="false"
:before-close="closeDialog"
>
<el-form ref="form" :rules="rules" class="login_container" :model="form"
style="margin-top:-10px" status-icon label-width="100px" >
<el-form-item label="公告标题" prop="title">
<el-input v-model="form.title" placeholder='公告标题' clearable></el-input>
</el-form-item>
<el-form-item label="公告内容" prop="content" >
<el-input v-model="form.content" placeholder='公告内容' clearable ></el-input>
</el-form-item>
<el-form-item label="公告链接" prop="url">
<el-input v-model="form.url" placeholder='公告连接' clearable ></el-input>
</el-form-item>
<el-form-item>
<div style="display: flex;flex-direction: row;align-items: center;flex-wrap: nowrap;justify-content: space-between">
<el-button @click="addCategory('form')" type="primary" style=";margin-top:10px">确认</el-button>
</div>
</el-form-item>
</el-form>
</el-dialog>
</div>
</div>
</template>
<script>
import axios from "axios";
import Vue from "vue";
export default {
name: "NoticeManage",
data() {
return {
// 表头名字:
titlename:null,
// 新增目录页面:
openAddCategory:false,
// 对话框显示:
dialogVisible:false,
// 允许对话框修改:
isEdit:true,
searchCate:'',
userId:null,
List:[],
form:{
title: null,
content: null,
url: null,
},
// 校验规则
rules: {
title: [{ required: 'true', message: '请输入通标题', trigger: 'blur' }],
content: [{ required: 'true', message: '请输入通知内容', trigger: 'blur' }],
// needLogin: [{ required: 'true', message: '请完善信息', trigger: 'blur' }],
// status: [{ required: 'true', message: '请输入是否启用', trigger: 'blur' }],
url: [{ required: 'true', message: '请慎入跳转连接', trigger: 'blur' }],
}
}
},
mounted() {
this.getFormatDate();
},
created() {
this.getUserInfo();
// this.GetData();
},
computed: {},
methods: {
// 删除网址:
handleDelete(index) {
var that=this;
this.$confirm('此操作将永久删除该通知, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
axios({
method: 'get',
// 请求的地址
url: '/api/notice/delete',
// URL 中的查询参数
params: {
id: index.id,
}
}).then(function (res) {
if (res.data.code === 500) {
Vue.prototype.$notify.error({
title: '错误',
message: res.data.msg,
offset: 50
});
} else {
Vue.prototype.$notify({
title: '成功',
message: ('i', {style: 'color: teal'}, "删除成功"),
type: 'success',
offset: 50
});
that.GetData();
}
});
}).catch(() => {
// 点击取消:不删除了
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
// 关闭弹出对话框之前:
closeDialog() {
var that = this;
// 先重置
this.GetData();
//表单重置
that.form = {
title: null,
content: null,
url: null,
}
// 后关闭
this.dialogVisible = false;
this.openAddCategory=false;
that.getUserInfo();
},
// 新增按钮:
openAddCategoryFun(){
var _this = this;
// console.log(_this.List);
_this.titlename="新增通知";
this.openAddCategory=true;
},
// 编辑按钮:
handleEdit(index) {
var _this = this;
this.openAddCategoryFun();
_this.titlename="编辑通知";
// 深拷贝
this.form = index;
},
// 提交新增:
addCategory(rulelist){
var _this = this;
_this.$refs[rulelist].validate((valid)=>{
if(valid){
axios({
method: 'post',
// 请求的地址
url: '/api/notice/add',
// URL 中的查询参数
params: {
title: this.form.title,
content: this.form.content,
url: this.form.url,
}
}).then(function (res) {
if (res.data.code === 500) {
Vue.prototype.$notify.error({
title: '错误',
message: res.data.msg,
offset: 50
});
} else {
_this.closeDialog();
Vue.prototype.$notify({
title: '成功',
message: ('i', {style: 'color: teal'}, "更新成功!"),
type: 'success',
offset: 50
});
}
}).catch((error)=>{
})
}
})
//调用方法提交
},
// 时间转换:
getFormatDate() {
var that = this;
console.log(that.List.length + "changdu");
for(let i = 0 ; i < that.List.length; i++){
var date = new Date(that.List[i].createtime);// 时间戳为10位需*1000时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '年';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
var D = date.getDate() + '日 ';
console.log("date: " + Y + M + D);
that.List[i].createtime = "" + Y + M + D;
}
},
// 获取条数:
hIndex(index){
var linenum = parseInt( parseInt(index) + parseInt(1))
return linenum;
},
// 获取用户ID
getUserInfo() {
let _this = this;
if(localStorage.getItem("Authorization") && localStorage.getItem("userId")){
_this.userId = localStorage.getItem("userId")
_this.GetData();
} else {
Vue.prototype.$notify.error({
title: '错误',
message: "登录状态失效,请重新登录!",
offset: 0
});
}
},
GetData(){
// 获取数据
var that = this;
axios({
method:'get',
url:'/api/notice/select',
params:{
}
}).then(function(res){
that.List = res.data;
for(let i = 0 ; i < that.List.length; i++){
var date = new Date(that.List[i].createtime);// 时间戳为10位需*1000时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '年';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
var D = date.getDate() + '日 ';
that.List[i].createtime = "" + Y + M + D;
}
})
// /selectAllArticleByadmin
that.form.userId = that.userId;
},
}
}
</script>
<style scoped>
.base-style{
display: flex;
flex-direction: column;
}
/**表格样式,直接复制**/
::v-deep .table_header_class th{
background-color: var(--table-bg-color)!important;
color:var(--theme-color);
text-align: center;
}
.MyTable{
margin-top:10px;
width: 100%;
background-color:var(--table-bg-color);
color:var(--theme-color);
border-radius: 5px;
}
::v-deep .el-table__body tr:hover > td {
background-color: var(--table-bg-color-hover) !important;
}
::v-deep .el-table tr,
.el-table th.el-table__cell {
background-color: var(--table-bg-color);
border: var(--table-border) solid 3px;
}
::v-deep .el-table--border{
border: var(--table-border) solid 3px;
}
.login_container {
width: 400px;
border: 1px solid #eaeaea;
margin: 100px auto;
padding: 35px 35px 15px 35px;
box-sizing: border-box;
border-radius: 15px;
background-color: #fff;
box-shadow: 0 0 25px #cac6c6;
.login_title{
color: #505458;
text-align: center;
margin-bottom: 40px;}
}
::v-deep .el-dialog__body{
background-image: url("../../../assets/img/SkyPic.jpg");
margin-top:15px;
height:400px;
}
</style>