feat(notice): 公告内容使用富文本编辑器替换普通文本域

- 用 Editor 组件替换了原有的 el-input textarea
- 添加了上传配置,支持文件上传
- 对富文本内容进行 URL 编码和解码,确保数据传输的正确性
-优化了表单提交逻辑,增加了错误处理
This commit is contained in:
syruan 2025-06-02 16:13:45 +08:00
parent 527a31753f
commit 7361779af9
1 changed files with 56 additions and 14 deletions

View File

@ -207,15 +207,11 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-form-item label="内容" prop="noticeContent"> <el-form-item label="公告内容" prop="noticeContent">
<!-- <editor v-model="form.noticeContent" :min-height="192" /> --> <editor
<el-input
type="textarea"
v-model="form.noticeContent" v-model="form.noticeContent"
:rows="8" :min-height="192"
show-word-limit :upload-config="uploadConfig"
maxlength="500"
placeholder="请输入内容"
/> />
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -233,11 +229,15 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from '@/api/system/notice' import { listNotice, getNotice, delNotice, addNotice, updateNotice } from '@/api/system/notice'
import { deptTreeSelect } from '@/api/system/user' import { deptTreeSelect } from '@/api/system/user'
import { listRole } from '@/api/system/role' import { listRole } from '@/api/system/role'
import Editor from '@/components/Editor'
export default { export default {
name: 'Notice', name: 'Notice',
dicts: ['sys_notice_status', 'sys_notice_type'], dicts: ['sys_notice_status', 'sys_notice_type'],
components: { Treeselect }, components: {
Treeselect,
Editor
},
data() { data() {
return { return {
// //
@ -292,6 +292,30 @@ export default {
return time.getTime() < new Date().setHours(0, 0, 0, 0) return time.getTime() < new Date().setHours(0, 0, 0, 0)
}, },
}, },
uploadConfig: {
action: process.env.VUE_APP_BASE_API + '/file/upload',
headers: {
Authorization: 'Bearer ' + this.$store.getters.token
},
data: {
//
},
//
onSuccess: (response) => {
//
if (response.code === 200) {
return {
url: response.data?.url || response.url,
name: response.data?.name || response.name
}
}
return false
},
onError: (error) => {
this.$modal.msgError('文件上传失败')
console.error('上传错误:', error)
}
},
} }
}, },
created() { created() {
@ -360,7 +384,12 @@ export default {
this.reset() this.reset()
const noticeId = row.noticeId || this.ids const noticeId = row.noticeId || this.ids
listNotice({ noticeId, isHome: 1 }).then((response) => { listNotice({ noticeId, isHome: 1 }).then((response) => {
this.form = response.data.rows[0] const data = response.data.rows[0]
this.form = {
...data,
//
noticeContent: data.noticeContent ? decodeURIComponent(data.noticeContent) : ''
}
this.open = true this.open = true
}) })
}, },
@ -368,18 +397,31 @@ export default {
submitForm: function () { submitForm: function () {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
console.log('🚀 ~ 提交 ~ this.form:', this.form) const formData = {
if (this.form.noticeId != undefined) { ...this.form,
updateNotice(this.form).then((response) => { // URLJSON
noticeContent: encodeURIComponent(this.form.noticeContent || '')
}
console.log('🚀 ~ 提交 ~ formData:', formData)
if (formData.noticeId != undefined) {
updateNotice(formData).then((response) => {
this.$modal.msgSuccess('修改成功') this.$modal.msgSuccess('修改成功')
this.open = false this.open = false
this.getList() this.getList()
}).catch(error => {
console.error('更新失败:', error)
this.$modal.msgError('更新失败,请检查输入内容')
}) })
} else { } else {
addNotice(this.form).then((response) => { addNotice(formData).then((response) => {
this.$modal.msgSuccess('新增成功') this.$modal.msgSuccess('新增成功')
this.open = false this.open = false
this.getList() this.getList()
}).catch(error => {
console.error('新增失败:', error)
this.$modal.msgError('新增失败,请检查输入内容')
}) })
} }
} }