Browse Source

新闻和通知模块添加功能-有数据权限的新闻和通知列表

master
曲树通 6 years ago
parent
commit
92d7dfcafd
  1. 382
      src/views/modules/news/allnews-add-or-update.vue
  2. 392
      src/views/modules/news/allnews.vue
  3. 286
      src/views/modules/news/allnotice-add-or-update.vue
  4. 159
      src/views/modules/news/allnotice.vue

382
src/views/modules/news/allnews-add-or-update.vue

@ -0,0 +1,382 @@
<template>
<el-dialog :visible.sync="visible"
title="查看"
:close-on-click-modal="false"
:close-on-press-escape="false"
@close="visible= false">
<el-form :model="dataForm"
:rules="dataRule"
ref="dataForm"
:label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
<el-form-item label="所属机构:">
<el-form-item>
{{dataForm.allDeptNames}}
</el-form-item>
</el-form-item>
<el-form-item label="类别"
prop="newsCateroryId">
<el-form-item>
{{dataForm.newsProperty}}
</el-form-item>
</el-form-item>
<el-form-item label="新闻标题"
prop="newsTitle">
<el-form-item>
{{dataForm.newsTitle}}
</el-form-item>
</el-form-item>
<el-form-item prop="newsContent"
label="正文编辑">
<!-- 富文本编辑器, 容器 -->
<div id="J_quillEditor"></div>
<!-- 自定义上传图片功能 (使用element upload组件) -->
<el-upload :action="uploadUrl"
:show-file-list="false"
:before-upload="uploadBeforeUploadHandle"
:on-success="uploadSuccessHandle"
style="display: none;">
<el-button ref="uploadBtn"
type="primary"
size="small">{{ $t('upload.button') }}</el-button>
</el-upload>
</el-form-item>
<el-form-item label="新闻首图"
v-loading="loading"
prop="newsImageUrl">
<el-upload class="avatar-uploader"
:action="uploadUrl"
:show-file-list="false"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload">
<img v-if="dataForm.newsImageUrl"
:src="dataForm.newsImageUrl"
class="avatar">
<i v-else
class="el-icon-plus avatar-uploader-icon"></i>
<div slot="tip"
class="el-upload__tip">只能上传jpg/png文件且不超过500kb</div>
</el-upload>
</el-form-item>
<el-form-item label="显示时长"
prop="newsReleaseStartTime">
<el-date-picker @change='setRegistTime'
v-model="time"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
</template>
</el-dialog>
</template>
<script>
import Cookies from 'js-cookie'
import debounce from 'lodash/debounce'
import 'quill/dist/quill.snow.css'
import Quill from 'quill'
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './news-add-or-update'
export default {
mixins: [mixinViewModule],
data () {
return {
mixinViewModuleOptions: {
getDataListURL: '/news/news/page',
getDataListIsPage: true,
deleteURL: '/news/news',
deleteIsBatch: true
},
dataForm: {
id: '',
streetId: null,
street: null,
communityId: null,
community: null,
gridId: null,
grid: null,
newsCateroryId: '',
newsProperty: '',
newsTitle: '',
newsReleaseStartTime: '',
newsReleaseEndTime: '',
newsContent: '',
newsImageUrl: '',
allDeptIdsShow: []
},
time: [],
streetList: [],
communityList: [],
gridList: [],
options: [],
categorys: [],
loading: false,
//
quillEditor: null,
quillEditorToolbarOptions: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block', 'image'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
['clean']
],
uploadUrl: '',
// end
fileList: [],
visible: false
}
},
created () {
this.$http
.get(`/sys/user/deptOptions/getByLoginUser`)
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.options = res.data.options
})
.catch(() => { })
this.getDeptInfoList('street', localStorage.getItem('street') === null ? '1169154711480528897' : localStorage.getItem('street'))
this.getListCategory()
this.visible = true
this.$nextTick(() => {
this.dataForm.communityId = this.dataForm.streetId = this.dataForm.gridId = null
//
this.hideUpload = false
this.uploadUrl = `${window.SITE_CONFIG['apiURL']}/oss/file/upload?token=${Cookies.get('token')}`
if (this.quillEditor) {
this.quillEditor.deleteText(0, this.quillEditor.getLength())
} else {
this.quillEditorHandle()
}
// end
})
},
computed: {
dataRule () {
return {
streetId: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
newsTitle: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
newsReleaseStartTime: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
newsImageUrl: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
newsCateroryId: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
newsContent: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
]
}
}
},
methods: {
init () {
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.getInfo()
}
})
},
//
getInfo () {
this.$http.get(`/news/news/${this.dataForm.id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.dataForm = { ...this.dataForm, ...res.data }
this.resetRegistTime()
this.quillEditor.root.innerHTML = res.data.newsContent
if (this.dataForm.streetId) {
if (this.dataForm.communityId === 0) {
this.dataForm.communityId = this.dataForm.gridId = null
}
this.getDeptInfoList('community', this.dataForm.streetId)
}
if (this.dataForm.communityId) {
if (this.dataForm.gridId === 0) {
this.dataForm.gridId = null
}
this.getDeptInfoList('grid', this.dataForm.communityId)
}
}).catch(() => { })
},
//
getDeptInfoList (dataReceiver, faDeptId) {
if (!faDeptId) {
return
}
this.$http.get(`/sys/dept/sublist/` + faDeptId).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
if (dataReceiver === 'street') {
let all = [{ id: '1', name: '全部' }]
this.streetList = all.concat(res.data)
} else if (dataReceiver === 'community') {
this.communityList = res.data
} else if (dataReceiver === 'grid') {
this.gridList = res.data
}
}).catch(() => { })
},
changeStreet (event) {
let choosenItem = this.streetList.filter(item => item.id === this.dataForm.streetId)[0]
this.dataForm.street = choosenItem.name
this.dataForm.communityId = this.dataForm.gridId = this.dataForm.community = this.dataForm.grid = null
this.communityList = this.gridList = []
this.getDeptInfoList('community', event)
},
changeCommunity (event) {
let choosenItem = this.communityList.filter(item => item.id === this.dataForm.communityId)[0]
this.dataForm.community = choosenItem.name
this.dataForm.gridId = this.dataForm.grid = null
this.gridList = []
this.getDeptInfoList('grid', event)
},
changeGrid (event) {
let choosenItem = this.gridList.filter(item => item.id === this.dataForm.gridId)[0]
this.dataForm.grid = choosenItem.name
},
changeCaterory () {
//
let choosenItem = this.categorys.filter(item => item.id === this.dataForm.newsCateroryId)[0]
this.dataForm.newsProperty = choosenItem.name
},
getListCategory () {
this.$http.get(`/news/newscategory/category`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.categorys = res.data
}).catch(() => { })
},
//
quillEditorHandle () {
this.quillEditor = new Quill('#J_quillEditor', {
modules: {
toolbar: this.quillEditorToolbarOptions
},
theme: 'snow'
})
this.quillEditor.container.style.height = `${300}px`
// // (使element upload)
this.quillEditor.getModule('toolbar').addHandler('image', () => {
this.$refs.uploadBtn.$el.click()
})
//
this.quillEditor.on('text-change', () => {
this.dataForm.newsContent = this.quillEditor.root.innerHTML
if ((this.dataForm.newsContent).length > 10000) {
return this.$message.error('您输入的的内容已超过字数不能提交')
}
})
},
// ()
uploadBeforeUploadHandle (file) {
if (file.type !== 'image/jpg' && file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
this.$message.error(this.$t('upload.tip', { 'format': 'jpg、png、gif' }))
return false
}
},
// ()
uploadSuccessHandle (res, file, fileList) {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.quillEditor.insertEmbed(this.quillEditor.getSelection().index, 'image', res.data.url)
},
//
handleAvatarSuccess (res, file) {
this.loading = false
this.dataForm.newsImageUrl = res.data.url
},
beforeAvatarUpload (file) {
this.loading = true
},
setRegistTime () {
this.dataForm.newsReleaseStartTime = this.time[0]
this.dataForm.newsReleaseEndTime = this.time[1]
},
resetRegistTime () {
this.time = [this.dataForm.newsReleaseStartTime.substr(0, 10), this.dataForm.newsReleaseEndTime.substr(0, 10)]
},
// end
//
dataFormSubmitHandle: debounce(function () {
if ((this.dataForm.newsContent).length > 10000) {
return this.$message.error('您输入的的内容已超过字数不能提交')
}
this.$refs['dataForm'].validate((valid) => {
if (!valid) {
return false
}
this.$http['put']('/news/news/', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
this.dataForm = {}
}
})
}).catch(() => { })
})
}, 1000, { 'leading': true, 'trailing': false })
},
components: {
AddOrUpdate
}
}
</script>
<style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>

392
src/views/modules/news/allnews.vue

@ -0,0 +1,392 @@
<template>
<el-card shadow="never"
class="aui-card--fill">
<div class="mod-news__news}">
<el-form :inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()">
<!-- <el-form-item label="所属机构">
<el-cascader v-model="deptIdList"
:options="options"
:props="{ checkStrictly: true }"
clearable></el-cascader>
</el-form-item> -->
<!--<el-form-item label="所属街道"
prop="deptId">
<el-select v-model="dataForm.streetId"
@change="changeStreet"
clearable
placeholder="所属街道">
<el-option v-for="item in streetList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="所属社区">
<el-select v-model="dataForm.communityId"
@change="changeCommunity"
clearable
placeholder="所属社区">
<el-option v-for="item in communityList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="所属网格">
<el-select v-model="dataForm.gridId"
@change="changeGrid"
clearable
placeholder="所属网格">
<el-option v-for="item in gridList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>-->
<br>
<span class="demonstration">提交时间</span>&nbsp;&nbsp;
<el-date-picker @change='setRegistTime'
v-model="time"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker> &nbsp; &nbsp;
<el-form-item label="类别">
<el-select v-model="dataForm.category"
clearable
placeholder="所属类别">
<el-option v-for="item in categorys"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-form-item>
<el-input v-model="dataForm.keyword"
placeholder="请输入标题"
clearable></el-input>
</el-form-item>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">{{ $t('query') }}</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="$hasPermission('news:news:save')"
type="primary"
@click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="$hasPermission('news:news:delete')"
type="danger"
@click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
</el-form-item>
</el-form>
<el-table v-loading="dataListLoading"
:data="dataList"
border
@selection-change="dataListSelectionChangeHandle"
style="width: 100%;">
<el-table-column label="序号"
width="70px">
<template slot-scope="scope">
{{scope.$index+1}}
</template>
</el-table-column>
<el-table-column prop="newsTitle"
label="标题名称"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="readingAmount"
label="阅读量"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="likeNumber"
label="支持数"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="unLikeNumber"
label="不支持数"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="createdTime"
label="提交时间"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="creatorName"
label="提交人"
header-align="center"
align="center"></el-table-column>
<el-table-column label="有效时间">
<template slot-scope="scope">
{{scope.row.newsReleaseStartTime}}<br /> <br /> {{scope.row.newsReleaseEndTime}}
</template>
</el-table-column>
<el-table-column label="发布状态"
:formatter="publishState"
header-align="center"
align="center">
</el-table-column>
<!-- <el-table-column prop="newsUpDownState" label="新闻上下线状态" :formatter="newsUpDownState" header-align="center" align="center"></el-table-column> -->
<el-table-column :label="$t('handle')"
fixed="right"
header-align="center"
align="center"
width="200">
<template slot-scope="scope">
<el-button type="text"
size="small"
@click="addOrUpdateHandle(scope.row.id)">查看</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination :current-page="page"
:page-sizes="[10, 20, 50, 100]"
:page-size="limit"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="pageSizeChangeHandle"
@current-change="pageCurrentChangeHandle">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"></add-or-update>
</div>
</el-card>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './allnews-add-or-update'
export default {
mixins: [mixinViewModule],
data () {
return {
mixinViewModuleOptions: {
getDataListURL: '/news/news/allPage',
getDataListIsPage: true,
deleteURL: '/news/news',
deleteIsBatch: true
},
dataForm: {
id: '',
streetId: '',
communityId: '',
gridId: '',
startTime: '',
endTime: '',
keyword: '',
category: ''
},
time: '',
options: [],
deptIdList: [],
streetList: [],
communityList: [],
gridList: [],
categorys: [],
onLine: {
id: '',
onLineState: ''
}
}
},
created () {
this.$http
.get(`/sys/user/deptOptions/getByLoginUser`)
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.options = res.data.options
})
.catch(() => { })
this.getDeptInfoList('street', localStorage.getItem('street') === null ? '1169154711480528897' : localStorage.getItem('street'))
this.getListCategory()
},
methods: {
newsUpDownState: function (row) {
return row.newsUpDownState === '1' ? '下线' : '上线'
},
publishState: function (row) {
var stdt = new Date(row.newsReleaseStartTime.replace('-', '/'))
var eddt = new Date(row.newsReleaseEndTime.replace('-', '/'))
var nowdt = new Date()
if (row.newsUpDownState === '1') {
// 线
return '已下线'
}
if (nowdt > stdt && nowdt < eddt && row.newsUpDownState === '0') {
return '已上线'
}
if (nowdt < stdt) {
return '未上线'
}
if (nowdt > eddt) {
return '已下线'
}
},
//
getDeptInfoList (dataReceiver, faDeptId) {
this.$http.get(`/sys/dept/sublist/` + faDeptId).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
if (dataReceiver === 'street') {
this.streetList = res.data
} else if (dataReceiver === 'community') {
this.communityList = res.data
} else if (dataReceiver === 'grid') {
this.gridList = res.data
}
}).catch(() => { })
},
changeStreet (event) {
if (this.dataForm.streetId === '') {
this.communityList = []
this.gridList = []
this.dataForm.communityId = ''
this.dataForm.gridId = ''
return
}
this.dataForm.streetId = event
let choosenItem = this.streetList.filter(item => item.id === this.dataForm.streetId)[0]
this.initDeptIdAndName(choosenItem)
this.dataForm.communityId = this.dataForm.gridId = null
this.communityList = this.gridList = []
this.getDeptInfoList('community', event)
},
changeCommunity (event) {
if (this.dataForm.communityId === '') {
this.gridList = []
this.dataForm.gridId = ''
return
}
this.communityId = event
let choosenItem = this.communityList.filter(item => item.id === this.dataForm.communityId)[0]
this.initDeptIdAndName(choosenItem)
this.dataForm.gridId = null
this.gridList = []
this.getDeptInfoList('grid', event)
},
changeGrid (event) {
this.dataForm.gridId = event
let choosenItem = this.gridList.filter(item => item.id === this.gridId)[0]
this.initDeptIdAndName(choosenItem)
},
initDeptIdAndName (choosenItem) {
this.dataForm.dept = choosenItem.name
this.dataForm.deptId = choosenItem.id
},
setRegistTime () {
console.log(this.time[0])
this.dataForm.startTime = this.time[0]
this.dataForm.endTime = this.time[1]
},
getListCategory () {
this.$http.get(`/news/newscategory/category/`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.categorys = res.data
}).catch(() => { })
},
modifyOnLine (row) {
this.$confirm(this.$t('prompt.info', { 'handle': '下线' }), this.$t('下线'), {
confirmButtonText: this.$t('confirm'),
cancelButtonText: this.$t('cancel'),
type: 'warning'
}).then(() => {
this.onLine.id = row.id
this.onLine.onLineState = '0'
console.log(this.onLine)
this.$http.post(`/news/news/modifyOnLine/`, this.onLine).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
}
})
this.getDataList()
}).catch(() => { })
}).catch(() => { })
},
newsToBanner (row) {
this.$confirm(this.$t('prompt.info', { 'handle': '上banner' }), this.$t('上banner'), {
confirmButtonText: this.$t('confirm'),
cancelButtonText: this.$t('cancel'),
type: 'warning'
}).then(() => {
this.$http.post(`/news/news/newsToBanner/` + row.id).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
}
})
this.getDataList()
}).catch(() => { })
}).catch(() => { })
},
//
getDataList () {
if (this.time === null) {
this.dataForm.startTime = ''
this.dataForm.endTime = ''
}
this.dataListLoading = true
this.$http.get(
this.mixinViewModuleOptions.getDataListURL,
{
params: {
order: this.order,
orderField: this.orderField,
page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
limit: this.mixinViewModuleOptions.getDataListIsPage ? this.limit : null,
...this.dataForm
}
}
).then(({ data: res }) => {
this.dataListLoading = false
if (res.code !== 0) {
this.dataList = []
this.total = 0
return this.$message.error(res.msg)
}
this.dataList = this.mixinViewModuleOptions.getDataListIsPage ? res.data.list : res.data
this.total = this.mixinViewModuleOptions.getDataListIsPage ? res.data.total : 0
}).catch(() => {
this.dataListLoading = false
})
}
},
components: {
AddOrUpdate
},
watch: {
'deptIdList': function (val) {
if (val.length !== 0) {
this.dataForm.gridId = val[val.length - 1]
} else {
this.dataForm.gridId = ''
}
}
}
}
</script>

286
src/views/modules/news/allnotice-add-or-update.vue

@ -0,0 +1,286 @@
<template>
<el-dialog :visible.sync="visible"
title="查看"
:close-on-click-modal="false"
:close-on-press-escape="false">
<el-form :model="dataForm"
:rules="dataRule"
ref="dataForm"
:label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
<el-form-item label="所属机构"
prop="allDeptIdsShow">
<el-form-item>
{{dataForm.allDeptNames}}
</el-form-item>
</el-form-item>
<el-form-item label="通知标题"
prop="noticeTitle">
<el-form-item>
{{dataForm.noticeTitle}}
</el-form-item>
</el-form-item>
<el-form-item prop="noticeContent"
label="通知内容">
<el-row style="height: 550px;">
<!-- 富文本编辑器, 容器 -->
<div id="J_quillEditor"
style="height: 500px;"></div>
</el-row>
<!-- 自定义上传图片功能 (使用element upload组件) -->
<el-upload :action="uploadUrl"
:show-file-list="false"
:before-upload="uploadBeforeUploadHandle"
:on-success="uploadSuccessHandle"
style="display: none;">
<el-button ref="uploadBtn"
type="primary"
size="small">{{ $t('upload.button') }}</el-button>
</el-upload>
</el-form-item>
</el-form>
<template slot="footer">
<el-button @click="visible = false">{{ $t('cancel') }}</el-button>
</template>
</el-dialog>
</template>
<script>
import Cookies from 'js-cookie'
import debounce from 'lodash/debounce'
import 'quill/dist/quill.snow.css'
import Quill from 'quill'
export default {
data () {
return {
visible: false,
dataForm: {
id: '',
streetId: null,
street: null,
communityId: null,
community: null,
gridId: null,
grid: null,
noticeTitle: '',
noticeContent: '',
allDeptIdsShow: []
},
value: '',
//
quillEditor: null,
quillEditorToolbarOptions: [
['bold', 'italic', 'underline', 'strike'],
['image'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': [] }],
[{ 'align': [] }],
['clean']
],
uploadUrl: '',
// end
streetList: [],
communityList: [],
gridList: [],
options: []
}
},
computed: {
dataRule () {
return {
streetId: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
allDeptIdsShow: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
noticeTitle: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
noticeContent: [
{ required: true, message: this.$t(' ') }
]
}
}
},
created () {
this.$http
.get(`/sys/user/deptOptions/getAllByLoginUser`)
.then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.options = res.data.options
})
.catch(() => { })
// 1169154711480528897 ID
this.getDeptInfoList('street', localStorage.getItem('street') === null ? '1169154711480528897' : localStorage.getItem('street'))
},
methods: {
//
quillEditorHandle () {
this.quillEditor = new Quill('#J_quillEditor', {
modules: {
toolbar: this.quillEditorToolbarOptions
},
theme: 'snow'
})
// // (使element upload)
this.quillEditor.getModule('toolbar').addHandler('image', () => {
this.$refs.uploadBtn.$el.click()
})
//
this.quillEditor.on('text-change', () => {
this.dataForm.noticeContent = this.quillEditor.root.innerHTML
if ((this.dataForm.noticeContent).length > 10000) {
return this.$message.error('您输入的的内容已超过字数不能提交')
}
})
},
// ()
uploadBeforeUploadHandle (file) {
if (file.type !== 'image/jpg' && file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
this.$message.error(this.$t('upload.tip', { 'format': 'jpg、png、gif' }))
return false
}
},
// ()
uploadSuccessHandle (res, file, fileList) {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.quillEditor.insertEmbed(this.quillEditor.getSelection().index, 'image', res.data.url)
},
init () {
this.visible = true
this.$nextTick(() => {
this.dataForm.communityId = this.dataForm.streetId = this.dataForm.gridId = null
this.communityList = this.gridList = []
//
this.hideUpload = false
this.uploadUrl = `${window.SITE_CONFIG['apiURL']}/oss/file/upload?token=${Cookies.get('token')}`
if (this.quillEditor) {
this.quillEditor.deleteText(0, this.quillEditor.getLength())
} else {
this.quillEditorHandle()
}
// end
this.$refs['dataForm'].resetFields()
if (this.dataForm.id) {
this.getInfo()
} else {
this.dataForm = {}
}
})
},
//
getInfo () {
this.$http.get(`/news/notice/${this.dataForm.id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.dataForm = { ...this.dataForm, ...res.data }
this.quillEditor.root.innerHTML = res.data.noticeContent
if (this.dataForm.streetId) {
if (this.dataForm.communityId === 0) {
this.dataForm.communityId = this.dataForm.gridId = null
}
this.getDeptInfoList('community', this.dataForm.streetId)
}
if (this.dataForm.communityId) {
if (this.dataForm.gridId === 0) {
this.dataForm.gridId = null
}
this.getDeptInfoList('grid', this.dataForm.communityId)
}
}).catch(() => { })
},
removeHTMLTag (str) {
str = str.replace('<p><br></p>', '')
return str
},
//
dataFormSubmitHandle: debounce(function () {
console.log(this.dataForm.noticeContent)
if (this.dataForm.noticeContent != null && this.dataForm.noticeContent !== undefined) {
this.dataForm.noticeContent = this.removeHTMLTag(this.dataForm.noticeContent)
if ((this.dataForm.noticeContent).length > 10000) {
return this.$message.error('您输入的的内容已超过字数不能提交')
} else if (this.dataForm.noticeContent.length === 0) {
return this.$message.error('通知内容不能空')
}
} else {
return this.$message.error('通知内容不能为空')
}
this.$refs['dataForm'].validate((valid) => {
if (!valid) {
return false
}
this.$http[!this.dataForm.id ? 'post' : 'put']('/news/notice', this.dataForm).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
}).catch(() => { })
})
}, 1000, { 'leading': true, 'trailing': false }),
//
getDeptInfoList (dataReceiver, faDeptId) {
this.$http.get(`/sys/dept/sublist/` + faDeptId).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
if (dataReceiver === 'street') {
this.streetList = res.data
} else if (dataReceiver === 'community') {
this.communityList = res.data
} else if (dataReceiver === 'grid') {
this.gridList = res.data
}
}).catch(() => { })
},
changeStreet () {
//
let choosenItem = this.streetList.filter(item => item.id === this.dataForm.streetId)[0]
this.dataForm.street = choosenItem.name
//
this.dataForm.communityId = this.dataForm.gridId = this.dataForm.community = this.dataForm.grid = null
this.communityList = this.gridList = []
//
this.getDeptInfoList('community', this.dataForm.streetId)
},
changeCommunity () {
//
let choosenItem = this.communityList.filter(item => item.id === this.dataForm.communityId)[0]
this.dataForm.community = choosenItem.name
//
this.dataForm.gridId = this.dataForm.grid = null
this.gridList = []
//
this.getDeptInfoList('grid', this.dataForm.communityId)
},
changeGrid (item) {
console.log(item)
//
// let choosenItem = this.gridList.filter(item => item.id === this.dataForm.gridId)[0]
// this.dataForm.grid = choosenItem.name
// this.dataForm = Object.assign(this.dataForm, { gridId: item })
console.log(this.dataForm)
}
}
}
</script>

159
src/views/modules/news/allnotice.vue

@ -0,0 +1,159 @@
<template>
<el-card shadow="never"
class="aui-card--fill">
<div class="mod-news__notice}">
<el-form :inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()">
<el-form-item>
<el-input v-model="dataForm.noticeTitle"
placeholder="通知标题"
clearable></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">{{ $t('query') }}</el-button>
</el-form-item>
<!-- <el-form-item>
<el-button v-if="$hasPermission('news:notice:save')"
type="primary"
@click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
</el-form-item>
<el-form-item>
<el-button v-if="$hasPermission('news:notice:delete')"
type="danger"
@click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
</el-form-item> -->
</el-form>
<el-table v-loading="dataListLoading"
:data="dataList"
border
@selection-change="dataListSelectionChangeHandle"
style="width: 100%;">
<el-table-column type="selection"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="noticeTitle"
label="通知标题"
header-align="center"
align="center"
width="350"></el-table-column>
<el-table-column prop="deptName"
label="通知所属部门"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="readingAmount"
label="阅读量"
header-align="center"
align="center"
width="100"></el-table-column>
<el-table-column prop="creatorName"
label="创建人"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="createdTime"
label="创建时间"
header-align="center"
align="center"></el-table-column>
<el-table-column prop="noticeReleaseState"
label="已发布"
header-align="center"
:formatter="showIsPublishFormatter"
align="center"
width="100"></el-table-column>
<el-table-column prop="releaseTime"
label="发布时间"
header-align="center"
align="center"></el-table-column>
<el-table-column :label="$t('handle')"
fixed="right"
header-align="center"
align="center"
width="300">
<template slot-scope="scope">
<el-button v-if="$hasPermission('news:notice:update')"
type="primary"
size="mini"
@click="addOrUpdateHandle(scope.row.id)">查看</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination :current-page="page"
:page-sizes="[10, 20, 50, 100]"
:page-size="limit"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="pageSizeChangeHandle"
@current-change="pageCurrentChangeHandle">
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"></add-or-update>
</div>
</el-card>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './allnotice-add-or-update'
export default {
mixins: [mixinViewModule],
data () {
return {
mixinViewModuleOptions: {
getDataListURL: '/news/notice/pageForReadOnly',
getDataListIsPage: true,
deleteURL: '/news/notice',
deleteIsBatch: true
},
dataForm: {
noticeTitle: ''
}
}
},
components: {
AddOrUpdate
},
methods: {
//
noticePublishHandle (id) {
this.$confirm(this.$t('prompt.info', { 'handle': '发布' }), this.$t('发布'), {
confirmButtonText: this.$t('confirm'),
cancelButtonText: this.$t('cancel'),
type: 'warning'
}).then(() => {
this.$http.post(`/news/notice/publish/${id}`).then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
this.$message({
message: this.$t('prompt.success'),
type: 'success',
duration: 500,
onClose: () => {
this.getDataList()
}
})
}).catch(() => { })
}).catch(() => { })
},
showIsPublishFormatter: function (row, column) {
if (row.noticeReleaseState === '0') {
return '否'
}
return '是'
},
showDeptNameFormatter: function (row, column) {
if (row.grid) {
return row.grid
}
if (row.community) {
return row.community
}
if (row.street) {
return row.street
}
}
}
}
</script>
Loading…
Cancel
Save