From bb34c2b75c490988c5a3fe56aa0d0ae6d11f6bdf Mon Sep 17 00:00:00 2001 From: cherishsince Date: Thu, 4 Jul 2024 15:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91openai=20?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ai/image/dall3/index.vue | 53 +++++++++++++----------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/views/ai/image/dall3/index.vue b/src/views/ai/image/dall3/index.vue index 988a2b9d..69e767a3 100644 --- a/src/views/ai/image/dall3/index.vue +++ b/src/views/ai/image/dall3/index.vue @@ -37,7 +37,7 @@
@@ -79,7 +79,7 @@ v-for="imageSize in imageSizeList" :key="imageSize.key" @click="handlerSizeClick(imageSize)"> -
+
{{ imageSize.name }}
@@ -120,7 +120,7 @@ const prompt = ref('') // 提示词 const drawIn = ref(false) // 生成中 const selectHotWord = ref('') // 选中的热词 const hotWords = ref(['中国旗袍', '古装美女', '卡通头像', '机甲战士', '童话小屋', '中国长城']) // 热词 -const selectModel = ref({}) // 模型 +const selectModel = ref('dall-e-3') // 模型 // message const message = useMessage() // TODO @fan:image 改成项目里自己的哈 @@ -137,9 +137,8 @@ const models = ref([ image: 'https://h5.cxyhub.com/images/model_1.png', }, ]) // 模型 -selectModel.value = models.value[0] -const selectImageStyle = ref({}) // style 样式 +const selectImageStyle = ref('vivid') // style 样式 // TODO @fan:image 改成项目里自己的哈 const imageStyleList = ref([ { @@ -153,9 +152,8 @@ const imageStyleList = ref([ image: 'https://h5.cxyhub.com/images/model_2.png', }, ]) // style -selectImageStyle.value = imageStyleList.value[0] -const selectImageSize = ref({} as ImageSizeVO) // 选中 size +const selectImageSize = ref('1024x1024') // 选中 size const imageSizeList = ref([ { key: '1024x1024', @@ -179,7 +177,6 @@ const imageSizeList = ref([ style: 'width: 50px; height: 30px;background-color: #dcdcdc;', } ]) // size -selectImageSize.value = imageSizeList.value[0] // 定义 Props const props = defineProps({}) @@ -203,29 +200,17 @@ const handlerHotWordClick = async (hotWord: string) => { /** 模型 - click */ const handlerModelClick = async (model: ImageModelVO) => { - if (selectModel.value === model) { - selectModel.value = {} as ImageModelVO - return - } - selectModel.value = model + selectModel.value = model.key } /** 样式 - click */ const handlerStyleClick = async (imageStyle: ImageModelVO) => { - if (selectImageStyle.value === imageStyle) { - selectImageStyle.value = {} as ImageModelVO - return - } - selectImageStyle.value = imageStyle + selectImageStyle.value = imageStyle.key } /** size - click */ const handlerSizeClick = async (imageSize: ImageSizeVO) => { - if (selectImageSize.value === imageSize) { - selectImageSize.value = {} as ImageSizeVO - return - } - selectImageSize.value = imageSize + selectImageSize.value = imageSize.key } /** 图片生产 */ @@ -236,22 +221,23 @@ const handlerGenerateImage = async () => { // 加载中 drawIn.value = true // 回调 - emits('onDrawStart', selectModel.value.key) + emits('onDrawStart', selectModel.value) + const imageSize = imageSizeList.value.find(item => item.key === selectImageSize.value) as ImageSizeVO const form = { platform: 'OpenAI', prompt: prompt.value, // 提示词 - model: selectModel.value.key, // 模型 - width: selectImageSize.value.width, // size 不能为空 - height: selectImageSize.value.height, // size 不能为空 + model: selectModel.value, // 模型 + width: imageSize.width, // size 不能为空 + height: imageSize.height, // size 不能为空 options: { - style: selectImageStyle.value.key, // 图像生成的风格 + style: selectImageStyle.value, // 图像生成的风格 } } as ImageDrawReqVO // 发送请求 await ImageApi.drawImage(form) } finally { // 回调 - emits('onDrawComplete', selectModel.value.key) + emits('onDrawComplete', selectModel.value) // 加载结束 drawIn.value = false } @@ -260,6 +246,13 @@ const handlerGenerateImage = async () => { /** 填充值 */ const settingValues = async (imageDetail: ImageVO) => { prompt.value = imageDetail.prompt + selectModel.value = imageDetail.model + // + selectImageStyle.value = imageDetail.options?.style + // + const imageSize = imageSizeList.value.find(item => item.key === `${imageDetail.width}x${imageDetail.height}`) as ImageSizeVO + console.log('imageSize', imageSize) + await handlerSizeClick(imageSize) } /** 暴露组件方法 */