3
3
<div class =" prompt" >
4
4
<el-text tag =" b" >画面描述</el-text >
5
5
<el-text tag =" p" >建议使用“形容词+动词+风格”的格式,使用“,”隔开</el-text >
6
- <!-- TODO @fan:style 看看能不能哟 unocss 替代 @芋艿 尝试了下没效果,哪个地方有使用么,我看看 -->
7
6
<el-input
8
7
v-model =" prompt"
9
8
maxlength =" 1024"
10
9
rows =" 5"
11
- style = " width : 100% ; margin-top : 15px ; "
10
+ class = " w- 100% mt- 15px"
12
11
input-style =" border-radius: 7px;"
13
12
placeholder =" 例如:童话里的小屋应该是什么样子?"
14
13
show-word-limit
20
19
<el-text tag =" b" >随机热词</el-text >
21
20
</div >
22
21
<el-space wrap class =" word-list" >
23
- <el-button round
24
- class =" btn"
25
- :type =" (selectHotWord === hotWord ? 'primary' : 'default')"
26
- v-for =" hotWord in hotWords"
27
- :key =" hotWord"
28
- @click =" handleHotWordClick(hotWord)"
22
+ <el-button
23
+ round
24
+ class =" btn"
25
+ :type =" selectHotWord === hotWord ? 'primary' : 'default'"
26
+ v-for =" hotWord in ImageHotWords"
27
+ :key =" hotWord"
28
+ @click =" handleHotWordClick(hotWord)"
29
29
>
30
30
{{ hotWord }}
31
31
</el-button >
37
37
</div >
38
38
<el-space wrap class =" model-list" >
39
39
<div
40
- :class =" selectModel === model.key ? 'modal-item selectModel' : 'modal-item'"
41
- v-for =" model in models "
40
+ :class =" model === model.key ? 'modal-item selectModel' : 'modal-item'"
41
+ v-for =" model in Dall3Models "
42
42
:key =" model.key"
43
-
44
43
>
45
- <el-image
46
- :src =" model.image"
47
- fit =" contain"
48
- @click =" handleModelClick(model)"
49
- />
50
- <div class =" model-font" >{{model.name}}</div >
44
+ <el-image :src =" model.image" fit =" contain" @click =" handleModelClick(model)" />
45
+ <div class =" model-font" >{{ model.name }}</div >
51
46
</div >
52
47
</el-space >
53
48
</div >
57
52
</div >
58
53
<el-space wrap class =" image-style-list" >
59
54
<div
60
- :class =" selectImageStyle === imageStyle.key ? 'image-style-item selectImageStyle' : 'image-style-item'"
55
+ :class ="
56
+ selectImageStyle === imageStyle.key
57
+ ? 'image-style-item selectImageStyle'
58
+ : 'image-style-item'
59
+ "
61
60
v-for =" imageStyle in imageStyleList"
62
61
:key =" imageStyle.key"
63
62
>
64
- <el-image
65
- :src =" imageStyle.image"
66
- fit =" contain"
67
- @click =" handleStyleClick(imageStyle)"
68
- />
69
- <div class =" style-font" >{{imageStyle.name}}</div >
63
+ <el-image :src =" imageStyle.image" fit =" contain" @click =" handleStyleClick(imageStyle)" />
64
+ <div class =" style-font" >{{ imageStyle.name }}</div >
70
65
</div >
71
66
</el-space >
72
67
</div >
75
70
<el-text tag =" b" >画面比例</el-text >
76
71
</div >
77
72
<el-space wrap class =" size-list" >
78
- <div class =" size-item"
79
- v-for =" imageSize in imageSizeList"
80
- :key =" imageSize.key"
81
- @click =" handleSizeClick(imageSize)" >
82
- <div :class =" selectImageSize === imageSize.key ? 'size-wrapper selectImageSize' : 'size-wrapper'" >
73
+ <div
74
+ class =" size-item"
75
+ v-for =" imageSize in imageSizeList"
76
+ :key =" imageSize.key"
77
+ @click =" handleSizeClick(imageSize)"
78
+ >
79
+ <div :class =" size === imageSize.key ? 'size-wrapper selectImageSize' : 'size-wrapper'" >
83
80
<div :style =" imageSize.style" ></div >
84
81
</div >
85
82
<div class =" size-font" >{{ imageSize.name }}</div >
86
83
</div >
87
84
</el-space >
88
85
</div >
89
86
<div class =" btns" >
90
- <el-button type =" primary"
91
- size =" large"
92
- round
93
- :loading =" drawIn"
94
- @click =" handleGenerateImage" >
95
- {{drawIn ? '生成中' : '生成内容'}}
87
+ <el-button type =" primary" size =" large" round :loading =" drawIn" @click =" handleGenerateImage" >
88
+ {{ drawIn ? '生成中' : '生成内容' }}
96
89
</el-button >
97
90
</div >
98
91
</template >
99
92
<script setup lang="ts">
100
- import {ImageApi , ImageDrawReqVO , ImageVO } from ' @/api/ai/image' ;
93
+ import { ImageApi , ImageDrawReqVO , ImageVO } from ' @/api/ai/image'
94
+ import { Dall3Models , ImageHotWords } from ' @/views/ai/utils/constants'
95
+
96
+ const message = useMessage () // 消息弹窗
101
97
102
98
// image 模型
103
99
interface ImageModelVO {
@@ -109,70 +105,55 @@ interface ImageModelVO {
109
105
// image 大小
110
106
interface ImageSizeVO {
111
107
key: string
112
- name: string ,
113
- style: string ,
114
- width: string ,
115
- height: string ,
108
+ name: string
109
+ style: string
110
+ width: string
111
+ height: string
116
112
}
117
113
118
114
// 定义属性
119
- const prompt = ref <string >(' ' ) // 提示词
120
- const drawIn = ref <boolean >(false ) // 生成中
115
+ const prompt = ref <string >(' ' ) // 提示词
116
+ const drawIn = ref <boolean >(false ) // 生成中
121
117
const selectHotWord = ref <string >(' ' ) // 选中的热词
122
- const hotWords = ref <string []>([' 中国旗袍' , ' 古装美女' , ' 卡通头像' , ' 机甲战士' , ' 童话小屋' , ' 中国长城' ]) // 热词
123
- const selectModel = ref <string >(' dall-e-3' ) // 模型
124
- // message
125
- const message = useMessage ()
126
- const models = ref <ImageModelVO []>([
127
- {
128
- key: ' dall-e-3' ,
129
- name: ' DALL·E 3' ,
130
- image: ` /src/assets/ai/dall2.jpg ` ,
131
- },
132
- {
133
- key: ' dall-e-2' ,
134
- name: ' DALL·E 2' ,
135
- image: ` /src/assets/ai/dall3.jpg ` ,
136
- },
137
- ]) // 模型
118
+ const model = ref <string >(' dall-e-3' ) // 模型
119
+ const size = ref <string >(' 1024x1024' ) // 选中 size
138
120
139
121
const selectImageStyle = ref <string >(' vivid' ) // style 样式
140
122
141
123
const imageStyleList = ref <ImageModelVO []>([
142
124
{
143
125
key: ' vivid' ,
144
126
name: ' 清晰' ,
145
- image: ` /src/assets/ai/qingxi.jpg ` ,
127
+ image: ` /src/assets/ai/qingxi.jpg `
146
128
},
147
129
{
148
130
key: ' natural' ,
149
131
name: ' 自然' ,
150
- image: ` /src/assets/ai/ziran.jpg ` ,
151
- },
152
- ]) // style
132
+ image: ` /src/assets/ai/ziran.jpg `
133
+ }
134
+ ]) // style
153
135
154
- const selectImageSize = ref <string >(' 1024x1024' ) // 选中 size
155
136
const imageSizeList = ref <ImageSizeVO []>([
156
137
{
157
138
key: ' 1024x1024' ,
158
139
name: ' 1:1' ,
159
140
width: ' 1024' ,
160
141
height: ' 1024' ,
161
- style: ' width: 30px; height: 30px;background-color: #dcdcdc;' ,
142
+ style: ' width: 30px; height: 30px;background-color: #dcdcdc;'
162
143
},
163
144
{
164
145
key: ' 1024x1792' ,
165
146
name: ' 3:5' ,
166
147
width: ' 1024' ,
167
148
height: ' 1792' ,
168
- style: ' width: 30px; height: 50px;background-color: #dcdcdc;' ,
149
+ style: ' width: 30px; height: 50px;background-color: #dcdcdc;'
169
150
},
170
151
{
171
152
key: ' 1792x1024' ,
172
153
name: ' 5:3' ,
173
154
width: ' 1792' ,
174
155
height: ' 1024' ,
175
- style: ' width: 50px; height: 30px;background-color: #dcdcdc;' ,
156
+ style: ' width: 50px; height: 30px;background-color: #dcdcdc;'
176
157
}
177
158
]) // size
178
159
@@ -196,7 +177,7 @@ const handleHotWordClick = async (hotWord: string) => {
196
177
197
178
/** 模型 - click */
198
179
const handleModelClick = async (model : ImageModelVO ) => {
199
- selectModel .value = model .key
180
+ model .value = model .key
200
181
}
201
182
202
183
/** 样式 - click */
@@ -206,7 +187,7 @@ const handleStyleClick = async (imageStyle: ImageModelVO) => {
206
187
207
188
/** size - click */
208
189
const handleSizeClick = async (imageSize : ImageSizeVO ) => {
209
- selectImageSize .value = imageSize .key
190
+ size .value = imageSize .key
210
191
}
211
192
212
193
/** 图片生产 */
@@ -217,23 +198,23 @@ const handleGenerateImage = async () => {
217
198
// 加载中
218
199
drawIn .value = true
219
200
// 回调
220
- emits (' onDrawStart' , selectModel .value )
221
- const imageSize = imageSizeList .value .find (item => item .key === selectImageSize .value ) as ImageSizeVO
201
+ emits (' onDrawStart' , model .value )
202
+ const imageSize = imageSizeList .value .find (( item ) => item .key === size .value ) as ImageSizeVO
222
203
const form = {
223
204
platform: ' OpenAI' ,
224
205
prompt: prompt .value , // 提示词
225
- model: selectModel .value , // 模型
206
+ model: model .value , // 模型
226
207
width: imageSize .width , // size 不能为空
227
208
height: imageSize .height , // size 不能为空
228
209
options: {
229
- style: selectImageStyle .value , // 图像生成的风格
210
+ style: selectImageStyle .value // 图像生成的风格
230
211
}
231
212
} as ImageDrawReqVO
232
213
// 发送请求
233
214
await ImageApi .drawImage (form )
234
215
} finally {
235
216
// 回调
236
- emits (' onDrawComplete' , selectModel .value )
217
+ emits (' onDrawComplete' , model .value )
237
218
// 加载结束
238
219
drawIn .value = false
239
220
}
@@ -242,17 +223,18 @@ const handleGenerateImage = async () => {
242
223
/** 填充值 */
243
224
const settingValues = async (imageDetail : ImageVO ) => {
244
225
prompt .value = imageDetail .prompt
245
- selectModel .value = imageDetail .model
226
+ model .value = imageDetail .model
246
227
//
247
228
selectImageStyle .value = imageDetail .options ?.style
248
229
//
249
- const imageSize = imageSizeList .value .find (item => item .key === ` ${imageDetail .width }x${imageDetail .height } ` ) as ImageSizeVO
230
+ const imageSize = imageSizeList .value .find (
231
+ (item ) => item .key === ` ${imageDetail .width }x${imageDetail .height } `
232
+ ) as ImageSizeVO
250
233
await handleSizeClick (imageSize )
251
234
}
252
235
253
236
/** 暴露组件方法 */
254
237
defineExpose ({ settingValues })
255
-
256
238
</script >
257
239
<style scoped lang="scss">
258
240
// 提示词
@@ -309,7 +291,6 @@ defineExpose({ settingValues })
309
291
}
310
292
}
311
293
312
-
313
294
// 样式 style
314
295
.image-style {
315
296
margin-top : 30px ;
0 commit comments