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
61bf6fb8
authored
Jul 09, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【代码优化】AI:绘图 index.vue 代码梳理 60%(StableDiffusion.vue)
parent
ac46a376
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
252 additions
and
14 deletions
+252
-14
src/api/ai/image/index.ts
+3
-3
src/views/ai/image/index/components/ImageDetail.vue
+75
-7
src/views/ai/image/index/components/stableDiffusion/index.vue
+0
-0
src/views/ai/image/index/index.vue
+3
-3
src/views/ai/utils/constants.ts
+170
-0
src/views/ai/utils/utils.ts
+1
-1
No files found.
src/api/ai/image/index.ts
View file @
61bf6fb8
...
...
@@ -12,11 +12,11 @@ export interface ImageVO {
publicStatus
:
boolean
// 公开状态
picUrl
:
string
// 任务地址
errorMessage
:
string
// 错误信息
options
:
object
// 配置 Map<string, string>
options
:
any
// 配置 Map<string, string>
taskId
:
number
// 任务编号
buttons
:
ImageMidjourneyButtonsVO
[]
// mj 操作按钮
createTime
:
string
// 创建时间
finishTime
:
string
// 完成时间
createTime
:
Date
// 创建时间
finishTime
:
Date
// 完成时间
}
export
interface
ImageDrawReqVO
{
...
...
src/views/ai/image/index/components/ImageDetail.vue
View file @
61bf6fb8
...
...
@@ -20,8 +20,8 @@
<div
class=
"item"
>
<div
class=
"tip"
>
时间
</div>
<div
class=
"body"
>
<div>
提交时间:
{{
detail
.
createTime
}}
</div>
<div>
生成时间:
{{
detail
.
finishTime
}}
</div>
<div>
提交时间:
{{
formatTime
(
detail
.
createTime
,
'yyyy-MM-dd HH:mm:ss'
)
}}
</div>
<div>
生成时间:
{{
formatTime
(
detail
.
finishTime
,
'yyyy-MM-dd HH:mm:ss'
)
}}
</div>
</div>
</div>
<!-- 模型 -->
...
...
@@ -43,13 +43,73 @@
{{
detail
.
picUrl
}}
</div>
</div>
<!-- 风格 -->
<div
class=
"item"
v-if=
"detail?.options?.style"
>
<!-- StableDiffusion 专属区域 -->
<div
class=
"item"
v-if=
"detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.sampler"
>
<div
class=
"tip"
>
采样方法
</div>
<div
class=
"body"
>
{{
StableDiffusionSamplers
.
find
(
(
item
:
ImageModelVO
)
=>
item
.
key
===
detail
?.
options
?.
sampler
)?.
name
}}
</div>
</div>
<div
class=
"item"
v-if=
"
detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.clipGuidancePreset
"
>
<div
class=
"tip"
>
CLIP
</div>
<div
class=
"body"
>
{{
StableDiffusionClipGuidancePresets
.
find
(
(
item
:
ImageModelVO
)
=>
item
.
key
===
detail
?.
options
?.
clipGuidancePreset
)?.
name
}}
</div>
</div>
<div
class=
"item"
v-if=
"detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.stylePreset"
>
<div
class=
"tip"
>
风格
</div>
<div
class=
"body"
>
<!-- TODO @fan:貌似需要把 imageStyleList 搞到 api/image/index.ts 枚举起来? -->
<!-- TODO @fan:这里的展示,可能需要按照平台做区分 -->
{{
detail
?.
options
?.
style
}}
{{
StableDiffusionStylePresets
.
find
(
(
item
:
ImageModelVO
)
=>
item
.
key
===
detail
?.
options
?.
stylePreset
)?.
name
}}
</div>
</div>
<div
class=
"item"
v-if=
"detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.steps"
>
<div
class=
"tip"
>
迭代步数
</div>
<div
class=
"body"
>
{{
detail
?.
options
?.
steps
}}
</div>
</div>
<div
class=
"item"
v-if=
"detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.scale"
>
<div
class=
"tip"
>
引导系数
</div>
<div
class=
"body"
>
{{
detail
?.
options
?.
scale
}}
</div>
</div>
<div
class=
"item"
v-if=
"detail.platform === AiPlatformEnum.STABLE_DIFFUSION && detail?.options?.seed"
>
<div
class=
"tip"
>
随机因子
</div>
<div
class=
"body"
>
{{
detail
?.
options
?.
seed
}}
</div>
</div>
</el-drawer>
...
...
@@ -58,6 +118,14 @@
<
script
setup
lang=
"ts"
>
import
{
ImageApi
,
ImageVO
}
from
'@/api/ai/image'
import
ImageCard
from
'./ImageCard.vue'
import
{
AiPlatformEnum
,
ImageModelVO
,
StableDiffusionClipGuidancePresets
,
StableDiffusionSamplers
,
StableDiffusionStylePresets
}
from
'@/views/ai/utils/constants'
import
{
formatTime
}
from
'@/utils'
const
showDrawer
=
ref
<
boolean
>
(
false
)
// 是否显示
const
detail
=
ref
<
ImageVO
>
({}
as
ImageVO
)
// 图片详细信息
...
...
src/views/ai/image/index/
stable-d
iffusion/index.vue
→
src/views/ai/image/index/
components/stableD
iffusion/index.vue
View file @
61bf6fb8
This diff is collapsed.
Click to expand it.
src/views/ai/image/index/index.vue
View file @
61bf6fb8
...
...
@@ -27,12 +27,12 @@
</
template
>
<
script
setup
lang=
"ts"
>
import
Dall3
from
'./dall3/index.vue'
import
Midjourney
from
'./midjourney/index.vue'
import
StableDiffusion
from
'./stable-diffusion/index.vue'
import
ImageList
from
'./components/ImageList.vue'
import
{
AiPlatformEnum
}
from
'@/views/ai/utils/constants'
import
{
ImageVO
}
from
'@/api/ai/image'
import
Dall3
from
'./dall3/index.vue'
import
Midjourney
from
'./midjourney/index.vue'
import
StableDiffusion
from
'./components/stableDiffusion/index.vue'
const
imageListRef
=
ref
<
any
>
()
// image 列表 ref
const
dall3Ref
=
ref
<
any
>
()
// openai ref
...
...
src/views/ai/utils/constants.ts
View file @
61bf6fb8
...
...
@@ -40,3 +40,173 @@ export const AiMusicStatusEnum = {
SUCCESS
:
20
,
// 已完成
FAIL
:
30
// 已失败
}
// ========== 【图片 UI】相关的枚举 ==========
export
const
ImageHotWords
=
[
'中国旗袍'
,
'古装美女'
,
'卡通头像'
,
'机甲战士'
,
'童话小屋'
,
'中国长城'
]
// 图片热词
export
const
ImageHotEnglishWords
=
[
'Chinese Cheongsam'
,
'Ancient Beauty'
,
'Cartoon Avatar'
,
'Mech Warrior'
,
'Fairy Tale Cottage'
,
'The Great Wall of China'
]
// 图片热词(英文)
export
interface
ImageModelVO
{
key
:
string
name
:
string
}
export
const
StableDiffusionSamplers
=
ref
<
ImageModelVO
[]
>
([
{
key
:
'DDIM'
,
name
:
'DDIM'
},
{
key
:
'DDPM'
,
name
:
'DDPM'
},
{
key
:
'K_DPMPP_2M'
,
name
:
'K_DPMPP_2M'
},
{
key
:
'K_DPMPP_2S_ANCESTRAL'
,
name
:
'K_DPMPP_2S_ANCESTRAL'
},
{
key
:
'K_DPM_2'
,
name
:
'K_DPM_2'
},
{
key
:
'K_DPM_2_ANCESTRAL'
,
name
:
'K_DPM_2_ANCESTRAL'
},
{
key
:
'K_EULER'
,
name
:
'K_EULER'
},
{
key
:
'K_EULER_ANCESTRAL'
,
name
:
'K_EULER_ANCESTRAL'
},
{
key
:
'K_HEUN'
,
name
:
'K_HEUN'
},
{
key
:
'K_LMS'
,
name
:
'K_LMS'
}
])
export
const
StableDiffusionStylePresets
=
ref
<
ImageModelVO
[]
>
([
{
key
:
'3d-model'
,
name
:
'3d-model'
},
{
key
:
'analog-film'
,
name
:
'analog-film'
},
{
key
:
'anime'
,
name
:
'anime'
},
{
key
:
'cinematic'
,
name
:
'cinematic'
},
{
key
:
'comic-book'
,
name
:
'comic-book'
},
{
key
:
'digital-art'
,
name
:
'digital-art'
},
{
key
:
'enhance'
,
name
:
'enhance'
},
{
key
:
'fantasy-art'
,
name
:
'fantasy-art'
},
{
key
:
'isometric'
,
name
:
'isometric'
},
{
key
:
'line-art'
,
name
:
'line-art'
},
{
key
:
'low-poly'
,
name
:
'low-poly'
},
{
key
:
'modeling-compound'
,
name
:
'modeling-compound'
},
// neon-punk origami photographic pixel-art tile-texture
{
key
:
'neon-punk'
,
name
:
'neon-punk'
},
{
key
:
'origami'
,
name
:
'origami'
},
{
key
:
'photographic'
,
name
:
'photographic'
},
{
key
:
'pixel-art'
,
name
:
'pixel-art'
},
{
key
:
'tile-texture'
,
name
:
'tile-texture'
}
])
export
const
StableDiffusionClipGuidancePresets
=
ref
<
ImageModelVO
[]
>
([
{
key
:
'NONE'
,
name
:
'NONE'
},
{
key
:
'FAST_BLUE'
,
name
:
'FAST_BLUE'
},
{
key
:
'FAST_GREEN'
,
name
:
'FAST_GREEN'
},
{
key
:
'SIMPLE'
,
name
:
'SIMPLE'
},
{
key
:
'SLOW'
,
name
:
'SLOW'
},
{
key
:
'SLOWER'
,
name
:
'SLOWER'
},
{
key
:
'SLOWEST'
,
name
:
'SLOWEST'
}
])
src/views/ai/utils/utils.ts
View file @
61bf6fb8
...
...
@@ -8,6 +8,6 @@
*/
/** 判断字符串是否包含中文 */
export
const
hasChinese
=
async
(
str
)
=>
{
export
const
hasChinese
=
(
str
:
string
)
=>
{
return
/
[\u
4e00-
\u
9fa5
]
/
.
test
(
str
)
}
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