2 changed files with 356 additions and 4 deletions
@ -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(/ /ig, '') // 去掉 |
|||
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> |
Loading…
Reference in new issue