Skip to content

Commit 80d87b8

Browse files
committed
【代码优化】AI:绘图 index.vue 代码梳理 20%
1 parent 6224602 commit 80d87b8

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

src/views/ai/image/index/ImageDetailDrawer.vue renamed to src/views/ai/image/index/components/ImageDetail.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<!-- </div>-->
1414
<!-- </div>-->
1515
<div class="body">
16-
<!-- TODO @fan: 要不,这里只展示图片???不用 ImageTaskCard -->
17-
<ImageTaskCard :image-detail="imageDetail" />
16+
<!-- TODO @fan: 要不,这里只展示图片???不用 ImageCard -->
17+
<ImageCard :image-detail="imageDetail" />
1818
</div>
1919
</div>
2020
<!-- 时间 -->
@@ -60,7 +60,7 @@
6060

6161
<script setup lang="ts">
6262
import { ImageApi, ImageVO } from '@/api/ai/image'
63-
import ImageTaskCard from './ImageTaskCard.vue'
63+
import ImageCard from './ImageCard.vue'
6464
6565
const showDrawer = ref<boolean>(false) // 是否显示
6666
const imageDetail = ref<ImageVO>({} as ImageVO) // 图片详细信息

src/views/ai/image/index/ImageTask.vue renamed to src/views/ai/image/index/components/ImageList.vue

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<template>
22
<el-card class="dr-task" body-class="task-card" shadow="never">
33
<template #header>绘画任务</template>
4+
<!-- 图片列表 -->
45
<div class="task-image-list" ref="imageTaskRef">
5-
<ImageTaskCard
6+
<ImageCard
67
v-for="image in imageList"
7-
:key="image"
8+
:key="image.id"
89
:image-detail="image"
910
@on-btn-click="handleImageBtnClick"
1011
@on-mj-btn-click="handleImageMjBtnClick"
@@ -20,17 +21,18 @@
2021
/>
2122
</div>
2223
</el-card>
23-
<!-- 图片 detail 抽屉 -->
24-
<ImageDetailDrawer
24+
25+
<!-- 图片详情 -->
26+
<ImageDetail
2527
:show="isShowImageDetail"
2628
:id="showImageDetailId"
2729
@handle-drawer-close="handleDrawerClose"
2830
/>
2931
</template>
3032
<script setup lang="ts">
3133
import { ImageApi, ImageVO, ImageMjActionVO, ImageMjButtonsVO } from '@/api/ai/image'
32-
import ImageDetailDrawer from './ImageDetailDrawer.vue'
33-
import ImageTaskCard from './ImageTaskCard.vue'
34+
import ImageDetail from './ImageDetail.vue'
35+
import ImageCard from './ImageCard.vue'
3436
import { ElLoading, LoadingOptionsResolved } from 'element-plus'
3537
import { AiImageStatusEnum } from '@/views/ai/utils/constants'
3638
import { downloadImage } from '@/utils/download'
@@ -181,6 +183,7 @@ onUnmounted(async () => {
181183
})
182184
</script>
183185

186+
<!-- TODO fan:这 2 个 scss 可以合并么? -->
184187
<style lang="scss">
185188
.task-card {
186189
margin: 0;
@@ -197,8 +200,7 @@ onUnmounted(async () => {
197200
align-content: flex-start;
198201
height: 100%;
199202
overflow: auto;
200-
padding: 20px;
201-
padding-bottom: 140px;
203+
padding: 20px 20px 140px;
202204
box-sizing: border-box; /* 确保内边距不会增加高度 */
203205
204206
> div {
@@ -224,7 +226,6 @@ onUnmounted(async () => {
224226
align-items: center;
225227
}
226228
</style>
227-
228229
<style scoped lang="scss">
229230
.dr-task {
230231
width: 100%;

src/views/ai/image/index/index.vue

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
@on-draw-start="handleDrawStart"
1313
@on-draw-complete="handleDrawComplete"
1414
/>
15-
<Midjourney
16-
v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY"
17-
ref="midjourneyRef"
18-
/>
15+
<Midjourney v-if="selectPlatform === AiPlatformEnum.MIDJOURNEY" ref="midjourneyRef" />
1916
<StableDiffusion
2017
v-if="selectPlatform === AiPlatformEnum.STABLE_DIFFUSION"
2118
ref="stableDiffusionRef"
@@ -24,22 +21,20 @@
2421
</div>
2522
</div>
2623
<div class="main">
27-
<ImageTask ref="imageTaskRef" @on-regeneration="handleRegeneration" />
24+
<ImageList ref="imageListRef" @on-regeneration="handleRegeneration" />
2825
</div>
2926
</div>
3027
</template>
3128

3229
<script setup lang="ts">
33-
// TODO @fan:在整个挪到 /views/ai/image/index 目录。因为我想在 /views/ai/image/manager 做管理的功能,进行下区分!
3430
import Dall3 from './dall3/index.vue'
3531
import Midjourney from './midjourney/index.vue'
3632
import StableDiffusion from './stable-diffusion/index.vue'
37-
import ImageTask from './ImageTask.vue'
33+
import ImageList from './components/ImageList.vue'
3834
import { AiPlatformEnum } from '@/views/ai/utils/constants'
39-
import {ImageVO} from "@/api/ai/image";
40-
35+
import { ImageVO } from '@/api/ai/image'
4136
42-
const imageTaskRef = ref<any>() // image task ref
37+
const imageListRef = ref<any>() // image 列表 ref
4338
const dall3Ref = ref<any>() // openai ref
4439
const midjourneyRef = ref<any>() // midjourney ref
4540
const stableDiffusionRef = ref<any>() // stable diffusion ref
@@ -61,35 +56,27 @@ const platformOptions = [
6156
}
6257
]
6358
64-
/** 绘画 - start */
65-
const handleDrawStart = async (type) => {
66-
}
59+
/** 绘画 start */
60+
const handleDrawStart = async (type) => {}
6761
68-
/** 绘画 - complete */
62+
/** 绘画 complete */
6963
const handleDrawComplete = async (type) => {
70-
await imageTaskRef.value.getImageList()
64+
await imageListRef.value.getImageList()
7165
}
7266
73-
/** 绘画 - 重新生成 */
74-
const handleRegeneration = async (imageDetail: ImageVO) => {
67+
/** 重新生成:将画图详情填充到对应平台 */
68+
const handleRegeneration = async (image: ImageVO) => {
7569
// 切换平台
76-
selectPlatform.value = imageDetail.platform
77-
console.log('切换平台', imageDetail.platform)
78-
// 根据不同平台填充 imageDetail
79-
if (imageDetail.platform === AiPlatformEnum.MIDJOURNEY) {
80-
await nextTick(async () => {
81-
midjourneyRef.value.settingValues(imageDetail)
82-
})
83-
} else if (imageDetail.platform === AiPlatformEnum.OPENAI) {
84-
await nextTick(async () => {
85-
dall3Ref.value.settingValues(imageDetail)
86-
})
87-
} else if (imageDetail.platform === AiPlatformEnum.STABLE_DIFFUSION) {
88-
await nextTick(async () => {
89-
stableDiffusionRef.value.settingValues(imageDetail)
90-
})
70+
selectPlatform.value = image.platform
71+
// 根据不同平台填充 image
72+
await nextTick()
73+
if (image.platform === AiPlatformEnum.MIDJOURNEY) {
74+
midjourneyRef.value.settingValues(image)
75+
} else if (image.platform === AiPlatformEnum.OPENAI) {
76+
dall3Ref.value.settingValues(image)
77+
} else if (image.platform === AiPlatformEnum.STABLE_DIFFUSION) {
78+
stableDiffusionRef.value.settingValues(image)
9179
}
92-
9380
}
9481
</script>
9582

0 commit comments

Comments
 (0)