update(journal): Add journal recommend and userCollectCount.

mack-mac
mackt 7 months ago
parent 26e60cd197
commit b20e608853

@ -1,10 +1,9 @@
/** 期刊详情 */ /** 期刊详情 */
import Link from 'next/link'; import Link from 'next/link';
import { notFound } from 'next/navigation'; import { notFound } from 'next/navigation';
import { JournalCard, SongCardList, HotJournalList, Comment, Collect } from '@/components'; import { JournalCard, SongCardList, JournalRecommendList, Comment, Collect } from '@/components';
import { apiGetJournalInfoById, apiGetSongsByJournalNo } from '@/services'; import { apiGetJournalInfoById, apiGetSongsByJournalNo, apiGetJournalRecommendById } from '@/services';
export async function generateMetadata({ params: { journalId } }: { params: { journalId: string } }) { export async function generateMetadata({ params: { journalId } }: { params: { journalId: string } }) {
const res = await apiGetJournalInfoById({ id: journalId }); const res = await apiGetJournalInfoById({ id: journalId });
@ -13,16 +12,17 @@ export async function generateMetadata({ params: { journalId } }: { params: { jo
} }
const getData = async (journalId: string) => { const getData = async (journalId: string) => {
const [journalInfoRes, songListRes] = await Promise.all([ const [journalInfoRes, songListRes, recommendList] = await Promise.all([
apiGetJournalInfoById({ id: journalId }), apiGetJournalInfoById({ id: journalId }),
apiGetSongsByJournalNo({ id: journalId }), apiGetSongsByJournalNo({ id: journalId }),
apiGetJournalRecommendById({ id: journalId, limit: 8 }),
]); ]);
if (!(journalInfoRes.code === 200 && songListRes.code === 200)) return notFound(); if (!(journalInfoRes.code === 200 && songListRes.code === 200)) return notFound();
return { journalInfo: journalInfoRes.data, songList: songListRes.data }; return { journalInfo: journalInfoRes.data, songList: songListRes.data, recommendList: recommendList.data };
}; };
export default async function JournalDetail({ params: { journalId } }: { params: { journalId: string } }) { export default async function JournalDetail({ params: { journalId } }: { params: { journalId: string } }) {
const { journalInfo, songList } = await getData(journalId); const { journalInfo, songList, recommendList } = await getData(journalId);
return ( return (
<main className="w-[1200px] mx-auto flex flex-row justify-between items-left pt-[145px] pb-[104px] "> <main className="w-[1200px] mx-auto flex flex-row justify-between items-left pt-[145px] pb-[104px] ">
@ -59,7 +59,7 @@ export default async function JournalDetail({ params: { journalId } }: { params:
{/* 收藏 */} {/* 收藏 */}
<Collect <Collect
active={journalInfo.haveCollect} active={journalInfo.haveCollect}
text={`${journalInfo.totalCommentReply}人收藏`} text={`${journalInfo.userCollectCount}人收藏`}
id={journalInfo.id} id={journalInfo.id}
type="1" type="1"
/> />
@ -83,7 +83,7 @@ export default async function JournalDetail({ params: { journalId } }: { params:
<div className="w-[346px]"> <div className="w-[346px]">
{/* 热门推荐 */} {/* 热门推荐 */}
<HotJournalList type="journal" journalId={journalInfo.id} /> {recommendList.length ? <JournalRecommendList list={recommendList} /> : <div />}
</div> </div>
</main> </main>
); );

@ -1,7 +1,8 @@
/** 期刊列表 */ /** 期刊列表 */
import { notFound } from 'next/navigation';
import { Category, JournalList, HotJournalList } from '@/components'; import { Category, JournalList, JournalRecommendList } from '@/components';
import { apiSearchCategory } from '@/services'; import { apiSearchCategoryList, apiGetJournalRecommendWithCollect } from '@/services';
import type { Metadata } from 'next'; import type { Metadata } from 'next';
@ -9,14 +10,18 @@ export const metadata: Metadata = {
title: '期刊', title: '期刊',
}; };
const getCategoryList = async () => { const getData = async () => {
const result = await apiSearchCategory(); const [categoryList, recomendList] = await Promise.all([
return result.code === 200 ? result.data : []; apiSearchCategoryList(),
apiGetJournalRecommendWithCollect(),
]);
if (categoryList.code !== 200) return notFound();
return { categoryList: categoryList.data, recomendList: recomendList.data };
}; };
export default async function Journal({ params }: { params: { category?: string; page?: number } }) { export default async function Journal({ params }: { params: { category?: string; page?: number } }) {
const { category = 'all', page = 1 } = params; const { category = 'all', page = 1 } = params;
const categoryList = await getCategoryList(); const { categoryList, recomendList } = await getData();
const categoryInfo: Category | undefined = categoryList.find((item: Category) => item.nameEn === category); const categoryInfo: Category | undefined = categoryList.find((item: Category) => item.nameEn === category);
return ( return (
@ -32,7 +37,7 @@ export default async function Journal({ params }: { params: { category?: string;
{/* 右侧 */} {/* 右侧 */}
<div className="w-[346px] mt-[218px]"> <div className="w-[346px] mt-[218px]">
{/* 热门推荐 */} {/* 热门推荐 */}
<HotJournalList type="hot" /> <JournalRecommendList list={recomendList} />
</div> </div>
</main> </main>
); );

@ -1,9 +1,9 @@
import Link from 'next/link'; import Link from 'next/link';
import { apiSearchCategory } from '@/services/server/journal'; import { apiSearchCategoryList } from '@/services/server/journal';
const getCategoryList = async () => { const getCategoryList = async () => {
const result = await apiSearchCategory(); const result = await apiSearchCategoryList();
return result.code === 200 ? result.data : []; return result.code === 200 ? result.data : [];
}; };

@ -1,43 +0,0 @@
import Link from 'next/link';
import HotJournalCard from './HotJournalCard';
import { apiJournalRecommend } from '@/services/server/journal';
interface HotProp {
type: 'hot';
}
interface JournalProp {
type: 'journal';
journalId: string;
}
const getData = async (id: string) => {
const res = await apiJournalRecommend({ id });
return res.code === 200 ? res.data : [];
};
const RecommondJournal = async (prop: HotProp | JournalProp) => {
let journalList: JournalInfo[] = [];
if (prop.type === 'hot') journalList = [];
if (prop.type === 'journal') journalList = await getData(prop.journalId);
return (
<div className="flex flex-col">
{/* 分类 & 电台 */}
<div className="text-[17px] leading-[23.8px]"></div>
{/* 期刊 list */}
<div className="flex flex-col gap-[30px] mt-[17px]">
{!!journalList?.length &&
journalList.map((item: JournalInfo) => (
<Link key={item.id} href={`/vol/${item.journalNo}`}>
<HotJournalCard key={item.id} {...item} />
</Link>
))}
</div>
</div>
);
};
export default RecommondJournal;

@ -11,6 +11,7 @@ export default function JournalItem({
haveCollect, haveCollect,
totalCommentReply, totalCommentReply,
commentList, commentList,
userCollectCount,
}: JournalInfo) { }: JournalInfo) {
return ( return (
<div className="flex flex-col w-[712px] rounded-[6px] bg-base "> <div className="flex flex-col w-[712px] rounded-[6px] bg-base ">
@ -52,7 +53,7 @@ export default function JournalItem({
unoptimized unoptimized
/> />
<p className="ml-[6px] text-[14px] leading-[16px] text-[rgba(0,0,0,0.4) cursor-pointer hover:text-brand"> <p className="ml-[6px] text-[14px] leading-[16px] text-[rgba(0,0,0,0.4) cursor-pointer hover:text-brand">
{totalCommentReply} {userCollectCount}
</p> </p>
</div> </div>
</div> </div>

@ -1,6 +1,6 @@
import Image from 'next/image'; import Image from 'next/image';
export default function JournalItem({ title, image, totalCommentReply }: JournalInfo) { export default function JournalRecommendCard({ title, image, userCollectCount }: JournalInfo) {
return ( return (
<div className="flex flex-row items-center h-[56px] group"> <div className="flex flex-row items-center h-[56px] group">
<Image src={image} alt={title} width={80} height={56} unoptimized className="w-[80px] h-[56px] rounded-[3px]" />{' '} <Image src={image} alt={title} width={80} height={56} unoptimized className="w-[80px] h-[56px] rounded-[3px]" />{' '}
@ -8,7 +8,7 @@ export default function JournalItem({ title, image, totalCommentReply }: Journal
<p className="w-[200px] text-[15px] leading-[21px] cursor-pointer group-hover:text-brand overflow-hidden whitespace-nowrap truncate"> <p className="w-[200px] text-[15px] leading-[21px] cursor-pointer group-hover:text-brand overflow-hidden whitespace-nowrap truncate">
{title} {title}
</p> </p>
<p className="text-[13px] leading-[18.2px] cursor-pointer group-hover:text-brand">{`${totalCommentReply}人收藏`}</p> <p className="text-[13px] leading-[18.2px] cursor-pointer group-hover:text-brand">{`${userCollectCount}人收藏`}</p>
</div> </div>
</div> </div>
); );

@ -0,0 +1,27 @@
import Link from 'next/link';
import JournalRecommendCard from './JournalRecommendCard';
interface Props {
list: JournalInfo[];
}
const JournalRecommendList = async ({ list }: Props) => {
return (
<div className="flex flex-col">
{/* 分类 & 电台 */}
<div className="text-[17px] leading-[23.8px]"></div>
{/* 期刊 list */}
<div className="flex flex-col gap-[30px] mt-[17px]">
{!!list?.length &&
list.map((item: JournalInfo) => (
<Link key={item.id} href={`/vol/${item.journalNo}`}>
<JournalRecommendCard key={item.id} {...item} />
</Link>
))}
</div>
</div>
);
};
export default JournalRecommendList;

@ -14,8 +14,8 @@ export { default as LoginForm } from './Login/LoginForm';
export { default as JournalItem } from './Journal/JournalItem'; export { default as JournalItem } from './Journal/JournalItem';
export { default as JournalCard } from './Journal/JournalCard'; export { default as JournalCard } from './Journal/JournalCard';
export { default as JournalList } from './Journal/JournalList'; export { default as JournalList } from './Journal/JournalList';
export { default as HotJournalCard } from './Journal/HotJournalCard'; export { default as JournalRecommendCard } from './Journal/JournalRecommendCard';
export { default as HotJournalList } from './Journal/HotJournalList'; export { default as JournalRecommendList } from './Journal/JournalRecommendList';
// Common // Common
export { default as Input } from './common/Input'; export { default as Input } from './common/Input';

@ -36,7 +36,7 @@ export const apiJournalList: (params: {
/** /**
* @description * @description
*/ */
export const apiSearchCategory: () => Promise<FetchResponse<Category[]>> = async () => { export const apiSearchCategoryList: () => Promise<FetchResponse<Category[]>> = async () => {
const request = new Request('http://localhost', { const request = new Request('http://localhost', {
method: 'GET', method: 'GET',
headers: { headers: {
@ -47,17 +47,33 @@ export const apiSearchCategory: () => Promise<FetchResponse<Category[]>> = async
return res; return res;
}; };
/**
* @description 8
* @id
*/
export const apiGetJournalRecommendWithCollect: () => Promise<FetchResponse<JournalInfo[]>> = async () => {
const request = new Request('http://localhost', {
method: 'GET',
headers: {
requestUrl: `/music/journal/recommend`,
},
});
const res = await serverHttp.get(request);
return res;
};
/** /**
* @description 6 * @description 6
* @id * @id
*/ */
export const apiJournalRecommend: (params: { id: string }) => Promise<FetchResponse<JournalInfo[]>> = async ({ export const apiGetJournalRecommendById: (params: {
id, id: string;
}) => { limit: number;
}) => Promise<FetchResponse<JournalInfo[]>> = async ({ id, limit }) => {
const request = new Request('http://localhost', { const request = new Request('http://localhost', {
method: 'GET', method: 'GET',
headers: { headers: {
requestUrl: `/music/journal/recommend/${id}`, requestUrl: `/music/journal/recommend/${id}/${limit}`,
}, },
}); });
const res = await serverHttp.get(request); const res = await serverHttp.get(request);

@ -85,6 +85,8 @@ declare interface JournalInfo {
totalCommentReply: string; totalCommentReply: string;
/** 期刊总评论数 int */ /** 期刊总评论数 int */
totalCommentReplyInt: number; totalCommentReplyInt: number;
/** 期刊总收藏数 int */
userCollectCount: number;
} }
/** /**

Loading…
Cancel
Save