creatEditor() {
let _ = this
this.editor = new E("#editBindDiv");
this.editor.config.customUploadImg = async (files, insert) => {
var xhr = new XMLHttpRequest();
var formdata = new FormData();
let params = this.uploadOssData
await this.getOss()
for (let i in params) {
formdata.append(i, params[i]);
}
files.forEach(function(file) {
formdata.append("file", file);
});
xhr.open('POST', 'https://cool-brain.oss-cn-hangzhou.aliyuncs.com');
xhr.send(formdata);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status < 200 || xhr.status >= 300) {
this.$message.error("图片上传失败");
}
let url = 'https://cool-brain.oss-cn-hangzhou.aliyuncs.com/' + params.key
insert(url);
}
}
}
this.editor.config.height = 500
this.editor.create();
},
getEditorText() {
this.article.content = this.editor.txt.html()
},
classChange(id) {
this.article.classifications = [id]
},
async getOss() {
let res = await this.$api.get_oss();
if (res.code == 1000) {
let oss = res.data
let time = new Date();
this.key = `${oss.dir}${this.userId}${time.getTime()}.png`;
this.uploadUrl = oss.host
this.uploadOssData = {
'key': this.key,
'policy': oss.policy,
'signature': oss.signature,
'success_action_status': '200',
'OSSAccessKeyId': oss.accessid,
"expire": oss.expire,
"dir": oss.dir,
}
} else {
this.$message.error(res.msg)
}
},