import '../../static/ueditor/ueditor.config.js'
import '../../static/ueditor/ueditor.all.js'
import '../../static/ueditor/lang/zh-cn/zh-cn.js'
import '../../static/ueditor/ueditor.parse.min.js'
import constants from '@/utils/constants'
import { getToken } from '@/utils/auth'
export default {
name: 'UE',
props: {
catalog: {
type: String,
required: true
},
// 默认的初始内容
defaultMsg: {
type: String,
default: ''
},
// 配置项,工具栏
config: {
type: Object,
default: () => {
return {}
}
}
},
data() {
return {
editor: null
}
},
mounted() {
const _this = this
this.config.chishipConfig = {
headers: {
'App-Key': this.constants.APP_KEY,
'App-Id': this.constants.APP_ID,
'Access-Token': getToken()
},
fileViewServer: this.global.getFileView('{UUID}')
}
this.config.serverUrl = process.env.BASE_API + this.constants.UPMS + 'ue'
// eslint-disable-next-line no-undef
this.editor = UE.getEditor('editor', this.config)
this.editor.addListener('ready', function() {
_this.editor.setContent(_this.defaultMsg)
})
// eslint-disable-next-line no-undef
if (!UE.Editor.prototype._bkGetActionUrl) {
// eslint-disable-next-line no-undef
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl
// eslint-disable-next-line no-undef
UE.Editor.prototype.getActionUrl = function(action) {
console.log(action)
if (action === 'uploadimage') {
return (
process.env.BASE_API + constants.DOCS + 'file/ueUpload?catalogId=' + _this.catalog
)
} else if (action === 'uploadfile') {
return process.env.BASE_API + constants.DOCS + 'file/ueUpload?catalogId=' + _this.catalog
} else if (action === 'uploadvideo') {
return process.env.BASE_API + constants.DOCS + 'file/ueUpload?catalogId=' + _this.catalog
} else if (action === 'uploadscrawl') {
return process.env.BASE_API + constants.DOCS + 'file/base64UploadForm?catalogId=' + _this.catalog
} else {
// eslint-disable-next-line no-useless-call
return this._bkGetActionUrl.call(this, action)
}
}
// eslint-disable-next-line no-undef
UE.Editor.prototype._bkGetContentLength = UE.Editor.prototype.getContentLength
// eslint-disable-next-line no-undef
UE.Editor.prototype.getContentLength = function() {
return this.getContent().length
}
}
},
destroyed() {
this.editor.destroy()
},
methods: {
setUEContent(content) {
// 编辑器内回显内容方法
return this.editor.setContent(content)
},
getUEContent() {
// 获取内容方法
return this.editor.getContent()
}
}
}
.edui-editor-iframeholder {
height: 300px !important;
overflow: hidden !important;
}
#ueditor_0 body.view {
overflow-y: scroll !important;
}
说明:绿色部分 1.为每个模块js配置appid、appkey、token及文件预览地址,文件上传成功后只返回UUID!获取config配置文件接口地址
config: {
autoHeightEnabled: false,
elementPathEnabled: false,
wordCount: false,
initialFrameWidth: null,
initialFrameHeight: 320,
toolbars: [this.global.UE_TOOL_BAR]
},
修改dialogs\image\image.js
1.将消息头X_Requested_With改为x-requested-with,目的是与项目进行统一
2.添加消息头 App-Key、App-Id、Access-Token,目的是后台文件上传接口需要登录并且验证App-Id与App-Key
注:第1、2条修改位置为uploader.on('uploadBeforeSend'......
3.由于文件上传接口统一返回指定格式,因此需要修改上传成功后解析文件,修改如下:
位置:uploader.on('uploadSuccess'......
var fileViewServer=editor.options.chishipConfig.fileViewServer
if (json.success) {
_this.imageList.push({
url:fileViewServer.replace("{UUID}",json.data.uuid),
title:json.data.originalName,
original:json.data.originalName
});
console.log(_this.imageList)
$file.append('');
} else {
$file.find('.error').text((json.data ? json.data : json.message)).show();
}
红线是改动的地方,chishipConfig.fileViewServer是组件封装传递的,前面有介绍!
去掉在线附件:dialogs\attachment\attachment.html
注释
修改dialogs\attachment\attachment.js
1.将消息头X_Requested_With改为x-requested-with,目的是与项目进行统一
2.添加消息头 App-Key、App-Id、Access-Token,目的是后台文件上传接口需要登录并且验证App-Id与App-Key
注:第1、2条修改位置为uploader.on('uploadBeforeSend'......
3.由于文件上传接口统一返回指定格式,因此需要修改上传成功后解析文件,修改如下:
位置:uploader.on('uploadSuccess'......
var fileViewServer=editor.options.chishipConfig.fileViewServer
if (json.success) {
_this.fileList.push({
url:fileViewServer.replace("{UUID}",json.data.uuid),
title:json.data.originalName,
original:json.data.originalName
});
console.log(_this.fileList)
$file.append('');
} else {
$file.find('.error').text((json.data ? json.data : json.message)).show();
}
红线是改动的地方,chishipConfig.fileViewServer是组件封装传递的,前面有介绍!
3.改动重组fileList方法
位置:getInsertList(......
title: data.original, 此属性直接获取原标题即可,不需要截断代码!
4.修改插入成功,回显问题
位置:ueditor.all.js
UE.plugin.register('insertfile',
增加'xlsx': 'icon_xls.gif',
由于回显,ue本身向数组多添加了一个,所以删除数组多余的一个,filelist=filelist.slice(0,1)
Icon改为通过title截取icon = iconDir + getFileIcon(item.title)
修改dialogs\video\video.js
1.将消息头X_Requested_With改为x-requested-with,目的是与项目进行统一
2.添加消息头 App-Key、App-Id、Access-Token,目的是后台文件上传接口需要登录并且验证App-Id与App-Key
注:第1、2条修改位置为uploader.on('uploadBeforeSend'......
3.由于文件上传接口统一返回指定格式,因此需要修改上传成功后解析文件,修改如下:
位置:uploader.on('uploadSuccess'......
var fileViewServer=editor.options.chishipConfig.fileViewServer
if (json.success) {
_this.uploadVideoList.push({
url:fileViewServer.replace("{UUID}",json.data.uuid),
Type:’video’,
original:json.data.originalName
});
$file.append('');
} else {
$file.find('.error').text((json.data ? json.data : json.message)).show();
}
红线是改动的地方,chishipConfig.fileViewServer是组件封装传递的,前面有介绍!
修改dialogs\scrawl\scrawl.js
// 执行确认按钮方法
function exec(scrawlObj) {
if (scrawlObj.isScrawl) {
addMaskLayer(lang.scrawlUpLoading)
var base64 = scrawlObj.getCanvasData()
if (base64) {
var chishipConfig = editor.options.chishipConfig
var options = {
timeout: 100000,
setRequestHeader: chishipConfig.headers,
......
onerror: function() {
alert(lang.imageError)
dialog.close()
}
}
options.data = {
base64: 'data:image/png;base64,' + base64 }
红色下划线为修改内容
修改static\ueditor\ueditor.all.js 8168行
if (method == 'POST') {
const header = ajaxOptions.setRequestHeader
const keys = Object.keys(header)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const value = header[key]
xhr.setRequestHeader(key, value)
}
// application/x-www-form-urlencoded;charset=UTF-8;
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')
xhr.send(submitStr)
红色下划线为修改内容