You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.6 KiB
88 lines
2.6 KiB
// Any plugins you want to setting has to be imported
|
|
// Detail plugins list see https://www.tinymce.com/docs/plugins/
|
|
// Custom builds see https://www.tinymce.com/download/custom-builds/
|
|
// colorpicker/contextmenu/textcolor plugin is now built in to the core editor, please remove it from your editor configuration
|
|
|
|
import setting from '@/config/setting';
|
|
let token = localStorage.getItem('access_token')
|
|
|
|
|
|
const GLOB_UPLOAD_URL = setting.uploadImageUrl+'?upload_type=img'
|
|
// @ts-ignore
|
|
export const file_picker_callback = (callback, value, meta) => {
|
|
// 文件分类
|
|
var filetype = '.pdf, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .mp3, .mp4'
|
|
// 后端接收上传文件的地址
|
|
var upurl = GLOB_UPLOAD_URL
|
|
// 为不同插件指定文件类型及后端地址
|
|
switch (meta.filetype) {
|
|
case 'image':
|
|
filetype = '.jpg, .jpeg, .png, .gif'
|
|
break
|
|
case 'media':
|
|
filetype = '.mp3, .mp4'
|
|
break
|
|
case 'file':
|
|
default:
|
|
}
|
|
// 模拟出一个input用于添加本地文件
|
|
var input = document.createElement('input')
|
|
input.setAttribute('type', 'file')
|
|
input.setAttribute('accept', filetype)
|
|
input.click()
|
|
input.onchange = () => {
|
|
// @ts-ignore
|
|
var file = this.files[0]
|
|
|
|
var xhr, formData
|
|
xhr = new XMLHttpRequest()
|
|
xhr.withCredentials = false
|
|
xhr.open('POST', upurl)
|
|
xhr.onload = () => {
|
|
var json
|
|
if (xhr.status !== 200) {
|
|
// failure('HTTP Error: ' + xhr.status)
|
|
return
|
|
}
|
|
json = JSON.parse(xhr.responseText)
|
|
if (!json || json.code !== '200') {
|
|
// failure('Invalid JSON: ' + xhr.responseText)
|
|
return
|
|
}
|
|
callback(json.message, { text: file.name })
|
|
}
|
|
formData = new FormData()
|
|
formData.append('file', file, file.name)
|
|
formData.append('token', token)
|
|
xhr.send(formData)
|
|
}
|
|
}
|
|
|
|
export const images_upload_handler = (blobInfo, succFun, failFun) => {
|
|
var xhr, formData
|
|
var file = blobInfo.blob() // 转化为易于理解的file对象
|
|
// console.log(file)
|
|
xhr = new XMLHttpRequest()
|
|
xhr.withCredentials = false
|
|
xhr.open('POST', GLOB_UPLOAD_URL)
|
|
xhr.onload = () => {
|
|
var json
|
|
if (xhr.status !== 200) {
|
|
failFun('HTTP Error: ' + xhr.status)
|
|
return
|
|
}
|
|
json = JSON.parse(xhr.responseText)
|
|
console.log(xhr.responseText)
|
|
|
|
if (!json || json.code !== 0) {
|
|
// failFun('Invalid JSON: ' + xhr.responseText)
|
|
return
|
|
}
|
|
console.log(json.url)
|
|
succFun(json.url)
|
|
}
|
|
formData = new FormData()
|
|
formData.append('file', file, file.name) // 此处与源文档不一样
|
|
formData.append('token', token)
|
|
xhr.send(formData)
|
|
}
|
|
|