This commit is contained in:
2026-07-14 16:40:42 +08:00
parent 33687bbd66
commit 2168888ca7
149 changed files with 2784 additions and 692 deletions
@@ -170,6 +170,16 @@ module.exports = {
type: Number,
default: 300
},
// 富文本编辑器占位提示,透传给 wangEditor 初始化配置。
placeholder: {
type: String,
default: ""
},
// 编辑区顶部红色提示,只做展示,不写入编辑器正文内容。
topTip: {
type: String,
default: ""
},
menus: {
type: Array,
default: () => {
@@ -205,13 +215,18 @@ module.exports = {
data() {
return {
editor: null,
cursorPos: 0
cursorPos: 0,
topTipElement: null
}
},
mounted() {
this.initEditor()
},
beforeDestroy() {
this.removeTopTip()
},
watch: {
value: {
handler: function (newValue) {
@@ -229,6 +244,13 @@ module.exports = {
})
},
immediate: true
},
topTip: {
handler: function () {
this.$nextTick(() => {
this.renderTopTip()
})
}
}
},
@@ -266,7 +288,43 @@ module.exports = {
this.editor.config.pasteFilterStyle = false
this.editor.config.height = this.height
this.editor.config.menus = this.menus
// wangEditor 的 placeholder 必须在 create 前设置,父页面传入才会生效。
this.editor.config.placeholder = this.placeholder
this.editor.create()
this.renderTopTip()
},
renderTopTip() {
if (!this.editor || !this.$refs.editorRef) {
return
}
const textContainer = this.$refs.editorRef.querySelector(".w-e-text-container")
if (!textContainer) {
return
}
if (!this.topTip) {
this.removeTopTip()
return
}
if (!this.topTipElement) {
this.topTipElement = document.createElement("div")
this.topTipElement.setAttribute("contenteditable", "false")
this.topTipElement.style.color = "#f56c6c"
this.topTipElement.style.fontSize = "12px"
this.topTipElement.style.lineHeight = "20px"
this.topTipElement.style.padding = "6px 10px 0"
this.topTipElement.style.userSelect = "none"
this.topTipElement.style.pointerEvents = "none"
}
// 提示节点放在可编辑正文区域外层,保证用户无法删除且保存内容不携带该提示。
this.topTipElement.innerText = this.topTip
if (textContainer.firstChild !== this.topTipElement) {
textContainer.insertBefore(this.topTipElement, textContainer.firstChild)
}
},
removeTopTip() {
if (this.topTipElement && this.topTipElement.parentNode) {
this.topTipElement.parentNode.removeChild(this.topTipElement)
}
},
uploadFiles(resultFiles) {
return resultFiles.map(async (file) => {
@@ -133,6 +133,12 @@ module.exports = {
default: 1024 * 1024 * 10,
required: false
},
// 是否限制上传文件大小,默认保留原有大小校验逻辑。
limit_upload_size: {
type: Boolean,
default: true,
required: false
},
// 上传按钮文字
upload_text: {
type: String,
@@ -216,7 +222,7 @@ module.exports = {
} else {
tips = tips + '不限格式;'
}
if (fileSize) {
if (this.limit_upload_size && fileSize) {
tips = tips + `单个文件大小不能超过<span style="color: red">${fileSize / 1024 / 1024}</span>M`
}
return tips
@@ -313,7 +319,8 @@ module.exports = {
// 这是兜底逻辑,保准只让这个image类型上传图片
beforeUpload(file) {
if (file.size > this.upload_size) {
// 需要兼容部分业务不限制附件大小,关闭后仅跳过大小校验,不影响数量和格式控制。
if (this.limit_upload_size && file.size > this.upload_size) {
this.$message.error("文件过大,请上传小于" + (this.upload_size / 1024 / 1024).toFixed(0) + "M的文件!")
return false
}