PersonalSetting.js 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  1. import React, { useContext, useEffect, useState } from 'react';
  2. import { useNavigate } from 'react-router-dom';
  3. import {
  4. API,
  5. copy,
  6. isRoot,
  7. isAdmin,
  8. showError,
  9. showInfo,
  10. showSuccess,
  11. } from '../helpers';
  12. import Turnstile from 'react-turnstile';
  13. import { UserContext } from '../context/User';
  14. import {
  15. onGitHubOAuthClicked,
  16. onOIDCClicked,
  17. onLinuxDOOAuthClicked,
  18. } from './utils';
  19. import {
  20. Avatar,
  21. Banner,
  22. Button,
  23. Card,
  24. Image,
  25. Input,
  26. InputNumber,
  27. Layout,
  28. Modal,
  29. Space,
  30. Tag,
  31. Typography,
  32. Collapsible,
  33. Radio,
  34. RadioGroup,
  35. AutoComplete,
  36. Checkbox,
  37. Tabs,
  38. TabPane,
  39. } from '@douyinfe/semi-ui';
  40. import {
  41. IconMail,
  42. IconLock,
  43. IconShield,
  44. IconUser,
  45. IconSetting,
  46. IconBell,
  47. IconGithubLogo,
  48. IconKey,
  49. IconCreditCard,
  50. IconLink,
  51. IconDelete,
  52. IconChevronDown,
  53. IconChevronUp,
  54. } from '@douyinfe/semi-icons';
  55. import { SiTelegram, SiWechat, SiLinux } from 'react-icons/si';
  56. import { Bell, Shield, Webhook, Globe, Settings, UserPlus, ShieldCheck } from 'lucide-react';
  57. import {
  58. getQuotaPerUnit,
  59. renderQuota,
  60. renderQuotaWithPrompt,
  61. stringToColor,
  62. } from '../helpers/render';
  63. import TelegramLoginButton from 'react-telegram-login';
  64. import { useTranslation } from 'react-i18next';
  65. const PersonalSetting = () => {
  66. const [userState, userDispatch] = useContext(UserContext);
  67. let navigate = useNavigate();
  68. const { t } = useTranslation();
  69. const [inputs, setInputs] = useState({
  70. wechat_verification_code: '',
  71. email_verification_code: '',
  72. email: '',
  73. self_account_deletion_confirmation: '',
  74. original_password: '',
  75. set_new_password: '',
  76. set_new_password_confirmation: '',
  77. });
  78. const [status, setStatus] = useState({});
  79. const [showChangePasswordModal, setShowChangePasswordModal] = useState(false);
  80. const [showWeChatBindModal, setShowWeChatBindModal] = useState(false);
  81. const [showEmailBindModal, setShowEmailBindModal] = useState(false);
  82. const [showAccountDeleteModal, setShowAccountDeleteModal] = useState(false);
  83. const [turnstileEnabled, setTurnstileEnabled] = useState(false);
  84. const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
  85. const [turnstileToken, setTurnstileToken] = useState('');
  86. const [loading, setLoading] = useState(false);
  87. const [disableButton, setDisableButton] = useState(false);
  88. const [countdown, setCountdown] = useState(30);
  89. const [affLink, setAffLink] = useState('');
  90. const [systemToken, setSystemToken] = useState('');
  91. const [models, setModels] = useState([]);
  92. const [openTransfer, setOpenTransfer] = useState(false);
  93. const [transferAmount, setTransferAmount] = useState(0);
  94. const [isModelsExpanded, setIsModelsExpanded] = useState(() => {
  95. // Initialize from localStorage if available
  96. const savedState = localStorage.getItem('modelsExpanded');
  97. return savedState ? JSON.parse(savedState) : false;
  98. });
  99. const MODELS_DISPLAY_COUNT = 25; // 默认显示的模型数量
  100. const [notificationSettings, setNotificationSettings] = useState({
  101. warningType: 'email',
  102. warningThreshold: 100000,
  103. webhookUrl: '',
  104. webhookSecret: '',
  105. notificationEmail: '',
  106. acceptUnsetModelRatioModel: false,
  107. });
  108. const [showWebhookDocs, setShowWebhookDocs] = useState(true);
  109. useEffect(() => {
  110. let status = localStorage.getItem('status');
  111. if (status) {
  112. status = JSON.parse(status);
  113. setStatus(status);
  114. if (status.turnstile_check) {
  115. setTurnstileEnabled(true);
  116. setTurnstileSiteKey(status.turnstile_site_key);
  117. }
  118. }
  119. getUserData().then((res) => {
  120. console.log(userState);
  121. });
  122. loadModels().then();
  123. getAffLink().then();
  124. setTransferAmount(getQuotaPerUnit());
  125. }, []);
  126. useEffect(() => {
  127. let countdownInterval = null;
  128. if (disableButton && countdown > 0) {
  129. countdownInterval = setInterval(() => {
  130. setCountdown(countdown - 1);
  131. }, 1000);
  132. } else if (countdown === 0) {
  133. setDisableButton(false);
  134. setCountdown(30);
  135. }
  136. return () => clearInterval(countdownInterval); // Clean up on unmount
  137. }, [disableButton, countdown]);
  138. useEffect(() => {
  139. if (userState?.user?.setting) {
  140. const settings = JSON.parse(userState.user.setting);
  141. setNotificationSettings({
  142. warningType: settings.notify_type || 'email',
  143. warningThreshold: settings.quota_warning_threshold || 500000,
  144. webhookUrl: settings.webhook_url || '',
  145. webhookSecret: settings.webhook_secret || '',
  146. notificationEmail: settings.notification_email || '',
  147. acceptUnsetModelRatioModel:
  148. settings.accept_unset_model_ratio_model || false,
  149. });
  150. }
  151. }, [userState?.user?.setting]);
  152. // Save models expanded state to localStorage whenever it changes
  153. useEffect(() => {
  154. localStorage.setItem('modelsExpanded', JSON.stringify(isModelsExpanded));
  155. }, [isModelsExpanded]);
  156. const handleInputChange = (name, value) => {
  157. setInputs((inputs) => ({ ...inputs, [name]: value }));
  158. };
  159. const generateAccessToken = async () => {
  160. const res = await API.get('/api/user/token');
  161. const { success, message, data } = res.data;
  162. if (success) {
  163. setSystemToken(data);
  164. await copy(data);
  165. showSuccess(t('令牌已重置并已复制到剪贴板'));
  166. } else {
  167. showError(message);
  168. }
  169. };
  170. const getAffLink = async () => {
  171. const res = await API.get('/api/user/aff');
  172. const { success, message, data } = res.data;
  173. if (success) {
  174. let link = `${window.location.origin}/register?aff=${data}`;
  175. setAffLink(link);
  176. } else {
  177. showError(message);
  178. }
  179. };
  180. const getUserData = async () => {
  181. let res = await API.get(`/api/user/self`);
  182. const { success, message, data } = res.data;
  183. if (success) {
  184. userDispatch({ type: 'login', payload: data });
  185. } else {
  186. showError(message);
  187. }
  188. };
  189. const loadModels = async () => {
  190. let res = await API.get(`/api/user/models`);
  191. const { success, message, data } = res.data;
  192. if (success) {
  193. if (data != null) {
  194. setModels(data);
  195. }
  196. } else {
  197. showError(message);
  198. }
  199. };
  200. const handleAffLinkClick = async (e) => {
  201. e.target.select();
  202. await copy(e.target.value);
  203. showSuccess(t('邀请链接已复制到剪切板'));
  204. };
  205. const handleSystemTokenClick = async (e) => {
  206. e.target.select();
  207. await copy(e.target.value);
  208. showSuccess(t('系统令牌已复制到剪切板'));
  209. };
  210. const deleteAccount = async () => {
  211. if (inputs.self_account_deletion_confirmation !== userState.user.username) {
  212. showError(t('请输入你的账户名以确认删除!'));
  213. return;
  214. }
  215. const res = await API.delete('/api/user/self');
  216. const { success, message } = res.data;
  217. if (success) {
  218. showSuccess(t('账户已删除!'));
  219. await API.get('/api/user/logout');
  220. userDispatch({ type: 'logout' });
  221. localStorage.removeItem('user');
  222. navigate('/login');
  223. } else {
  224. showError(message);
  225. }
  226. };
  227. const bindWeChat = async () => {
  228. if (inputs.wechat_verification_code === '') return;
  229. const res = await API.get(
  230. `/api/oauth/wechat/bind?code=${inputs.wechat_verification_code}`,
  231. );
  232. const { success, message } = res.data;
  233. if (success) {
  234. showSuccess(t('微信账户绑定成功!'));
  235. setShowWeChatBindModal(false);
  236. } else {
  237. showError(message);
  238. }
  239. };
  240. const changePassword = async () => {
  241. if (inputs.original_password === '') {
  242. showError(t('请输入原密码!'));
  243. return;
  244. }
  245. if (inputs.set_new_password === '') {
  246. showError(t('请输入新密码!'));
  247. return;
  248. }
  249. if (inputs.original_password === inputs.set_new_password) {
  250. showError(t('新密码需要和原密码不一致!'));
  251. return;
  252. }
  253. if (inputs.set_new_password !== inputs.set_new_password_confirmation) {
  254. showError(t('两次输入的密码不一致!'));
  255. return;
  256. }
  257. const res = await API.put(`/api/user/self`, {
  258. original_password: inputs.original_password,
  259. password: inputs.set_new_password,
  260. });
  261. const { success, message } = res.data;
  262. if (success) {
  263. showSuccess(t('密码修改成功!'));
  264. setShowWeChatBindModal(false);
  265. } else {
  266. showError(message);
  267. }
  268. setShowChangePasswordModal(false);
  269. };
  270. const transfer = async () => {
  271. if (transferAmount < getQuotaPerUnit()) {
  272. showError(t('划转金额最低为') + ' ' + renderQuota(getQuotaPerUnit()));
  273. return;
  274. }
  275. const res = await API.post(`/api/user/aff_transfer`, {
  276. quota: transferAmount,
  277. });
  278. const { success, message } = res.data;
  279. if (success) {
  280. showSuccess(message);
  281. setOpenTransfer(false);
  282. getUserData().then();
  283. } else {
  284. showError(message);
  285. }
  286. };
  287. const sendVerificationCode = async () => {
  288. if (inputs.email === '') {
  289. showError(t('请输入邮箱!'));
  290. return;
  291. }
  292. setDisableButton(true);
  293. if (turnstileEnabled && turnstileToken === '') {
  294. showInfo(t('请稍后几秒重试,Turnstile 正在检查用户环境!'));
  295. return;
  296. }
  297. setLoading(true);
  298. const res = await API.get(
  299. `/api/verification?email=${inputs.email}&turnstile=${turnstileToken}`,
  300. );
  301. const { success, message } = res.data;
  302. if (success) {
  303. showSuccess(t('验证码发送成功,请检查邮箱!'));
  304. } else {
  305. showError(message);
  306. }
  307. setLoading(false);
  308. };
  309. const bindEmail = async () => {
  310. if (inputs.email_verification_code === '') {
  311. showError(t('请输入邮箱验证码!'));
  312. return;
  313. }
  314. setLoading(true);
  315. const res = await API.get(
  316. `/api/oauth/email/bind?email=${inputs.email}&code=${inputs.email_verification_code}`,
  317. );
  318. const { success, message } = res.data;
  319. if (success) {
  320. showSuccess(t('邮箱账户绑定成功!'));
  321. setShowEmailBindModal(false);
  322. userState.user.email = inputs.email;
  323. } else {
  324. showError(message);
  325. }
  326. setLoading(false);
  327. };
  328. const getUsername = () => {
  329. if (userState.user) {
  330. return userState.user.username;
  331. } else {
  332. return 'null';
  333. }
  334. };
  335. const getAvatarText = () => {
  336. const username = getUsername();
  337. if (username && username.length > 0) {
  338. // 获取前两个字符,支持中文和英文
  339. return username.slice(0, 2).toUpperCase();
  340. }
  341. return 'NA';
  342. };
  343. const handleCancel = () => {
  344. setOpenTransfer(false);
  345. };
  346. const copyText = async (text) => {
  347. if (await copy(text)) {
  348. showSuccess(t('已复制:') + text);
  349. } else {
  350. // setSearchKeyword(text);
  351. Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
  352. }
  353. };
  354. const handleNotificationSettingChange = (type, value) => {
  355. setNotificationSettings((prev) => ({
  356. ...prev,
  357. [type]: value.target ? value.target.value : value, // 处理 Radio 事件对象
  358. }));
  359. };
  360. const saveNotificationSettings = async () => {
  361. try {
  362. const res = await API.put('/api/user/setting', {
  363. notify_type: notificationSettings.warningType,
  364. quota_warning_threshold: parseFloat(
  365. notificationSettings.warningThreshold,
  366. ),
  367. webhook_url: notificationSettings.webhookUrl,
  368. webhook_secret: notificationSettings.webhookSecret,
  369. notification_email: notificationSettings.notificationEmail,
  370. accept_unset_model_ratio_model:
  371. notificationSettings.acceptUnsetModelRatioModel,
  372. });
  373. if (res.data.success) {
  374. showSuccess(t('通知设置已更新'));
  375. await getUserData();
  376. } else {
  377. showError(res.data.message);
  378. }
  379. } catch (error) {
  380. showError(t('更新通知设置失败'));
  381. }
  382. };
  383. return (
  384. <div className="min-h-screen bg-gray-50">
  385. <Layout>
  386. <Layout.Content>
  387. {/* 划转模态框 */}
  388. <Modal
  389. title={
  390. <div className="flex items-center">
  391. <IconCreditCard className="mr-2" />
  392. {t('请输入要划转的数量')}
  393. </div>
  394. }
  395. visible={openTransfer}
  396. onOk={transfer}
  397. onCancel={handleCancel}
  398. maskClosable={false}
  399. size={'small'}
  400. centered={true}
  401. >
  402. <div className="space-y-4 py-4">
  403. <div>
  404. <Typography.Text strong className="block mb-2">
  405. {t('可用额度')} {renderQuotaWithPrompt(userState?.user?.aff_quota)}
  406. </Typography.Text>
  407. <Input
  408. value={userState?.user?.aff_quota}
  409. disabled={true}
  410. size="large"
  411. className="!rounded-lg"
  412. />
  413. </div>
  414. <div>
  415. <Typography.Text strong className="block mb-2">
  416. {t('划转额度')} {renderQuotaWithPrompt(transferAmount)}{' '}
  417. {t('最低') + renderQuota(getQuotaPerUnit())}
  418. </Typography.Text>
  419. <InputNumber
  420. min={0}
  421. value={transferAmount}
  422. onChange={(value) => setTransferAmount(value)}
  423. disabled={false}
  424. size="large"
  425. className="!rounded-lg w-full"
  426. />
  427. </div>
  428. </div>
  429. </Modal>
  430. <div className="flex justify-center">
  431. <div className="w-full max-w-6xl">
  432. {/* 主卡片容器 */}
  433. <Card className="!rounded-2xl shadow-lg border-0">
  434. {/* 顶部用户信息区域 */}
  435. <Card
  436. className="!rounded-2xl !border-0 !shadow-2xl overflow-hidden"
  437. style={{
  438. background: 'linear-gradient(135deg, #6366f1 0%, #8b5cf6 25%, #a855f7 50%, #c084fc 75%, #d8b4fe 100%)',
  439. position: 'relative'
  440. }}
  441. bodyStyle={{ padding: 0 }}
  442. >
  443. {/* 装饰性背景元素 */}
  444. <div className="absolute inset-0 overflow-hidden">
  445. <div className="absolute -top-10 -right-10 w-40 h-40 bg-white opacity-5 rounded-full"></div>
  446. <div className="absolute -bottom-16 -left-16 w-48 h-48 bg-white opacity-3 rounded-full"></div>
  447. <div className="absolute top-1/2 right-1/4 w-24 h-24 bg-yellow-400 opacity-10 rounded-full"></div>
  448. </div>
  449. <div className="relative p-4 sm:p-6 md:p-8" style={{ color: 'white' }}>
  450. <div className="flex justify-between items-start mb-4 sm:mb-6">
  451. <div className="flex items-center flex-1 min-w-0">
  452. <Avatar
  453. size='large'
  454. color={stringToColor(getUsername())}
  455. border={{ motion: true }}
  456. contentMotion={true}
  457. className="mr-3 sm:mr-4 shadow-lg flex-shrink-0"
  458. >
  459. {getAvatarText()}
  460. </Avatar>
  461. <div className="flex-1 min-w-0">
  462. <div className="text-base sm:text-lg font-semibold truncate" style={{ color: 'white' }}>
  463. {getUsername()}
  464. </div>
  465. <div className="mt-1 flex flex-wrap gap-1 sm:gap-2">
  466. {isRoot() ? (
  467. <Tag
  468. color='red'
  469. size='small'
  470. style={{
  471. backgroundColor: 'rgba(255, 255, 255, 0.95)',
  472. color: '#dc2626',
  473. fontWeight: '600'
  474. }}
  475. className="!rounded-full"
  476. >
  477. {t('超级管理员')}
  478. </Tag>
  479. ) : isAdmin() ? (
  480. <Tag
  481. color='orange'
  482. size='small'
  483. style={{
  484. backgroundColor: 'rgba(255, 255, 255, 0.95)',
  485. color: '#ea580c',
  486. fontWeight: '600'
  487. }}
  488. className="!rounded-full"
  489. >
  490. {t('管理员')}
  491. </Tag>
  492. ) : (
  493. <Tag
  494. color='blue'
  495. size='small'
  496. style={{
  497. backgroundColor: 'rgba(255, 255, 255, 0.95)',
  498. color: '#2563eb',
  499. fontWeight: '600'
  500. }}
  501. className="!rounded-full"
  502. >
  503. {t('普通用户')}
  504. </Tag>
  505. )}
  506. <Tag
  507. color='green'
  508. size='small'
  509. className="!rounded-full"
  510. style={{
  511. backgroundColor: 'rgba(255, 255, 255, 0.95)',
  512. color: '#16a34a',
  513. fontWeight: '600'
  514. }}
  515. >
  516. ID: {userState?.user?.id}
  517. </Tag>
  518. </div>
  519. </div>
  520. </div>
  521. <div
  522. className="w-10 h-10 sm:w-12 sm:h-12 rounded-lg flex items-center justify-center shadow-lg flex-shrink-0 ml-2"
  523. style={{
  524. background: `linear-gradient(135deg, ${stringToColor(getUsername())} 0%, #f59e0b 100%)`
  525. }}
  526. >
  527. <IconUser size="default" style={{ color: 'white' }} />
  528. </div>
  529. </div>
  530. <div className="mb-4 sm:mb-6">
  531. <div className="text-xs sm:text-sm mb-1 sm:mb-2" style={{ color: 'rgba(255, 255, 255, 0.7)' }}>
  532. {t('当前余额')}
  533. </div>
  534. <div className="text-2xl sm:text-3xl md:text-4xl font-bold tracking-wide" style={{ color: 'white' }}>
  535. {renderQuota(userState?.user?.quota)}
  536. </div>
  537. </div>
  538. <div className="flex flex-col sm:flex-row sm:justify-between sm:items-end">
  539. <div className="grid grid-cols-3 gap-2 sm:flex sm:space-x-6 lg:space-x-8 mb-3 sm:mb-0">
  540. <div className="text-center sm:text-left">
  541. <div className="text-xs" style={{ color: 'rgba(255, 255, 255, 0.6)' }}>
  542. {t('历史消耗')}
  543. </div>
  544. <div className="text-xs sm:text-sm font-medium truncate" style={{ color: 'white' }}>
  545. {renderQuota(userState?.user?.used_quota)}
  546. </div>
  547. </div>
  548. <div className="text-center sm:text-left">
  549. <div className="text-xs" style={{ color: 'rgba(255, 255, 255, 0.6)' }}>
  550. {t('请求次数')}
  551. </div>
  552. <div className="text-xs sm:text-sm font-medium truncate" style={{ color: 'white' }}>
  553. {userState.user?.request_count || 0}
  554. </div>
  555. </div>
  556. <div className="text-center sm:text-left">
  557. <div className="text-xs" style={{ color: 'rgba(255, 255, 255, 0.6)' }}>
  558. {t('用户分组')}
  559. </div>
  560. <div className="text-xs sm:text-sm font-medium truncate" style={{ color: 'white' }}>
  561. {userState?.user?.group || t('默认')}
  562. </div>
  563. </div>
  564. </div>
  565. </div>
  566. <div className="absolute top-0 left-0 w-full h-2 bg-gradient-to-r from-yellow-400 via-orange-400 to-red-400" style={{ opacity: 0.6 }}></div>
  567. </div>
  568. </Card>
  569. {/* 主内容区域 - 使用Tabs组织不同功能模块 */}
  570. <div className="p-4">
  571. <Tabs type='line' defaultActiveKey='models' className="modern-tabs">
  572. {/* 模型与邀请Tab */}
  573. <TabPane
  574. tab={
  575. <div className="flex items-center">
  576. <Settings size={16} className="mr-2" />
  577. {t('模型与邀请')}
  578. </div>
  579. }
  580. itemKey='models'
  581. >
  582. <div className="grid grid-cols-1 lg:grid-cols-2 gap-6 py-4">
  583. {/* 可用模型部分 */}
  584. <div className="bg-gray-50 rounded-xl">
  585. <div className="flex items-center mb-4">
  586. <div className="w-10 h-10 rounded-full bg-purple-50 flex items-center justify-center mr-3">
  587. <Settings size={20} className="text-purple-500" />
  588. </div>
  589. <div>
  590. <Typography.Title heading={6} className="mb-0">{t('可用模型')}</Typography.Title>
  591. <div className="text-gray-500 text-sm">{t('点击模型名称可复制')}</div>
  592. </div>
  593. </div>
  594. <div className="bg-white rounded-lg p-3">
  595. {models.length <= MODELS_DISPLAY_COUNT ? (
  596. <Space wrap>
  597. {models.map((model) => (
  598. <Tag
  599. key={model}
  600. color={stringToColor(model)}
  601. onClick={() => copyText(model)}
  602. className="cursor-pointer hover:opacity-80 transition-opacity !rounded-lg"
  603. >
  604. {model}
  605. </Tag>
  606. ))}
  607. </Space>
  608. ) : (
  609. <>
  610. <Collapsible isOpen={isModelsExpanded}>
  611. <Space wrap>
  612. {models.map((model) => (
  613. <Tag
  614. key={model}
  615. color={stringToColor(model)}
  616. onClick={() => copyText(model)}
  617. className="cursor-pointer hover:opacity-80 transition-opacity !rounded-lg"
  618. >
  619. {model}
  620. </Tag>
  621. ))}
  622. <Tag
  623. color='grey'
  624. type='light'
  625. className="cursor-pointer !rounded-lg"
  626. onClick={() => setIsModelsExpanded(false)}
  627. icon={<IconChevronUp />}
  628. >
  629. {t('收起')}
  630. </Tag>
  631. </Space>
  632. </Collapsible>
  633. {!isModelsExpanded && (
  634. <Space wrap>
  635. {models
  636. .slice(0, MODELS_DISPLAY_COUNT)
  637. .map((model) => (
  638. <Tag
  639. key={model}
  640. color={stringToColor(model)}
  641. onClick={() => copyText(model)}
  642. className="cursor-pointer hover:opacity-80 transition-opacity !rounded-lg"
  643. >
  644. {model}
  645. </Tag>
  646. ))}
  647. <Tag
  648. color='grey'
  649. type='light'
  650. className="cursor-pointer !rounded-lg"
  651. onClick={() => setIsModelsExpanded(true)}
  652. icon={<IconChevronDown />}
  653. >
  654. {t('更多')} {models.length - MODELS_DISPLAY_COUNT} {t('个模型')}
  655. </Tag>
  656. </Space>
  657. )}
  658. </>
  659. )}
  660. </div>
  661. </div>
  662. {/* 邀请信息部分 */}
  663. <div className="bg-gray-50 rounded-xl">
  664. <div className="flex items-center mb-4">
  665. <div className="w-10 h-10 rounded-full bg-orange-50 flex items-center justify-center mr-3">
  666. <IconLink size={20} className="text-orange-500" />
  667. </div>
  668. <div>
  669. <Typography.Title heading={6} className="mb-0">{t('邀请信息')}</Typography.Title>
  670. <div className="text-gray-500 text-sm">{t('管理您的邀请链接和收益')}</div>
  671. </div>
  672. </div>
  673. <div className="space-y-3">
  674. <div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
  675. <Card
  676. className="!rounded-2xl text-center"
  677. bodyStyle={{ padding: '16px' }}
  678. shadows='hover'
  679. >
  680. <div className="text-gray-600 text-xs font-medium">{t('待使用收益')}</div>
  681. <div className="text-gray-900 text-lg font-bold mt-1">
  682. {renderQuota(userState?.user?.aff_quota)}
  683. </div>
  684. <Button
  685. type="primary"
  686. theme="solid"
  687. onClick={() => setOpenTransfer(true)}
  688. size="small"
  689. className="!rounded-lg !bg-blue-500 hover:!bg-blue-600 mt-2 w-full"
  690. icon={<IconCreditCard />}
  691. >
  692. {t('划转')}
  693. </Button>
  694. </Card>
  695. <Card
  696. className="!rounded-2xl text-center"
  697. bodyStyle={{ padding: '16px' }}
  698. shadows='hover'
  699. >
  700. <div className="text-gray-600 text-xs font-medium">{t('总收益')}</div>
  701. <div className="text-gray-900 text-lg font-bold mt-1">
  702. {renderQuota(userState?.user?.aff_history_quota)}
  703. </div>
  704. </Card>
  705. <Card
  706. className="!rounded-2xl text-center"
  707. bodyStyle={{ padding: '16px' }}
  708. shadows='hover'
  709. >
  710. <div className="text-gray-600 text-xs font-medium">{t('邀请人数')}</div>
  711. <div className="text-gray-900 text-lg font-bold mt-1">
  712. {userState?.user?.aff_count || 0}
  713. </div>
  714. </Card>
  715. </div>
  716. <div className="bg-white rounded-lg p-3">
  717. <Typography.Text strong className="block mb-2 text-sm">{t('邀请链接')}</Typography.Text>
  718. <Input
  719. value={affLink}
  720. onClick={handleAffLinkClick}
  721. readOnly
  722. size="large"
  723. className="!rounded-lg"
  724. prefix={<IconLink />}
  725. />
  726. </div>
  727. </div>
  728. </div>
  729. </div>
  730. </TabPane>
  731. {/* 账户绑定Tab */}
  732. <TabPane
  733. tab={
  734. <div className="flex items-center">
  735. <UserPlus size={16} className="mr-2" />
  736. {t('账户绑定')}
  737. </div>
  738. }
  739. itemKey='account'
  740. >
  741. <div className="py-4">
  742. <div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
  743. {/* 邮箱绑定 */}
  744. <Card
  745. className="!rounded-xl transition-shadow"
  746. bodyStyle={{ padding: '16px' }}
  747. shadows='hover'
  748. >
  749. <div className="flex items-center justify-between">
  750. <div className="flex items-center flex-1">
  751. <div className="w-10 h-10 rounded-full bg-red-50 flex items-center justify-center mr-3">
  752. <IconMail size="default" className="text-red-500" />
  753. </div>
  754. <div className="flex-1 min-w-0">
  755. <div className="font-medium text-gray-900">{t('邮箱')}</div>
  756. <div className="text-sm text-gray-500 truncate">
  757. {userState.user && userState.user.email !== ''
  758. ? userState.user.email
  759. : t('未绑定')}
  760. </div>
  761. </div>
  762. </div>
  763. <Button
  764. type="primary"
  765. theme="outline"
  766. size="small"
  767. onClick={() => setShowEmailBindModal(true)}
  768. className="!rounded-lg"
  769. >
  770. {userState.user && userState.user.email !== ''
  771. ? t('修改绑定')
  772. : t('绑定邮箱')}
  773. </Button>
  774. </div>
  775. </Card>
  776. {/* 微信绑定 */}
  777. <Card
  778. className="!rounded-xl transition-shadow"
  779. bodyStyle={{ padding: '16px' }}
  780. shadows='hover'
  781. >
  782. <div className="flex items-center justify-between">
  783. <div className="flex items-center flex-1">
  784. <div className="w-10 h-10 rounded-full bg-green-50 flex items-center justify-center mr-3">
  785. <SiWechat size={20} className="text-green-500" />
  786. </div>
  787. <div className="flex-1 min-w-0">
  788. <div className="font-medium text-gray-900">{t('微信')}</div>
  789. <div className="text-sm text-gray-500 truncate">
  790. {userState.user && userState.user.wechat_id !== ''
  791. ? t('已绑定')
  792. : t('未绑定')}
  793. </div>
  794. </div>
  795. </div>
  796. <Button
  797. type="primary"
  798. theme="outline"
  799. size="small"
  800. disabled={!status.wechat_login}
  801. onClick={() => setShowWeChatBindModal(true)}
  802. className="!rounded-lg"
  803. >
  804. {userState.user && userState.user.wechat_id !== ''
  805. ? t('修改绑定')
  806. : status.wechat_login
  807. ? t('绑定')
  808. : t('未启用')}
  809. </Button>
  810. </div>
  811. </Card>
  812. {/* GitHub绑定 */}
  813. <Card
  814. className="!rounded-xl transition-shadow"
  815. bodyStyle={{ padding: '16px' }}
  816. shadows='hover'
  817. >
  818. <div className="flex items-center justify-between">
  819. <div className="flex items-center flex-1">
  820. <div className="w-10 h-10 rounded-full bg-gray-100 flex items-center justify-center mr-3">
  821. <IconGithubLogo size="default" className="text-gray-700" />
  822. </div>
  823. <div className="flex-1 min-w-0">
  824. <div className="font-medium text-gray-900">{t('GitHub')}</div>
  825. <div className="text-sm text-gray-500 truncate">
  826. {userState.user && userState.user.github_id !== ''
  827. ? userState.user.github_id
  828. : t('未绑定')}
  829. </div>
  830. </div>
  831. </div>
  832. <Button
  833. type="primary"
  834. theme="outline"
  835. size="small"
  836. onClick={() => onGitHubOAuthClicked(status.github_client_id)}
  837. disabled={
  838. (userState.user && userState.user.github_id !== '') ||
  839. !status.github_oauth
  840. }
  841. className="!rounded-lg"
  842. >
  843. {status.github_oauth ? t('绑定') : t('未启用')}
  844. </Button>
  845. </div>
  846. </Card>
  847. {/* OIDC绑定 */}
  848. <Card
  849. className="!rounded-xl transition-shadow"
  850. bodyStyle={{ padding: '16px' }}
  851. shadows='hover'
  852. >
  853. <div className="flex items-center justify-between">
  854. <div className="flex items-center flex-1">
  855. <div className="w-10 h-10 rounded-full bg-indigo-50 flex items-center justify-center mr-3">
  856. <IconShield size="default" className="text-indigo-500" />
  857. </div>
  858. <div className="flex-1 min-w-0">
  859. <div className="font-medium text-gray-900">{t('OIDC')}</div>
  860. <div className="text-sm text-gray-500 truncate">
  861. {userState.user && userState.user.oidc_id !== ''
  862. ? userState.user.oidc_id
  863. : t('未绑定')}
  864. </div>
  865. </div>
  866. </div>
  867. <Button
  868. type="primary"
  869. theme="outline"
  870. size="small"
  871. onClick={() => onOIDCClicked(
  872. status.oidc_authorization_endpoint,
  873. status.oidc_client_id,
  874. )}
  875. disabled={
  876. (userState.user && userState.user.oidc_id !== '') ||
  877. !status.oidc_enabled
  878. }
  879. className="!rounded-lg"
  880. >
  881. {status.oidc_enabled ? t('绑定') : t('未启用')}
  882. </Button>
  883. </div>
  884. </Card>
  885. {/* Telegram绑定 */}
  886. <Card
  887. className="!rounded-xl transition-shadow"
  888. bodyStyle={{ padding: '16px' }}
  889. shadows='hover'
  890. >
  891. <div className="flex items-center justify-between">
  892. <div className="flex items-center flex-1">
  893. <div className="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
  894. <SiTelegram size={20} className="text-blue-500" />
  895. </div>
  896. <div className="flex-1 min-w-0">
  897. <div className="font-medium text-gray-900">{t('Telegram')}</div>
  898. <div className="text-sm text-gray-500 truncate">
  899. {userState.user && userState.user.telegram_id !== ''
  900. ? userState.user.telegram_id
  901. : t('未绑定')}
  902. </div>
  903. </div>
  904. </div>
  905. <div className="flex-shrink-0">
  906. {status.telegram_oauth ? (
  907. userState.user.telegram_id !== '' ? (
  908. <Button disabled={true} size="small" className="!rounded-lg">
  909. {t('已绑定')}
  910. </Button>
  911. ) : (
  912. <div className="scale-75">
  913. <TelegramLoginButton
  914. dataAuthUrl='/api/oauth/telegram/bind'
  915. botName={status.telegram_bot_name}
  916. />
  917. </div>
  918. )
  919. ) : (
  920. <Button disabled={true} size="small" className="!rounded-lg">
  921. {t('未启用')}
  922. </Button>
  923. )}
  924. </div>
  925. </div>
  926. </Card>
  927. {/* LinuxDO绑定 */}
  928. <Card
  929. className="!rounded-xl transition-shadow"
  930. bodyStyle={{ padding: '16px' }}
  931. shadows='hover'
  932. >
  933. <div className="flex items-center justify-between">
  934. <div className="flex items-center flex-1">
  935. <div className="w-10 h-10 rounded-full bg-orange-50 flex items-center justify-center mr-3">
  936. <SiLinux size={20} className="text-orange-500" />
  937. </div>
  938. <div className="flex-1 min-w-0">
  939. <div className="font-medium text-gray-900">{t('LinuxDO')}</div>
  940. <div className="text-sm text-gray-500 truncate">
  941. {userState.user && userState.user.linux_do_id !== ''
  942. ? userState.user.linux_do_id
  943. : t('未绑定')}
  944. </div>
  945. </div>
  946. </div>
  947. <Button
  948. type="primary"
  949. theme="outline"
  950. size="small"
  951. onClick={() => onLinuxDOOAuthClicked(status.linuxdo_client_id)}
  952. disabled={
  953. (userState.user && userState.user.linux_do_id !== '') ||
  954. !status.linuxdo_oauth
  955. }
  956. className="!rounded-lg"
  957. >
  958. {status.linuxdo_oauth ? t('绑定') : t('未启用')}
  959. </Button>
  960. </div>
  961. </Card>
  962. </div>
  963. </div>
  964. </TabPane>
  965. {/* 安全设置Tab */}
  966. <TabPane
  967. tab={
  968. <div className="flex items-center">
  969. <ShieldCheck size={16} className="mr-2" />
  970. {t('安全设置')}
  971. </div>
  972. }
  973. itemKey='security'
  974. >
  975. <div className="py-4">
  976. <div className="space-y-6">
  977. <Space vertical className='w-full'>
  978. {/* 系统访问令牌 */}
  979. <Card
  980. className="!rounded-xl w-full"
  981. bodyStyle={{ padding: '20px' }}
  982. shadows='hover'
  983. >
  984. <div className="flex flex-col sm:flex-row items-start sm:justify-between gap-4">
  985. <div className="flex items-start w-full sm:w-auto">
  986. <div className="w-12 h-12 rounded-full bg-blue-50 flex items-center justify-center mr-4 flex-shrink-0">
  987. <IconKey size="large" className="text-blue-500" />
  988. </div>
  989. <div className="flex-1">
  990. <Typography.Title heading={6} className="mb-1">
  991. {t('系统访问令牌')}
  992. </Typography.Title>
  993. <Typography.Text type="tertiary" className="text-sm">
  994. {t('用于API调用的身份验证令牌,请妥善保管')}
  995. </Typography.Text>
  996. {systemToken && (
  997. <div className="mt-3">
  998. <Input
  999. readOnly
  1000. value={systemToken}
  1001. onClick={handleSystemTokenClick}
  1002. size="large"
  1003. className="!rounded-lg"
  1004. prefix={<IconKey />}
  1005. />
  1006. </div>
  1007. )}
  1008. </div>
  1009. </div>
  1010. <Button
  1011. type="primary"
  1012. theme="solid"
  1013. onClick={generateAccessToken}
  1014. className="!rounded-lg !bg-blue-500 hover:!bg-blue-600 w-full sm:w-auto"
  1015. icon={<IconKey />}
  1016. >
  1017. {systemToken ? t('重新生成') : t('生成令牌')}
  1018. </Button>
  1019. </div>
  1020. </Card>
  1021. {/* 密码管理 */}
  1022. <Card
  1023. className="!rounded-xl w-full"
  1024. bodyStyle={{ padding: '20px' }}
  1025. shadows='hover'
  1026. >
  1027. <div className="flex flex-col sm:flex-row items-start sm:justify-between gap-4">
  1028. <div className="flex items-start w-full sm:w-auto">
  1029. <div className="w-12 h-12 rounded-full bg-orange-50 flex items-center justify-center mr-4 flex-shrink-0">
  1030. <IconLock size="large" className="text-orange-500" />
  1031. </div>
  1032. <div>
  1033. <Typography.Title heading={6} className="mb-1">
  1034. {t('密码管理')}
  1035. </Typography.Title>
  1036. <Typography.Text type="tertiary" className="text-sm">
  1037. {t('定期更改密码可以提高账户安全性')}
  1038. </Typography.Text>
  1039. </div>
  1040. </div>
  1041. <Button
  1042. type="primary"
  1043. theme="solid"
  1044. onClick={() => setShowChangePasswordModal(true)}
  1045. className="!rounded-lg !bg-orange-500 hover:!bg-orange-600 w-full sm:w-auto"
  1046. icon={<IconLock />}
  1047. >
  1048. {t('修改密码')}
  1049. </Button>
  1050. </div>
  1051. </Card>
  1052. {/* 危险区域 */}
  1053. <Card
  1054. className="!rounded-xl border-red-200 w-full"
  1055. bodyStyle={{ padding: '20px' }}
  1056. shadows='hover'
  1057. >
  1058. <div className="flex flex-col sm:flex-row items-start sm:justify-between gap-4">
  1059. <div className="flex items-start w-full sm:w-auto">
  1060. <div className="w-12 h-12 rounded-full bg-red-50 flex items-center justify-center mr-4 flex-shrink-0">
  1061. <IconDelete size="large" className="text-red-500" />
  1062. </div>
  1063. <div>
  1064. <Typography.Title heading={6} className="mb-1 text-red-600">
  1065. {t('删除账户')}
  1066. </Typography.Title>
  1067. <Typography.Text type="tertiary" className="text-sm">
  1068. {t('此操作不可逆,所有数据将被永久删除')}
  1069. </Typography.Text>
  1070. </div>
  1071. </div>
  1072. <Button
  1073. type="danger"
  1074. theme="solid"
  1075. onClick={() => setShowAccountDeleteModal(true)}
  1076. className="!rounded-lg w-full sm:w-auto"
  1077. icon={<IconDelete />}
  1078. >
  1079. {t('删除账户')}
  1080. </Button>
  1081. </div>
  1082. </Card>
  1083. </Space>
  1084. </div>
  1085. </div>
  1086. </TabPane>
  1087. {/* 通知设置Tab */}
  1088. <TabPane
  1089. tab={
  1090. <div className="flex items-center">
  1091. <Bell size={16} className="mr-2" />
  1092. {t('通知设置')}
  1093. </div>
  1094. }
  1095. itemKey='notification'
  1096. >
  1097. <div className="py-4">
  1098. <Tabs type='card' defaultActiveKey='notify' className="!rounded-lg">
  1099. <TabPane
  1100. tab={t('通知设置')}
  1101. itemKey='notify'
  1102. >
  1103. <div className="space-y-6">
  1104. {/* 通知方式选择 */}
  1105. <div className="bg-gray-50 rounded-xl">
  1106. <Typography.Text strong className="block mb-4 pt-4">{t('通知方式')}</Typography.Text>
  1107. <RadioGroup
  1108. value={notificationSettings.warningType}
  1109. onChange={(value) =>
  1110. handleNotificationSettingChange('warningType', value)
  1111. }
  1112. type="pureCard"
  1113. >
  1114. <Radio value='email' className="!p-4 !rounded-lg">
  1115. <div className="flex items-center">
  1116. <IconMail className="mr-2 text-blue-500" />
  1117. <div>
  1118. <div className="font-medium">{t('邮件通知')}</div>
  1119. <div className="text-sm text-gray-500">{t('通过邮件接收通知')}</div>
  1120. </div>
  1121. </div>
  1122. </Radio>
  1123. <Radio value='webhook' className="!p-4 !rounded-lg">
  1124. <div className="flex items-center">
  1125. <Webhook size={16} className="mr-2 text-green-500" />
  1126. <div>
  1127. <div className="font-medium">{t('Webhook通知')}</div>
  1128. <div className="text-sm text-gray-500">{t('通过HTTP请求接收通知')}</div>
  1129. </div>
  1130. </div>
  1131. </Radio>
  1132. </RadioGroup>
  1133. </div>
  1134. {/* Webhook设置 */}
  1135. {notificationSettings.warningType === 'webhook' && (
  1136. <div className="space-y-4">
  1137. <div className="bg-white rounded-xl">
  1138. <Typography.Text strong className="block mb-3">{t('Webhook地址')}</Typography.Text>
  1139. <Input
  1140. value={notificationSettings.webhookUrl}
  1141. onChange={(val) =>
  1142. handleNotificationSettingChange('webhookUrl', val)
  1143. }
  1144. placeholder={t('请输入Webhook地址,例如: https://example.com/webhook')}
  1145. size="large"
  1146. className="!rounded-lg"
  1147. prefix={<Webhook size={16} className="m-2" />}
  1148. />
  1149. <div className="text-gray-500 text-sm mt-2">
  1150. {t('只支持https,系统将以 POST 方式发送通知,请确保地址可以接收 POST 请求')}
  1151. </div>
  1152. </div>
  1153. <div className="bg-white rounded-xl">
  1154. <Typography.Text strong className="block mb-3">{t('接口凭证(可选)')}</Typography.Text>
  1155. <Input
  1156. value={notificationSettings.webhookSecret}
  1157. onChange={(val) =>
  1158. handleNotificationSettingChange('webhookSecret', val)
  1159. }
  1160. placeholder={t('请输入密钥')}
  1161. size="large"
  1162. className="!rounded-lg"
  1163. prefix={<IconKey />}
  1164. />
  1165. <div className="text-gray-500 text-sm mt-2">
  1166. {t('密钥将以 Bearer 方式添加到请求头中,用于验证webhook请求的合法性')}
  1167. </div>
  1168. </div>
  1169. <div className="bg-yellow-50 rounded-xl">
  1170. <div className="flex items-center justify-between cursor-pointer" onClick={() => setShowWebhookDocs(!showWebhookDocs)}>
  1171. <div className="flex items-center">
  1172. <Globe size={16} className="mr-2 text-yellow-600" />
  1173. <Typography.Text strong className="text-yellow-800">
  1174. {t('Webhook请求结构')}
  1175. </Typography.Text>
  1176. </div>
  1177. {showWebhookDocs ? <IconChevronUp /> : <IconChevronDown />}
  1178. </div>
  1179. <Collapsible isOpen={showWebhookDocs}>
  1180. <pre className="mt-4 bg-gray-800 text-gray-100 rounded-lg text-sm overflow-x-auto">
  1181. {`{
  1182. "type": "quota_exceed", // 通知类型
  1183. "title": "标题", // 通知标题
  1184. "content": "通知内容", // 通知内容,支持 {{value}} 变量占位符
  1185. "values": ["值1", "值2"], // 按顺序替换content中的 {{value}} 占位符
  1186. "timestamp": 1739950503 // 时间戳
  1187. }
  1188. 示例:
  1189. {
  1190. "type": "quota_exceed",
  1191. "title": "额度预警通知",
  1192. "content": "您的额度即将用尽,当前剩余额度为 {{value}}",
  1193. "values": ["$0.99"],
  1194. "timestamp": 1739950503
  1195. }`}
  1196. </pre>
  1197. </Collapsible>
  1198. </div>
  1199. </div>
  1200. )}
  1201. {/* 邮件设置 */}
  1202. {notificationSettings.warningType === 'email' && (
  1203. <div className="bg-white rounded-xl">
  1204. <Typography.Text strong className="block mb-3">{t('通知邮箱')}</Typography.Text>
  1205. <Input
  1206. value={notificationSettings.notificationEmail}
  1207. onChange={(val) =>
  1208. handleNotificationSettingChange('notificationEmail', val)
  1209. }
  1210. placeholder={t('留空则使用账号绑定的邮箱')}
  1211. size="large"
  1212. className="!rounded-lg"
  1213. prefix={<IconMail />}
  1214. />
  1215. <div className="text-gray-500 text-sm mt-2">
  1216. {t('设置用于接收额度预警的邮箱地址,不填则使用账号绑定的邮箱')}
  1217. </div>
  1218. </div>
  1219. )}
  1220. {/* 预警阈值 */}
  1221. <div className="bg-white rounded-xl">
  1222. <Typography.Text strong className="block mb-3">
  1223. {t('额度预警阈值')} {renderQuotaWithPrompt(notificationSettings.warningThreshold)}
  1224. </Typography.Text>
  1225. <AutoComplete
  1226. value={notificationSettings.warningThreshold}
  1227. onChange={(val) =>
  1228. handleNotificationSettingChange('warningThreshold', val)
  1229. }
  1230. size="large"
  1231. className="!rounded-lg w-full max-w-xs"
  1232. placeholder={t('请输入预警额度')}
  1233. data={[
  1234. { value: 100000, label: '0.2$' },
  1235. { value: 500000, label: '1$' },
  1236. { value: 1000000, label: '5$' },
  1237. { value: 5000000, label: '10$' },
  1238. ]}
  1239. prefix={<IconBell />}
  1240. />
  1241. <div className="text-gray-500 text-sm mt-2">
  1242. {t('当剩余额度低于此数值时,系统将通过选择的方式发送通知')}
  1243. </div>
  1244. </div>
  1245. </div>
  1246. </TabPane>
  1247. <TabPane
  1248. tab={t('价格设置')}
  1249. itemKey='price'
  1250. >
  1251. <div className="py-4">
  1252. <div className="bg-white rounded-xl">
  1253. <div className="flex items-start">
  1254. <div className="w-10 h-10 rounded-full bg-orange-50 flex items-center justify-center mt-1">
  1255. <Shield size={20} className="text-orange-500" />
  1256. </div>
  1257. <div className="flex-1">
  1258. <div className="flex items-center justify-between">
  1259. <div>
  1260. <Typography.Text strong className="block mb-2">
  1261. {t('接受未设置价格模型')}
  1262. </Typography.Text>
  1263. <div className="text-gray-500 text-sm">
  1264. {t('当模型没有设置价格时仍接受调用,仅当您信任该网站时使用,可能会产生高额费用')}
  1265. </div>
  1266. </div>
  1267. <Checkbox
  1268. checked={notificationSettings.acceptUnsetModelRatioModel}
  1269. onChange={(e) =>
  1270. handleNotificationSettingChange(
  1271. 'acceptUnsetModelRatioModel',
  1272. e.target.checked,
  1273. )
  1274. }
  1275. className="ml-4"
  1276. />
  1277. </div>
  1278. </div>
  1279. </div>
  1280. </div>
  1281. </div>
  1282. </TabPane>
  1283. </Tabs>
  1284. <div className="mt-6 flex justify-end">
  1285. <Button
  1286. type='primary'
  1287. onClick={saveNotificationSettings}
  1288. size="large"
  1289. className="!rounded-lg !bg-purple-500 hover:!bg-purple-600"
  1290. icon={<IconSetting />}
  1291. >
  1292. {t('保存设置')}
  1293. </Button>
  1294. </div>
  1295. </div>
  1296. </TabPane>
  1297. </Tabs>
  1298. </div>
  1299. </Card>
  1300. </div>
  1301. </div>
  1302. </Layout.Content>
  1303. </Layout>
  1304. {/* 邮箱绑定模态框 */}
  1305. <Modal
  1306. title={
  1307. <div className="flex items-center">
  1308. <IconMail className="mr-2 text-blue-500" />
  1309. {t('绑定邮箱地址')}
  1310. </div>
  1311. }
  1312. visible={showEmailBindModal}
  1313. onCancel={() => setShowEmailBindModal(false)}
  1314. onOk={bindEmail}
  1315. size={'small'}
  1316. centered={true}
  1317. maskClosable={false}
  1318. className="modern-modal"
  1319. >
  1320. <div className="space-y-4 py-4">
  1321. <div className="flex gap-3">
  1322. <Input
  1323. placeholder={t('输入邮箱地址')}
  1324. onChange={(value) => handleInputChange('email', value)}
  1325. name='email'
  1326. type='email'
  1327. size="large"
  1328. className="!rounded-lg flex-1"
  1329. prefix={<IconMail />}
  1330. />
  1331. <Button
  1332. onClick={sendVerificationCode}
  1333. disabled={disableButton || loading}
  1334. className="!rounded-lg"
  1335. type="primary"
  1336. theme="outline"
  1337. size='large'
  1338. >
  1339. {disableButton ? `${t('重新发送')} (${countdown})` : t('获取验证码')}
  1340. </Button>
  1341. </div>
  1342. <Input
  1343. placeholder={t('验证码')}
  1344. name='email_verification_code'
  1345. value={inputs.email_verification_code}
  1346. onChange={(value) =>
  1347. handleInputChange('email_verification_code', value)
  1348. }
  1349. size="large"
  1350. className="!rounded-lg"
  1351. prefix={<IconKey />}
  1352. />
  1353. {turnstileEnabled && (
  1354. <div className="flex justify-center">
  1355. <Turnstile
  1356. sitekey={turnstileSiteKey}
  1357. onVerify={(token) => {
  1358. setTurnstileToken(token);
  1359. }}
  1360. />
  1361. </div>
  1362. )}
  1363. </div>
  1364. </Modal>
  1365. {/* 微信绑定模态框 */}
  1366. <Modal
  1367. title={
  1368. <div className="flex items-center">
  1369. <SiWechat className="mr-2 text-green-500" size={20} />
  1370. {t('绑定微信账户')}
  1371. </div>
  1372. }
  1373. visible={showWeChatBindModal}
  1374. onCancel={() => setShowWeChatBindModal(false)}
  1375. footer={null}
  1376. size={'small'}
  1377. centered={true}
  1378. className="modern-modal"
  1379. >
  1380. <div className="space-y-4 py-4 text-center">
  1381. <Image src={status.wechat_qrcode} className="mx-auto" />
  1382. <div className="text-gray-600">
  1383. <p>{t('微信扫码关注公众号,输入「验证码」获取验证码(三分钟内有效)')}</p>
  1384. </div>
  1385. <Input
  1386. placeholder={t('验证码')}
  1387. name='wechat_verification_code'
  1388. value={inputs.wechat_verification_code}
  1389. onChange={(v) =>
  1390. handleInputChange('wechat_verification_code', v)
  1391. }
  1392. size="large"
  1393. className="!rounded-lg"
  1394. prefix={<IconKey />}
  1395. />
  1396. <Button
  1397. type="primary"
  1398. theme="solid"
  1399. size='large'
  1400. onClick={bindWeChat}
  1401. className="!rounded-lg w-full !bg-green-500 hover:!bg-green-600"
  1402. icon={<SiWechat size={16} />}
  1403. >
  1404. {t('绑定')}
  1405. </Button>
  1406. </div>
  1407. </Modal>
  1408. {/* 账户删除模态框 */}
  1409. <Modal
  1410. title={
  1411. <div className="flex items-center">
  1412. <IconDelete className="mr-2 text-red-500" />
  1413. {t('删除账户确认')}
  1414. </div>
  1415. }
  1416. visible={showAccountDeleteModal}
  1417. onCancel={() => setShowAccountDeleteModal(false)}
  1418. onOk={deleteAccount}
  1419. size={'small'}
  1420. centered={true}
  1421. className="modern-modal"
  1422. >
  1423. <div className="space-y-4 py-4">
  1424. <Banner
  1425. type='danger'
  1426. description={t('您正在删除自己的帐户,将清空所有数据且不可恢复')}
  1427. closeIcon={null}
  1428. className="!rounded-lg"
  1429. />
  1430. <div>
  1431. <Typography.Text strong className="block mb-2 text-red-600">
  1432. {t('请输入您的用户名以确认删除')}
  1433. </Typography.Text>
  1434. <Input
  1435. placeholder={t('输入你的账户名{{username}}以确认删除', { username: ` ${userState?.user?.username} ` })}
  1436. name='self_account_deletion_confirmation'
  1437. value={inputs.self_account_deletion_confirmation}
  1438. onChange={(value) =>
  1439. handleInputChange('self_account_deletion_confirmation', value)
  1440. }
  1441. size="large"
  1442. className="!rounded-lg"
  1443. prefix={<IconUser />}
  1444. />
  1445. </div>
  1446. {turnstileEnabled && (
  1447. <div className="flex justify-center">
  1448. <Turnstile
  1449. sitekey={turnstileSiteKey}
  1450. onVerify={(token) => {
  1451. setTurnstileToken(token);
  1452. }}
  1453. />
  1454. </div>
  1455. )}
  1456. </div>
  1457. </Modal>
  1458. {/* 修改密码模态框 */}
  1459. <Modal
  1460. title={
  1461. <div className="flex items-center">
  1462. <IconLock className="mr-2 text-orange-500" />
  1463. {t('修改密码')}
  1464. </div>
  1465. }
  1466. visible={showChangePasswordModal}
  1467. onCancel={() => setShowChangePasswordModal(false)}
  1468. onOk={changePassword}
  1469. size={'small'}
  1470. centered={true}
  1471. className="modern-modal"
  1472. >
  1473. <div className="space-y-4 py-4">
  1474. <div>
  1475. <Typography.Text strong className="block mb-2">{t('原密码')}</Typography.Text>
  1476. <Input
  1477. name='original_password'
  1478. placeholder={t('请输入原密码')}
  1479. type='password'
  1480. value={inputs.original_password}
  1481. onChange={(value) =>
  1482. handleInputChange('original_password', value)
  1483. }
  1484. size="large"
  1485. className="!rounded-lg"
  1486. prefix={<IconLock />}
  1487. />
  1488. </div>
  1489. <div>
  1490. <Typography.Text strong className="block mb-2">{t('新密码')}</Typography.Text>
  1491. <Input
  1492. name='set_new_password'
  1493. placeholder={t('请输入新密码')}
  1494. type='password'
  1495. value={inputs.set_new_password}
  1496. onChange={(value) =>
  1497. handleInputChange('set_new_password', value)
  1498. }
  1499. size="large"
  1500. className="!rounded-lg"
  1501. prefix={<IconLock />}
  1502. />
  1503. </div>
  1504. <div>
  1505. <Typography.Text strong className="block mb-2">{t('确认新密码')}</Typography.Text>
  1506. <Input
  1507. name='set_new_password_confirmation'
  1508. placeholder={t('请再次输入新密码')}
  1509. type='password'
  1510. value={inputs.set_new_password_confirmation}
  1511. onChange={(value) =>
  1512. handleInputChange('set_new_password_confirmation', value)
  1513. }
  1514. size="large"
  1515. className="!rounded-lg"
  1516. prefix={<IconLock />}
  1517. />
  1518. </div>
  1519. {turnstileEnabled && (
  1520. <div className="flex justify-center">
  1521. <Turnstile
  1522. sitekey={turnstileSiteKey}
  1523. onVerify={(token) => {
  1524. setTurnstileToken(token);
  1525. }}
  1526. />
  1527. </div>
  1528. )}
  1529. </div>
  1530. </Modal>
  1531. </div>
  1532. );
  1533. };
  1534. export default PersonalSetting;