【解决todo】如果有生成中的图片,轮询改成 get 接口去轮询,不基于 page 轮询

pull/468/MERGE
cherishsince 2024-06-28 16:41:12 +08:00
parent 8daf9bb347
commit 6f9cb4f8f2
2 changed files with 35 additions and 4 deletions

View File

@ -64,6 +64,10 @@ export const ImageApi = {
getImageMy: async (id: number) => {
return await request.get({ url: `/ai/image/get-my?id=${id}` })
},
// 获取我的图片
getImageMyIds: async (params) => {
return await request.get({ url: `/ai/image/get-my-ids`, params})
},
// 生成图片
drawImage: async (data: ImageDrawReqVO) => {
return await request.post({ url: `/ai/image/draw`, data })

View File

@ -26,7 +26,7 @@
/>
</template>
<script setup lang="ts">
import {ImageApi, ImageRespVO, ImageMjActionVO, ImageMjButtonsVO} from '@/api/ai/image';
import {ImageApi, ImageMjActionVO, ImageMjButtonsVO, ImageRespVO} from '@/api/ai/image';
import ImageDetailDrawer from './ImageDetailDrawer.vue'
import ImageTaskCard from './ImageTaskCard.vue'
import {ElLoading, LoadingOptionsResolved} from "element-plus";
@ -34,7 +34,7 @@ import {ElLoading, LoadingOptionsResolved} from "element-plus";
const message = useMessage() //
const imageList = ref<ImageRespVO[]>([]) // image
const watchImageList = ref<ImageRespVO[]>([]) // image list
const watchImages = ref<{}>({}) // image list
const imageListInterval = ref<any>() // image
const isShowImageDetail = ref<boolean>(false) // task
const showImageDetailId = ref<number>(0) // task
@ -72,6 +72,13 @@ const getImageList = async (apply:boolean = false) => {
imageList.value = list
}
pageTotal.value = total
// watch
imageList.value.map(item => {
if (item.status === 10) {
watchImages.value[item.id] = item
}
})
} finally {
if (imageTaskLoadingInstance.value) {
imageTaskLoadingInstance.value.close();
@ -80,6 +87,26 @@ const getImageList = async (apply:boolean = false) => {
}
}
/**
* 获取 - image 列表
*/
const refreshWatchImages = async () => {
const imageIds = Object.keys(watchImages.value)
if (imageIds.length < 1) {
return
}
const res = await ImageApi.getImageMyIds({ids: imageIds.join(',')}) as ImageRespVO[]
res.forEach(image => {
const index = imageList.value.findIndex(oldImage => image.id === oldImage.id)
if (index !== -1) {
// imageList
imageList.value[index] = image
// watchImages
delete watchImages.value[image.id];
}
})
}
/** 图片 - btn click */
const handlerImageBtnClick = async (type, imageDetail: ImageRespVO) => {
// image detail id
@ -145,8 +172,8 @@ onMounted(async () => {
await getImageList()
// image
imageListInterval.value = setInterval(async () => {
await getImageList(false)
}, 1000 * 20)
await refreshWatchImages()
}, 1000 * 3)
})
/** 组件取消挂在的时候 */