2
2
<el-card class =" dr-task" body-class =" task-card" shadow =" never" >
3
3
<template #header >绘画任务</template >
4
4
<!-- 图片列表 -->
5
- <div class =" task-image-list" ref =" imageTaskRef " >
5
+ <div class =" task-image-list" ref =" imageListRef " >
6
6
<ImageCard
7
7
v-for =" image in imageList"
8
8
:key =" image.id"
9
9
:image-detail =" image"
10
- @on-btn-click =" handleImageBtnClick "
11
- @on-mj-btn-click =" handleImageMjBtnClick "
10
+ @on-btn-click =" handleImageButtonClick "
11
+ @on-mj-btn-click =" handleImageMidjourneyButtonClick "
12
12
/>
13
13
</div >
14
14
<div class =" task-image-pagination" >
15
- <el-pagination
16
- background
17
- layout =" prev, pager, next"
18
- :default-page-size =" pageSize"
15
+ <Pagination
19
16
:total =" pageTotal"
20
- @change =" handlePageChange"
17
+ v-model:page =" queryParams.pageNo"
18
+ v-model:limit =" queryParams.pageSize"
19
+ @pagination =" getImageList"
21
20
/>
22
21
</div >
23
22
</el-card >
26
25
<ImageDetail
27
26
:show =" isShowImageDetail"
28
27
:id =" showImageDetailId"
29
- @handle-drawer-close =" handleDrawerClose "
28
+ @handle-drawer-close =" handleDetailClose "
30
29
/>
31
30
</template >
32
31
<script setup lang="ts">
33
- import { ImageApi , ImageVO , ImageMjActionVO , ImageMjButtonsVO } from ' @/api/ai/image'
32
+ import {
33
+ ImageApi ,
34
+ ImageVO ,
35
+ ImageMidjourneyActionVO ,
36
+ ImageMidjourneyButtonsVO
37
+ } from ' @/api/ai/image'
34
38
import ImageDetail from ' ./ImageDetail.vue'
35
39
import ImageCard from ' ./ImageCard.vue'
36
40
import { ElLoading , LoadingOptionsResolved } from ' element-plus'
37
41
import { AiImageStatusEnum } from ' @/views/ai/utils/constants'
38
- import { downloadImage } from ' @/utils/download'
42
+ import download from ' @/utils/download'
39
43
40
44
const message = useMessage () // 消息弹窗
41
45
46
+ // 图片分页相关的参数
47
+ const queryParams = reactive ({
48
+ pageNo: 1 ,
49
+ pageSize: 10
50
+ })
51
+ const pageTotal = ref <number >(0 ) // page size
42
52
const imageList = ref <ImageVO []>([]) // image 列表
53
+ const imageListLoadingInstance = ref <any >() // image 列表是否正在加载中
54
+ const imageListRef = ref <any >() // ref
55
+ // 图片轮询相关的参数(正在生成中的)
43
56
const inProgressImageMap = ref <{}>({}) // 监听的 image 映射,一般是生成中(需要轮询),key 为 image 编号,value 为 image
44
- const imageListInterval = ref <any >() // image 列表定时器,刷新列表
45
- const isShowImageDetail = ref <boolean >(false ) // 是否显示 task 详情
46
- const showImageDetailId = ref <number >(0 ) // 是否显示 task 详情
47
- const imageTaskRef = ref <any >() // ref
48
- const imageTaskLoadingInstance = ref <any >() // loading
49
- const imageTaskLoading = ref <boolean >(false ) // loading
50
- const pageNo = ref <number >(1 ) // page no
51
- const pageSize = ref <number >(10 ) // page size
52
- const pageTotal = ref <number >(0 ) // page size
57
+ const inProgressTimer = ref <any >() // 生成中的 image 定时器,轮询生成进展
58
+ // 图片详情相关的参数
59
+ const isShowImageDetail = ref <boolean >(false ) // 图片详情是否展示
60
+ const showImageDetailId = ref <number >(0 ) // 图片详情的图片编号
53
61
54
- /** 抽屉 - close */
55
- const handleDrawerClose = async () => {
56
- isShowImageDetail .value = false
62
+ /** 查看图片的详情 */
63
+ const handleDetailOpen = async () => {
64
+ isShowImageDetail .value = true
57
65
}
58
66
59
- /** 任务 - detail */
60
- const handleDrawerOpen = async () => {
61
- isShowImageDetail .value = true
67
+ /** 关闭图片的详情 */
68
+ const handleDetailClose = async () => {
69
+ isShowImageDetail .value = false
62
70
}
63
71
64
- /**
65
- * 获取 - image 列表
66
- */
67
- const getImageList = async (apply : boolean = false ) => {
68
- imageTaskLoading .value = true
72
+ /** 获得 image 图片列表 */
73
+ const getImageList = async () => {
69
74
try {
70
- imageTaskLoadingInstance .value = ElLoading .service ({
71
- target: imageTaskRef .value ,
75
+ // 1. 加载图片列表
76
+ imageListLoadingInstance .value = ElLoading .service ({
77
+ target: imageListRef .value ,
72
78
text: ' 加载中...'
73
79
} as LoadingOptionsResolved )
74
- const { list, total } = await ImageApi .getImagePageMy ({
75
- pageNo: pageNo .value ,
76
- pageSize: pageSize .value
77
- })
78
- if (apply ) {
79
- imageList .value = [... imageList .value , ... list ]
80
- } else {
81
- imageList .value = list
82
- }
80
+ const { list, total } = await ImageApi .getImagePageMy (queryParams )
81
+ imageList .value = list
83
82
pageTotal .value = total
84
- // 需要 watch 的数据
83
+
84
+ // 2. 计算需要轮询的图片
85
85
const newWatImages = {}
86
86
imageList .value .forEach ((item ) => {
87
87
if (item .status === AiImageStatusEnum .IN_PROGRESS ) {
@@ -90,9 +90,10 @@ const getImageList = async (apply: boolean = false) => {
90
90
})
91
91
inProgressImageMap .value = newWatImages
92
92
} finally {
93
- if (imageTaskLoadingInstance .value ) {
94
- imageTaskLoadingInstance .value .close ()
95
- imageTaskLoadingInstance .value = null
93
+ // 关闭正在“加载中”的 Loading
94
+ if (imageListLoadingInstance .value ) {
95
+ imageListLoadingInstance .value .close ()
96
+ imageListLoadingInstance .value = null
96
97
}
97
98
}
98
99
}
@@ -119,66 +120,68 @@ const refreshWatchImages = async () => {
119
120
inProgressImageMap .value = newWatchImages
120
121
}
121
122
122
- /** 图片 - btn click */
123
- const handleImageBtnClick = async (type : string , imageDetail : ImageVO ) => {
124
- // 获取 image detail id
125
- showImageDetailId .value = imageDetail .id
126
- // 处理不用 btn
123
+ /** 图片的点击事件 */
124
+ const handleImageButtonClick = async (type : string , imageDetail : ImageVO ) => {
125
+ // 详情
127
126
if (type === ' more' ) {
128
- await handleDrawerOpen ()
129
- } else if (type === ' delete' ) {
127
+ showImageDetailId .value = imageDetail .id
128
+ await handleDetailOpen ()
129
+ return
130
+ }
131
+ // 删除
132
+ if (type === ' delete' ) {
130
133
await message .confirm (` 是否删除照片? ` )
131
134
await ImageApi .deleteImageMy (imageDetail .id )
132
135
await getImageList ()
133
136
message .success (' 删除成功!' )
134
- } else if (type === ' download' ) {
135
- await downloadImage (imageDetail .picUrl )
136
- } else if (type === ' regeneration' ) {
137
- // Midjourney 平台
138
- console .log (' regeneration' , imageDetail .id )
137
+ return
138
+ }
139
+ // 下载
140
+ if (type === ' download' ) {
141
+ await download .image (imageDetail .picUrl )
142
+ return
143
+ }
144
+ // 重新生成
145
+ if (type === ' regeneration' ) {
139
146
await emits (' onRegeneration' , imageDetail )
147
+ return
140
148
}
141
149
}
142
150
143
- /** 图片 - mj btn click */
144
- const handleImageMjBtnClick = async (button : ImageMjButtonsVO , imageDetail : ImageVO ) => {
145
- // 1、构建 params 参数
151
+ /** 处理 Midjourney 按钮点击事件 */
152
+ const handleImageMidjourneyButtonClick = async (
153
+ button : ImageMidjourneyButtonsVO ,
154
+ imageDetail : ImageVO
155
+ ) => {
156
+ // 1. 构建 params 参数
146
157
const data = {
147
158
id: imageDetail .id ,
148
159
customId: button .customId
149
- } as ImageMjActionVO
150
- // 2、 发送 action
160
+ } as ImageMidjourneyActionVO
161
+ // 2. 发送 action
151
162
await ImageApi .midjourneyAction (data )
152
- // 3、 刷新列表
163
+ // 3. 刷新列表
153
164
await getImageList ()
154
165
}
155
166
156
- // page change
157
- const handlePageChange = async (page ) => {
158
- pageNo .value = page
159
- await getImageList (false )
160
- }
161
-
162
- /** 暴露组件方法 */
163
- defineExpose ({ getImageList })
167
+ defineExpose ({ getImageList }) // 暴露组件方法
164
168
165
- // emits
166
169
const emits = defineEmits ([' onRegeneration' ])
167
170
168
171
/** 组件挂在的时候 */
169
172
onMounted (async () => {
170
173
// 获取 image 列表
171
174
await getImageList ()
172
175
// 自动刷新 image 列表
173
- imageListInterval .value = setInterval (async () => {
176
+ inProgressTimer .value = setInterval (async () => {
174
177
await refreshWatchImages ()
175
178
}, 1000 * 3 )
176
179
})
177
180
178
181
/** 组件取消挂在的时候 */
179
182
onUnmounted (async () => {
180
- if (imageListInterval .value ) {
181
- clearInterval (imageListInterval .value )
183
+ if (inProgressTimer .value ) {
184
+ clearInterval (inProgressTimer .value )
182
185
}
183
186
})
184
187
</script >
0 commit comments