parent
16cf6aadba
commit
143f4ac065
After Width: | Height: | Size: 303 B |
@ -0,0 +1,47 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { apiCollect } from '@/services';
|
||||
|
||||
interface Props {
|
||||
haveCollect: boolean;
|
||||
id: string;
|
||||
type: string;
|
||||
size?: number;
|
||||
count?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export default function Collect({ haveCollect, id, type, size = 24, count = '0', text = '' }: Props) {
|
||||
const [state, setState] = useState<boolean>(false); // 收藏状态
|
||||
|
||||
useEffect(() => {
|
||||
setState(haveCollect);
|
||||
}, [haveCollect]);
|
||||
|
||||
// 收藏/取消收藏
|
||||
const handleCollect = async () => {
|
||||
setState(!state);
|
||||
const res = await apiCollect({ isAdd: !state, objectId: id, collectType: type });
|
||||
if (res.code !== 200) {
|
||||
setState(!state);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-row items-center gap-[9px] cursor-pointer group" onClick={handleCollect}>
|
||||
{/* 文案 */}
|
||||
{!!text && (
|
||||
<p className="text-[rgba(0,0,0,0.4)] text-[13px] leading-[18.2px] group-hover:text-theme">
|
||||
{`${count}${text}`}
|
||||
</p>
|
||||
)}
|
||||
{/* 图标 */}
|
||||
|
||||
<div
|
||||
className={`w-[${size}px] h-[${size}px] ${state ? 'bg-[url(/img/icon/love-active.svg)]' : 'bg-[url(/img/icon/love.svg)]'} group-hover:bg-[url(/img/icon/love-active.svg)]`}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
export type IAuthType = 'noToken' | 'default' | 'ai';
|
||||
|
||||
export interface IOptions {
|
||||
headers?: { [key: string]: string };
|
||||
body?: any;
|
||||
authType?: IAuthType;
|
||||
requestUrl: string;
|
||||
}
|
||||
|
||||
export interface IResponse<T> {
|
||||
code: number;
|
||||
data: T;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export type IQueryParams = {
|
||||
[key: string]: any;
|
||||
};
|
Loading…
Reference in new issue