diff --git a/apps/web/src/api/subscription/index.ts b/apps/web/src/api/subscription/index.ts new file mode 100644 index 000000000..74bdd8f84 --- /dev/null +++ b/apps/web/src/api/subscription/index.ts @@ -0,0 +1,26 @@ +/** + * 订阅 API — 目录化入口 + * 保持与原 subscription.ts 相同导出,向后兼容 + */ + +// 类型 +export type { + PlanType, + SubscriptionStatus, + BillingStatus, + BillingCycle, + Plan, + SubscriptionInfo, + BillingRecord, + ChangePlanRequest, + ChangePlanResponse, +} from "./types" + +// API 函数 +export { + getCurrentSubscription, + getBillingRecords, + changePlan, + cancelSubscription, + toggleAutoRenew, +} from "./subscription" diff --git a/apps/web/src/api/subscription/subscription.ts b/apps/web/src/api/subscription/subscription.ts new file mode 100644 index 000000000..3a6a0010f --- /dev/null +++ b/apps/web/src/api/subscription/subscription.ts @@ -0,0 +1,47 @@ +/** + * 订阅相关 API 函数 + */ +import apiClient from "../client" +import type { + BillingRecord, + ChangePlanRequest, + ChangePlanResponse, + SubscriptionInfo, +} from "./types" + +/** 获取当前订阅信息 */ +export const getCurrentSubscription = async (): Promise => { + const response = await apiClient.get("/subscription/current") + return response.data +} + +/** 获取账单记录列表 */ +export const getBillingRecords = async (): Promise => { + const response = await apiClient.get("/subscription/billing-records") + return response.data +} + +/** 升级/降级套餐 */ +export const changePlan = async (request: ChangePlanRequest): Promise => { + const response = await apiClient.post("/subscription/change-plan", request) + return response.data +} + +/** 取消订阅 */ +export const cancelSubscription = async (): Promise<{ + success: boolean + message: string +}> => { + const response = await apiClient.post("/subscription/cancel") + return response.data +} + +/** 切换自动续费 */ +export const toggleAutoRenew = async ( + enabled: boolean, +): Promise<{ success: boolean; message: string }> => { + const response = await apiClient.post("/subscription/toggle-auto-renew", { + enabled, + }) + return response.data +} diff --git a/apps/web/src/api/subscription.ts b/apps/web/src/api/subscription/types.ts similarity index 52% rename from apps/web/src/api/subscription.ts rename to apps/web/src/api/subscription/types.ts index 2d4303801..fefabf5bc 100644 --- a/apps/web/src/api/subscription.ts +++ b/apps/web/src/api/subscription/types.ts @@ -1,8 +1,6 @@ /** - * 订阅 API 模块 - * 对接后端订阅管理接口 + * 订阅相关类型定义 */ -import apiClient from "./client" /** 套餐类型 */ export type PlanType = "free" | "standard" | "pro" | "enterprise" @@ -65,42 +63,3 @@ export interface ChangePlanResponse { message: string new_subscription?: SubscriptionInfo } - -// ============ API 函数 ============ - -/** 获取当前订阅信息 */ -export const getCurrentSubscription = async (): Promise => { - const response = await apiClient.get("/subscription/current") - return response.data -} - -/** 获取账单记录列表 */ -export const getBillingRecords = async (): Promise => { - const response = await apiClient.get("/subscription/billing-records") - return response.data -} - -/** 升级/降级套餐 */ -export const changePlan = async (request: ChangePlanRequest): Promise => { - const response = await apiClient.post("/subscription/change-plan", request) - return response.data -} - -/** 取消订阅 */ -export const cancelSubscription = async (): Promise<{ - success: boolean - message: string -}> => { - const response = await apiClient.post("/subscription/cancel") - return response.data -} - -/** 切换自动续费 */ -export const toggleAutoRenew = async ( - enabled: boolean, -): Promise<{ success: boolean; message: string }> => { - const response = await apiClient.post("/subscription/toggle-auto-renew", { - enabled, - }) - return response.data -}