Commit a5ecd425 by 张立顺

fix:图片跨域导致下载空白问题

1 parent 3dacb62c
......@@ -256,6 +256,10 @@ export default {
this.getOptionsList()
})
getPlatformMerchantList({}).then(res => {
res.unshift({
merchantId: -1,
merchantName: '嘀加智慧云'
})
this.baseData.PlatformMerchantList = res
this.getOptionsList()
})
......
......@@ -145,7 +145,8 @@
<span v-if="scope.row.divisionStatus"
:style="{ 'color': [4, 5].includes(+scope.row.divisionStatus) ? 'red' : '#606266' }">{{baseData.divisionStatusList.find(item => +item.confId === scope.row.divisionStatus).confLabel}}</span>
<span v-else>-</span>
</template></el-table-column>
</template>
</el-table-column>
<el-table-column label="分账时间"
prop="divisionDateStr"
align="center"
......@@ -304,6 +305,10 @@ export default {
this.getOptionsList()
})
getPlatformMerchantList({}).then(res => {
res.unshift({
merchantId: -1,
merchantName: '嘀加智慧云'
})
this.baseData.PlatformMerchantList = res
this.getOptionsList()
})
......
......@@ -11,13 +11,15 @@
id="view">
<img style="width:100%;height:100%"
src="./images/code3.png">
<div class="imgDiv">
<img v-if="qrCodeURL"
style="width:100%;height:100%"
:src="qrCodeURL">
<div v-else
class="el-icon-loading loadingIcon"></div>
</div>
<!-- v-if="qrCodeURL" <div class="imgDiv"> -->
<img v-if="qrCodeURL"
class="qrImg"
id="img1"
crossorigin="anonymous"
:src="qrCodeURL">
<div v-if="!qrCodeURL"
class="el-icon-loading loadingIcon"></div>
<!-- </div> -->
<div class="merchantNameDiv">{{info.yqMerchantName}}</div>
</div>
</d2-dialog>
......@@ -69,7 +71,31 @@ export default {
},
methods: {
/**
* @description: 图片转base64
* @param {String} url 需要转换的图片原链接(http://....jpg)
* @param {String} outputFormat 转换出来的图片的类型(canvas支持jpg/png格式)
* @return: 返回图片对应的base64编码
*/
getBas64(url, outputFormat = 'image/png') {
return new Promise(function (resolve, reject) {
let canvas = document.createElement('CANVAS')
const ctx = canvas.getContext('2d')
const img = new Image()
img.crossOrigin = 'Anonymous' // 重点!设置image对象可跨域请求
img.onload = function () {
canvas.height = img.height
canvas.width = img.width
ctx.drawImage(img, 0, 0)
const dataURL = canvas.toDataURL(outputFormat)
canvas = null
resolve(dataURL)
}
// img.src = url; // 旧的方式
img.src = url + '?t=' + new Date().valueOf() // 防止oss的缓存问题
})
},
createQrcodeImage() {
const oParams = {}
oParams.channelType = 1
......@@ -81,16 +107,47 @@ export default {
createWeappQrcode(oParams).then(res => {
this.qrCodeURL = res
// function getBase64(imgUrl) {
// window.URL = window.URL || window.webkitURL
// var xhr = new XMLHttpRequest()
// xhr.open('get', imgUrl, true)
// xhr.responseType = 'blob'
// xhr.onload = function () {
// if (this.status == 200) {
// // 得到一个blob对象
// var blob = this.response
// console.log('blob', blob)
// // 至关重要
// const oFileReader = new FileReader()
// oFileReader.onloadend = function (e) {
// // 此处拿到的已经是base64的图片了,可以赋值做相应的处理
// console.log(e.target.result)
// }
// oFileReader.readAsDataURL(blob)
// }
// }
// xhr.send()
// }
// console.log(getBase64(res))
// getBase64('需要转成base64的图片url')
})
},
// 下载保存图片
takeScreenshot() {
html2canvas(document.getElementById('view')).then(canvas => {
// const opts = {
// useCORS: true
// }
html2canvas(document.getElementById('view'), {
backgroundColor: null,
allowTaint: true, // 允许污染
taintTest: true, // 在渲染前测试图片(没整明白有啥用)
useCORS: true // 使用跨域(当allowTaint为true时这段代码没什么用,下面解释)
}).then(canvas => {
this.convertCanvasToImg(canvas)
})
},
// 转换图片格式
convertCanvasToImg(canvas) {
// canvas base64 转 blob
......@@ -148,22 +205,29 @@ export default {
position: relative;
/* background-image: url('./images/code3.png'); */
}
.imgDiv {
.qrImg {
width: 150px;
height: 150px;
position: absolute;
left: 50%;
top: 42%;
transform: translate(-50%, -50%);
background-color: #d8d8d8;
/* background-color: #d8d8d8; */
z-index: 2;
}
.loadingIcon {
position: absolute;
/* width: 44px;
height: 44px; */
font-size: 30px;
top: 60px;
left: 60px;
/* top: 60px;
left: 60px; */
/* transform: translate(-50%, -50%); */
/* width: 150px;
height: 150px; */
position: absolute;
left: 46%;
top: 40%;
transform: translate(-50%, -50%);
}
.merchantNameDiv {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!