|
@@ -1,6 +1,7 @@
|
|
|
<template>
|
|
|
<div :class="{ fullscreen: fullscreen }" class="tinymce-container" :style="{ width: containerWidth }">
|
|
|
<textarea :id="tinymceId" class="tinymce-textarea" />
|
|
|
+
|
|
|
<!-- <div class="editor-custom-btn-container"> -->
|
|
|
<!-- <editorImage color="#1890ff" class="editor-upload-btn" @successCBK="imageSuccessCBK" /> -->
|
|
|
<!-- </div> -->
|
|
@@ -17,6 +18,7 @@
|
|
|
import plugins from './plugins';
|
|
|
import toolbar from './toolbar';
|
|
|
import load from './dynamicLoadScript';
|
|
|
+import envConfig from '../../../src/config';
|
|
|
|
|
|
// why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
|
|
|
const tinymceCDN = 'https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js';
|
|
@@ -55,6 +57,7 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ times: null,
|
|
|
hasChange: false,
|
|
|
hasInit: false,
|
|
|
tinymceId: this.id,
|
|
@@ -82,8 +85,11 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
value(val) {
|
|
|
+ console.log('tinymceValue============', val);
|
|
|
if (!this.hasChange && this.hasInit) {
|
|
|
- this.$nextTick(() => window.tinymce.get(this.tinymceId).setContent(val || ''));
|
|
|
+ this.$nextTick(() => {
|
|
|
+ window.tinymce.get(this.tinymceId).setContent(val || '');
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
language() {
|
|
@@ -116,6 +122,42 @@ export default {
|
|
|
this.initTinymce();
|
|
|
});
|
|
|
},
|
|
|
+ onPaste(event) {
|
|
|
+ new Promise((resolve) => {
|
|
|
+ const items = (event.clipboardData || window.clipboardData).items;
|
|
|
+ if (items[0].type.indexOf('image') !== -1) {
|
|
|
+ console.log('粘贴的是图片类型');
|
|
|
+ const file = items[0].getAsFile();
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('file', file);
|
|
|
+ var imageUrl = '';
|
|
|
+ // 上传图片
|
|
|
+ this.$http.post('/sc-community-web/upload/uploadFile', formData).then((res) => {
|
|
|
+ console.log('onPaste', res);
|
|
|
+ if (res.status === 0) {
|
|
|
+ // 放到内容当中
|
|
|
+ let img = `<img class="wscnph" src="${res.data}" />`;
|
|
|
+ // let img = `<div class="wscnph" id="${res.data}" >[图片]</div>`;
|
|
|
+ window.tinymce.get(this.tinymceId).insertContent(img);
|
|
|
+ // window.tinymce.get(this.tinymceId).insertContent(`<img class="wscnph" src="${res.data}" />`);
|
|
|
+ // let content = window.tinymce.get(this.tinymceId).getContent();
|
|
|
+ // let newContent = content.replace(/<img \s*class="wscnph"\s*src="[\s\S]*"\/>/g, '2');
|
|
|
+ // window.tinymce.get(this.tinymceId).setContent(newContent);
|
|
|
+ resolve && resolve();
|
|
|
+ } else {
|
|
|
+ this.$message.error(res.msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log('粘贴的不是图片,不能上传');
|
|
|
+ }
|
|
|
+ }).then(() => {
|
|
|
+ let content = window.tinymce.get(this.tinymceId).getContent();
|
|
|
+ let newContent = content.replace(/<img *src="data.*?\/>/g, '');
|
|
|
+ window.tinymce.get(this.tinymceId).setContent(newContent);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
initTinymce() {
|
|
|
const _this = this;
|
|
|
window.tinymce.init({
|
|
@@ -140,16 +182,22 @@ export default {
|
|
|
// imagetools_cors_hosts: ['www.tinymce.com', 'codepen.io'],
|
|
|
default_link_target: '_blank',
|
|
|
link_title: false,
|
|
|
- // nonbreaking_force_tab: true, // inserting nonbreaking space need Nonbreaking Space Plugin
|
|
|
init_instance_callback: (editor) => {
|
|
|
if (_this.value) {
|
|
|
editor.setContent(_this.value);
|
|
|
}
|
|
|
_this.hasInit = true;
|
|
|
editor.on('NodeChange Change KeyUp SetContent', () => {
|
|
|
+ this.times = null;
|
|
|
this.hasChange = true;
|
|
|
+ // const val = editor.getContent().replace(/<p><img\s?src="data.*?<\/p>/g, '')
|
|
|
this.$emit('input', editor.getContent());
|
|
|
});
|
|
|
+ editor.on('paste', (evt) => {
|
|
|
+ console.log('粘贴paste');
|
|
|
+ // 监听粘贴事件
|
|
|
+ this.onPaste(evt);
|
|
|
+ });
|
|
|
},
|
|
|
setup(editor) {
|
|
|
editor.on('FullscreenStateChanged', (e) => {
|
|
@@ -159,40 +207,60 @@ export default {
|
|
|
// it will try to keep these URLs intact
|
|
|
// https://www.tiny.cloud/docs-3x/reference/configuration/Configuration3x@convert_urls/
|
|
|
// https://stackoverflow.com/questions/5196205/disable-tinymce-absolute-to-relative-url-conversions
|
|
|
- convert_urls: false
|
|
|
+ convert_urls: false,
|
|
|
+ paste_data_images: false // 粘贴的同时能把内容里的图片自动上传
|
|
|
// 整合七牛上传
|
|
|
// images_dataimg_filter(img) {
|
|
|
- // setTimeout(() => {
|
|
|
- // const $image = $(img);
|
|
|
- // $image.removeAttr('width');
|
|
|
- // $image.removeAttr('height');
|
|
|
- // if ($image[0].height && $image[0].width) {
|
|
|
- // $image.attr('data-wscntype', 'image');
|
|
|
- // $image.attr('data-wscnh', $image[0].height);
|
|
|
- // $image.attr('data-wscnw', $image[0].width);
|
|
|
- // $image.addClass('wscnph');
|
|
|
- // }
|
|
|
- // }, 0);
|
|
|
- // return img
|
|
|
- // },
|
|
|
+ // setTimeout(() => {
|
|
|
+ // const $image = $(img);
|
|
|
+ // $image.removeAttr('width');
|
|
|
+ // $image.removeAttr('height');
|
|
|
+ // if ($image[0].height && $image[0].width) {
|
|
|
+ // $image.attr('data-wscntype', 'image');
|
|
|
+ // $image.attr('data-wscnh', $image[0].height);
|
|
|
+ // $image.attr('data-wscnw', $image[0].width);
|
|
|
+ // $image.addClass('wscnph');
|
|
|
+ // }
|
|
|
+ // }, 0);
|
|
|
+ // console.log(' images_dataimg_filter', img);
|
|
|
+ // return img;
|
|
|
+ // }
|
|
|
// images_upload_handler(blobInfo, success, failure, progress) {
|
|
|
- // progress(0);
|
|
|
- // const token = _this.$store.getters.token;
|
|
|
- // getToken(token).then(response => {
|
|
|
- // const url = response.data.qiniu_url;
|
|
|
- // const formData = new FormData();
|
|
|
- // formData.append('token', response.data.qiniu_token);
|
|
|
- // formData.append('key', response.data.qiniu_key);
|
|
|
- // formData.append('file', blobInfo.blob(), url);
|
|
|
- // upload(formData).then(() => {
|
|
|
- // success(url);
|
|
|
- // progress(100);
|
|
|
- // })
|
|
|
- // }).catch(err => {
|
|
|
- // failure('出现未知问题,刷新页面,或者联系程序员')
|
|
|
- // console.log(err);
|
|
|
- // });
|
|
|
- // },
|
|
|
+ // // progress(0);
|
|
|
+ // // console.log('images_upload_handler========', blobInfo, success, failure, progress);
|
|
|
+ // // const formData = new FormData();
|
|
|
+ // // formData = formData.append('file', blobInfo.blob(), blobInfo.filename());
|
|
|
+ // // this.$http
|
|
|
+ // // .post('/sc-community-web/upload/uploadFile', formData)
|
|
|
+ // // .then((res) => {
|
|
|
+ // // success(url);
|
|
|
+ // // progress(100);
|
|
|
+ // // console.log('====================================');
|
|
|
+ // // console.log('res', res);
|
|
|
+ // // console.log('====================================');
|
|
|
+ // // })
|
|
|
+ // // .catch((err) => {
|
|
|
+ // // failure('出现未知问题,刷新页面,或者联系程序员');
|
|
|
+ // // console.log(err);
|
|
|
+ // // });
|
|
|
+ // // const token = _this.$store.getters.token;
|
|
|
+ // // getToken(token)
|
|
|
+ // // .then((response) => {
|
|
|
+ // // const url = '/sc-community-web/upload/uploadFile';
|
|
|
+ // // const formData = new FormData();
|
|
|
+ // // formData.append('token', response.data.qiniu_token);
|
|
|
+ // // formData.append('key', response.data.qiniu_key);
|
|
|
+ // // formData.append('file', blobInfo.blob(), url);
|
|
|
+ // // upload(formData).then(() => {
|
|
|
+ // // success(url);
|
|
|
+ // // progress(100);
|
|
|
+ // // });
|
|
|
+ // // })
|
|
|
+ // // .catch((err) => {
|
|
|
+ // // failure('出现未知问题,刷新页面,或者联系程序员');
|
|
|
+ // // console.log(err);
|
|
|
+ // // });
|
|
|
+ // }
|
|
|
});
|
|
|
},
|
|
|
destroyTinymce() {
|
|
@@ -228,7 +296,7 @@ export default {
|
|
|
if (img.length >= 3) {
|
|
|
return this.$message.warning('最多插入三张图片');
|
|
|
}
|
|
|
- arr.forEach((v) => window.tinymce.get(this.tinymceId).insertContent(`<img class="wscnph" src="${v.url}" >`));
|
|
|
+ arr.forEach((v) => window.tinymce.get(this.tinymceId).insertContent(`<img class="wscnph" src="${v.url}" />`));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -236,6 +304,11 @@ export default {
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
+/deep/ .wscnph {
|
|
|
+ width: 200px !important;
|
|
|
+ height: 100px;
|
|
|
+ vertical-align: middle;
|
|
|
+}
|
|
|
.tinymce-container {
|
|
|
position: relative;
|
|
|
line-height: normal;
|