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
749e4408
authored
Jul 09, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码优化】AI:绘图 index.vue 代码梳理 40%(ImageCard)
parent
51621913
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
49 deletions
+50
-49
src/views/ai/image/index/components/ImageCard.vue
+49
-46
src/views/ai/image/index/components/ImageDetail.vue
+0
-2
src/views/ai/image/index/components/ImageList.vue
+1
-1
No files found.
src/views/ai/image/index/components/ImageCard.vue
View file @
749e4408
...
...
@@ -2,53 +2,53 @@
<el-card
body-class=
""
class=
"image-card"
>
<div
class=
"image-operation"
>
<div>
<el-button
type=
"primary"
text
bg
v-if=
"imageDetail?.status === AiImageStatusEnum.IN_PROGRESS"
>
<el-button
type=
"primary"
text
bg
v-if=
"detail?.status === AiImageStatusEnum.IN_PROGRESS"
>
生成中
</el-button>
<el-button
text
bg
v-else-if=
"
imageD
etail?.status === AiImageStatusEnum.SUCCESS"
>
<el-button
text
bg
v-else-if=
"
d
etail?.status === AiImageStatusEnum.SUCCESS"
>
已完成
</el-button>
<el-button
type=
"danger"
text
bg
v-else-if=
"
imageD
etail?.status === AiImageStatusEnum.FAIL"
>
<el-button
type=
"danger"
text
bg
v-else-if=
"
d
etail?.status === AiImageStatusEnum.FAIL"
>
异常
</el-button>
</div>
<!-- 操作区 -->
<div>
<el-button
class=
"btn"
text
:icon=
"Download"
@
click=
"handleB
tnClick('download', imageD
etail)"
@
click=
"handleB
uttonClick('download', d
etail)"
/>
<el-button
class=
"btn"
text
:icon=
"RefreshRight"
@
click=
"handleB
tnClick('regeneration', imageD
etail)"
@
click=
"handleB
uttonClick('regeneration', d
etail)"
/>
<el-button
class=
"btn"
text
:icon=
"Delete"
@
click=
"handleB
tnClick('delete', imageD
etail)"
/>
<el-button
class=
"btn"
text
:icon=
"More"
@
click=
"handleB
tnClick('more', imageD
etail)"
/>
<el-button
class=
"btn"
text
:icon=
"Delete"
@
click=
"handleB
uttonClick('delete', d
etail)"
/>
<el-button
class=
"btn"
text
:icon=
"More"
@
click=
"handleB
uttonClick('more', d
etail)"
/>
</div>
</div>
<div
class=
"image-wrapper"
ref=
"cardImageRef"
>
<!-- TODO @fan:要不加个点击,大图预览? -->
<img
class=
"image"
:src=
"imageDetail?.picUrl"
/>
<div
v-if=
"imageDetail?.status === AiImageStatusEnum.FAIL"
>
{{
imageDetail
?.
errorMessage
}}
<el-image
class=
"image"
:src=
"detail?.picUrl"
:preview-src-list=
"[detail.picUrl]"
preview-teleported
/>
<div
v-if=
"detail?.status === AiImageStatusEnum.FAIL"
>
{{
detail
?.
errorMessage
}}
</div>
</div>
<!--
TODO @fan:style 使用 unocss 替代下
-->
<!--
Midjourney 专属操作
-->
<div
class=
"image-mj-btns"
>
<el-button
size=
"small"
v-for=
"button in
imageD
etail?.buttons"
v-for=
"button in
d
etail?.buttons"
:key=
"button"
style=
"min-width: 40px; margin-left: 0; margin-right: 10px; margin-top:
5px"
@
click=
"handleM
j
BtnClick(button)"
class=
"min-w-40px ml-0 mr-10px mt-
5px"
@
click=
"handleM
idjourney
BtnClick(button)"
>
{{
button
.
label
}}{{
button
.
emoji
}}
</el-button>
...
...
@@ -62,28 +62,47 @@ import { PropType } from 'vue'
import
{
ElLoading
,
LoadingOptionsResolved
}
from
'element-plus'
import
{
AiImageStatusEnum
}
from
'@/views/ai/utils/constants'
const
cardImageRef
=
ref
<
any
>
()
// 卡片 image ref
const
cardImageLoadingInstance
=
ref
<
any
>
()
// 卡片 image ref
const
message
=
useMessage
()
const
message
=
useMessage
()
// 消息
const
props
=
defineProps
({
imageD
etail
:
{
d
etail
:
{
type
:
Object
as
PropType
<
ImageVO
>
,
require
:
true
}
})
/** 按钮 - 点击事件 */
const
handleBtnClick
=
async
(
type
,
imageDetail
:
ImageVO
)
=>
{
emits
(
'onBtnClick'
,
type
,
imageDetail
)
const
cardImageRef
=
ref
<
any
>
()
// 卡片 image ref
const
cardImageLoadingInstance
=
ref
<
any
>
()
// 卡片 image ref
/** 处理点击事件 */
const
handleButtonClick
=
async
(
type
,
detail
:
ImageVO
)
=>
{
emits
(
'onBtnClick'
,
type
,
detail
)
}
/** 处理 Midjourney 按钮点击事件 */
const
handleMidjourneyBtnClick
=
async
(
button
:
ImageMidjourneyButtonsVO
)
=>
{
// 确认窗体
await
message
.
confirm
(
`确认操作 "
${
button
.
label
}
${
button
.
emoji
}
" ?`
)
emits
(
'onMjBtnClick'
,
button
,
props
.
detail
)
}
const
emits
=
defineEmits
([
'onBtnClick'
,
'onMjBtnClick'
])
// emits
/** 监听详情 */
const
{
detail
}
=
toRefs
(
props
)
watch
(
detail
,
async
(
newVal
,
oldVal
)
=>
{
await
handleLoading
(
newVal
.
status
as
string
)
})
/** 处理加载状态 */
const
handleLoading
=
async
(
status
:
number
)
=>
{
//
TODO @芋艿:这个搞成 Loading 组件,然后通过数据驱动,这样搞可以哇?
//
情况一:如果是生成中,则设置加载中的 loading
if
(
status
===
AiImageStatusEnum
.
IN_PROGRESS
)
{
cardImageLoadingInstance
.
value
=
ElLoading
.
service
({
target
:
cardImageRef
.
value
,
text
:
'生成中...'
}
as
LoadingOptionsResolved
)
// 情况二:如果已经生成结束,则移除 loading
}
else
{
if
(
cardImageLoadingInstance
.
value
)
{
cardImageLoadingInstance
.
value
.
close
()
...
...
@@ -92,25 +111,9 @@ const handleLoading = async (status: number) => {
}
}
/** mj 按钮 click */
const
handleMjBtnClick
=
async
(
button
:
ImageMidjourneyButtonsVO
)
=>
{
// 确认窗体
await
message
.
confirm
(
`确认操作 "
${
button
.
label
}
${
button
.
emoji
}
" ?`
)
emits
(
'onMjBtnClick'
,
button
,
props
.
imageDetail
)
}
// watch
const
{
imageDetail
}
=
toRefs
(
props
)
watch
(
imageDetail
,
async
(
newVal
,
oldVal
)
=>
{
await
handleLoading
(
newVal
.
status
as
string
)
})
// emits
const
emits
=
defineEmits
([
'onBtnClick'
,
'onMjBtnClick'
])
//
/** 初始化 */
onMounted
(
async
()
=>
{
await
handleLoading
(
props
.
imageD
etail
.
status
as
string
)
await
handleLoading
(
props
.
d
etail
.
status
as
string
)
})
</
script
>
...
...
src/views/ai/image/index/components/ImageDetail.vue
View file @
749e4408
...
...
@@ -107,8 +107,6 @@ watch(id, async (newVal, oldVal) => {
})
//
const
emits
=
defineEmits
([
'handleDrawerClose'
])
//
onMounted
(
async
()
=>
{})
</
script
>
<
style
scoped
lang=
"scss"
>
.item
{
...
...
src/views/ai/image/index/components/ImageList.vue
View file @
749e4408
...
...
@@ -6,7 +6,7 @@
<ImageCard
v-for=
"image in imageList"
:key=
"image.id"
:
image-
detail=
"image"
:detail=
"image"
@
on-btn-click=
"handleImageButtonClick"
@
on-mj-btn-click=
"handleImageMidjourneyButtonClick"
/>
...
...
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