【代码评审】AI:绘制功能的测试和 review

This commit is contained in:
YunaiV 2024-06-01 16:49:42 +08:00
parent 1eacbe62d6
commit 3c4327e4dd
6 changed files with 67 additions and 45 deletions

View File

@ -1,10 +1,11 @@
import request from '@/config/axios'
// AI API 密钥 VO
// TODO @fan要不前端不弄太多 VO就用这个 ImageDetailVO
export interface ImageDetailVO {
id: number // 编号
prompt: string // 提示词
status: string // 状态
status: number // 状态
errorMessage: string // 错误信息
type: string // 模型下分不同的类型(清晰、真实...)
taskId: number // dr 任务id
@ -31,11 +32,14 @@ export interface ImageDallReqVO {
height: string // 图片高度
}
export interface ImageDallReqVO {
export interface ImageDrawReqVO {
platform: string // 平台
prompt: string // 提示词
model: string // 模型
style: string // 图像生成的风格
size: string // size不能为空
width: string // 图片宽度
height: string // 图片高度
options: object // 绘制参数Map<String, String>
}
export interface ImageMidjourneyImagineReqVO {
@ -57,9 +61,9 @@ export const ImageApi = {
getImageDetail: async (id: number) => {
return await request.get({ url: `/ai/image/get-my?id=${id}`})
},
// dall2、dall3 调用
dall: async (data: ImageDallReqVO)=> {
return await request.post({ url: `/ai/image/dall`, data })
// 生成图片
drawImage: async (data: ImageDrawReqVO)=> {
return await request.post({ url: `/ai/image/draw`, data })
},
// midjourney - imagine
midjourneyImagine: async (data: ImageMidjourneyImagineReqVO)=> {

View File

@ -5,7 +5,7 @@
@close="handlerDrawerClose"
custom-class="drawer-class"
>
<!-- 图片 -->
<!-- 图片 -->
<div class="item">
<!-- <div class="header">-->
<!-- <div>图片</div>-->
@ -13,6 +13,7 @@
<!-- </div>-->
<!-- </div>-->
<div class="body">
<!-- TODO @fan: 要不这里只展示图片不用 ImageTaskCard -->
<ImageTaskCard :image-detail="imageDetail" />
</div>
</div>
@ -21,6 +22,7 @@
<div class="tip">时间</div>
<div class="body">
<div>提交时间{{imageDetail.createTime}}</div>
<!-- TODO @fan要不加个完成时间的字段 finishTimeupdateTime 不算特别合理哈 -->
<div>生成时间{{imageDetail.updateTime}}</div>
</div>
</div>
@ -38,34 +40,35 @@
{{imageDetail.prompt}}
</div>
</div>
<!-- 风格 -->
<div class="item">
<div class="tip">风格</div>
<div class="body">
{{imageDetail.style}}
</div>
</div>
<!-- 地址 -->
<div class="item">
<div class="tip">地址</div>
<div class="tip">图片地址</div>
<div class="body">
{{imageDetail.picUrl}}
</div>
</div>
<!-- 生成地址 -->
<!-- 生成地址 TODO @fan这个字段我删除了要不干掉 -->
<div class="item">
<div class="tip">生成地址</div>
<div class="body">
{{imageDetail.originalPicUrl}}
</div>
</div>
<!-- 风格 -->
<div class="item">
<div class="tip">风格</div>
<div class="body">
<!-- TODO @fan貌似需要把 imageStyleList 搞到 api/image/index.ts 枚举起来 -->
<!-- TODO @fan这里的展示可能需要按照平台做区分 -->
{{imageDetail.options.style}}
</div>
</div>
</el-drawer>
</template>
<script setup lang="ts">
import {ImageApi, ImageDetailVO} from '@/api/ai/image';
import ImageTaskCard from './ImageTaskCard.vue';
import {Delete, Download, More} from "@element-plus/icons-vue";
const showDrawer = ref<boolean>(false) //
const imageDetail = ref<ImageDetailVO>({} as ImageDetailVO) //

View File

@ -1,4 +1,3 @@
<template>
<el-card class="dr-task" body-class="task-card" shadow="never">
<template #header>绘画任务</template>
@ -19,15 +18,16 @@
import {ImageApi, ImageDetailVO} from '@/api/ai/image';
import ImageDetailDrawer from './ImageDetailDrawer.vue'
import ImageTaskCard from './ImageTaskCard.vue'
import {bool} from "vue-types";
const message = useMessage() //
const imageList = ref<ImageDetailVO[]>([]) // image
const imageListInterval = ref<any>() // image
const isShowImageDetail = ref<bool>(false) // task
const isShowImageDetail = ref<boolean>(false) // task
const showImageDetailId = ref<number>(0) // task
// TODO @fan /** */~
/**
* 抽屉 - close
*/
@ -72,6 +72,7 @@ const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => {
/**
* 下载 - image
*/
// TODO @fan download
const downloadImage = async (imageUrl) => {
const image = new Image()
image.setAttribute('crossOrigin', 'anonymous')

View File

@ -2,10 +2,11 @@
<el-card body-class="" class="image-card">
<div class="image-operation">
<div>
<el-button type="" text bg v-if="imageDetail.status === '10'">生成中</el-button>
<el-button type="" text bg v-else-if="imageDetail.status === '20'">已完成</el-button>
<el-button type="danger" text bg v-else-if="imageDetail.status === '30'">异常</el-button>
<el-button type="primary" text bg v-if="imageDetail?.status === 10">生成中</el-button>
<el-button text bg v-else-if="imageDetail?.status === 20">已完成</el-button>
<el-button type="danger" text bg v-else-if="imageDetail?.status === 30">异常</el-button>
</div>
<!-- TODO @fan1按钮要不调整成详情下载再次生成删除2如果是再次生成就把当前的参数填写到左侧的框框里 -->
<div>
<el-button class="btn" text :icon="Download"
@click="handlerBtnClick('download', imageDetail)"/>
@ -14,8 +15,9 @@
</div>
</div>
<div class="image-wrapper" ref="cardImageRef">
<!-- TODO @fan要不加个点击大图预览 -->
<img class="image" :src="imageDetail?.picUrl"/>
<div v-if="imageDetail.status === '30'">{{imageDetail.errorMessage}}</div>
<div v-if="imageDetail?.status === 30">{{imageDetail?.errorMessage}}</div>
</div>
</el-card>
</template>
@ -42,8 +44,9 @@ const handlerBtnClick = async (type, imageDetail: ImageDetailVO) => {
emits('onBtnClick', type, imageDetail)
}
const handlerLoading = async (status: string) => {
if (status === '10') {
const handlerLoading = async (status: number) => {
// TODO @fan Loading
if (status === 10) {
cardImageLoadingInstance.value = ElLoading.service({
target: cardImageRef.value,
text: '生成中...'

View File

@ -2,7 +2,8 @@
<template>
<div class="prompt">
<el-text tag="b">画面描述</el-text>
<el-text tag="p">建议使用形容词+动词+风格的格式使用隔开.</el-text>
<el-text tag="p">建议使用形容词+动词+风格的格式使用隔开</el-text>
<!-- TODO @fanstyle 看看能不能哟 unocss 替代 -->
<el-input
v-model="prompt"
maxlength="1024"
@ -32,7 +33,7 @@
</div>
<div class="model">
<div>
<el-text tag="b">模型</el-text>
<el-text tag="b">模型选择</el-text>
</div>
<el-space wrap class="model-list">
<div
@ -52,14 +53,13 @@
</div>
<div class="image-style">
<div>
<el-text tag="b">样式</el-text>
<el-text tag="b">风格选择</el-text>
</div>
<el-space wrap class="image-style-list">
<div
:class="selectImageStyle === imageStyle ? 'image-style-item selectImageStyle' : 'image-style-item'"
v-for="imageStyle in imageStyleList"
:key="imageStyle"
:key="imageStyle.key"
>
<el-image
:src="imageStyle.image"
@ -72,7 +72,7 @@
</div>
<div class="image-size">
<div>
<el-text tag="b">尺寸</el-text>
<el-text tag="b">画面比例</el-text>
</div>
<el-space wrap class="size-list">
<div class="size-item"
@ -97,7 +97,7 @@
</div>
</template>
<script setup lang="ts">
import {ImageApi, ImageDallReqVO} from '@/api/ai/image';
import {ImageApi, ImageDrawReqVO} from '@/api/ai/image';
// image
interface ImageModelVO {
@ -109,6 +109,7 @@ interface ImageModelVO {
// image
interface ImageSizeVO {
key: string
name: string,
style: string,
width: string,
height: string,
@ -120,21 +121,24 @@ const drawIn = ref<boolean>(false) // 生成中
const selectHotWord = ref<string>('') //
const hotWords = ref<string[]>(['中国旗袍', '古装美女', '卡通头像', '机甲战士', '童话小屋', '中国长城']) //
const selectModel = ref<any>({}) //
// TODO @fanimage
// TODO @fan image
const models = ref<ImageModelVO[]>([
{
key: 'dall-e-2',
name: 'dall2',
image: 'https://h5.cxyhub.com/images/model_1.png',
key: 'dall-e-3',
name: 'DALL·E 3',
image: 'https://h5.cxyhub.com/images/model_2.png',
},
{
key: 'dall-e-3',
name: 'dall3',
image: 'https://h5.cxyhub.com/images/model_2.png',
key: 'dall-e-2',
name: 'DALL·E 2',
image: 'https://h5.cxyhub.com/images/model_1.png',
},
]) //
selectModel.value = models.value[0]
const selectImageStyle = ref<any>({}) // style
// TODO @fanimage
const imageStyleList = ref<ImageModelVO[]>([
{
key: 'vivid',
@ -180,11 +184,13 @@ const props = defineProps({})
// emits
const emits = defineEmits(['onDrawStart', 'onDrawComplete'])
// TODO @fan /** */~
// TODO @fanhandler handle
/**
* 热词 - click
*/
const handlerHotWordClick = async (hotWord: string) => {
//
//
if (selectHotWord.value == hotWord) {
selectHotWord.value = ''
return
@ -238,14 +244,17 @@ const handlerGenerateImage = async () => {
//
emits('onDrawStart', selectModel.value.key)
const form = {
platform: 'OpenAI',
prompt: prompt.value, //
model: selectModel.value.key, //
style: selectImageStyle.value.key, //
width: selectImageSize.value.width, // size
height: selectImageSize.value.height, // size
} as ImageDallReqVO
width: selectImageSize.value.width, // size
height: selectImageSize.value.height, // size
options: {
style: selectImageStyle.value.key, //
}
} as ImageDrawReqVO
//
await ImageApi.dall(form)
await ImageApi.drawImage(form)
} finally {
//
emits('onDrawComplete', selectModel.value.key)

View File

@ -6,6 +6,7 @@
<el-segmented v-model="selectModel" :options="modelOptions" />
</div>
<div class="modal-switch-container">
<!-- TODO @fan1建议 Dall3 改成 OpenAI 绘图因为 dall3 其实本质是模型2涉及到中英文的地方中文和英文之间有个空格哈 -->
<Dall3 v-if="selectModel === 'DALL3绘画'"
@on-draw-start="handlerDrawStart"
@on-draw-complete="handlerDrawComplete" />
@ -19,6 +20,7 @@
</template>
<script setup lang="ts">
// TODO @fan /views/ai/image/index /views/ai/image/manager
import Dall3 from './dall3/index.vue'
import Midjourney from './midjourney/index.vue'
import ImageTask from './ImageTask.vue'