<template>
|
<div class="main">
|
<div class="main_header">
|
<div class="header_item">
|
<span class="header_label">公告名称:</span>
|
<el-input v-model="noticeName" clearable placeholder="请输入公告名称"></el-input>
|
</div>
|
<div class="header_item">
|
<span class="header_label">发布时间:</span>
|
<el-date-picker
|
v-model="timeDate"
|
type="daterange"
|
value-format="yyyy-MM-dd"
|
range-separator="至"
|
start-placeholder="开始日期"
|
end-placeholder="结束日期">
|
</el-date-picker>
|
</div>
|
<div class="header_item">
|
<el-button v-if="showButton('search')" icon="el-icon-search" @click="searchSafetyAfficheList(true)">查询</el-button>
|
<el-button class="search_btn" v-if="showButton('insert')" icon="el-icon-plus" @click="propInsert()">新增</el-button>
|
</div>
|
</div>
|
<div class="main_content">
|
<el-table
|
ref="table"
|
v-loading="loading"
|
:data="afficheList"
|
height="100%">
|
<el-table-column label="序号" width="60" align="center">
|
<template #default="scope">
|
<span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="noticeName" label="公告名称" width="180" align="center"></el-table-column>
|
<el-table-column prop="noticeTypeName" label="公告分类" align="center"></el-table-column>
|
<el-table-column label="公告内容" show-overflow-tooltip align="center">
|
<template #default="{ row }">
|
<div class="notice_content" v-html="row.noticeContent"></div>
|
</template>
|
</el-table-column>
|
<el-table-column prop="publishTime" label="发布时间" align="center"></el-table-column>
|
<el-table-column label="操作" align="center">
|
<template #default="{ row }">
|
<el-button class="table_btn" size="mini" v-if="showButton('update')" @click="propUpdate(row)">修改</el-button>
|
<el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteInfo(row)">删除</el-button>
|
<el-button class="table_btn" size="mini" v-if="showButton('delete') && row.status === 2" @click="changeStatus(row, 1)">发布</el-button>
|
<el-button class="table_btn" size="mini" v-if="showButton('delete') && row.status === 1" @click="changeStatus(row, 2)">下架</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
<div class="main_footer">
|
<el-pagination
|
background
|
@current-change="changePageNum"
|
@size-change="changePageSize"
|
:current-page="pageNum"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="pageSize"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total">
|
</el-pagination>
|
</div>
|
<!-- 新增公告 修改公告信息 -->
|
<el-dialog
|
class="prop_dialog"
|
:title="asyncTitle ? '新增公告' : '修改公告信息'"
|
:visible.sync="asyncAffiche"
|
width="45%">
|
<el-form ref="form" :model="formAffiche" :rules="rulesAffiche" label-width="auto" class="rule_form">
|
<el-form-item label="公告名称:" prop="noticeName">
|
<el-input v-model="formAffiche.noticeName" clearable placeholder="请输入公告名称"></el-input>
|
</el-form-item>
|
<el-form-item label="公告分类:" prop="noticeType">
|
<el-select v-model="formAffiche.noticeType" clearable placeholder="请选择公告分类">
|
<el-option
|
v-for="item in afficheType"
|
:key="item.dictId"
|
:label="item.dictName"
|
:value="item.dictId">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="公告内容:" prop="noticeContent">
|
<edit-forms v-if="asyncAffiche" :editor-show.sync="formAffiche.noticeContent" @editorCreate="editorCreate" />
|
</el-form-item>
|
</el-form>
|
<div slot="footer">
|
<el-button @click="asyncAffiche = false">取 消</el-button>
|
<el-button class="submit_btn" @click="asyncTitle ? submitInsertForm() : submitUpdateForm()">提 交</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { buttonPinia } from '../../pinia';
|
import EditForms from '@/components/EditForms.vue'
|
import { throttle } from '../../plugins/public';
|
export default {
|
components: {
|
EditForms
|
},
|
data() {
|
var validatePass = (rule, value, callback) => {
|
if (this.editInstance.getText().length > 5000) {
|
callback(new Error('公告文字数量应在5000字以内'));
|
} else {
|
callback();
|
}
|
};
|
return {
|
noticeName: '',
|
timeDate: '',
|
pageNum: 1,
|
pageSize: 10,
|
total: 0,
|
loading: false,
|
afficheList: [],
|
asyncTitle: true, // true 新增 false 修改
|
asyncAffiche: false, // 弹窗
|
formAffiche: {}, // 表单信息
|
rulesAffiche: {
|
noticeName: [{
|
required: true,
|
message: '请输入公告名称',
|
tirgger: 'blur'
|
}],
|
noticeType: [{
|
required: true,
|
message: '请选择公告分类',
|
tirgger: ['blur', 'change']
|
}],
|
noticeContent: [{
|
required: true,
|
message: '请输入公告内容',
|
tirgger: 'blur'
|
}, {
|
validator: validatePass,
|
trigger: 'blur'
|
}]
|
}, // 表单校验规则
|
afficheType: [], // 分类信息
|
editInstance: '', // 富文本实例
|
}
|
},
|
mounted() {
|
this.searchSafetyAfficheList(true);
|
},
|
methods: {
|
// 获取公告类型
|
async getAfficheTypeData() {
|
const { data } = await this.$api.Dictionary.searchDictionary({
|
dictType: 'su_notice_type',
|
pageNum: 1,
|
pageSize: 100000
|
});
|
this.afficheType = data.list;
|
},
|
// 查询安全公告信息
|
searchSafetyAfficheList(bol) {
|
if(bol) {
|
this.pageNum = 1;
|
}
|
this.loading = true;
|
this.afficheList = [];
|
this.$api.Safety.searchSafetyAfficheList({
|
pageNum: this.pageNum,
|
pageSize: this.pageSize,
|
noticeName: this.noticeName,
|
startTime: this.timeDate ? `${this.timeDate[0]} 00:00:00` : '',
|
endTime: this.timeDate ? `${this.timeDate[1]} 23:23:59` : ''
|
}).then((res) => {
|
if(res.success) {
|
this.total = res.data.total;
|
this.afficheList = res.data.list;
|
}
|
this.loading = false;
|
}).catch(() => {
|
this.loading = false;
|
})
|
},
|
// 打开添加信息
|
propInsert() {
|
this.asyncTitle = true;
|
this.asyncAffiche = true;
|
},
|
// 打开修改信息
|
propUpdate(row) {
|
this.asyncTitle = false;
|
this.asyncAffiche = true;
|
this.$nextTick(() => {
|
this.$set(this.formAffiche, 'id', row.id);
|
this.$set(this.formAffiche, 'noticeName', row.noticeName);
|
this.$set(this.formAffiche, 'noticeType', row.noticeType);
|
this.$set(this.formAffiche, 'noticeContent', row.noticeContent);
|
})
|
},
|
// 删除公告信息
|
deleteInfo(row) {
|
this.$confirm("该操作将删除该公告信息,是否继续删除?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning"
|
})
|
.then(() => {
|
this.$api.Safety.deleteSafetyAfficheInfo({
|
id: row.id
|
}).then(res => {
|
if(res.success) {
|
this.searchSafetyAfficheList(true);
|
this.$message.success("删除成功!");
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
})
|
.catch(() => {
|
this.$message.warning("您已取消");
|
})
|
},
|
// 修改发布状态
|
changeStatus(row, status) {
|
this.$api.Safety.upAndDownSafetyAfficheInfo({
|
id: row.id,
|
status: status
|
}).then((res) => {
|
if(res.success) {
|
this.$message.success(status === 1 ? '发布成功!': '下架成功!');
|
this.searchSafetyAfficheList();
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
},
|
// 提交添加信息
|
submitInsertForm: throttle(function() {
|
this.$refs.form.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.formAffiche);
|
this.$api.Safety.insertSafetyAfficheInfo(params).then((res) => {
|
if(res.success) {
|
this.asyncAffiche = false;
|
this.$message.success('添加成功!');
|
this.searchSafetyAfficheList(true);
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
// 提交修改信息
|
submitUpdateForm: throttle(function() {
|
this.$refs.form.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.formAffiche);
|
this.$api.Safety.insertSafetyAfficheInfo(params).then((res) => {
|
if(res.success) {
|
this.asyncAffiche = false;
|
this.$message.success('修改成功!');
|
this.searchSafetyAfficheList(true);
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
//富文本返回结果
|
editorCreate(editors){
|
this.editInstance = editors;
|
},
|
// 切换页码
|
changePageNum(page) {
|
this.pageNum = page;
|
this.searchSafetyAfficheList();
|
},
|
// 切换每页条数
|
changePageSize(size) {
|
this.pageSize = size;
|
this.searchSafetyAfficheList();
|
},
|
// 判断按钮权限信息
|
showButton(str) {
|
const pinia = buttonPinia();
|
return pinia.$state.buttonInfo.includes(str);
|
}
|
},
|
watch: {
|
asyncAffiche(bol) {
|
if(!bol) {
|
this.formAffiche = {};
|
this.$refs.form.resetFields();
|
} else {
|
this.getAfficheTypeData();
|
}
|
}
|
},
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import '@/style/layout-main.scss';
|
|
.notice_content {
|
white-space: nowrap;
|
overflow: hidden;
|
max-height: 48px;
|
text-overflow: ellipsis;
|
display: -webkit-box;
|
-webkit-line-clamp: 1; // 超出多少行
|
-webkit-box-orient: vertical;
|
}
|
|
::v-deep .w-e-scroll {
|
color: #fff;
|
background: #061C48;
|
}
|
|
::v-deep .editor_index {
|
margin-top: 0 !important;
|
}
|
</style>
|