Commit 882b7a87 by crushh

Merge branch 'bugfix/下载' into dev

parents f2a1227e 1a4a6297
......@@ -219,20 +219,6 @@ export const base64ToBlob = code => {
return new Blob([uInt8Array], { type: contentType });
};
//下载
export const downloadFile = (fileName, content) => {
let aLink = document.createElement('a');
let blob = base64ToBlob(content); //new Blob([content]);
let evt = document.createEvent('HTMLEvents');
evt.initEvent('click', true, true); //initEvent 不加后两个参数在FF下会报错 事件类型,是否冒泡,是否阻止浏览器的默认行为
fileName = fileName.replaceAll('.', '-');
aLink.download = fileName;
aLink.href = URL.createObjectURL(blob);
// aLink.dispatchEvent(evt);
//aLink.click()
aLink.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })); //兼容火狐
};
export const sleep = delay => {
let start = new Date().getTime();
while (new Date().getTime() - start < delay) {
......
......@@ -50,7 +50,7 @@
</template>
<script>
import VueQr from 'vue-qr';
import { formatDateTimeByType, downloadFile } from '@/utils/index.js';
import { formatDateTimeByType } from '@/utils/index.js';
import { generateMiniProgramLink } from '@/service/api/gameApi.js';
import { api as viewerApi } from 'v-viewer';
import 'viewerjs/dist/viewer.css';
......@@ -132,11 +132,6 @@ export default {
close() {
this.$emit('update:show', false);
},
downloadImg() {
const qrWrap = document.getElementById('qrWrap');
const qrImg = qrWrap && qrWrap.childNodes[0].src;
downloadFile(this.gameTypeName + '-' + this.obj.gameName + '-服务号-' + formatDateTimeByType(this.obj.gameStartTime, 'yyyy-MM-dd-HH-mm-ss') || '游戏链接', qrImg);
},
onView(isH5) {
let qrImg = '';
if (isH5) {
......@@ -161,13 +156,12 @@ export default {
const x = new XMLHttpRequest();
x.open('GET', url, true);
x.responseType = 'blob';
fileName = fileName.replaceAll('.', '-');
x.onload = function(e) {
const blob = new Blob([x.response], { type: 'image/png' });
const blob = new Blob([x.response]);
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = fileName;
a.download = fileName + '.png';
a.click();
};
x.send();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment