|
@@ -1,8 +1,8 @@
|
|
|
-import { useEffect, useMemo } from 'react';
|
|
|
|
|
|
|
+import { useEffect, useMemo, useState } from 'react';
|
|
|
|
|
|
|
|
import { PlanTagType, PayMethodType } from '@/defines';
|
|
import { PlanTagType, PayMethodType } from '@/defines';
|
|
|
import { userConfigModel } from '@/models/userConfigModel';
|
|
import { userConfigModel } from '@/models/userConfigModel';
|
|
|
-import { fetchGetUserConfig } from '@/services/config';
|
|
|
|
|
|
|
+import { fetchGetUserConfig, fetchPlanList } from '@/services/config';
|
|
|
import { getToken, setToken } from '@/utils/authUtils';
|
|
import { getToken, setToken } from '@/utils/authUtils';
|
|
|
import { currentUnixTimestamp } from '@/utils/timeUtils';
|
|
import { currentUnixTimestamp } from '@/utils/timeUtils';
|
|
|
|
|
|
|
@@ -24,6 +24,8 @@ export interface UseServiceReturn {
|
|
|
export function useService(): UseServiceReturn {
|
|
export function useService(): UseServiceReturn {
|
|
|
const { setUserConfig } = userConfigModel.useModel();
|
|
const { setUserConfig } = userConfigModel.useModel();
|
|
|
|
|
|
|
|
|
|
+ const [plans, setPlans] = useState<Plan[]>([]);
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
const userinfo = getToken();
|
|
const userinfo = getToken();
|
|
|
const expired = (userinfo?.accessExpires ?? 0) - currentUnixTimestamp() <= 0;
|
|
const expired = (userinfo?.accessExpires ?? 0) - currentUnixTimestamp() <= 0;
|
|
@@ -39,60 +41,27 @@ export function useService(): UseServiceReturn {
|
|
|
.catch(() => {});
|
|
.catch(() => {});
|
|
|
}, [setUserConfig]);
|
|
}, [setUserConfig]);
|
|
|
|
|
|
|
|
- const plans = useMemo<Plan[]>(
|
|
|
|
|
- () => [
|
|
|
|
|
- {
|
|
|
|
|
- id: 1,
|
|
|
|
|
- title: '12个月',
|
|
|
|
|
- subTitle: 'USD 53.99',
|
|
|
|
|
- introduce: '折合 USD 0.15/天',
|
|
|
|
|
- tag: '0.6折优惠',
|
|
|
|
|
- tagType: PlanTagType.MOST_POPULAR,
|
|
|
|
|
- price: 53.99,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- id: 2,
|
|
|
|
|
- title: '3个月',
|
|
|
|
|
- subTitle: 'USD 15.99',
|
|
|
|
|
- introduce: '折合 USD 0.18/天',
|
|
|
|
|
- tag: '0.8折优惠',
|
|
|
|
|
- tagType: PlanTagType.LIMITED_TIME,
|
|
|
|
|
- price: 15.99,
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- id: 3,
|
|
|
|
|
- title: '1个月',
|
|
|
|
|
- subTitle: 'USD 2.99',
|
|
|
|
|
- introduce: '折合 USD 0.22/天',
|
|
|
|
|
- tag: '0.9折优惠',
|
|
|
|
|
- tagType: PlanTagType.NONE,
|
|
|
|
|
- price: 2.99,
|
|
|
|
|
- },
|
|
|
|
|
- // {
|
|
|
|
|
- // id: 4,
|
|
|
|
|
- // title: '7天',
|
|
|
|
|
- // subTitle: 'USD 1.99',
|
|
|
|
|
- // introduce: '折合 USD 0.28/天',
|
|
|
|
|
- // tag: '无优惠',
|
|
|
|
|
- // tagType: PlanTagType.NONE,
|
|
|
|
|
- // price: 1.99,
|
|
|
|
|
- // },
|
|
|
|
|
- // {
|
|
|
|
|
- // id: 5,
|
|
|
|
|
- // title: '7天',
|
|
|
|
|
- // subTitle: 'USD 1.99',
|
|
|
|
|
- // introduce: '折合 USD 0.28/天',
|
|
|
|
|
- // tag: '无优惠',
|
|
|
|
|
- // tagType: PlanTagType.NONE,
|
|
|
|
|
- // price: 1.99,
|
|
|
|
|
- // },
|
|
|
|
|
- ],
|
|
|
|
|
- []
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ fetchPlanList({})
|
|
|
|
|
+ .then((res) => {
|
|
|
|
|
+ const list = res?.data?.list ?? [];
|
|
|
|
|
+ const mapped: Plan[] = list.map((item, index) => ({
|
|
|
|
|
+ id: item.ServiceChannelPlanId ?? index,
|
|
|
|
|
+ title: item.title ?? '',
|
|
|
|
|
+ subTitle: item.subTitle ?? '',
|
|
|
|
|
+ introduce: item.introduce ?? '',
|
|
|
|
|
+ tag: item.tag,
|
|
|
|
|
+ tagType: item.tagType ?? PlanTagType.NONE,
|
|
|
|
|
+ price: item.price ?? 0,
|
|
|
|
|
+ }));
|
|
|
|
|
+ setPlans(mapped);
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {});
|
|
|
|
|
+ }, []);
|
|
|
|
|
|
|
|
const payMethods = useMemo<PayMethodType[]>(
|
|
const payMethods = useMemo<PayMethodType[]>(
|
|
|
() => [
|
|
() => [
|
|
|
- PayMethodType.APPLE_PAY,
|
|
|
|
|
|
|
+ PayMethodType.APPLE_PAY,
|
|
|
PayMethodType.GOOGLE_PAY,
|
|
PayMethodType.GOOGLE_PAY,
|
|
|
// PayMethodType.PAYPAL,
|
|
// PayMethodType.PAYPAL,
|
|
|
// PayMethodType.WECHAT,
|
|
// PayMethodType.WECHAT,
|