【代码调整】AI:MJ 二次 Action 的接口修改

pull/466/head
YunaiV 2024-06-26 12:38:21 +08:00
parent 7fe8b8b7a9
commit 36dc3c0b5c
5 changed files with 47 additions and 63 deletions

View File

@ -1,51 +1,28 @@
import request from '@/config/axios' import request from '@/config/axios'
// AI API 密钥 VO // AI API 密钥 VO
// TODO @fan要不前端不弄太多 VO就用这个 ImageDetailVO export interface ImageRespVO {
export interface ImageDetailVO {
id: number // 编号 id: number // 编号
prompt: string // 提示词
status: number // 状态
errorMessage: string // 错误信息
type: string // 模型下分不同的类型(清晰、真实...)
taskId: number // dr 任务id
picUrl: string // 任务地址
originalPicUrl: string // 绘制图片地址
platform: string // 平台 platform: string // 平台
model: string // 模型 model: string // 模型
style: string // 图像生成的风格 prompt: string // 提示词
size: string // 图片尺寸 width: number // 图片宽度
height: number // 图片高度
status: number // 状态
publicStatus: string // 公开状态
picUrl: string // 任务地址
errorMessage: string // 错误信息
options: object // 配置 Map<string, string>
taskId: number // 任务编号
buttons: ImageMjButtonsVO[] // mj 操作按钮 buttons: ImageMjButtonsVO[] // mj 操作按钮
createTime: string // 创建时间 createTime: string // 创建时间
updateTime: string // 更新事件
} }
export interface ImageMjButtonsVO {
customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
emoji: string // 图标 emoji
label: string // Make Variations 文本
style: number // 样式: 2Primary、3Green
}
export interface ImageMjActionVO {
id: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
}
export interface ImagePageReqVO { export interface ImagePageReqVO {
pageNo: number // 分页编号 pageNo: number // 分页编号
pageSize: number // 分页大小 pageSize: number // 分页大小
} }
export interface ImageDallReqVO {
prompt: string // 提示词
model: string // 模型
style: string // 图像生成的风格
width: string // 图片宽度
height: string // 图片高度
}
export interface ImageDrawReqVO { export interface ImageDrawReqVO {
platform: string // 平台 platform: string // 平台
prompt: string // 提示词 prompt: string // 提示词
@ -65,34 +42,45 @@ export interface ImageMidjourneyImagineReqVO {
version: string // 版本 version: string // 版本
} }
// TODO 芋艿review 下整体注释、方法名 export interface ImageMjActionVO {
id: number // 图片编号
customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
}
export interface ImageMjButtonsVO {
customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识
emoji: string // 图标 emoji
label: string // Make Variations 文本
style: number // 样式: 2Primary、3Green
}
// AI API 密钥 API // AI API 密钥 API
export const ImageApi = { export const ImageApi = {
// 获取 image 列表 // 获取我的图片列表
getImageList: async (params: ImagePageReqVO) => { getImagePageMy: async (params: ImagePageReqVO) => {
return await request.get({ url: `/ai/image/my-page`, params }) return await request.get({ url: `/ai/image/my-page`, params })
}, },
// 获取 image 详细信息 // 获取我的图片
getImageDetail: async (id: number) => { getImageMy: 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}`})
}, },
// 生成图片 // 生成图片
drawImage: async (data: ImageDrawReqVO)=> { drawImage: async (data: ImageDrawReqVO)=> {
return await request.post({ url: `/ai/image/draw`, data }) return await request.post({ url: `/ai/image/draw`, data })
}, },
// 删除 // 删除我的图片
deleteImage: async (id: number)=> { deleteImageMy: async (id: number)=> {
return await request.delete({ url: `/ai/image/delete-my?id=${id}`}) return await request.delete({ url: `/ai/image/delete-my?id=${id}`})
}, },
// ------------ midjourney // ================ midjourney 专属 ================
// midjourney - imagine // 【Midjourney】生成图片
midjourneyImagine: async (data: ImageMidjourneyImagineReqVO)=> { midjourneyImagine: async (data: ImageMidjourneyImagineReqVO)=> {
return await request.post({ url: `/ai/image/midjourney/imagine`, data }) return await request.post({ url: `/ai/image/midjourney/imagine`, data })
}, },
// midjourney - action // 【Midjourney】Action 操作(二次生成图片)
midjourneyAction: async (params: ImageMjActionVO)=> { midjourneyAction: async (data: ImageMjActionVO)=> {
return await request.get({ url: `/ai/image/midjourney/action`, params }) return await request.post({ url: `/ai/image/midjourney/action`, data })
}, },
} }

View File

@ -60,11 +60,11 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ImageApi, ImageDetailVO} from '@/api/ai/image'; import {ImageApi, ImageRespVO} from '@/api/ai/image';
import ImageTaskCard from './ImageTaskCard.vue'; import ImageTaskCard from './ImageTaskCard.vue';
const showDrawer = ref<boolean>(false) // const showDrawer = ref<boolean>(false) //
const imageDetail = ref<ImageDetailVO>({} as ImageDetailVO) // const imageDetail = ref<ImageRespVO>({} as ImageRespVO) //
const props = defineProps({ const props = defineProps({
show: { show: {
@ -86,7 +86,7 @@ const handlerDrawerClose = async () => {
/** 获取 - 图片 detail */ /** 获取 - 图片 detail */
const getImageDetail = async (id) => { const getImageDetail = async (id) => {
// //
imageDetail.value = await ImageApi.getImageDetail(id) imageDetail.value = await ImageApi.getImageMy(id)
} }
/** 任务 - detail */ /** 任务 - detail */

View File

@ -26,14 +26,14 @@
/> />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ImageApi, ImageDetailVO, ImageMjActionVO, ImageMjButtonsVO} from '@/api/ai/image'; import {ImageApi, ImageRespVO, ImageMjActionVO, ImageMjButtonsVO} 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 {ElLoading, LoadingOptionsResolved} from "element-plus"; import {ElLoading, LoadingOptionsResolved} from "element-plus";
const message = useMessage() // const message = useMessage() //
const imageList = ref<ImageDetailVO[]>([]) // image const imageList = ref<ImageRespVO[]>([]) // image
const imageListInterval = ref<any>() // image const imageListInterval = ref<any>() // image
const isShowImageDetail = ref<boolean>(false) // task const isShowImageDetail = ref<boolean>(false) // task
const showImageDetailId = ref<number>(0) // task const showImageDetailId = ref<number>(0) // task
@ -64,7 +64,7 @@ const getImageList = async (apply:boolean = false) => {
target: imageTaskRef.value, target: imageTaskRef.value,
text: '加载中...' text: '加载中...'
} as LoadingOptionsResolved) } as LoadingOptionsResolved)
const { list, total } = await ImageApi.getImageList({pageNo: pageNo.value, pageSize: pageSize.value}) const { list, total } = await ImageApi.getImagePageMy({pageNo: pageNo.value, pageSize: pageSize.value})
if (apply) { if (apply) {
imageList.value = [...imageList.value, ...list] imageList.value = [...imageList.value, ...list]
} else { } else {
@ -80,7 +80,7 @@ const getImageList = async (apply:boolean = false) => {
} }
/** 图片 - btn click */ /** 图片 - btn click */
const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => { const handlerImageBtnClick = async (type, imageDetail: ImageRespVO) => {
// image detail id // image detail id
showImageDetailId.value = imageDetail.id showImageDetailId.value = imageDetail.id
console.log('type', imageDetail.id) console.log('type', imageDetail.id)
@ -89,7 +89,7 @@ const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => {
await handlerDrawerOpen() await handlerDrawerOpen()
} else if (type === 'delete') { } else if (type === 'delete') {
await message.confirm(`是否删除照片?`) await message.confirm(`是否删除照片?`)
await ImageApi.deleteImage(imageDetail.id) await ImageApi.deleteImageMy(imageDetail.id)
await getImageList() await getImageList()
await message.success("删除成功!") await message.success("删除成功!")
} else if (type === 'download') { } else if (type === 'download') {
@ -98,14 +98,14 @@ const handlerImageBtnClick = async (type, imageDetail: ImageDetailVO) => {
} }
/** 图片 - mj btn click */ /** 图片 - mj btn click */
const handlerImageMjBtnClick = async (button: ImageMjButtonsVO, imageDetail: ImageDetailVO) => { const handlerImageMjBtnClick = async (button: ImageMjButtonsVO, imageDetail: ImageRespVO) => {
// 1 params // 1 params
const params = { const data = {
id: imageDetail.id, id: imageDetail.id,
customId: button.customId, customId: button.customId,
} as ImageMjActionVO } as ImageMjActionVO
// 2 action // 2 action
await ImageApi.midjourneyAction(params) await ImageApi.midjourneyAction(data)
// 3 // 3
await getImageList() await getImageList()
} }

View File

@ -32,7 +32,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {Delete, Download, More} from "@element-plus/icons-vue"; import {Delete, Download, More} from "@element-plus/icons-vue";
import {ImageDetailVO, ImageMjButtonsVO} from "@/api/ai/image"; import {ImageRespVO, ImageMjButtonsVO} from "@/api/ai/image";
import {PropType} from "vue"; import {PropType} from "vue";
import {ElLoading, ElMessageBox} from "element-plus"; import {ElLoading, ElMessageBox} from "element-plus";
@ -41,13 +41,13 @@ const cardImageLoadingInstance = ref<any>() // 卡片 image ref
const message = useMessage() const message = useMessage()
const props = defineProps({ const props = defineProps({
imageDetail: { imageDetail: {
type: Object as PropType<ImageDetailVO>, type: Object as PropType<ImageRespVO>,
require: true require: true
} }
}) })
/** 按钮 - 点击事件 */ /** 按钮 - 点击事件 */
const handlerBtnClick = async (type, imageDetail: ImageDetailVO) => { const handlerBtnClick = async (type, imageDetail: ImageRespVO) => {
emits('onBtnClick', type, imageDetail) emits('onBtnClick', type, imageDetail)
} }

View File

@ -170,7 +170,6 @@ const imageSizeList = ref<ImageSizeVO[]>([
]) // size ]) // size
selectImageSize.value = imageSizeList.value[0] selectImageSize.value = imageSizeList.value[0]
// version // version
let versionList = ref<any>([]) // version let versionList = ref<any>([]) // version
const midjourneyVersionList = ref<any>([ const midjourneyVersionList = ref<any>([
@ -204,9 +203,6 @@ const nijiVersionList = ref<any>([
const selectVersion = ref<any>('6.0') // version const selectVersion = ref<any>('6.0') // version
versionList.value = midjourneyVersionList.value // midjourney versionList.value = midjourneyVersionList.value // midjourney
// Props
const props = defineProps({})
/** 热词 - click */ /** 热词 - click */
const handlerHotWordClick = async (hotWord: string) => { const handlerHotWordClick = async (hotWord: string) => {
// //