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

pull/491/MERGE
YunaiV 2024-07-30 00:00:44 +08:00
parent 108dcccafe
commit 2ff21aa65e
4 changed files with 76 additions and 48 deletions

View File

@ -53,13 +53,9 @@ export interface ImageMidjourneyButtonsVO {
// AI 图片 API
export const ImageApi = {
// 获取【我的】绘图分页
getImagePageMy: async (params: PageParam) => {
getImagePageMy: async (params: any) => {
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) => {
return await request.get({ url: `/ai/image/get-my?id=${id}` })
@ -97,7 +93,7 @@ export const ImageApi = {
// 更新绘画发布状态
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',
component: Layout,
@ -593,6 +573,27 @@ const remainingRouter: AppRouteRecordRaw[] = [
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>
<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">
<ImageCard
@ -42,6 +46,7 @@ import { AiImageStatusEnum } from '@/views/ai/utils/constants'
import download from '@/utils/download'
const message = useMessage() //
const router = useRouter() //
//
const queryParams = reactive({
@ -59,6 +64,13 @@ const inProgressTimer = ref<any>() // 生成中的 image 定时器,轮询生
const isShowImageDetail = ref<boolean>(false) //
const showImageDetailId = ref<number>(0) //
/** 处理查看绘图作品 */
const handleViewPublic = () => {
router.push({
name: 'AiImageSquare'
})
}
/** 查看图片的详情 */
const handleDetailOpen = async () => {
isShowImageDetail.value = true

View File

@ -1,48 +1,67 @@
<template>
<div class="square-container">
<!-- TODO @fanstyle 建议换成 unocss -->
<!-- TODO @fanSearch 可以换成 Icon 组件么 -->
<el-input
v-model="searchText"
v-model="queryParams.prompt"
style="width: 100%; margin-bottom: 20px"
size="large"
placeholder="请输入要搜索的内容"
:suffix-icon="Search"
@keyup.enter="handleSearch"
@keyup.enter="handleQuery"
/>
<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" />
</div>
</div>
<!-- TODO @fan缺少翻页 -->
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</div>
</template>
<script setup lang="ts">
import { ImageApi, ImageVO } from '@/api/ai/image'
import { Search } from '@element-plus/icons-vue'
/** 属性 */
// TODO @fanqueryParams
const pageNo = ref<number>(1)
const pageSize = ref<number>(20)
const publicList = ref<ImageVO[]>([])
const searchText = ref<string>('')
// TODO @fan loading
const loading = ref(true) //
const list = ref<ImageVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
publicStatus: true,
prompt: undefined
})
/** 获取数据 */
const getListData = async () => {
const res = await ImageApi.getImagePagePublic({
pageNo: pageNo.value,
pageSize: pageSize.value,
prompt: searchText.value
})
publicList.value = res.list as ImageVO[]
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await ImageApi.getImagePageMy(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索 */
const handleSearch = async () => {
await getListData()
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 初始化 */
onMounted(async () => {
await getListData()
await getList()
})
</script>
<style scoped lang="scss">