Skip to content

Let's use AI to Earn!

peizhi 1

daoyian3cc9c6e87748
diff --git a/src/api/youtube.ts b/src/api/youtube.ts
index a18dc82f..df12b34c 100644
--- a/src/api/youtube.ts
+++ b/src/api/youtube.ts
@@ -1,6 +1,10 @@
-import sxRequest from "@/utils/request";
+import sxRequest from '@/utils/request';
// 获取 YouTube 授权 URL
export const getYouTubeAuthUrlApi = (mail: string) => {
- return sxRequest.get<{ url: string }>(`plat/youtube/auth/url?mail=${mail}`);
+ return sxRequest.get(`plat/youtube/auth/url?mail=${mail}`);
+};
+
+export const checkYouTubeAuthApi = (mail: string) => {
+ return sxRequest.get(`plat/youtube/auth/check?mail=${mail}`);
};
\ No newline at end of file
diff --git a/src/app/[lng]/youtube/page.tsx b/src/app/[lng]/youtube/page.tsx
index ec17b065..86084eae 100644
--- a/src/app/[lng]/youtube/page.tsx
+++ b/src/app/[lng]/youtube/page.tsx
@@ -2,14 +2,40 @@
import React, { useState } from 'react';
import { useTransClient } from '@/app/i18n/client';
-import { Button, Input, message } from 'antd';
-import { MailOutlined } from '@ant-design/icons';
-import { getYouTubeAuthUrlApi } from '@/api/youtube';
+import { Button, Input, message, Card } from 'antd';
+import { MailOutlined, YoutubeOutlined, CheckOutlined } from '@ant-design/icons';
+import { getYouTubeAuthUrlApi, checkYouTubeAuthApi } from '@/api/youtube';
+import styles from './youtube.module.css';
const YouTubeAuth: React.FC = () => {
const { t } = useTransClient('youtube');
- const [email, setEmail] = useState('');
+ const [email, setEmail] = useState('[email protected]');
const [loading, setLoading] = useState(false);
+ const [checkLoading, setCheckLoading] = useState(false);
+ const [isAuthorized, setIsAuthorized] = useState(false);
+
+ const handleCheck = async () => {
+ if (!email) {
+ message.error(t('pleaseEnterEmail'));
+ return;
+ }
+
+ setCheckLoading(true);
+ try {
+ const response = await checkYouTubeAuthApi(email);
+ setIsAuthorized(response?.data?.authorized || false);
+ if (response?.data?.authorized) {
+ message.success(t('alreadyAuthorized'));
+ } else {
+ message.info(t('notAuthorized'));
+ }
+ } catch (error) {
+ console.error('检查授权状态失败:', error);
+ message.error(t('checkFailed'));
+ } finally {
+ setCheckLoading(false);
+ }
+ };
const handleAuth = async () => {
if (!email) {
@@ -25,8 +51,8 @@ const YouTubeAuth: React.FC = () => {
setLoading(true);
try {
const response = await getYouTubeAuthUrlApi(email);
- if (response?.data?.url) {
- window.location.href = response.data.url;
+ if (response?.data) {
+ window.open(response.data, '_blank', 'noopener,noreferrer');
}
} catch (error) {
console.error('获取授权 URL 失败:', error);
@@ -37,48 +63,65 @@ const YouTubeAuth: React.FC = () => {
};
return (
- <div className="min-h-screen flex items-center justify-center bg-gray-50">
- <div className="max-w-md w-full space-y-8 p-8 bg-white rounded-lg shadow-lg">
- <div>
- <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900">
+ <div className={styles.container}>
+ <Card
+ className={styles.card}
+ bodyStyle={{ padding: '2.5rem' }}
+ >
+ <div className={styles.header}>
+ <YoutubeOutlined className={styles.icon} />
+ <h2 className={styles.title}>
{t('youtubeAuth')}
</h2>
- <p className="mt-2 text-center text-sm text-gray-600">
+ <p className={styles.description}>
{t('authDescription')}
</p>
</div>
- <div className="mt-8 space-y-6">
- <div className="rounded-md shadow-sm -space-y-px">
- <div>
- <label htmlFor="email" className="sr-only">
- {t('email')}
- </label>
- <Input
- id="email"
- name="email"
- type="email"
- required
- className="appearance-none rounded-md relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
- placeholder={t('enterEmail')}
- value={email}
- onChange={(e) => setEmail(e.target.value)}
- prefix={<MailOutlined />}
- />
- </div>
+
+ <div className={styles.form}>
+ <div className={styles.formItem}>
+ <label htmlFor="email" className={styles.label}>
+ {t('email')}
+ </label>
+ <Input
+ id="email"
+ name="email"
+ type="email"
+ required
+ size="large"
+ className={styles.input}
+ placeholder={t('enterEmail')}
+ value={email}
+ onChange={(e) => setEmail(e.target.value)}
+ prefix={<MailOutlined className={styles.inputIcon} />}
+ />
</div>
- <div>
+ <div className={styles.buttonGroup}>
+ <Button
+ type="default"
+ size="large"
+ onClick={handleCheck}
+ loading={checkLoading}
+ className={styles.checkButton}
+ icon={<CheckOutlined />}
+ >
+ {t('checkAuth')}
+ </Button>
+
<Button
type="primary"
+ size="large"
onClick={handleAuth}
loading={loading}
- className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
+ className={styles.button}
+ icon={<YoutubeOutlined />}
>
{t('authorize')}
</Button>
</div>
</div>
- </div>
+ </Card>
</div>
);
};
diff --git a/src/app/[lng]/youtube/youtube.module.css b/src/app/[lng]/youtube/youtube.module.css
new file mode 100644
index 00000000..ed889607
--- /dev/null
+++ b/src/app/[lng]/youtube/youtube.module.css
@@ -0,0 +1,114 @@
+.container {
+ min-height: 100vh;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: linear-gradient(135deg, #f5f5f5 0%, #e5e5e5 100%);
+ padding: 3rem 1rem;
+}
+
+.card {
+ max-width: 28rem;
+ width: 100%;
+ margin: 0 auto;
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
+ border: none;
+}
+
+.header {
+ text-align: center;
+ margin-bottom: 2.5rem;
+}
+
+.icon {
+ font-size: 3rem;
+ color: #ff0000;
+ margin-bottom: 1.5rem;
+}
+
+.title {
+ font-size: 1.875rem;
+ font-weight: 700;
+ color: #1a1a1a;
+ margin-bottom: 0.75rem;
+}
+
+.description {
+ color: #666;
+ font-size: 1rem;
+}
+
+.authorized {
+ color: #52c41a;
+ font-size: 1rem;
+ margin-top: 1rem;
+ font-weight: 500;
+}
+
+.form {
+ display: flex;
+ flex-direction: column;
+ gap: 2rem;
+}
+
+.formItem {
+ display: flex;
+ flex-direction: column;
+}
+
+.label {
+ display: block;
+ font-size: 0.875rem;
+ font-weight: 500;
+ color: #4a4a4a;
+ margin-bottom: 0.5rem;
+}
+
+.input {
+ width: 100%;
+ height: 3rem;
+}
+
+.inputIcon {
+ color: #999;
+}
+
+.buttonGroup {
+ display: flex;
+ gap: 1rem;
+}
+
+.checkButton {
+ flex: 1;
+ height: 3rem;
+ font-size: 1rem;
+ font-weight: 500;
+ border-color: #d9d9d9;
+ transition: all 0.2s;
+}
+
+.checkButton:hover {
+ border-color: #ff0000;
+ color: #ff0000;
+}
+
+.button {
+ flex: 1;
+ height: 3rem;
+ font-size: 1rem;
+ font-weight: 500;
+ background-color: #ff0000;
+ border: none;
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
+ transition: all 0.2s;
+}
+
+.button:hover {
+ background-color: #cc0000;
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
+}
+
+.button:disabled {
+ background-color: #ff9999;
+ cursor: not-allowed;
+}
\ No newline at end of file
diff --git a/src/app/i18n/locales/en/youtube.json b/src/app/i18n/locales/en/youtube.json
index e243af2c..675919b5 100644
--- a/src/app/i18n/locales/en/youtube.json
+++ b/src/app/i18n/locales/en/youtube.json
@@ -6,5 +6,6 @@
"authorize": "Authorize",
"pleaseEnterEmail": "Please enter your email address",
"invalidEmail": "Please enter a valid email address",
- "authFailed": "Authorization failed, please try again later"
+ "authFailed": "Authorization failed, please try again later",
+ "checkAuth": "checkAuth"
}
\ No newline at end of file
diff --git a/src/app/i18n/locales/zh-CN/youtube.json b/src/app/i18n/locales/zh-CN/youtube.json
index 9c79673e..e838a38f 100644
--- a/src/app/i18n/locales/zh-CN/youtube.json
+++ b/src/app/i18n/locales/zh-CN/youtube.json
@@ -6,5 +6,6 @@
"authorize": "授权",
"pleaseEnterEmail": "请输入邮箱地址",
"invalidEmail": "请输入有效的邮箱地址",
- "authFailed": "授权失败,请稍后重试"
+ "authFailed": "授权失败,请稍后重试",
+ "checkAuth": "检查授权"
}
\ No newline at end of file