|
@@ -19,7 +19,8 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import axios from 'axios'
|
|
|
+import { keepLastIndex, uploadImg } from '@/utils/util'
|
|
|
+// import request from '@/utils/request'
|
|
|
import tinymce from 'tinymce/tinymce'
|
|
|
import Editor from '@tinymce/tinymce-vue'
|
|
|
import 'tinymce/themes/silver/theme'
|
|
@@ -108,7 +109,6 @@ export default {
|
|
|
watch: {
|
|
|
value: {
|
|
|
async handler(newV, oldV) {
|
|
|
- console.log('new', newV, 'old', oldV)
|
|
|
// resetImgSrc
|
|
|
this.resetImgSrc(newV)
|
|
|
},
|
|
@@ -124,62 +124,20 @@ export default {
|
|
|
const imgReg = /<img.*?(?:>|\/>)/gi
|
|
|
const srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
|
|
|
const imgArr = newStr.match(imgReg)
|
|
|
-
|
|
|
imgArr && imgArr.map(async t => {
|
|
|
var src = t.match(srcReg)
|
|
|
if (src[1] && src[1].includes('data:image')) {
|
|
|
- const newImgUrl = await this.uploadImg(src[1])
|
|
|
+ const newImgUrl = await uploadImg(src[1])
|
|
|
newStr = newStr.replace(src[1], newImgUrl)
|
|
|
console.log('newStr', newStr)
|
|
|
this.inputValue = newStr
|
|
|
// 光标最后
|
|
|
this.$nextTick(() => {
|
|
|
- var ifra = document.getElementById(`tinymce_${this.id}_ifr`);
|
|
|
- this.keepLastIndex(ifra.contentWindow.document.getElementById(`tinymce`), ifra.contentWindow)
|
|
|
+ var ifra = document.getElementById(`tinymce_${this.id}_ifr`)
|
|
|
+ keepLastIndex(ifra.contentWindow.document.getElementById(`tinymce`), ifra.contentWindow)
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- // return newStr
|
|
|
- },
|
|
|
- keepLastIndex (obj, window) {
|
|
|
- console.log('进来了')
|
|
|
- if (window.getSelection) { //ie11 10 9 ff safari
|
|
|
- console.log('进来了11111')
|
|
|
- obj.focus(); //解决ff不获取焦点无法定位问题
|
|
|
- var range = window.getSelection(); //创建range
|
|
|
- range.selectAllChildren(obj); //range 选择obj下所有子内容
|
|
|
- range.collapseToEnd(); //光标移至最后
|
|
|
- } else if (document.selection) { //ie10 9 8 7 6 5
|
|
|
- console.log('进来了2222')
|
|
|
- var range = document.selection.createRange(); //创建选择对象
|
|
|
- range.moveToElementText(obj); //range定位到obj
|
|
|
- range.collapse(false); //光标移至最后
|
|
|
- range.select();
|
|
|
- }
|
|
|
- },
|
|
|
- uploadImg(imgData) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const HTTP = axios.create({
|
|
|
- baseURL: '/apis', // 这是基础url
|
|
|
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
- transformRequest: [(data) => {
|
|
|
- // Do whatever you want to transform the data
|
|
|
- let ret = ''
|
|
|
- for (const it in data) {
|
|
|
- ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
|
|
|
- }
|
|
|
- return ret
|
|
|
- }]
|
|
|
- })
|
|
|
- HTTP.post('//star.xiaojukeji.com/upload/img.node', {
|
|
|
- 'imgData': imgData,
|
|
|
- 'innerPublic': true
|
|
|
- }).then((res) => {
|
|
|
- console.log('res', res)
|
|
|
- console.log('res.url', res.url)
|
|
|
- resolve(res.data.url)
|
|
|
- })
|
|
|
- })
|
|
|
},
|
|
|
changeText(e) { // 富文本内容改变
|
|
|
this.inputValue = e
|