【增加】openai 重新生成

pull/470/MERGE
cherishsince 2024-07-04 15:01:19 +08:00
parent 39facc2f49
commit bb34c2b75c
1 changed files with 23 additions and 30 deletions

View File

@ -37,7 +37,7 @@
</div>
<el-space wrap class="model-list">
<div
:class="selectModel === model ? 'modal-item selectModel' : 'modal-item'"
:class="selectModel === model.key ? 'modal-item selectModel' : 'modal-item'"
v-for="model in models"
:key="model.key"
@ -57,7 +57,7 @@
</div>
<el-space wrap class="image-style-list">
<div
:class="selectImageStyle === imageStyle ? 'image-style-item selectImageStyle' : 'image-style-item'"
:class="selectImageStyle === imageStyle.key ? 'image-style-item selectImageStyle' : 'image-style-item'"
v-for="imageStyle in imageStyleList"
:key="imageStyle.key"
>
@ -79,7 +79,7 @@
v-for="imageSize in imageSizeList"
:key="imageSize.key"
@click="handlerSizeClick(imageSize)">
<div :class="selectImageSize === imageSize ? 'size-wrapper selectImageSize' : 'size-wrapper'">
<div :class="selectImageSize === imageSize.key ? 'size-wrapper selectImageSize' : 'size-wrapper'">
<div :style="imageSize.style"></div>
</div>
<div class="size-font">{{ imageSize.name }}</div>
@ -120,7 +120,7 @@ const prompt = ref<string>('') // 提示词
const drawIn = ref<boolean>(false) //
const selectHotWord = ref<string>('') //
const hotWords = ref<string[]>(['中国旗袍', '古装美女', '卡通头像', '机甲战士', '童话小屋', '中国长城']) //
const selectModel = ref<any>({}) //
const selectModel = ref<string>('dall-e-3') //
// message
const message = useMessage()
// TODO @fanimage
@ -137,9 +137,8 @@ const models = ref<ImageModelVO[]>([
image: 'https://h5.cxyhub.com/images/model_1.png',
},
]) //
selectModel.value = models.value[0]
const selectImageStyle = ref<any>({}) // style
const selectImageStyle = ref<string>('vivid') // style
// TODO @fanimage
const imageStyleList = ref<ImageModelVO[]>([
{
@ -153,9 +152,8 @@ const imageStyleList = ref<ImageModelVO[]>([
image: 'https://h5.cxyhub.com/images/model_2.png',
},
]) // style
selectImageStyle.value = imageStyleList.value[0]
const selectImageSize = ref<ImageSizeVO>({} as ImageSizeVO) // size
const selectImageSize = ref<string>('1024x1024') // size
const imageSizeList = ref<ImageSizeVO[]>([
{
key: '1024x1024',
@ -179,7 +177,6 @@ const imageSizeList = ref<ImageSizeVO[]>([
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)
}
/** 暴露组件方法 */