2
2
<template >
3
3
<div class =" prompt" >
4
4
<el-text tag =" b" >画面描述</el-text >
5
- <el-text tag =" p" >建议使用“形容词+动词+ 风格”的格式,使用“,”隔开</el-text >
5
+ <el-text tag =" p" >建议使用“形容词 + 动词 + 风格”的格式,使用“,”隔开</el-text >
6
6
<el-input
7
7
v-model =" prompt"
8
8
maxlength =" 1024"
9
- rows =" 5"
9
+ : rows =" 5"
10
10
class =" w-100% mt-15px"
11
11
input-style =" border-radius: 7px;"
12
12
placeholder =" 例如:童话里的小屋应该是什么样子?"
128
128
</el-space >
129
129
</div >
130
130
<div class =" btns" >
131
- <el-button type =" primary" size =" large" round :loading =" drawIn" @click =" handleGenerateImage" >
131
+ <el-button
132
+ type =" primary"
133
+ size =" large"
134
+ round
135
+ :loading =" drawIn"
136
+ :disabled =" prompt.length === 0"
137
+ @click =" handleGenerateImage"
138
+ >
132
139
{{ drawIn ? '生成中' : '生成内容' }}
133
140
</el-button >
134
141
</div >
@@ -143,9 +150,19 @@ import {
143
150
StableDiffusionSamplers ,
144
151
StableDiffusionStylePresets
145
152
} from ' @/views/ai/utils/constants'
153
+ import { ModelVO } from ' @/api/ai/model/model'
146
154
147
155
const message = useMessage () // 消息弹窗
148
156
157
+ // 接收父组件传入的模型列表
158
+ const props = defineProps ({
159
+ models: {
160
+ type: Array < ModelVO > ,
161
+ default : () => [] as ModelVO []
162
+ }
163
+ })
164
+ const emits = defineEmits ([' onDrawStart' , ' onDrawComplete' ]) // 定义 emits
165
+
149
166
// 定义属性
150
167
const drawIn = ref <boolean >(false ) // 生成中
151
168
const selectHotWord = ref <string >(' ' ) // 选中的热词
@@ -160,8 +177,6 @@ const scale = ref<number>(7.5) // 引导系数
160
177
const clipGuidancePreset = ref <string >(' NONE' ) // 文本提示相匹配的图像(clip_guidance_preset) 简称 CLIP
161
178
const stylePreset = ref <string >(' 3d-model' ) // 风格
162
179
163
- const emits = defineEmits ([' onDrawStart' , ' onDrawComplete' ]) // 定义 emits
164
-
165
180
/** 选择热词 */
166
181
const handleHotWordClick = async (hotWord : string ) => {
167
182
// 情况一:取消选中
@@ -177,6 +192,16 @@ const handleHotWordClick = async (hotWord: string) => {
177
192
178
193
/** 图片生成 */
179
194
const handleGenerateImage = async () => {
195
+ // 从 models 中查找匹配的模型
196
+ const selectModel = ' stable-diffusion-v1-6'
197
+ const matchedModel = props .models .find (
198
+ (item ) => item .model === selectModel && item .platform === AiPlatformEnum .STABLE_DIFFUSION
199
+ )
200
+ if (! matchedModel ) {
201
+ message .error (' 该模型不可用,请选择其它模型' )
202
+ return
203
+ }
204
+
180
205
// 二次确认
181
206
if (hasChinese (prompt .value )) {
182
207
message .alert (' 暂不支持中文!' )
@@ -191,8 +216,7 @@ const handleGenerateImage = async () => {
191
216
emits (' onDrawStart' , AiPlatformEnum .STABLE_DIFFUSION )
192
217
// 发送请求
193
218
const form = {
194
- platform: AiPlatformEnum .STABLE_DIFFUSION ,
195
- model: ' stable-diffusion-v1-6' ,
219
+ modelId: matchedModel .id ,
196
220
prompt: prompt .value , // 提示词
197
221
width: width .value , // 图片宽度
198
222
height: height .value , // 图片高度
0 commit comments