瀏覽代碼

perf: 修改接口参数传递逻辑:参数为空时,传递一个空对象

BaiLuoYan 3 月之前
父節點
當前提交
14b9d409fe

+ 3 - 1
src/config/request/encryptionInterceptors.ts

@@ -52,7 +52,8 @@ export const requestEncryptionInterceptor: IRequestInterceptorAxios = async (con
         config.headers['X-Request-Timestamp'] = timestamp;
     }
 
-    if (['post', 'put'].includes(config.method?.toLowerCase() || '') && !isNil(config.data)) {
+    config.data = config.data ?? {}; // 如果请求体为空,则设置为空对象(后端需要非空请求体)
+    if (['post', 'put'].includes(config.method?.toLowerCase() || '')) {
         console.log('[requestEncryptionInterceptor] config:', config);
 
         // 设置 Content-Type 为 application/octet-stream
@@ -121,6 +122,7 @@ export const responseDecryptionInterceptor: IResponseInterceptor = async (respon
                     dataStr
                 );
                 response.data = JSON.parse(dataStr);
+                console.log('[responseDecryptionInterceptor] response.data:', response.data);
             } catch (error) {
                 console.error(
                     '[responseDecryptionInterceptor] Failed to parse decrypted response data:',

+ 1 - 1
src/pages/pricing/components/PlanCard/index.tsx

@@ -18,7 +18,7 @@ const PLAN_TAG_TYPE_I18N_KEY: Record<PlanTagType, string> = {
 };
 
 export interface PlanCardProps {
-    id: number;
+    id: string;
     title: string;
     subTitle: string;
     introduce: string;

+ 4 - 4
src/pages/pricing/useAction.ts

@@ -3,17 +3,17 @@ import { useState, useCallback } from 'react';
 import { PayMethodType } from '@/defines';
 
 export interface UseActionReturn {
-    selectedPlanId: number | null;
-    handlePlanClick: (planId: number) => void;
+    selectedPlanId: string | null;
+    handlePlanClick: (planId: string) => void;
     selectedPayMethod: PayMethodType | null;
     handlePayMethodClick: (payMethodId: PayMethodType) => void;
 }
 
 export function useAction(): UseActionReturn {
-    const [selectedPlanId, setSelectedPlanId] = useState<number | null>(null);
+    const [selectedPlanId, setSelectedPlanId] = useState<string | null>(null);
     const [selectedPayMethod, setSelectedPayMethod] = useState<PayMethodType | null>(null);
 
-    const handlePlanClick = useCallback((planId: number) => {
+    const handlePlanClick = useCallback((planId: string) => {
         setSelectedPlanId(planId);
     }, []);
 

+ 4 - 3
src/pages/pricing/useService.ts

@@ -5,9 +5,10 @@ import { userConfigModel } from '@/models/userConfigModel';
 import { fetchGetUserConfig, fetchPlanList } from '@/services/config';
 import { getToken, setToken } from '@/utils/authUtils';
 import { currentUnixTimestamp } from '@/utils/timeUtils';
+import * as stringUtils from '@/utils/stringUtils';
 
 export interface Plan {
-    id: number;
+    id: string;
     title: string;
     subTitle: string;
     introduce: string;
@@ -45,8 +46,8 @@ export function useService(): UseServiceReturn {
         fetchPlanList({})
             .then((res) => {
                 const list = res?.data?.list ?? [];
-                const mapped: Plan[] = list.map((item, index) => ({
-                    id: item.ServiceChannelPlanId ?? index,
+                const mapped: Plan[] = list.map((item) => ({
+                    id: item.channelItemId ?? stringUtils.getUniqueSign(),
                     title: item.title ?? '',
                     subTitle: item.subTitle ?? '',
                     introduce: item.introduce ?? '',

+ 0 - 2
src/services/config/typings.d.ts

@@ -20,8 +20,6 @@ declare namespace API {
         subscribePeriodValue?: number;
         payoutType?: string;
         payoutData?: string;
-        ServicePlanId?: number;
-        ServiceChannelPlanId?: number;
     };
 
     type PlanList = {