commit
This commit is contained in:
@@ -8,6 +8,67 @@
|
|||||||
<script>
|
<script>
|
||||||
const { $, BtnMenu, Panel, Tooltip } = wangEditor
|
const { $, BtnMenu, Panel, Tooltip } = wangEditor
|
||||||
|
|
||||||
|
class PDFMenu extends BtnMenu {
|
||||||
|
constructor(editor) {
|
||||||
|
const $elem = wangEditor.$(
|
||||||
|
`<div class="w-e-menu" data-title="上传pdf">
|
||||||
|
<i class="fa fa-file-pdf-o" aria-hidden="true" /></i>
|
||||||
|
</div>`
|
||||||
|
)
|
||||||
|
super($elem, editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
clickHandler() {
|
||||||
|
const _this = this
|
||||||
|
const inputFileElement = document.querySelector('#'+this.editor.textElemId).parentElement.parentElement.nextElementSibling
|
||||||
|
inputFileElement.click()
|
||||||
|
inputFileElement.addEventListener('change', function () {
|
||||||
|
const file = this.files[0];
|
||||||
|
const fileName = file.name
|
||||||
|
|
||||||
|
if (!fileName.toLowerCase().endsWith('.pdf')) {
|
||||||
|
alert('请上传pdf格式的文件')
|
||||||
|
_this.clearInputFile()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file, file.name)
|
||||||
|
/*axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "multipart/form-data"
|
||||||
|
}
|
||||||
|
})*/
|
||||||
|
axios.post("/platform/sys/file/uploadDynamicReturnUrl", formData, {}).then(response => {
|
||||||
|
console.log(response.data)
|
||||||
|
if (response.data.code === 0) {
|
||||||
|
const html = `<a target="_blank" href="${window.location.origin}${response.data.data}">
|
||||||
|
${file.name}
|
||||||
|
</a>`
|
||||||
|
_this.editor.txt.html(html)
|
||||||
|
} else {
|
||||||
|
alert(response.data.msg + ',上传pdf失败,请联系管理员!')
|
||||||
|
_this.clearInputFile()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error)
|
||||||
|
_this.clearInputFile()
|
||||||
|
alert('上传pdf失败,请联系管理员!')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInputFile() {
|
||||||
|
const obj = document.getElementById('fileInput');
|
||||||
|
obj.outerHTML = obj.outerHTML
|
||||||
|
}
|
||||||
|
|
||||||
|
tryChangeActive() {
|
||||||
|
this.active()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//注册上传word按钮
|
//注册上传word按钮
|
||||||
class DocMenu extends BtnMenu {
|
class DocMenu extends BtnMenu {
|
||||||
constructor(editor) {
|
constructor(editor) {
|
||||||
@@ -90,6 +151,7 @@ class DocMenu extends BtnMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wangEditor.registerMenu("docMenu", DocMenu)
|
wangEditor.registerMenu("docMenu", DocMenu)
|
||||||
|
wangEditor.registerMenu('pdfMenuKey', PDFMenu)
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: "textEditor",
|
name: "textEditor",
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
Reference in New Issue
Block a user