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

View File

@ -13,6 +13,7 @@
<!-- </div>--> <!-- </div>-->
<!-- </div>--> <!-- </div>-->
<div class="body"> <div class="body">
<!-- TODO @fan: 要不这里只展示图片不用 ImageTaskCard -->
<ImageTaskCard :image-detail="imageDetail" /> <ImageTaskCard :image-detail="imageDetail" />
</div> </div>
</div> </div>
@ -21,6 +22,7 @@
<div class="tip">时间</div> <div class="tip">时间</div>
<div class="body"> <div class="body">
<div>提交时间{{imageDetail.createTime}}</div> <div>提交时间{{imageDetail.createTime}}</div>
<!-- TODO @fan要不加个完成时间的字段 finishTimeupdateTime 不算特别合理哈 -->
<div>生成时间{{imageDetail.updateTime}}</div> <div>生成时间{{imageDetail.updateTime}}</div>
</div> </div>
</div> </div>
@ -38,34 +40,35 @@
{{imageDetail.prompt}} {{imageDetail.prompt}}
</div> </div>
</div> </div>
<!-- 风格 -->
<div class="item">
<div class="tip">风格</div>
<div class="body">
{{imageDetail.style}}
</div>
</div>
<!-- 地址 --> <!-- 地址 -->
<div class="item"> <div class="item">
<div class="tip">地址</div> <div class="tip">图片地址</div>
<div class="body"> <div class="body">
{{imageDetail.picUrl}} {{imageDetail.picUrl}}
</div> </div>
</div> </div>
<!-- 生成地址 --> <!-- 生成地址 TODO @fan这个字段我删除了要不干掉 -->
<div class="item"> <div class="item">
<div class="tip">生成地址</div> <div class="tip">生成地址</div>
<div class="body"> <div class="body">
{{imageDetail.originalPicUrl}} {{imageDetail.originalPicUrl}}
</div> </div>
</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> </el-drawer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ImageApi, ImageDetailVO} from '@/api/ai/image'; import {ImageApi, ImageDetailVO} from '@/api/ai/image';
import ImageTaskCard from './ImageTaskCard.vue'; import ImageTaskCard from './ImageTaskCard.vue';
import {Delete, Download, More} from "@element-plus/icons-vue";
const showDrawer = ref<boolean>(false) // const showDrawer = ref<boolean>(false) //
const imageDetail = ref<ImageDetailVO>({} as ImageDetailVO) // const imageDetail = ref<ImageDetailVO>({} as ImageDetailVO) //

View File

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

View File

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

View File

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

View File

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