37
37
</div >
38
38
<el-space wrap class =" model-list" >
39
39
<div
40
- :class =" model === model.key ? 'modal-item selectModel' : 'modal-item'"
40
+ :class =" selectModel === model.key ? 'modal-item selectModel' : 'modal-item'"
41
41
v-for =" model in Dall3Models"
42
42
:key =" model.key"
43
43
>
52
52
</div >
53
53
<el-space wrap class =" image-style-list" >
54
54
<div
55
- :class ="
56
- selectImageStyle === imageStyle.key
57
- ? 'image-style-item selectImageStyle'
58
- : 'image-style-item'
59
- "
60
- v-for =" imageStyle in imageStyleList"
55
+ :class =" style === imageStyle.key ? 'image-style-item selectImageStyle' : 'image-style-item'"
56
+ v-for =" imageStyle in Dall3StyleList"
61
57
:key =" imageStyle.key"
62
58
>
63
59
<el-image :src =" imageStyle.image" fit =" contain" @click =" handleStyleClick(imageStyle)" />
72
68
<el-space wrap class =" size-list" >
73
69
<div
74
70
class =" size-item"
75
- v-for =" imageSize in imageSizeList "
71
+ v-for =" imageSize in Dall3SizeList "
76
72
:key =" imageSize.key"
77
73
@click =" handleSizeClick(imageSize)"
78
74
>
79
- <div :class =" size === imageSize.key ? 'size-wrapper selectImageSize' : 'size-wrapper'" >
75
+ <div
76
+ :class =" selectSize === imageSize.key ? 'size-wrapper selectImageSize' : 'size-wrapper'"
77
+ >
80
78
<div :style =" imageSize.style" ></div >
81
79
</div >
82
80
<div class =" size-font" >{{ imageSize.name }}</div >
91
89
</template >
92
90
<script setup lang="ts">
93
91
import { ImageApi , ImageDrawReqVO , ImageVO } from ' @/api/ai/image'
94
- import { Dall3Models , ImageHotWords } from ' @/views/ai/utils/constants'
92
+ import {
93
+ Dall3Models ,
94
+ Dall3StyleList ,
95
+ ImageHotWords ,
96
+ Dall3SizeList ,
97
+ ImageModelVO ,
98
+ AiPlatformEnum
99
+ } from ' @/views/ai/utils/constants'
95
100
96
101
const message = useMessage () // 消息弹窗
97
102
98
- // image 模型
99
- interface ImageModelVO {
100
- key: string
101
- name: string
102
- image: string
103
- }
104
-
105
- // image 大小
106
- interface ImageSizeVO {
107
- key: string
108
- name: string
109
- style: string
110
- width: string
111
- height: string
112
- }
113
-
114
103
// 定义属性
115
104
const prompt = ref <string >(' ' ) // 提示词
116
105
const drawIn = ref <boolean >(false ) // 生成中
117
106
const selectHotWord = ref <string >(' ' ) // 选中的热词
118
- const model = ref <string >(' dall-e-3' ) // 模型
119
- const size = ref <string >(' 1024x1024' ) // 选中 size
120
-
121
- const selectImageStyle = ref <string >(' vivid' ) // style 样式
107
+ const selectModel = ref <string >(' dall-e-3' ) // 模型
108
+ const selectSize = ref <string >(' 1024x1024' ) // 选中 size
109
+ const style = ref <string >(' vivid' ) // style 样式
122
110
123
- const imageStyleList = ref <ImageModelVO []>([
124
- {
125
- key: ' vivid' ,
126
- name: ' 清晰' ,
127
- image: ` /src/assets/ai/qingxi.jpg `
128
- },
129
- {
130
- key: ' natural' ,
131
- name: ' 自然' ,
132
- image: ` /src/assets/ai/ziran.jpg `
133
- }
134
- ]) // style
135
-
136
- const imageSizeList = ref <ImageSizeVO []>([
137
- {
138
- key: ' 1024x1024' ,
139
- name: ' 1:1' ,
140
- width: ' 1024' ,
141
- height: ' 1024' ,
142
- style: ' width: 30px; height: 30px;background-color: #dcdcdc;'
143
- },
144
- {
145
- key: ' 1024x1792' ,
146
- name: ' 3:5' ,
147
- width: ' 1024' ,
148
- height: ' 1792' ,
149
- style: ' width: 30px; height: 50px;background-color: #dcdcdc;'
150
- },
151
- {
152
- key: ' 1792x1024' ,
153
- name: ' 5:3' ,
154
- width: ' 1792' ,
155
- height: ' 1024' ,
156
- style: ' width: 50px; height: 30px;background-color: #dcdcdc;'
157
- }
158
- ]) // size
111
+ const emits = defineEmits ([' onDrawStart' , ' onDrawComplete' ]) // 定义 emits
159
112
160
- // 定义 Props
161
- const props = defineProps ({})
162
- // 定义 emits
163
- const emits = defineEmits ([' onDrawStart' , ' onDrawComplete' ])
164
-
165
- /** 热词 - click */
113
+ /** 选择热词 */
166
114
const handleHotWordClick = async (hotWord : string ) => {
167
- // 取消选中
115
+ // 情况一: 取消选中
168
116
if (selectHotWord .value == hotWord ) {
169
117
selectHotWord .value = ' '
170
118
return
171
119
}
172
- // 选中
120
+
121
+ // 情况二:选中
173
122
selectHotWord .value = hotWord
174
- // 替换提示词
175
123
prompt .value = hotWord
176
124
}
177
125
178
- /** 模型 - click */
126
+ /** 选择 model 模型 */
179
127
const handleModelClick = async (model : ImageModelVO ) => {
180
- model .value = model .key
128
+ selectModel .value = model .key
181
129
}
182
130
183
- /** 样式 - click */
131
+ /** 选择 style 样式 */
184
132
const handleStyleClick = async (imageStyle : ImageModelVO ) => {
185
- selectImageStyle .value = imageStyle .key
133
+ style .value = imageStyle .key
186
134
}
187
135
188
- /** size - click */
136
+ /** 选择 size 大小 */
189
137
const handleSizeClick = async (imageSize : ImageSizeVO ) => {
190
- size .value = imageSize .key
138
+ selectSize .value = imageSize .key
191
139
}
192
140
193
141
/** 图片生产 */
@@ -198,37 +146,35 @@ const handleGenerateImage = async () => {
198
146
// 加载中
199
147
drawIn .value = true
200
148
// 回调
201
- emits (' onDrawStart' , model . value )
202
- const imageSize = imageSizeList . value . find ((item ) => item .key === size .value ) as ImageSizeVO
149
+ emits (' onDrawStart' , AiPlatformEnum . OPENAI )
150
+ const imageSize = Dall3SizeList . find ((item ) => item .key === selectSize .value ) as ImageSizeVO
203
151
const form = {
204
- platform: ' OpenAI ' ,
152
+ platform: AiPlatformEnum . OPENAI ,
205
153
prompt: prompt .value , // 提示词
206
- model: model .value , // 模型
154
+ model: selectModel .value , // 模型
207
155
width: imageSize .width , // size 不能为空
208
156
height: imageSize .height , // size 不能为空
209
157
options: {
210
- style: selectImageStyle .value // 图像生成的风格
158
+ style: style .value // 图像生成的风格
211
159
}
212
160
} as ImageDrawReqVO
213
161
// 发送请求
214
162
await ImageApi .drawImage (form )
215
163
} finally {
216
164
// 回调
217
- emits (' onDrawComplete' , model . value )
165
+ emits (' onDrawComplete' , AiPlatformEnum . OPENAI )
218
166
// 加载结束
219
167
drawIn .value = false
220
168
}
221
169
}
222
170
223
171
/** 填充值 */
224
- const settingValues = async (imageDetail : ImageVO ) => {
225
- prompt .value = imageDetail .prompt
226
- model .value = imageDetail .model
227
- //
228
- selectImageStyle .value = imageDetail .options ?.style
229
- //
230
- const imageSize = imageSizeList .value .find (
231
- (item ) => item .key === ` ${imageDetail .width }x${imageDetail .height } `
172
+ const settingValues = async (detail : ImageVO ) => {
173
+ prompt .value = detail .prompt
174
+ selectModel .value = detail .model
175
+ style .value = detail .options ?.style
176
+ const imageSize = Dall3SizeList .find (
177
+ (item ) => item .key === ` ${detail .width }x${detail .height } `
232
178
) as ImageSizeVO
233
179
await handleSizeClick (imageSize )
234
180
}
0 commit comments