Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6f9cb4f8
authored
Jun 28, 2024
by
cherishsince
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【解决todo】如果有生成中的图片,轮询改成 get 接口去轮询,不基于 page 轮询
parent
8daf9bb3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
4 deletions
+35
-4
src/api/ai/image/index.ts
+4
-0
src/views/ai/image/ImageTask.vue
+31
-4
No files found.
src/api/ai/image/index.ts
View file @
6f9cb4f8
...
...
@@ -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
})
...
...
src/views/ai/image/ImageTask.vue
View file @
6f9cb4f8
...
...
@@ -26,7 +26,7 @@
/>
</template>
<
script
setup
lang=
"ts"
>
import
{
ImageApi
,
Image
RespVO
,
ImageMjActionVO
,
ImageMjButtons
VO
}
from
'@/api/ai/image'
;
import
{
ImageApi
,
Image
MjActionVO
,
ImageMjButtonsVO
,
ImageResp
VO
}
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
watchImage
List
=
ref
<
ImageRespVO
[]
>
([]
)
// 监听的 image list,一般是生成中,需要轮训
const
watchImage
s
=
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
)
})
/** 组件取消挂在的时候 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment