fix: 修复ts
This commit is contained in:
parent
06909eaf57
commit
513e68743e
@ -26,23 +26,21 @@ export function SidebarLeft({ ...props }: React.ComponentProps<typeof Sidebar>)
|
||||
<SidebarMenu className={'gap-2.5'}>
|
||||
{navs.map((nav, navIndex) => (
|
||||
<SidebarMenu key={navIndex} className={navIndex === 0 ? 'mb-[42px]' : 'mb-0'}>
|
||||
{(nav.items || [nav]).map((item) => (
|
||||
<SidebarMenuItem key={item.title} className={''}>
|
||||
<SidebarMenuButton
|
||||
className={
|
||||
'h-[60px] rounded-full px-5 py-[18px] text-xl hover:bg-[#EAEAEA] hover:text-[#0F2C53] focus-visible:!outline-none focus-visible:!ring-0 active:bg-[#EAEAEA] active:text-[#0F2C53] data-[active=true]:bg-[#0F2C53]'
|
||||
}
|
||||
asChild
|
||||
tooltip={t(item.title)}
|
||||
isActive={item.url === pathname}
|
||||
>
|
||||
<Link href={item.url}>
|
||||
{item.icon && <Icon className={'!size-6'} icon={item.icon} />}
|
||||
<span>{t(item.title)}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
))}
|
||||
<SidebarMenuItem key={nav.title} className={''}>
|
||||
<SidebarMenuButton
|
||||
className={
|
||||
'h-[60px] rounded-full px-5 py-[18px] text-xl hover:bg-[#EAEAEA] hover:text-[#0F2C53] focus-visible:!outline-none focus-visible:!ring-0 active:bg-[#EAEAEA] active:text-[#0F2C53] data-[active=true]:bg-[#0F2C53]'
|
||||
}
|
||||
asChild
|
||||
tooltip={t(nav.title)}
|
||||
isActive={nav.url === pathname}
|
||||
>
|
||||
<Link href={nav.url}>
|
||||
{nav.icon && <Icon className={'!size-6'} icon={nav.icon} />}
|
||||
<span>{t(nav.title)}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
))}
|
||||
</SidebarMenu>
|
||||
|
||||
@ -254,12 +254,12 @@ const OfferDialog = forwardRef<OfferDialogRef>((props, ref) => {
|
||||
const response = await getSubscription({ skipErrorHandler: true });
|
||||
// 确保返回有效的数组,避免 undefined
|
||||
const list = response.data?.data?.list || [];
|
||||
return list.filter((v) => v.unit_time === 'Month') as unknown as ProcessedPlanData[];
|
||||
return list.filter((v) => v.unit_time === 'Month') as API.Subscribe[];
|
||||
} catch (err) {
|
||||
// 自定义错误处理
|
||||
console.error('获取订阅数据失败:', err);
|
||||
// 返回空数组而不是抛出错误,避免 queryFn 返回 undefined
|
||||
return [] as ProcessedPlanData[];
|
||||
return [] as API.Subscribe[];
|
||||
}
|
||||
},
|
||||
enabled: false, // 初始不执行,手动控制
|
||||
@ -301,7 +301,7 @@ const OfferDialog = forwardRef<OfferDialogRef>((props, ref) => {
|
||||
};
|
||||
|
||||
// 处理套餐数据的工具函数
|
||||
const processPlanData = (item: ProcessedPlanData, isYearly: boolean): ProcessedPlanData => {
|
||||
const processPlanData = (item: API.Subscribe, isYearly: boolean): ProcessedPlanData => {
|
||||
if (isYearly) {
|
||||
const discountItem = item.discount?.find((v) => v.quantity === 12);
|
||||
return {
|
||||
@ -323,12 +323,12 @@ const OfferDialog = forwardRef<OfferDialogRef>((props, ref) => {
|
||||
|
||||
// 使用 useMemo 优化数据处理性能
|
||||
const yearlyPlans: ProcessedPlanData[] = useMemo(
|
||||
() => data.map((item) => processPlanData(item, true)),
|
||||
() => (data || []).map((item) => processPlanData(item, true)),
|
||||
[data],
|
||||
);
|
||||
|
||||
const monthlyPlans: ProcessedPlanData[] = useMemo(
|
||||
() => data.map((item) => processPlanData(item, false)),
|
||||
() => (data || []).map((item) => processPlanData(item, false)),
|
||||
[data],
|
||||
);
|
||||
|
||||
|
||||
@ -20,7 +20,46 @@ export interface SubscriptionData {
|
||||
};
|
||||
}
|
||||
|
||||
export interface ProcessedPlanData extends SubscriptionData {
|
||||
// 以 API.Subscribe 为准的类型定义
|
||||
export interface ProcessedPlanData {
|
||||
id: number;
|
||||
name: string;
|
||||
description: string;
|
||||
unit_price: number;
|
||||
unit_time: string;
|
||||
discount: Array<{
|
||||
quantity: number;
|
||||
discount: number;
|
||||
}>;
|
||||
replacement: number;
|
||||
inventory: number;
|
||||
traffic: number;
|
||||
speed_limit: number;
|
||||
device_limit: number;
|
||||
quota: number;
|
||||
group_id: number;
|
||||
server_group: number[];
|
||||
server: number[];
|
||||
show: boolean;
|
||||
sell: boolean;
|
||||
sort: number;
|
||||
deduction_ratio: number;
|
||||
allow_deduction: boolean;
|
||||
reset_cycle: number;
|
||||
renewal_reset: boolean;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
// 处理后的价格字段
|
||||
origin_price: string;
|
||||
discount_price: string;
|
||||
// 添加features属性以兼容现有代码
|
||||
features?: {
|
||||
traffic: string;
|
||||
duration: string;
|
||||
onlineIPs: string;
|
||||
connections: string;
|
||||
bandwidth: string;
|
||||
nodes: string;
|
||||
stability: number;
|
||||
};
|
||||
}
|
||||
|
||||
@ -46,12 +46,6 @@ export function findNavByUrl(url: string) {
|
||||
if (nav.url && nav.url === url) {
|
||||
return [nav];
|
||||
}
|
||||
if (nav.items) {
|
||||
const current = nav.items.find((item) => item.url === url);
|
||||
if (current) {
|
||||
return [nav, current];
|
||||
}
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user