import { getHost, getToken } from "../../on"; class richText { #customUploadVideo #customUploadContent #primaryCallBack constructor() { this.richTextBox = document.createElement('div'); this.richTextBox.className = 'richText-box' this.richTextBox.style.position = 'absolute' this.richTextBox.style.width = '60%' this.richTextBox.style.height = '70%' this.richTextBox.style.backgroundColor = '#ffffff' this.richTextBox.style.zIndex = '999999' this.richTextBox.style.left = '20%' this.richTextBox.style.top = '15%' this.richTextBox.style.display = 'flex' this.richTextBox.style.flexDirection = 'column' this.uploadImageServer this.uploadVideoServer } // 打开 open(id, title = '', content = '') { let _this = this; this.title = title this.objectId = id if (document.body.getElementsByClassName('richText-box')[0]) { document.body.removeChild(this.richTextBox) } this.editor = null let html = `

${title}

` // let elm = document.createRange().createContextualFragment(html) this.richTextBox.innerHTML = html document.body.appendChild(this.richTextBox) const { createEditor, createToolbar } = window.wangEditor const editorConfig = { placeholder: '请输入正文...', MENU_CONF: { uploadImage: { fieldName: 'file', // maxFileSize: 50 * 1024 * 1024, // base64LimitSize: 50 * 1024 * 1024, // 50M 以下插入 base64 server: this.uploadImageServer, // // 上传之前触发 // onBeforeUpload(file) { // TS 语法 // // onBeforeUpload(file) { // JS 语法 // // file 选中的文件,格式如 { key: file } // return file // // 可以 return // // 1. return file 或者 new 一个 file ,接下来将上传 // // 2. return false ,不上传这个 file // }, // // 上传进度的回调函数 // onProgress(progress) { // TS 语法 // // onProgress(progress) { // JS 语法 // // progress 是 0-100 的数字 // console.log('progress', progress) // }, // // 单个文件上传成功之后 // onSuccess(file, res) { // TS 语法 // // onSuccess(file, res) { // JS 语法 // console.log(`${file.name} 上传成功`, res) // }, // // 单个文件上传失败 // onFailed(file, res) { // TS 语法 // // onFailed(file, res) { // JS 语法 // console.log(`${file.name} 上传失败`, res) // }, // // 上传错误,或者触发 timeout 超时 // onError(file, err, res) { // TS 语法 // // onError(file, err, res) { // JS 语法 // console.log(`${file.name} 上传出错`, err, res) // }, // 自定义上传 async customUpload(file, insertFn) { // TS 语法 // async customUpload(file, insertFn) { // JS 语法 // file 即选中的文件 // 自己实现上传,并得到图片 url alt href // 最后插入图片 let url = await _this.upload(file) insertFn((_this.host = _this.host || getHost()) + '/' + url) } }, uploadVideo: { // maxFileSize: 500 * 1024 * 1024, server: this.uploadVideoServer, allowedFileTypes: ['video/mp4', 'video/mp3', 'video/ogg', 'video/webm', 'video/avi'], // 自定义上传 async customUpload(file, insertFn) { // async customUpload(file, insertFn) { // file 即选中的文件 // 自己实现上传,并得到图片 url alt href // 最后插入图片 let url = await _this.upload(file) insertFn((_this.host = _this.host || getHost()) + '/' + url) // if(_this.#customUploadVideo) { // let url = await _this.#customUploadVideo(file) // insertFn(url, file.name) // } } } }, onChange(editor) { const html = editor.getHtml() // 也可以同步到