2024-05-26 20:47:29 +08:00
|
|
|
|
|
|
|
<template>
|
|
|
|
<el-card class="dr-task" body-class="task-card" shadow="never">
|
|
|
|
<template #header>绘画任务</template>
|
2024-05-28 10:37:44 +08:00
|
|
|
<ImageTaskCard
|
|
|
|
v-for="image in imageList"
|
|
|
|
:key="image"
|
|
|
|
:image-detail="image"
|
|
|
|
@on-btn-click="handlerImageBtnClick" />
|
2024-05-26 20:47:29 +08:00
|
|
|
</el-card>
|
2024-05-26 20:59:42 +08:00
|
|
|
<!-- 图片 detail 抽屉 -->
|
|
|
|
<ImageDetailDrawer
|
|
|
|
:show="showTaskDetail"
|
|
|
|
@handler-drawer-close="handlerDrawerClose"
|
|
|
|
/>
|
2024-05-26 20:47:29 +08:00
|
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
2024-05-26 21:51:42 +08:00
|
|
|
import {ImageApi, ImageDetailVO} from '@/api/ai/image';
|
2024-05-26 20:59:42 +08:00
|
|
|
import ImageDetailDrawer from './ImageDetailDrawer.vue'
|
2024-05-26 21:51:42 +08:00
|
|
|
import ImageTaskCard from './ImageTaskCard.vue'
|
2024-05-26 20:59:42 +08:00
|
|
|
import {bool} from "vue-types";
|
|
|
|
|
2024-05-28 10:37:44 +08:00
|
|
|
const message = useMessage() // 消息弹窗
|
|
|
|
|
2024-05-26 21:51:42 +08:00
|
|
|
const imageList = ref<ImageDetailVO[]>([]) // image 列表
|
2024-05-28 09:51:58 +08:00
|
|
|
const imageListInterval = ref<any>() // image 列表定时器,刷新列表
|
2024-05-26 20:59:42 +08:00
|
|
|
const showTaskDetail = ref<bool>(false) // 是否显示 task 详情
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 图片人物 - detail
|
|
|
|
*/
|
|
|
|
const handlerTaskDetail = async () => {
|
|
|
|
showTaskDetail.value = !showTaskDetail.value
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-05-26 21:51:42 +08:00
|
|
|
* 抽屉 - close
|
2024-05-26 20:59:42 +08:00
|
|
|
*/
|
|
|
|
const handlerDrawerClose = async () => {
|
|
|
|
showTaskDetail.value = false
|
|
|
|
}
|
|
|
|
|
2024-05-26 21:51:42 +08:00
|
|
|
/**
|
|
|
|
* 任务 - detail
|
|
|
|
*/
|
|
|
|
const handlerDrawerOpen = async () => {
|
|
|
|
showTaskDetail.value = true
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取 - image 列表
|
|
|
|
*/
|
|
|
|
const getImageList = async () => {
|
2024-05-27 17:14:03 +08:00
|
|
|
const { list } = await ImageApi.getImageList({pageNo: 1, pageSize: 20})
|
|
|
|
imageList.value = list
|
2024-05-26 21:51:42 +08:00
|
|
|
}
|
2024-05-26 20:59:42 +08:00
|
|
|
|
2024-05-26 21:56:10 +08:00
|
|
|
/**
|
|
|
|
* 图片 - btn click
|
|
|
|
*/
|
|
|
|
const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => {
|
|
|
|
if (type === 'more') {
|
|
|
|
await handlerDrawerOpen()
|
2024-05-28 10:37:44 +08:00
|
|
|
} else if (type === 'delete') {
|
|
|
|
await message.confirm(`是否删除照片?`)
|
|
|
|
await ImageApi.deleteImage(imageDetail.id)
|
|
|
|
await getImageList()
|
|
|
|
await message.success("删除成功!")
|
2024-05-28 11:35:02 +08:00
|
|
|
} else if (type === 'download') {
|
|
|
|
downloadImage(imageDetail.picUrl)
|
2024-05-26 21:56:10 +08:00
|
|
|
}
|
|
|
|
}
|
2024-05-28 11:35:02 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 下载 - 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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-27 17:35:18 +08:00
|
|
|
//
|
|
|
|
defineExpose({getImageList})
|
2024-05-26 21:51:42 +08:00
|
|
|
//
|
|
|
|
onMounted(async () => {
|
2024-05-28 09:51:58 +08:00
|
|
|
// 获取 image 列表
|
2024-05-26 21:51:42 +08:00
|
|
|
await getImageList()
|
2024-05-28 09:51:58 +08:00
|
|
|
// 自动刷新 image 列表
|
|
|
|
imageListInterval.value = setInterval(async () => {
|
|
|
|
await getImageList()
|
|
|
|
}, 3000)
|
|
|
|
})
|
|
|
|
//
|
|
|
|
onUnmounted(async () => {
|
|
|
|
|
2024-05-26 21:51:42 +08:00
|
|
|
})
|
2024-05-26 20:47:29 +08:00
|
|
|
</script>
|
|
|
|
|
2024-05-27 17:20:03 +08:00
|
|
|
<style lang="scss">
|
|
|
|
.task-card {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-wrap: wrap;
|
2024-05-27 17:43:03 +08:00
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
2024-05-27 17:20:03 +08:00
|
|
|
|
|
|
|
>div {
|
|
|
|
margin-right: 20px;
|
2024-05-27 17:35:18 +08:00
|
|
|
margin-bottom: 20px;
|
2024-05-27 17:20:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
2024-05-26 20:47:29 +08:00
|
|
|
|
2024-05-27 17:20:03 +08:00
|
|
|
<style scoped lang="scss">
|
2024-05-26 20:47:29 +08:00
|
|
|
.dr-task {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|