Browse Source

后台内容管理开发

origin/feature/monitoring
Jackwang 4 years ago
parent
commit
4d262dcc20
  1. 346
      src/views/modules/news/noticeadmin-add-or-update.vue
  2. 14
      src/views/modules/news/noticeadmin.vue

346
src/views/modules/news/noticeadmin-add-or-update.vue

@ -0,0 +1,346 @@
<template>
<el-dialog :visible.sync="visible"
:title="!dataForm.id ? $t('add') : $t('update')"
: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-cascader v-model="dataForm.allDeptIdsShow"
:options="options"
:props="{ multiple: true }"
clearable
collapse-tags></el-cascader>
</el-form-item>
<el-form-item label="栏目" prop="allTypeId">
<el-cascader v-model="dataForm.allTypeId" :options="moduleOptions" @change="changeHandle"
:props="{ checkStrictly: true, multiple: false, emitPath: true }"
clearable>
</el-cascader>
</el-form-item>
<el-form-item label="置顶" prop="topFlag">
<el-select v-model="dataForm.topFlag" clearable placeholder="置顶状态">
<el-option v-for="item in topFlagList" :key="item.dictValue" :label="item.dictName" :value="item.dictValue">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="上下架" prop="noticeUpDownState">
<el-select v-model="dataForm.noticeUpDownState" clearable placeholder="上下架状态">
<el-option v-for="item in noticeUpDownStateList" :key="item.dictValue" :label="item.dictName" :value="item.dictValue">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="标题"
prop="noticeTitle">
<el-input v-model="dataForm.noticeTitle"
maxlength="50"
show-word-limit
placeholder="标题"></el-input>
</el-form-item>
<el-form-item prop="noticeContent"
label="内容">
<el-row style="height: 550px;">
<!-- 富文本编辑器, 容器 -->
<div id="J_quillEditor" class="ql-editor"
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>
<el-button type="primary"
@click="dataFormSubmitHandle()">{{ $t('confirm') }}</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: [],
allTypeId:[],
typeId:'',
topFlag:'',
noticeUpDownStateList:''
},
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: [],
moduleOptions:[],
topFlagList: [
{dictValue: '0', dictName: '否'},
{dictValue: '1', dictName: '是'},
],
noticeUpDownStateList: [
{dictValue: '0', dictName: '下架'},
{dictValue: '1', dictName: '上架'},
]
}
},
computed: {
dataRule () {
return {
topFlag: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
allTypeId: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
noticeUpDownState: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
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: {
changeHandle(value){
this.dataForm.typeId = this.dataForm.allTypeId[value.length-1]
},
//
getModuleTypeInfo() {
this.$http.get(`news/moduletype/getModuleListByRole`).then(({data: res}) => {
this.moduleOptions = res.data.moduleOptions
}).catch(() => {
})
},
//
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.getModuleTypeInfo()
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>', '')
str = str.replace(/<\/?[^>]*>/g, '') // HTML tag
str = str.replace(/[ | ]*\n/g, '\n') //
str = str.replace(/&nbsp;/ig, '') // &nbsp;
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/saveOrUpContent', 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>

14
src/views/modules/news/noticeadmin.vue

@ -41,11 +41,17 @@
align="left" align="left"
min-width="400px" min-width="400px"
show-overflow-tooltip></el-table-column> show-overflow-tooltip></el-table-column>
<el-table-column prop="typeName"
label="所属栏目"
header-align="center"
align="center"
min-width="130px"
show-overflow-tooltip></el-table-column>
<el-table-column prop="deptName" <el-table-column prop="deptName"
label="所属网格" label="所属网格"
header-align="center" header-align="center"
min-width="150px" min-width="150px"
align="left"></el-table-column> align="center"></el-table-column>
<!-- <el-table-column prop="readingAmount"--> <!-- <el-table-column prop="readingAmount"-->
<!-- label="阅读量"--> <!-- label="阅读量"-->
<!-- header-align="center"--> <!-- header-align="center"-->
@ -55,7 +61,7 @@
label="创建人" label="创建人"
header-align="center" header-align="center"
width="100px" width="100px"
align="left"></el-table-column> align="center"></el-table-column>
<el-table-column prop="createdTime" <el-table-column prop="createdTime"
label="创建时间" label="创建时间"
header-align="center" header-align="center"
@ -111,13 +117,13 @@
<script> <script>
import mixinViewModule from '@/mixins/view-module' import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './notice-add-or-update' import AddOrUpdate from './noticeadmin-add-or-update'
export default { export default {
mixins: [mixinViewModule], mixins: [mixinViewModule],
data () { data () {
return { return {
mixinViewModuleOptions: { mixinViewModuleOptions: {
getDataListURL: '/news/notice/page', getDataListURL: '/news/notice/modulePage',
getDataListIsPage: true, getDataListIsPage: true,
deleteURL: '/news/notice', deleteURL: '/news/notice',
deleteIsBatch: true deleteIsBatch: true

Loading…
Cancel
Save