130 lines
3.1 KiB
Vue
Raw Normal View History

2024-05-25 15:36:21 +08:00
<!-- image -->
<template>
<div class="ai-image">
<div class="left">
<div class="segmented">
2024-07-03 13:52:00 +08:00
<el-segmented v-model="selectPlatform" :options="platformOptions" />
2024-05-25 15:36:21 +08:00
</div>
<div class="modal-switch-container">
2024-07-03 13:52:00 +08:00
<Dall3
v-if="selectPlatform === AiPlatformEnum.OPENAI"
ref="dall3Ref"
2024-07-04 16:01:08 +08:00
@on-draw-start="handleDrawStart"
@on-draw-complete="handleDrawComplete"
2024-07-03 13:52:00 +08:00
/>
<Midjourney v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY" ref="midjourneyRef" />
2024-07-03 13:52:00 +08:00
<StableDiffusion
v-if="selectPlatform === AiPlatformEnum.STABLE_DIFFUSION"
ref="stableDiffusionRef"
2024-07-04 16:01:08 +08:00
@on-draw-complete="handleDrawComplete"
2024-07-03 13:52:00 +08:00
/>
2024-05-25 15:36:21 +08:00
</div>
</div>
<div class="main">
<ImageList ref="imageListRef" @on-regeneration="handleRegeneration" />
2024-05-25 15:36:21 +08:00
</div>
</div>
</template>
2024-05-25 15:36:21 +08:00
<script setup lang="ts">
import ImageList from './components/ImageList.vue'
2024-07-03 13:52:00 +08:00
import { AiPlatformEnum } from '@/views/ai/utils/constants'
import { ImageVO } from '@/api/ai/image'
import Dall3 from './dall3/index.vue'
import Midjourney from './midjourney/index.vue'
import StableDiffusion from './components/stableDiffusion/index.vue'
2024-05-25 15:36:21 +08:00
const imageListRef = ref<any>() // image 列表 ref
const dall3Ref = ref<any>() // openai ref
const midjourneyRef = ref<any>() // midjourney ref
const stableDiffusionRef = ref<any>() // stable diffusion ref
// 定义属性
2024-07-03 13:52:00 +08:00
const selectPlatform = ref('StableDiffusion')
const platformOptions = [
{
label: 'DALL3 绘画',
value: AiPlatformEnum.OPENAI
},
{
label: 'MJ 绘画',
value: AiPlatformEnum.MIDJOURNEY
},
{
label: 'Stable Diffusion',
value: AiPlatformEnum.STABLE_DIFFUSION
}
]
2024-05-25 15:36:21 +08:00
/** 绘画 start */
const handleDrawStart = async (type) => {}
/** 绘画 complete */
2024-07-04 16:01:08 +08:00
const handleDrawComplete = async (type) => {
await imageListRef.value.getImageList()
}
/** 重新生成:将画图详情填充到对应平台 */
const handleRegeneration = async (image: ImageVO) => {
// 切换平台
selectPlatform.value = image.platform
// 根据不同平台填充 image
await nextTick()
if (image.platform === AiPlatformEnum.MIDJOURNEY) {
midjourneyRef.value.settingValues(image)
} else if (image.platform === AiPlatformEnum.OPENAI) {
dall3Ref.value.settingValues(image)
} else if (image.platform === AiPlatformEnum.STABLE_DIFFUSION) {
stableDiffusionRef.value.settingValues(image)
}
}
2024-05-25 15:36:21 +08:00
</script>
2024-05-25 15:36:21 +08:00
<style scoped lang="scss">
.ai-image {
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
display: flex;
flex-direction: row;
height: 100%;
width: 100%;
.left {
display: flex;
flex-direction: column;
padding: 20px;
width: 350px;
.segmented {
}
2024-05-25 15:36:21 +08:00
.segmented .el-segmented {
--el-border-radius-base: 16px;
--el-segmented-item-selected-color: #fff;
background-color: #ececec;
width: 350px;
}
.modal-switch-container {
height: 100%;
overflow-y: auto;
margin-top: 30px;
2024-05-25 15:36:21 +08:00
}
}
.main {
flex: 1;
background-color: #fff;
}
.right {
width: 350px;
background-color: #f7f8fa;
}
}
</style>