2
2
<el-card body-class =" " class =" image-card" >
3
3
<div class =" image-operation" >
4
4
<div >
5
- <el-button
6
- type =" primary"
7
- text
8
- bg
9
- v-if =" imageDetail?.status === AiImageStatusEnum.IN_PROGRESS"
10
- >
5
+ <el-button type =" primary" text bg v-if =" detail?.status === AiImageStatusEnum.IN_PROGRESS" >
11
6
生成中
12
7
</el-button >
13
- <el-button text bg v-else-if =" imageDetail ?.status === AiImageStatusEnum.SUCCESS" >
8
+ <el-button text bg v-else-if =" detail ?.status === AiImageStatusEnum.SUCCESS" >
14
9
已完成
15
10
</el-button >
16
- <el-button type =" danger" text bg v-else-if =" imageDetail ?.status === AiImageStatusEnum.FAIL" >
11
+ <el-button type =" danger" text bg v-else-if =" detail ?.status === AiImageStatusEnum.FAIL" >
17
12
异常
18
13
</el-button >
19
14
</div >
15
+ <!-- 操作区 -->
20
16
<div >
21
17
<el-button
22
18
class =" btn"
23
19
text
24
20
:icon =" Download"
25
- @click =" handleBtnClick ('download', imageDetail )"
21
+ @click =" handleButtonClick ('download', detail )"
26
22
/>
27
23
<el-button
28
24
class =" btn"
29
25
text
30
26
:icon =" RefreshRight"
31
- @click =" handleBtnClick ('regeneration', imageDetail )"
27
+ @click =" handleButtonClick ('regeneration', detail )"
32
28
/>
33
- <el-button class =" btn" text :icon =" Delete" @click =" handleBtnClick ('delete', imageDetail )" />
34
- <el-button class =" btn" text :icon =" More" @click =" handleBtnClick ('more', imageDetail )" />
29
+ <el-button class =" btn" text :icon =" Delete" @click =" handleButtonClick ('delete', detail )" />
30
+ <el-button class =" btn" text :icon =" More" @click =" handleButtonClick ('more', detail )" />
35
31
</div >
36
32
</div >
37
33
<div class =" image-wrapper" ref =" cardImageRef" >
38
- <!-- TODO @fan:要不加个点击,大图预览? -->
39
- <img class =" image" :src =" imageDetail?.picUrl" />
40
- <div v-if =" imageDetail?.status === AiImageStatusEnum.FAIL" >
41
- {{ imageDetail?.errorMessage }}
34
+ <el-image
35
+ class =" image"
36
+ :src =" detail?.picUrl"
37
+ :preview-src-list =" [detail.picUrl]"
38
+ preview-teleported
39
+ />
40
+ <div v-if =" detail?.status === AiImageStatusEnum.FAIL" >
41
+ {{ detail?.errorMessage }}
42
42
</div >
43
43
</div >
44
- <!-- TODO @fan:style 使用 unocss 替代下 -->
44
+ <!-- Midjourney 专属操作 -->
45
45
<div class =" image-mj-btns" >
46
46
<el-button
47
47
size =" small"
48
- v-for =" button in imageDetail ?.buttons"
48
+ v-for =" button in detail ?.buttons"
49
49
:key =" button"
50
- style =" min-width : 40px ; margin-left : 0 ; margin-right : 10px ; margin-top : 5px "
51
- @click =" handleMjBtnClick (button)"
50
+ class =" min-w- 40px ml-0 mr- 10px mt- 5px"
51
+ @click =" handleMidjourneyBtnClick (button)"
52
52
>
53
53
{{ button.label }}{{ button.emoji }}
54
54
</el-button >
@@ -62,28 +62,47 @@ import { PropType } from 'vue'
62
62
import { ElLoading , LoadingOptionsResolved } from ' element-plus'
63
63
import { AiImageStatusEnum } from ' @/views/ai/utils/constants'
64
64
65
- const cardImageRef = ref <any >() // 卡片 image ref
66
- const cardImageLoadingInstance = ref <any >() // 卡片 image ref
67
- const message = useMessage ()
65
+ const message = useMessage () // 消息
66
+
68
67
const props = defineProps ({
69
- imageDetail : {
68
+ detail : {
70
69
type: Object as PropType <ImageVO >,
71
70
require: true
72
71
}
73
72
})
74
73
75
- /** 按钮 - 点击事件 */
76
- const handleBtnClick = async (type , imageDetail : ImageVO ) => {
77
- emits (' onBtnClick' , type , imageDetail )
74
+ const cardImageRef = ref <any >() // 卡片 image ref
75
+ const cardImageLoadingInstance = ref <any >() // 卡片 image ref
76
+
77
+ /** 处理点击事件 */
78
+ const handleButtonClick = async (type , detail : ImageVO ) => {
79
+ emits (' onBtnClick' , type , detail )
80
+ }
81
+
82
+ /** 处理 Midjourney 按钮点击事件 */
83
+ const handleMidjourneyBtnClick = async (button : ImageMidjourneyButtonsVO ) => {
84
+ // 确认窗体
85
+ await message .confirm (` 确认操作 "${button .label } ${button .emoji }" ? ` )
86
+ emits (' onMjBtnClick' , button , props .detail )
78
87
}
79
88
89
+ const emits = defineEmits ([' onBtnClick' , ' onMjBtnClick' ]) // emits
90
+
91
+ /** 监听详情 */
92
+ const { detail } = toRefs (props )
93
+ watch (detail , async (newVal , oldVal ) => {
94
+ await handleLoading (newVal .status as string )
95
+ })
96
+
97
+ /** 处理加载状态 */
80
98
const handleLoading = async (status : number ) => {
81
- // TODO @芋艿:这个搞成 Loading 组件,然后通过数据驱动,这样搞可以哇?
99
+ // 情况一:如果是生成中,则设置加载中的 loading
82
100
if (status === AiImageStatusEnum .IN_PROGRESS ) {
83
101
cardImageLoadingInstance .value = ElLoading .service ({
84
102
target: cardImageRef .value ,
85
103
text: ' 生成中...'
86
104
} as LoadingOptionsResolved )
105
+ // 情况二:如果已经生成结束,则移除 loading
87
106
} else {
88
107
if (cardImageLoadingInstance .value ) {
89
108
cardImageLoadingInstance .value .close ()
@@ -92,25 +111,9 @@ const handleLoading = async (status: number) => {
92
111
}
93
112
}
94
113
95
- /** mj 按钮 click */
96
- const handleMjBtnClick = async (button : ImageMidjourneyButtonsVO ) => {
97
- // 确认窗体
98
- await message .confirm (` 确认操作 "${button .label } ${button .emoji }" ? ` )
99
- emits (' onMjBtnClick' , button , props .imageDetail )
100
- }
101
-
102
- // watch
103
- const { imageDetail } = toRefs (props )
104
- watch (imageDetail , async (newVal , oldVal ) => {
105
- await handleLoading (newVal .status as string )
106
- })
107
-
108
- // emits
109
- const emits = defineEmits ([' onBtnClick' , ' onMjBtnClick' ])
110
-
111
- //
114
+ /** 初始化 */
112
115
onMounted (async () => {
113
- await handleLoading (props .imageDetail .status as string )
116
+ await handleLoading (props .detail .status as string )
114
117
})
115
118
</script >
116
119
0 commit comments