fix: 修复ts
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user