Skip to content

Let's use AI to Earn!

日历相关

daoyiana56bab0d1a4e
diff --git a/@types/resources.d.ts b/@types/resources.d.ts
index d751db09..7a4ba3a0 100644
--- a/@types/resources.d.ts
+++ b/@types/resources.d.ts
@@ -222,6 +222,23 @@ interface Resources {
"materialLibrary": "素材库",
"draftBox": "草稿箱"
},
+ "signIn": {
+ "title": "每日签到得积分",
+ "myPoints": "我的积分",
+ "signIn": "签到",
+ "today": "今天",
+ "rules": "签到规则",
+ "rules1": "连续签到 1-7天, 每天1积分",
+ "rules2": "连续签到 8-21天, 每天2积分",
+ "rules3": "连续签到 22天以上, 每天3积分",
+ "signedIn": "已签到",
+ "notSignedIn": "未签到",
+ "signInSuccess": "签到成功",
+ "signInFailed": "签到失败",
+ "alreadySignedIn": "今日已签到",
+ "consecutiveDays": "连续签到天数",
+ "totalPoints": "总积分"
+ },
"websit": {
"termsOfService": {
"title": "用户协议",
diff --git a/src/api/signIn.ts b/src/api/signIn.ts
index 3c152cd0..0fc5621b 100644
--- a/src/api/signIn.ts
+++ b/src/api/signIn.ts
@@ -32,4 +32,25 @@ export const signInApi = {
});
return res!.data;
},
+
+ /**
+ * 获取签到日历数据
+ */
+ async getSignInCalendar(year: number, month: number) {
+ const res = await http.get<any>(`reward/signIn/calendar`, {
+ isToken: true,
+ params: { year, month },
+ });
+ return res!.data;
+ },
+
+ /**
+ * 获取用户积分信息
+ */
+ async getUserPoints() {
+ const res = await http.get<any>(`reward/points`, {
+ isToken: true,
+ });
+ return res!.data;
+ },
};
diff --git a/src/app/i18n/locales/en/common.json b/src/app/i18n/locales/en/common.json
index 96549bbb..437ebbbf 100644
--- a/src/app/i18n/locales/en/common.json
+++ b/src/app/i18n/locales/en/common.json
@@ -30,6 +30,23 @@
"materialLibrary": "Material Library",
"draftBox": "Draft Box"
},
+ "signIn": {
+ "title": "Daily Sign-in to Earn Points",
+ "myPoints": "My Points",
+ "signIn": "Sign In",
+ "today": "Today",
+ "rules": "Sign-in Rules",
+ "rules1": "Consecutive sign-ins 1-7 days, 1 point per day",
+ "rules2": "Consecutive sign-ins 8-21 days, 2 points per day",
+ "rules3": "Consecutive sign-ins 22 days or more, 3 points per day",
+ "signedIn": "Signed In",
+ "notSignedIn": "Not Signed In",
+ "signInSuccess": "Sign-in successful",
+ "signInFailed": "Sign-in failed",
+ "alreadySignedIn": "Already signed in today",
+ "consecutiveDays": "Consecutive Days",
+ "totalPoints": "Total Points"
+ },
"websit": {
"termsOfService": {
"title": "Terms of Service",
diff --git a/src/app/i18n/locales/zh-CN/common.json b/src/app/i18n/locales/zh-CN/common.json
index edc74e8c..4da28105 100644
--- a/src/app/i18n/locales/zh-CN/common.json
+++ b/src/app/i18n/locales/zh-CN/common.json
@@ -30,6 +30,23 @@
"materialLibrary": "素材库",
"draftBox": "草稿箱"
},
+ "signIn": {
+ "title": "每日签到得积分",
+ "myPoints": "我的积分",
+ "signIn": "签到",
+ "today": "今天",
+ "rules": "签到规则",
+ "rules1": "连续签到 1-7天, 每天1积分",
+ "rules2": "连续签到 8-21天, 每天2积分",
+ "rules3": "连续签到 22天以上, 每天3积分",
+ "signedIn": "已签到",
+ "notSignedIn": "未签到",
+ "signInSuccess": "签到成功",
+ "signInFailed": "签到失败",
+ "alreadySignedIn": "今日已签到",
+ "consecutiveDays": "连续签到天数",
+ "totalPoints": "总积分"
+ },
"websit": {
"termsOfService": {
"title": "用户协议",
diff --git a/src/app/layout/LyaoutHeader.tsx b/src/app/layout/LyaoutHeader.tsx
index 87ee7137..32484f87 100644
--- a/src/app/layout/LyaoutHeader.tsx
+++ b/src/app/layout/LyaoutHeader.tsx
@@ -19,6 +19,7 @@ import { useRouter } from "next/navigation";
import { useTransClient } from "@/app/i18n/client";
import NotificationPanel from "@/components/notification/NotificationPanel";
import { useNotification } from "@/hooks/useNotification";
+import SignInCalendar from "@/components/SignInCalendar";
export interface ILyaoutHeaderRef {}
@@ -157,6 +158,9 @@ const LyaoutHeader = memo(
{userStore.lang === "zh-CN" ? "EN" : "中文"}
</Button>
<NoSSR>
+ {userStore.token && (
+ <SignInCalendar className={styles.signInCalendarButton} />
+ )}
{userStore.token && (
<Badge count={unreadCount} size="small">
<Button
diff --git a/src/app/layout/styles/lyaoutHeader.module.scss b/src/app/layout/styles/lyaoutHeader.module.scss
index 8e7806d1..54f8a7c3 100644
--- a/src/app/layout/styles/lyaoutHeader.module.scss
+++ b/src/app/layout/styles/lyaoutHeader.module.scss
@@ -106,6 +106,26 @@
color: #666;
}
}
+
+ .signInCalendarButton {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 40px;
+ height: 40px;
+ border-radius: 50%;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background-color: #f5f5f5;
+ transform: scale(1.05);
+ }
+
+ .anticon {
+ font-size: 18px;
+ color: #666;
+ }
+ }
}
}
}
diff --git a/src/components/SignInCalendar/SignInCalendar.module.scss b/src/components/SignInCalendar/SignInCalendar.module.scss
new file mode 100644
index 00000000..185c1896
--- /dev/null
+++ b/src/components/SignInCalendar/SignInCalendar.module.scss
@@ -0,0 +1,232 @@
+.signInButton {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 40px;
+ height: 40px;
+ border-radius: 50%;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background-color: #f5f5f5;
+ transform: scale(1.05);
+ }
+
+ .anticon {
+ font-size: 18px;
+ color: #666;
+ }
+}
+
+.signInModal {
+ .ant-modal-header {
+ border-bottom: 1px solid #f0f0f0;
+ padding: 16px 24px;
+ }
+
+ .ant-modal-body {
+ padding: 24px;
+ }
+}
+
+.modalHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ width: 100%;
+
+ span {
+ font-size: 16px;
+ font-weight: 600;
+ color: #333;
+ }
+}
+
+.pointsLink {
+ color: #722ed1;
+ font-size: 14px;
+ padding: 0;
+ height: auto;
+
+ &:hover {
+ color: #9254de;
+ }
+}
+
+.calendarContainer {
+ .ant-picker-calendar {
+ border: none;
+
+ .ant-picker-calendar-header {
+ padding: 0;
+ margin-bottom: 16px;
+ }
+
+ .ant-picker-calendar-date {
+ border: none;
+ padding: 4px;
+ height: 32px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ &:hover {
+ background-color: #f5f5f5;
+ }
+ }
+
+ .ant-picker-calendar-date-today {
+ background-color: #e6f7ff;
+ border: 1px solid #1890ff;
+ }
+
+ .ant-picker-calendar-date-value {
+ font-size: 12px;
+ line-height: 1;
+ }
+
+ .ant-picker-calendar-date-content {
+ height: auto;
+ line-height: 1;
+ }
+ }
+}
+
+.calendarHeader {
+ text-align: center;
+ font-size: 16px;
+ font-weight: 600;
+ color: #333;
+ padding: 8px 0;
+}
+
+.calendarCell {
+ position: relative;
+ width: 100%;
+ height: 100%;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+}
+
+.signInBadge {
+ position: absolute;
+ top: 2px;
+ right: 2px;
+
+ .ant-badge-count {
+ background: #52c41a;
+ box-shadow: none;
+ min-width: 16px;
+ height: 16px;
+ line-height: 16px;
+ border-radius: 50%;
+ font-size: 10px;
+ }
+}
+
+.dateText {
+ font-size: 12px;
+ color: #333;
+
+ &.today {
+ color: #1890ff;
+ font-weight: 600;
+ }
+}
+
+.signInRules {
+ margin: 20px 0;
+ padding: 16px;
+ background-color: #f8f9fa;
+ border-radius: 8px;
+
+ h4 {
+ margin: 0 0 12px 0;
+ font-size: 14px;
+ font-weight: 600;
+ color: #333;
+ }
+
+ ul {
+ margin: 0;
+ padding-left: 16px;
+
+ li {
+ margin-bottom: 8px;
+ font-size: 12px;
+ color: #666;
+ line-height: 1.4;
+
+ &:last-child {
+ margin-bottom: 0;
+ }
+ }
+ }
+}
+
+.signInInfo {
+ display: flex;
+ justify-content: space-between;
+ margin-bottom: 20px;
+ padding: 12px 16px;
+ background-color: #f0f8ff;
+ border-radius: 6px;
+
+ .infoItem {
+ font-size: 13px;
+ color: #1890ff;
+ font-weight: 500;
+ }
+}
+
+.signInActionButton {
+ height: 44px;
+ font-size: 16px;
+ font-weight: 600;
+ border-radius: 8px;
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
+ border: none;
+
+ &:hover {
+ background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
+ transform: translateY(-1px);
+ box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
+ }
+
+ &:disabled {
+ background: #f5f5f5;
+ color: #999;
+ transform: none;
+ box-shadow: none;
+ }
+}
+
+// 响应式设计
+@media (max-width: 480px) {
+ .signInModal {
+ .ant-modal {
+ width: 90% !important;
+ max-width: 450px;
+ }
+ }
+
+ .calendarContainer {
+ .ant-picker-calendar-date {
+ height: 28px;
+ }
+
+ .dateText {
+ font-size: 11px;
+ }
+ }
+
+ .signInInfo {
+ flex-direction: column;
+ gap: 8px;
+
+ .infoItem {
+ text-align: center;
+ }
+ }
+}
diff --git a/src/components/SignInCalendar/index.ts b/src/components/SignInCalendar/index.ts
new file mode 100644
index 00000000..dd7dc300
--- /dev/null
+++ b/src/components/SignInCalendar/index.ts
@@ -0,0 +1 @@
+export { default } from './index';
diff --git a/src/components/SignInCalendar/index.tsx b/src/components/SignInCalendar/index.tsx
new file mode 100644
index 00000000..5d8f161c
--- /dev/null
+++ b/src/components/SignInCalendar/index.tsx
@@ -0,0 +1,187 @@
+"use client";
+
+import React, { useState, useEffect, useMemo } from 'react';
+import { Button, Modal, Calendar, Badge, message } from 'antd';
+import { CalendarOutlined, CheckOutlined } from '@ant-design/icons';
+import { useTransClient } from '@/app/i18n/client';
+import { signInApi, SignInType } from '@/api/signIn';
+import styles from './SignInCalendar.module.scss';
+
+interface SignInCalendarProps {
+ className?: string;
+}
+
+interface CalendarData {
+ signedDates: string[]; // 已签到的日期数组,格式: "YYYY-MM-DD"
+ todaySigned: boolean; // 今天是否已签到
+ consecutiveDays: number; // 连续签到天数
+ totalPoints: number; // 总积分
+}
+
+const SignInCalendar: React.FC<SignInCalendarProps> = ({ className }) => {
+ const { t } = useTransClient('common');
+ const [visible, setVisible] = useState(false);
+ const [loading, setLoading] = useState(false);
+ const [calendarData, setCalendarData] = useState<CalendarData>({
+ signedDates: [],
+ todaySigned: false,
+ consecutiveDays: 0,
+ totalPoints: 0
+ });
+ const [currentDate, setCurrentDate] = useState(new Date());
+
+ // 获取当前年月
+ const currentYear = currentDate.getFullYear();
+ const currentMonth = currentDate.getMonth() + 1;
+
+ // 获取日历数据
+ const fetchCalendarData = async () => {
+ try {
+ setLoading(true);
+ const data = await signInApi.getSignInCalendar(currentYear, currentMonth);
+ setCalendarData(data);
+ } catch (error) {
+ console.error('获取签到日历数据失败:', error);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ // 签到
+ const handleSignIn = async () => {
+ if (calendarData.todaySigned) {
+ message.warning(t('signIn.alreadySignedIn'));
+ return;
+ }
+
+ try {
+ setLoading(true);
+ await signInApi.createSignInRecord(SignInType.PUL_VIDEO);
+ message.success(t('signIn.signInSuccess'));
+ // 重新获取日历数据
+ await fetchCalendarData();
+ } catch (error) {
+ console.error('签到失败:', error);
+ message.error(t('signIn.signInFailed'));
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ // 日历日期渲染
+ const dateCellRender = (value: any) => {
+ const dateStr = value.format('YYYY-MM-DD');
+ const isSigned = calendarData.signedDates.includes(dateStr);
+ const isToday = value.isSame(new Date(), 'day');
+
+ return (
+ <div className={styles.calendarCell}>
+ {isSigned && (
+ <Badge
+ count={<CheckOutlined style={{ color: '#52c41a', fontSize: '12px' }} />}
+ className={styles.signInBadge}
+ />
+ )}
+ <span className={`${styles.dateText} ${isToday ? styles.today : ''}`}>
+ {isToday ? t('signIn.today') : value.date()}
+ </span>
+ </div>
+ );
+ };
+
+ // 月份变化处理
+ const onPanelChange = (value: any) => {
+ setCurrentDate(value.toDate());
+ };
+
+ // 监听月份变化,重新获取数据
+ useEffect(() => {
+ if (visible) {
+ fetchCalendarData();
+ }
+ }, [currentYear, currentMonth, visible]);
+
+ return (
+ <>
+ <Button
+ type="text"
+ icon={<CalendarOutlined />}
+ onClick={() => setVisible(true)}
+ className={`${styles.signInButton} ${className || ''}`}
+ title={t('signIn.title')}
+ />
+
+ <Modal
+ title={
+ <div className={styles.modalHeader}>
+ <span>{t('signIn.title')}</span>
+ <Button
+ type="link"
+ className={styles.pointsLink}
+ onClick={() => {
+ // 跳转到积分页面
+ window.open('/points', '_blank');
+ }}
+ >
+ {t('signIn.myPoints')} &gt;
+ </Button>
+ </div>
+ }
+ open={visible}
+ onCancel={() => setVisible(false)}
+ footer={null}
+ width={500}
+ className={styles.signInModal}
+ >
+ <div className={styles.calendarContainer}>
+ <Calendar
+ fullscreen={false}
+ dateCellRender={dateCellRender}
+ onPanelChange={onPanelChange}
+ headerRender={({ value, onChange }) => {
+ const year = value.year();
+ const month = value.month() + 1;
+ return (
+ <div className={styles.calendarHeader}>
+ <span>{year} / {month.toString().padStart(2, '0')}</span>
+ </div>
+ );
+ }}
+ />
+
+ <div className={styles.signInRules}>
+ <h4>{t('signIn.rules')}:</h4>
+ <ul>
+ <li>{t('signIn.rules1')}</li>
+ <li>{t('signIn.rules2')}</li>
+ <li>{t('signIn.rules3')}</li>
+ </ul>
+ </div>
+
+ <div className={styles.signInInfo}>
+ <div className={styles.infoItem}>
+ <span>{t('signIn.consecutiveDays')}: {calendarData.consecutiveDays}</span>
+ </div>
+ <div className={styles.infoItem}>
+ <span>{t('signIn.totalPoints')}: {calendarData.totalPoints}</span>
+ </div>
+ </div>
+
+ <Button
+ type="primary"
+ size="large"
+ onClick={handleSignIn}
+ loading={loading}
+ disabled={calendarData.todaySigned}
+ className={styles.signInActionButton}
+ block
+ >
+ {calendarData.todaySigned ? t('signIn.signedIn') : t('signIn.signIn')}
+ </Button>
+ </div>
+ </Modal>
+ </>
+ );
+};
+
+export default SignInCalendar;