|
@@ -55,6 +55,7 @@
|
|
|
} );
|
|
|
},
|
|
|
normalizeSpacing( htmlString ) {
|
|
|
+ htmlString = htmlString.replace( /<!--\[if gte vml 1]>/g, '' );
|
|
|
// Run normalizeSafariSpaceSpans() two times to cover nested spans.
|
|
|
return this.normalizeSafariSpaceSpans( this.normalizeSafariSpaceSpans( htmlString ) )
|
|
|
// Remove all \r\n from "spacerun spans" so the last replace line doesn't strip all whitespaces.
|
|
@@ -71,7 +72,6 @@
|
|
|
mounted() {
|
|
|
let stemEditor = new E(this.$refs.editor)
|
|
|
stemEditor.config.onchange = (html) => {
|
|
|
- console.log(html);
|
|
|
this.stemContent = html
|
|
|
}
|
|
|
this.$editorTools.initSimpleEditor(stemEditor, this)
|
|
@@ -86,15 +86,30 @@
|
|
|
if (item.kind === "string" && item.type === 'text/html') {
|
|
|
item.getAsString(async (str) => {
|
|
|
// 先排查粘贴的内容里面是否包含图片
|
|
|
- let html = that.normalizeSpacing(str)
|
|
|
+ console.log(that.normalizeSpacing(str))
|
|
|
+ let html = that.normalizeSpacing(str).replace(/[\r\n]/g, "") // 简化HTML字符串
|
|
|
+ let hasVshape = html.includes('</v:shape>')
|
|
|
+ let hasConvertImg = html.includes('<![endif]--><![if !vml]>')
|
|
|
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/ig;
|
|
|
- let srcArr = html.match(srcReg)
|
|
|
- let srcArrStr = str.match(srcReg)
|
|
|
- console.log(srcArr);
|
|
|
- console.log(srcArrStr);
|
|
|
+ let imgReg = /<img.*?(?:>|\/>)/gi;
|
|
|
+ let imagedataRef = /<v:imagedata.*?(?:>|\/>)/gi
|
|
|
+ let srcArr = []
|
|
|
+ let noImgMode = false
|
|
|
+ console.log(html)
|
|
|
+ // 如果没有v:shape 则代表是wps粘贴的 直接拿图片
|
|
|
+ if(!hasVshape || (hasVshape && hasConvertImg)){
|
|
|
+ srcArr = html.match(imgReg)
|
|
|
+ }else{
|
|
|
+ srcArr = html.match(imagedataRef)
|
|
|
+ noImgMode = true
|
|
|
+ }
|
|
|
+ console.error('匹配结果:',srcArr);
|
|
|
if(srcArr && srcArr.length){
|
|
|
// 如果有图片数据 则需要去唤起阅卷助手提供图片转换功能 把本地格式转换成base64
|
|
|
- let localImgArr = srcArr.map(i => i.replace('src=','').replace("\"","").replace("\"",""))
|
|
|
+ let localImgArr = srcArr.map(i => i.match(srcReg)[0].replace('src=','').replace("\"","").replace("\"",""))
|
|
|
+ console.log(localImgArr)
|
|
|
+ // return
|
|
|
+ // let localImgArr = srcArr
|
|
|
// 检查助手是否已经开启
|
|
|
let isToolAlive = await that.checkTools()
|
|
|
if(isToolAlive){
|
|
@@ -102,7 +117,9 @@
|
|
|
let base64Arrs = await that.transBase64ByTool(localImgArr)
|
|
|
console.log('转换前的',html);
|
|
|
console.log(base64Arrs);
|
|
|
- html = html.replace('v:imagedata', 'img')
|
|
|
+ if(noImgMode){
|
|
|
+ html = html.replace('v:imagedata', 'img')
|
|
|
+ }
|
|
|
// 获取到转换后的Base64要进行图片替换
|
|
|
localImgArr.forEach((i,index) => {
|
|
|
html = html.replace(i, base64Arrs[index])
|