From 82b53b9b030725e234ed541ae4ba76edfd0c080a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 9 Jul 2024 00:00:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91AI=EF=BC=9A=E7=BB=98=E5=9B=BE=20index.vue=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A2=B3=E7=90=86=2030%=EF=BC=88ImageList=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/ai/image/index.ts | 17 +- src/utils/download.ts | 37 ++-- .../ai/image/index/components/ImageCard.vue | 15 +- .../ai/image/index/components/ImageList.vue | 159 +++++++++--------- src/views/bpm/category/index.vue | 1 - 5 files changed, 110 insertions(+), 119 deletions(-) diff --git a/src/api/ai/image/index.ts b/src/api/ai/image/index.ts index 496fac53..b4818818 100644 --- a/src/api/ai/image/index.ts +++ b/src/api/ai/image/index.ts @@ -14,16 +14,11 @@ export interface ImageVO { errorMessage: string // 错误信息 options: object // 配置 Map taskId: number // 任务编号 - buttons: ImageMjButtonsVO[] // mj 操作按钮 + buttons: ImageMidjourneyButtonsVO[] // mj 操作按钮 createTime: string // 创建时间 finishTime: string // 完成时间 } -export interface ImagePageReqVO { - pageNo: number // 分页编号 - pageSize: number // 分页大小 -} - export interface ImageDrawReqVO { platform: string // 平台 prompt: string // 提示词 @@ -43,22 +38,22 @@ export interface ImageMidjourneyImagineReqVO { version: string // 版本 } -export interface ImageMjActionVO { +export interface ImageMidjourneyActionVO { id: number // 图片编号 customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识 } -export interface ImageMjButtonsVO { +export interface ImageMidjourneyButtonsVO { customId: string // MJ::JOB::upsample::1::85a4b4c1-8835-46c5-a15c-aea34fad1862 动作标识 emoji: string // 图标 emoji label: string // Make Variations 文本 style: number // 样式: 2(Primary)、3(Green) } -// AI API 密钥 API +// AI 图片 API export const ImageApi = { // 获取【我的】绘图分页 - getImagePageMy: async (params: ImagePageReqVO) => { + getImagePageMy: async (params: PageParam) => { return await request.get({ url: `/ai/image/my-page`, params }) }, // 获取【我的】绘图记录 @@ -85,7 +80,7 @@ export const ImageApi = { return await request.post({ url: `/ai/image/midjourney/imagine`, data }) }, // 【Midjourney】Action 操作(二次生成图片) - midjourneyAction: async (data: ImageMjActionVO) => { + midjourneyAction: async (data: ImageMidjourneyActionVO) => { return await request.post({ url: `/ai/image/midjourney/action`, data }) }, diff --git a/src/utils/download.ts b/src/utils/download.ts index 4e8b8c60..1d07484b 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -32,26 +32,25 @@ const download = { // 下载 Markdown 方法 markdown: (data: Blob, fileName: string) => { download0(data, fileName, 'text/markdown') + }, + // 下载图片(允许跨域) + image: (url: string) => { + const image = new Image() + image.setAttribute('crossOrigin', 'anonymous') + image.src = url + image.onload = () => { + const canvas = document.createElement('canvas') + canvas.width = image.width + canvas.height = image.height + const ctx = canvas.getContext('2d') as CanvasDrawImage + ctx.drawImage(image, 0, 0, image.width, image.height) + const url = canvas.toDataURL('image/png') + const a = document.createElement('a') + a.href = url + a.download = 'image.png' + a.click() + } } } export default download - -/** 图片下载(通过浏览器图片下载) */ -export const downloadImage = async (imageUrl) => { - const image = new Image() - image.setAttribute('crossOrigin', 'anonymous') - image.src = imageUrl - image.onload = () => { - const canvas = document.createElement('canvas') - canvas.width = image.width - canvas.height = image.height - const ctx = canvas.getContext('2d') as CanvasDrawImage - ctx.drawImage(image, 0, 0, image.width, image.height) - const url = canvas.toDataURL('image/png') - const a = document.createElement('a') - a.href = url - a.download = 'image.png' - a.click() - } -} diff --git a/src/views/ai/image/index/components/ImageCard.vue b/src/views/ai/image/index/components/ImageCard.vue index 0fbcc3ec..8b23f001 100644 --- a/src/views/ai/image/index/components/ImageCard.vue +++ b/src/views/ai/image/index/components/ImageCard.vue @@ -30,12 +30,7 @@ :icon="RefreshRight" @click="handleBtnClick('regeneration', imageDetail)" /> - + @@ -61,10 +56,10 @@ diff --git a/src/views/bpm/category/index.vue b/src/views/bpm/category/index.vue index 46fa6cf1..085b3715 100644 --- a/src/views/bpm/category/index.vue +++ b/src/views/bpm/category/index.vue @@ -126,7 +126,6 @@