提交 54888517 authored 作者: lihuihui's avatar lihuihui

fix:修改bug

上级 a067381f
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="cert" v-else> <div class="cert" v-else>
<el-button type="primary" @click="downImg">证书下载</el-button> <el-button type="primary" @click="downImg">证书下载</el-button>
<div class="img"> <div class="img">
<img :src="item.url" :key="index" alt="" v-for="(item, index) in data"> <img :src="item.url" :key="index" alt="" v-for="(item, index) in data" />
</div> </div>
</div> </div>
</app-container> </app-container>
...@@ -18,7 +18,7 @@ export default { ...@@ -18,7 +18,7 @@ export default {
msg: '' msg: ''
} }
}, },
mounted () { mounted() {
api.getCert().then(response => { api.getCert().then(response => {
console.log(response) console.log(response)
if (response.code === 1) { if (response.code === 1) {
...@@ -31,18 +31,44 @@ export default { ...@@ -31,18 +31,44 @@ export default {
methods: { methods: {
downImg() { downImg() {
this.data.forEach((item, index) => { this.data.forEach((item, index) => {
window.open(item.url) // window.open(item.url)
setTimeout(() => { setTimeout(() => {
this.downImg2(item.url, index)
}, index * 1000) }, index * 1000)
}) })
},
downImg2(url, name) {
const image = new Image()
image.setAttribute('crossOrigin', 'anonymous')
image.src = url
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const ctx = canvas.getContext('2d')
ctx.drawImage(image, 0, 0, image.width, image.height)
canvas.toBlob(blob => {
const url = URL.createObjectURL(blob)
this.download(url, name)
// 用完释放URL对象
URL.revokeObjectURL(url)
})
}
},
download(href, name) {
const eleLink = document.createElement('a')
eleLink.download = name
eleLink.href = href
eleLink.click()
eleLink.remove()
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.img{ .img {
width: 80%; width: 80%;
img{ img {
width: 100%; width: 100%;
display: block; display: block;
margin-top: 20px; margin-top: 20px;
......
...@@ -29,22 +29,25 @@ httpRequest.interceptors.request.use( ...@@ -29,22 +29,25 @@ httpRequest.interceptors.request.use(
httpRequest.interceptors.response.use( httpRequest.interceptors.response.use(
function (response) { function (response) {
const { data, config } = response const { data, config } = response
// if (config.url.indexOf('education/certificate') !== -1) {
// return data
// } else {
// if (data.code === 0) {
// return data
// } else {
// Message.error(data.msg || data.message)
// return Promise.reject(data)
// }
// return data
// }
if (config.url.indexOf('education/certificate') !== -1) { if (config.url.indexOf('education/certificate') !== -1) {
if (data.code === 0) { return data
return data }
} else { if (data.code) {
Message.error(data.msg || data.message) Message.error(data.msg || data.message)
return Promise.reject(data) return Promise.reject(data)
}
} else {
if (data.code === 0) {
return data
} else {
Message.error(data.msg || data.message)
return Promise.reject(data)
}
} }
// return data return data
}, },
function (error) { function (error) {
if (error.response) { if (error.response) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论