【代码优化】AI:image 作品中心的代码

pull/489/head
YunaiV 2024-07-30 00:00:44 +08:00
parent 1fe40b61a0
commit d5d783af25
4 changed files with 76 additions and 48 deletions

View File

@ -53,13 +53,9 @@ export interface ImageMidjourneyButtonsVO {
// AI 图片 API // AI 图片 API
export const ImageApi = { export const ImageApi = {
// 获取【我的】绘图分页 // 获取【我的】绘图分页
getImagePageMy: async (params: PageParam) => { getImagePageMy: async (params: any) => {
return await request.get({ url: `/ai/image/my-page`, params }) return await request.get({ url: `/ai/image/my-page`, params })
}, },
// 获取公开的绘图记录
getImagePagePublic: async (params) => {
return await request.get({ url: `/ai/image/public-page`, params })
},
// 获取【我的】绘图记录 // 获取【我的】绘图记录
getImageMy: 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}` })
@ -97,7 +93,7 @@ export const ImageApi = {
// 更新绘画发布状态 // 更新绘画发布状态
updateImage: async (data: any) => { updateImage: async (data: any) => {
return await request.put({ url: '/ai/image/update-public-status', data }) return await request.put({ url: '/ai/image/update', data })
}, },
// 删除绘画 // 删除绘画

View File

@ -70,26 +70,6 @@ const remainingRouter: AppRouteRecordRaw[] = [
} }
] ]
}, },
// {
// path: '/ai/music',
// component: Layout,
// redirect: '/index',
// name: 'AIMusic',
// meta: {},
// children: [
// {
// path: 'index',
// component: () => import('@/views/ai/music/components/index.vue'),
// name: 'AIMusicIndex',
// meta: {
// title: 'AI 音乐',
// icon: 'ep:home-filled',
// noCache: false,
// affix: true
// }
// }
// ]
// },
{ {
path: '/user', path: '/user',
component: Layout, component: Layout,
@ -593,6 +573,27 @@ const remainingRouter: AppRouteRecordRaw[] = [
component: () => import('@/views/crm/product/detail/index.vue') component: () => import('@/views/crm/product/detail/index.vue')
} }
] ]
},
{
path: '/ai',
component: Layout,
name: 'Ai',
meta: {
hidden: true
},
children: [
{
path: 'image/square',
component: () => import('@/views/ai/image/square/index.vue'),
name: 'AiImageSquare',
meta: {
title: '绘图作品',
icon: 'ep:home-filled',
noCache: false,
affix: true
}
}
]
} }
] ]

View File

@ -1,6 +1,10 @@
<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>
绘画任务
<!-- TODO @fan看看怎么优化下这个样子哈 -->
<el-button @click="handleViewPublic"></el-button>
</template>
<!-- 图片列表 --> <!-- 图片列表 -->
<div class="task-image-list" ref="imageListRef"> <div class="task-image-list" ref="imageListRef">
<ImageCard <ImageCard
@ -42,6 +46,7 @@ import { AiImageStatusEnum } from '@/views/ai/utils/constants'
import download from '@/utils/download' import download from '@/utils/download'
const message = useMessage() // const message = useMessage() //
const router = useRouter() //
// //
const queryParams = reactive({ const queryParams = reactive({
@ -59,6 +64,13 @@ const inProgressTimer = ref<any>() // 生成中的 image 定时器,轮询生
const isShowImageDetail = ref<boolean>(false) // const isShowImageDetail = ref<boolean>(false) //
const showImageDetailId = ref<number>(0) // const showImageDetailId = ref<number>(0) //
/** 处理查看绘图作品 */
const handleViewPublic = () => {
router.push({
name: 'AiImageSquare'
})
}
/** 查看图片的详情 */ /** 查看图片的详情 */
const handleDetailOpen = async () => { const handleDetailOpen = async () => {
isShowImageDetail.value = true isShowImageDetail.value = true

View File

@ -1,48 +1,67 @@
<template> <template>
<div class="square-container"> <div class="square-container">
<!-- TODO @fanstyle 建议换成 unocss -->
<!-- TODO @fanSearch 可以换成 Icon 组件么 -->
<el-input <el-input
v-model="searchText" v-model="queryParams.prompt"
style="width: 100%; margin-bottom: 20px" style="width: 100%; margin-bottom: 20px"
size="large" size="large"
placeholder="请输入要搜索的内容" placeholder="请输入要搜索的内容"
:suffix-icon="Search" :suffix-icon="Search"
@keyup.enter="handleSearch" @keyup.enter="handleQuery"
/> />
<div class="gallery"> <div class="gallery">
<div v-for="item in publicList" :key="item.id" class="gallery-item"> <!-- TODO @fan这个图片的风格要不和 ImageCard.vue 界面一致只有卡片没有操作因为看着更有相框的感觉~~~ -->
<div v-for="item in list" :key="item.id" class="gallery-item">
<img :src="item.picUrl" class="img" /> <img :src="item.picUrl" class="img" />
</div> </div>
</div> </div>
<!-- TODO @fan缺少翻页 -->
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ImageApi, ImageVO } from '@/api/ai/image' import { ImageApi, ImageVO } from '@/api/ai/image'
import { Search } from '@element-plus/icons-vue' import { Search } from '@element-plus/icons-vue'
/** 属性 */ // TODO @fan loading
// TODO @fanqueryParams const loading = ref(true) //
const pageNo = ref<number>(1) const list = ref<ImageVO[]>([]) //
const pageSize = ref<number>(20) const total = ref(0) //
const publicList = ref<ImageVO[]>([]) const queryParams = reactive({
const searchText = ref<string>('') pageNo: 1,
pageSize: 10,
publicStatus: true,
prompt: undefined
})
/** 获取数据 */ /** 查询列表 */
const getListData = async () => { const getList = async () => {
const res = await ImageApi.getImagePagePublic({ loading.value = true
pageNo: pageNo.value, try {
pageSize: pageSize.value, const data = await ImageApi.getImagePageMy(queryParams)
prompt: searchText.value list.value = data.list
}) total.value = data.total
publicList.value = res.list as ImageVO[] } finally {
loading.value = false
}
} }
/** 搜索 */ /** 搜索按钮操作 */
const handleSearch = async () => { const handleQuery = () => {
await getListData() queryParams.pageNo = 1
getList()
} }
/** 初始化 */
onMounted(async () => { onMounted(async () => {
await getListData() await getList()
}) })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">