【增加】Image card 增加图片下载
This commit is contained in:
parent
2211618ada
commit
fdeedcfe7b
@ -66,8 +66,32 @@ const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => {
|
|||||||
await ImageApi.deleteImage(imageDetail.id)
|
await ImageApi.deleteImage(imageDetail.id)
|
||||||
await getImageList()
|
await getImageList()
|
||||||
await message.success("删除成功!")
|
await message.success("删除成功!")
|
||||||
|
} else if (type === 'download') {
|
||||||
|
downloadImage(imageDetail.picUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载 - image
|
||||||
|
*/
|
||||||
|
const downloadImage = async (imageUrl) => {
|
||||||
|
const image = new Image()
|
||||||
|
image.setAttribute('crossOrigin', 'anonymous')
|
||||||
|
image.src = imageUrl
|
||||||
|
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)
|
||||||
|
const url = canvas.toDataURL('image/png')
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url
|
||||||
|
a.download = 'image.png'
|
||||||
|
a.click()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
defineExpose({getImageList})
|
defineExpose({getImageList})
|
||||||
//
|
//
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<el-card body-class="" class="image-card">
|
<el-card body-class="" class="image-card">
|
||||||
<div class="image-operation">
|
<div class="image-operation">
|
||||||
@ -8,7 +7,8 @@
|
|||||||
<el-button type="" text bg v-else-if="imageDetail.status === 'complete'">已完成</el-button>
|
<el-button type="" text bg v-else-if="imageDetail.status === 'complete'">已完成</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<el-button class="btn" text :icon="Download" @click="handlerBtnClick('download', imageDetail)" />
|
<el-button class="btn" text :icon="Download"
|
||||||
|
@click="handlerBtnClick('download', imageDetail)"/>
|
||||||
<el-button class="btn" text :icon="Delete" @click="handlerBtnClick('delete', imageDetail)"/>
|
<el-button class="btn" text :icon="Delete" @click="handlerBtnClick('delete', imageDetail)"/>
|
||||||
<el-button class="btn" text :icon="More" @click="handlerBtnClick('more', imageDetail)"/>
|
<el-button class="btn" text :icon="More" @click="handlerBtnClick('more', imageDetail)"/>
|
||||||
</div>
|
</div>
|
||||||
@ -41,13 +41,6 @@ const handlerBtnClick = async (type, imageDetail: ImageDetailVO ) => {
|
|||||||
emits('onBtnClick', type, imageDetail)
|
emits('onBtnClick', type, imageDetail)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听 imageDetail
|
|
||||||
// const { imageDetail } = toRefs(props)
|
|
||||||
// watch(imageDetail, async (newVal, oldValue) => {
|
|
||||||
// console.log('首次 watch')
|
|
||||||
//
|
|
||||||
// })
|
|
||||||
|
|
||||||
// emits
|
// emits
|
||||||
const emits = defineEmits(['onBtnClick'])
|
const emits = defineEmits(['onBtnClick'])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user