PersonalSetting.js 69 KB

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