Skip to content

Let's use AI to Earn!

goumaijifen

bulaienaofutuojiesenzhang82d627ba8f70
diff --git a/src/app/[lng]/profile/page.tsx b/src/app/[lng]/profile/page.tsx
index 21091b62..4434f052 100644
--- a/src/app/[lng]/profile/page.tsx
+++ b/src/app/[lng]/profile/page.tsx
@@ -3,7 +3,7 @@
import { useEffect, useState } from "react";
import { Card, Descriptions, Button, message, Modal, Form, Input, Tabs, Table, Tag, Popconfirm, DatePicker, Select, Space } from "antd";
import { CrownOutlined, TrophyOutlined, GiftOutlined, StarOutlined, RocketOutlined, ThunderboltOutlined, HistoryOutlined, DollarOutlined, ShoppingCartOutlined, UserOutlined, GiftFilled } from "@ant-design/icons";
-import { useRouter } from "next/navigation";
+import { useRouter, useSearchParams } from "next/navigation";
import { useUserStore } from "@/store/user";
import { getUserInfoApi, updateUserInfoApi, getPointsRecordsApi } from "@/api/apiReq";
import { createPaymentOrderApi, PaymentType as VipPaymentType } from "@/api/vip";
@@ -12,12 +12,14 @@ import type { Order, OrderListParams, SubscriptionListParams, RefundParams, Unsu
import { OrderStatus, PaymentType } from "@/api/types/payment";
import styles from "./profile.module.css";
import { useTransClient } from "@/app/i18n/client";
+import PointsRechargeModal from "@/components/modals/PointsRechargeModal";
const { TabPane } = Tabs;
const { Option } = Select;
export default function ProfilePage() {
const router = useRouter();
+ const searchParams = useSearchParams();
const { userInfo, setUserInfo, clearLoginStatus, token, lang } = useUserStore();
const { t } = useTransClient('profile');
const [loading, setLoading] = useState(true);
@@ -35,6 +37,8 @@ export default function ProfilePage() {
setHasShownFreeTrial(true);
}
}, []);
+
+ // removed URL-driven auto-open; now fully controlled by state
// 订单相关状态
const [orders, setOrders] = useState<Order[]>([]);
@@ -1185,98 +1189,8 @@ export default function ProfilePage() {
</div>
</Modal>
- {/* 积分充值弹窗 */}
- <Modal
- title={t('pointsPurchase.title' as any)}
- open={pointsRechargeVisible}
- onCancel={handleRechargeCancel}
- footer={null}
- width={500}
- centered
- maskClosable={false}
- closable={true}
- >
- <div className={styles.rechargeContent}>
- <div className={styles.currentPoints}>
- <span className={styles.pointsLabel}>{t('pointsPurchase.currentPoints' as any)}</span>
- <span className={styles.pointsValue}>{userInfo?.score || 0}</span>
- </div>
-
- <div className={styles.rechargeSection}>
- <h4>{t('pointsPurchase.selectAmount' as any)}</h4>
- <p className={styles.rechargeDescription}>{t('pointsPurchase.description' as any)}</p>
-
- <div className={styles.sliderContainer}>
- <div
- className={styles.sliderTrack}
- onClick={handleSliderClick}
- >
- <div
- className={styles.sliderHandle}
- style={{ left: `${(rechargeAmount / 50) * 100}%` }}
- onMouseDown={handleSliderMouseDown}
- />
- </div>
- <div className={styles.sliderLabels}>
- <span>1K</span>
- <span>50K</span>
- </div>
- </div>
-
- <div className={styles.amountInput}>
- <Input
- type="number"
- value={rechargeAmount}
- onChange={(e) => {
- const value = Number(e.target.value);
- if (value >= 1 && value <= 50) {
- setRechargeAmount(value);
- }
- }}
- min={1}
- max={50}
- style={{ width: '80px', marginRight: '8px' }}
- />
- <span>*1000积分</span>
- </div>
-
- <div className={styles.totalPrice}>
- <span>{t('pointsPurchase.purchasePoints' as any)}:</span>
- <span className={styles.priceValue}>{rechargeAmount * 1000}</span>
- </div>
-
- <div className={styles.totalPrice}>
- <span>{t('pointsPurchase.totalPrice' as any)}:</span>
- <span className={styles.priceValue}>${(rechargeAmount * 15).toFixed(2)}</span>
- </div>
- </div>
-
- <Button
- type="primary"
- size="large"
- block
- onClick={() => handleRechargeSubmit({ amount: rechargeAmount })}
- className={styles.rechargeButton}
- disabled={showPaymentSuccess}
- >
- {showPaymentSuccess ? t('pointsPurchase.paying' as any) : t('pointsPurchase.buyNow' as any)}
- </Button>
-
- {/* 支付成功提示 */}
- {showPaymentSuccess && (
- <div className={styles.paymentSuccessTip}>
- <p>{t('pointsPurchase.paymentTip' as any)}</p>
- <Button
- type="primary"
- onClick={handlePaymentSuccess}
- className={styles.paymentSuccessButton}
- >
- {t('pointsPurchase.confirmPayment' as any)}
- </Button>
- </div>
- )}
- </div>
- </Modal>
+ {/* 积分充值弹窗(复用组件) */}
+ <PointsRechargeModal open={pointsRechargeVisible} onClose={handleRechargeCancel} />
</div>
);
}
\ No newline at end of file
diff --git a/src/components/modals/PointsRechargeModal.tsx b/src/components/modals/PointsRechargeModal.tsx
new file mode 100644
index 00000000..9812a437
--- /dev/null
+++ b/src/components/modals/PointsRechargeModal.tsx
@@ -0,0 +1,167 @@
+"use client";
+
+import { memo, useEffect, useMemo, useRef, useState } from "react";
+import { Modal, Button, InputNumber, Typography, Space, message } from "antd";
+import styles from "./outsideCloseModal.module.css";
+import { createPaymentOrderApi, PaymentType } from "@/api/vip";
+import { useUserStore } from "@/store/user";
+
+interface PointsRechargeModalProps {
+ open: boolean;
+ onClose: () => void;
+}
+
+const PointsRechargeModal = memo(({ open, onClose }: PointsRechargeModalProps) => {
+ const [rechargeAmount, setRechargeAmount] = useState<number>(8);
+ const [buyLoading, setBuyLoading] = useState(false);
+ const userStore = useUserStore();
+ const modalWidth = useMemo(() => 520, []);
+ const sliderTrackRef = useRef<HTMLDivElement | null>(null);
+ const [dragging, setDragging] = useState(false);
+
+ const amountToPercent = (amount: number) => ((amount - 1) / 49) * 100; // 1..50
+ const percentToAmount = (percent: number) => {
+ const clamped = Math.max(0, Math.min(100, percent));
+ const val = 1 + Math.round((clamped / 100) * 49);
+ return val;
+ };
+
+ const handleSliderClick = (e: React.MouseEvent<HTMLDivElement>) => {
+ const rect = (e.currentTarget as HTMLDivElement).getBoundingClientRect();
+ const percent = ((e.clientX - rect.left) / rect.width) * 100;
+ setRechargeAmount(percentToAmount(percent));
+ };
+
+ const onMouseDownHandle = (e: React.MouseEvent<HTMLDivElement>) => {
+ e.stopPropagation();
+ setDragging(true);
+ };
+
+ useEffect(() => {
+ const onMove = (e: MouseEvent) => {
+ if (!dragging || !sliderTrackRef.current) return;
+ const rect = sliderTrackRef.current.getBoundingClientRect();
+ const percent = ((e.clientX - rect.left) / rect.width) * 100;
+ setRechargeAmount(percentToAmount(percent));
+ };
+ const onUp = () => setDragging(false);
+ if (dragging) {
+ document.addEventListener('mousemove', onMove);
+ document.addEventListener('mouseup', onUp);
+ }
+ return () => {
+ document.removeEventListener('mousemove', onMove);
+ document.removeEventListener('mouseup', onUp);
+ };
+ }, [dragging]);
+
+ return (
+ <Modal
+ title={<span style={{fontWeight:700}}>购买积分</span>}
+ open={open}
+ onCancel={onClose}
+ footer={null}
+ width={modalWidth}
+ centered
+ className={styles.outsideCloseModal}
+ destroyOnClose
+ >
+ <Space direction="vertical" size={16} style={{width:'100%'}}>
+ <div style={{display:'flex', justifyContent:'space-between', alignItems:'center'}}>
+ <span style={{color:'#6b7280'}}>当前积分</span>
+ <span style={{fontWeight:700}}>{userStore.userInfo?.score || 0}</span>
+ </div>
+ <div>
+ <Typography.Text type="secondary">每1000积分售价15美元</Typography.Text>
+ {/* Slider */}
+ <div style={{ marginTop: 12 }}>
+ <div
+ ref={sliderTrackRef}
+ onClick={handleSliderClick}
+ style={{
+ position: 'relative',
+ height: 8,
+ background: '#e5e7eb',
+ borderRadius: 6,
+ cursor: 'pointer'
+ }}
+ >
+ <div
+ style={{
+ position: 'absolute',
+ left: 0,
+ top: 0,
+ height: '100%',
+ width: `${amountToPercent(rechargeAmount)}%`,
+ background: 'var(--theColor5)',
+ borderRadius: 6
+ }}
+ />
+ <div
+ onMouseDown={onMouseDownHandle}
+ style={{
+ position: 'absolute',
+ top: '50%',
+ left: `calc(${amountToPercent(rechargeAmount)}% - 10px)`,
+ width: 20,
+ height: 20,
+ background: '#ffffff',
+ border: '2px solid var(--theColor5)',
+ borderRadius: '50%',
+ transform: 'translateY(-50%)',
+ boxShadow: '0 1px 4px rgba(0,0,0,0.15)',
+ cursor: 'grab'
+ }}
+ />
+ </div>
+ <div style={{ display:'flex', justifyContent:'space-between', fontSize:12, color:'#6b7280', marginTop:6 }}>
+ <span>1K</span>
+ <span>50K</span>
+ </div>
+ </div>
+ <div style={{marginTop:12, display:'flex', alignItems:'center', gap:12}}>
+ <InputNumber min={1} max={50} value={rechargeAmount} onChange={(v) => setRechargeAmount(Number(v) || 1)} />
+ <span>* 1000 积分</span>
+ </div>
+ </div>
+ <div style={{display:'flex', justifyContent:'space-between'}}>
+ <span>购买积分</span>
+ <span style={{fontWeight:700}}>{rechargeAmount * 1000}</span>
+ </div>
+ <div style={{display:'flex', justifyContent:'space-between'}}>
+ <span>总价</span>
+ <span style={{fontWeight:700}}>${(rechargeAmount * 15).toFixed(2)}</span>
+ </div>
+ <Button type="primary" block loading={buyLoading} onClick={async () => {
+ try {
+ setBuyLoading(true);
+ if (!userStore.userInfo?.id) {
+ message.error('请先登录');
+ return;
+ }
+ const res: any = await createPaymentOrderApi({
+ mode: 'payment',
+ payment: PaymentType.POINTS,
+ flagTrialPeriodDays: 0,
+ metadata: { userId: userStore.userInfo.id },
+ success_url: userStore.lang === 'zh-CN' ? '/zh-CN/profile' : '/en/profile'
+ });
+ if (res?.code === 0 && res.data?.url) {
+ window.open(res.data.url, '_blank');
+ } else {
+ message.error(res?.message || res?.msg || '创建支付订单失败');
+ }
+ } catch (e) {
+ message.error('创建支付订单失败');
+ } finally {
+ setBuyLoading(false);
+ }
+ }}>立即购买</Button>
+ </Space>
+ </Modal>
+ );
+});
+
+export default PointsRechargeModal;
+
+
diff --git a/src/components/modals/VipContentModal.tsx b/src/components/modals/VipContentModal.tsx
index 34975658..f9996e07 100644
--- a/src/components/modals/VipContentModal.tsx
+++ b/src/components/modals/VipContentModal.tsx
@@ -1,10 +1,12 @@
"use client";
import { memo, useMemo, useState } from "react";
-import { Modal, Button, Tag } from "antd";
+import { Modal, Button, Tag, message } from "antd";
import styles from "./outsideCloseModal.module.css";
import vipStyles from "./vipContentModal.module.css";
import IncomePage from "@/app/[lng]/income/page";
+import { useUserStore } from "@/store/user";
+import PointsRechargeModal from "@/components/modals/PointsRechargeModal";
interface VipContentModalProps {
open: boolean;
@@ -13,7 +15,9 @@ interface VipContentModalProps {
const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
const [pointsModalVisible, setPointsModalVisible] = useState(false);
+ const userStore = useUserStore();
const modalWidth = useMemo(() => "76%" as const, []);
+ const [rechargeVisible, setRechargeVisible] = useState(false);
return (
<Modal
@@ -36,7 +40,9 @@ const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
</h2>
<div className={vipStyles.links}>
<span>选择合适你的套餐,或直接</span>
- <span className={vipStyles.linkButton}>购买积分</span>
+ <span className={vipStyles.linkButton}
+ onClick={() => setRechargeVisible(true)}
+ >购买积分</span>
</div>
</div>
<div className={vipStyles.headerRight}>
@@ -132,6 +138,8 @@ const VipContentModal = memo(({ open, onClose }: VipContentModalProps) => {
>
<IncomePage />
</Modal>
+
+ <PointsRechargeModal open={rechargeVisible} onClose={() => setRechargeVisible(false)} />
</Modal>
);
});