fix(/my/collect): Fix request error.

mack-mac
mackt 7 months ago
parent b20e608853
commit 065b894e56

@ -6,7 +6,7 @@ import { useEffect, useState } from 'react';
import { useShallow } from 'zustand/react/shallow'; import { useShallow } from 'zustand/react/shallow';
import styles from './index.module.css'; import styles from '../index.module.css';
import { SongCardList } from '@/components'; import { SongCardList } from '@/components';
import { apiGetSongCollect } from '@/services'; import { apiGetSongCollect } from '@/services';
@ -26,21 +26,16 @@ export default function Journal() {
const handleChangeType = (type: 'single' | 'journal') => { const handleChangeType = (type: 'single' | 'journal') => {
setList([]); setList([]);
setType(type);
setPageNum(1); setPageNum(1);
setType(type);
}; };
const getList = async () => { const getList = async () => {
// const fn = {
// single: apiGetSongCollect,
// journal: apiGetSongCollect,
// };
const result = await apiGetSongCollect({ userId: userInfo?.id, pageNum, pageSize }); const result = await apiGetSongCollect({ userId: userInfo?.id, pageNum, pageSize });
// console.log(result); if (result.code === 200) setList(result.data?.rows || []);
if (result.code === 200) setList(result.data.rows);
}; };
const nav: Array<{ label: string; value: 'single' | 'journal' }> = [ const tabList: Array<{ label: string; value: 'single' | 'journal' }> = [
{ {
label: '收藏的单曲', label: '收藏的单曲',
value: 'single', value: 'single',
@ -52,16 +47,19 @@ export default function Journal() {
]; ];
useEffect(() => { useEffect(() => {
document.title = '我的收藏 - 雀乐';
getList(); getList();
}, [type, pageNum]); }, [type, pageNum]);
useEffect(() => {
document.title = '我的收藏 - 雀乐';
}, []);
return ( return (
<main className="w-[1200px] mx-auto items-left pt-[80px] pb-[104px] "> <main className="w-[1200px] mx-auto items-left pt-[80px] pb-[104px] ">
<div className="w-[712px]"> <div className="w-[712px]">
{/* Nav */} {/* Nav */}
<ul className="mt-[22px] h-[24px]"> <ul className="mt-[22px] h-[24px]">
{nav.map((item) => ( {tabList.map((item) => (
<li <li
key={item.value} key={item.value}
className={`relative float-left w-[85px] mr-[37px] text-[rgba(0,0,0,0.4)] text-[17px] leading-[24px] hover:text-base cursor-pointer ${type === item.value ? styles['tab-active'] : ''} `} className={`relative float-left w-[85px] mr-[37px] text-[rgba(0,0,0,0.4)] text-[17px] leading-[24px] hover:text-base cursor-pointer ${type === item.value ? styles['tab-active'] : ''} `}

@ -59,7 +59,7 @@ export default async function JournalDetail({ params: { journalId } }: { params:
{/* 收藏 */} {/* 收藏 */}
<Collect <Collect
active={journalInfo.haveCollect} active={journalInfo.haveCollect}
text={`${journalInfo.userCollectCount}人收藏`} text={journalInfo.userCollectCount ? `${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]">
{/* 热门推荐 */} {/* 热门推荐 */}
{recommendList.length ? <JournalRecommendList list={recommendList} /> : <div />} {!!recommendList?.length ? <JournalRecommendList list={recommendList} /> : <div />}
</div> </div>
</main> </main>
); );

@ -11,17 +11,17 @@ export const metadata: Metadata = {
}; };
const getData = async () => { const getData = async () => {
const [categoryList, recomendList] = await Promise.all([ const [categoryList, recommendList] = await Promise.all([
apiSearchCategoryList(), apiSearchCategoryList(),
apiGetJournalRecommendWithCollect(), apiGetJournalRecommendWithCollect(),
]); ]);
if (categoryList.code !== 200) return notFound(); if (categoryList.code !== 200) return notFound();
return { categoryList: categoryList.data, recomendList: recomendList.data }; return { categoryList: categoryList.data, recommendList: recommendList.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, recomendList } = await getData(); const { categoryList, recommendList } = 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 (
@ -37,7 +37,7 @@ export default async function Journal({ params }: { params: { category?: string;
{/* 右侧 */} {/* 右侧 */}
<div className="w-[346px] mt-[218px]"> <div className="w-[346px] mt-[218px]">
{/* 热门推荐 */} {/* 热门推荐 */}
<JournalRecommendList list={recomendList} /> {!!recommendList?.length ? <JournalRecommendList list={recommendList} /> : <div />}
</div> </div>
</main> </main>
); );

@ -14,9 +14,10 @@ interface Props {
className?: string; className?: string;
} }
interface TDataList { interface UserData {
label: string; label: string;
value: number; value: number;
url: string;
} }
export default function UserCard({ onClose, className }: Props) { export default function UserCard({ onClose, className }: Props) {
@ -27,24 +28,19 @@ export default function UserCard({ onClose, className }: Props) {
})), })),
); );
const [userDataList, setUserDataList] = useState<TDataList[]>([ const [userDataList, setUserDataList] = useState<UserData[]>([]);
{ label: '关注', value: userInfo.followCount },
{ label: '粉丝', value: userInfo.fansCount },
{ label: '评论', value: userInfo.commentReplyCount },
{ label: '获赞', value: userInfo.thumbUpCount },
]);
const handleGoMyList = () => { const handleGoMyCollect = () => {
router.push('/myList'); router.push('/my/collect');
onClose(); onClose();
}; };
useEffect(() => { useEffect(() => {
setUserDataList([ setUserDataList([
{ label: '关注', value: userInfo.followCount }, { label: '关注', value: userInfo.followCount, url: '' },
{ label: '粉丝', value: userInfo.fansCount }, { label: '粉丝', value: userInfo.fansCount, url: '' },
{ label: '评论', value: userInfo.commentReplyCount }, { label: '评论', value: userInfo.commentReplyCount, url: '' },
{ label: '获赞', value: userInfo.thumbUpCount }, { label: '获赞', value: userInfo.thumbUpCount, url: '' },
]); ]);
}, [userInfo]); }, [userInfo]);
@ -75,7 +71,7 @@ export default function UserCard({ onClose, className }: Props) {
<ul className="px-[15px] mt-[6px]"> <ul className="px-[15px] mt-[6px]">
<li <li
className="flex flex-row justify-between items-center w-[238px] h-[49px] px-[15px] rounded-[3px] text-[15px] leading-[21px] hover:bg-[#f2f3f7] cursor-pointer" className="flex flex-row justify-between items-center w-[238px] h-[49px] px-[15px] rounded-[3px] text-[15px] leading-[21px] hover:bg-[#f2f3f7] cursor-pointer"
onClick={handleGoMyList} onClick={handleGoMyCollect}
> >
<span></span> <span></span>
<Image width={24} height={24} src="/img/icon/love.svg" alt="我的收藏" /> <Image width={24} height={24} src="/img/icon/love.svg" alt="我的收藏" />

@ -19,7 +19,7 @@ export const apiGetSongCollect = async ({
userId: string; userId: string;
}) => { }) => {
const result: FetchResponse<Paging<SongInfo>> = await clientHttp.get( const result: FetchResponse<Paging<SongInfo>> = await clientHttp.get(
`queyueapi/music/song/collect?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`, `/queyueapi/music/song/collect?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`,
); );
return result; return result;
}; };

Loading…
Cancel
Save