Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,662 @@
/*
Copyright (C) 2025 QuantumNous
Video Tutorial Component Styles
*/
/* ===== 容器 ===== */
.video-tutorial {
display: flex;
flex-direction: column;
gap: 28px;
position: relative;
}
/* 装饰性背景元素 */
.video-tutorial::before {
content: '';
position: absolute;
top: -20px;
right: -20px;
width: 200px;
height: 200px;
background: radial-gradient(
circle,
color-mix(in srgb, var(--brand-primary) 8%, transparent) 0%,
transparent 70%
);
border-radius: 50%;
pointer-events: none;
z-index: -1;
}
.video-tutorial::after {
content: '';
position: absolute;
bottom: 20%;
left: -30px;
width: 150px;
height: 150px;
background: radial-gradient(
circle,
rgba(236, 72, 153, 0.06) 0%,
transparent 70%
);
border-radius: 50%;
pointer-events: none;
z-index: -1;
}
.video-tutorial-loading,
.video-tutorial-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 450px;
text-align: center;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 3%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 3%, transparent)
);
border-radius: 24px;
border: 2px dashed color-mix(in srgb, var(--brand-primary) 20%, transparent);
}
.video-tutorial-loading .semi-spin {
margin-bottom: 16px;
}
.video-tutorial-empty .semi-icon {
color: color-mix(in srgb, var(--brand-primary) 40%, transparent);
margin-bottom: 16px;
}
/* ===== 视频播放器区域 ===== */
.video-player-section {
width: 100%;
}
.video-player-card {
border-radius: 16px !important;
overflow: hidden;
border: 1px solid var(--semi-color-border) !important;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.video-player-wrapper {
position: relative;
width: 100%;
padding-top: 56.25%; /* 16:9 宽高比 */
background: #000;
}
.video-player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: contain;
}
/* 视频错误状态 */
.video-error {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20px;
background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
color: white;
z-index: 5;
}
.video-error .semi-icon {
font-size: 72px;
opacity: 0.4;
animation: errorPulse 2s ease-in-out infinite;
}
@keyframes errorPulse {
0%,
100% {
opacity: 0.4;
transform: scale(1);
}
50% {
opacity: 0.6;
transform: scale(1.05);
}
}
.video-retry-btn {
padding: 12px 32px;
background: linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-via));
border: none;
border-radius: 14px;
color: white;
font-weight: 600;
font-size: 14px;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
.video-retry-btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent,
rgba(255, 255, 255, 0.3),
transparent
);
transition: left 0.5s ease;
}
.video-retry-btn:hover::before {
left: 100%;
}
.video-retry-btn:hover {
transform: translateY(-3px) scale(1.02);
box-shadow: 0 12px 28px color-mix(in srgb, var(--brand-primary) 50%, transparent);
}
/* 视频信息 */
.video-info {
padding: 28px;
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.8),
rgba(255, 255, 255, 0.6)
);
backdrop-filter: blur(10px);
position: relative;
}
.video-info::before {
content: '🎬';
position: absolute;
top: 24px;
right: 24px;
font-size: 32px;
opacity: 0.15;
}
.video-title {
margin-bottom: 10px !important;
color: var(--semi-color-text-0);
font-size: 20px !important;
font-weight: 600 !important;
background: linear-gradient(135deg, #1a1a2e, #374151);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.video-description {
margin-bottom: 18px;
line-height: 1.7;
color: var(--semi-color-text-1);
}
.video-meta {
display: flex;
gap: 24px;
flex-wrap: wrap;
}
.video-meta-item {
display: flex;
align-items: center;
gap: 8px;
color: var(--semi-color-text-2);
font-size: 13px;
padding: 6px 14px;
background: color-mix(in srgb, var(--brand-primary) 6%, transparent);
border-radius: 20px;
transition: all 0.3s ease;
}
.video-meta-item:hover {
background: color-mix(in srgb, var(--brand-primary) 12%, transparent);
transform: translateY(-1px);
}
.video-meta-item .semi-icon {
color: var(--brand-primary);
font-size: 14px;
}
/* ===== 视频列表 ===== */
.video-list-section {
width: 100%;
position: relative;
}
.video-list-title {
margin-bottom: 20px !important;
padding-left: 8px;
display: flex;
align-items: center;
gap: 10px;
font-size: 18px !important;
}
.video-list-title::before {
content: '';
width: 4px;
height: 20px;
background: linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-via));
border-radius: 2px;
}
.video-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 18px;
}
.video-list-item {
display: flex;
gap: 16px;
padding: 16px;
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.9),
rgba(255, 255, 255, 0.7)
);
backdrop-filter: blur(10px);
border: 2px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
border-radius: 18px;
cursor: pointer;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
overflow: hidden;
}
/* 列表项悬停装饰 */
.video-list-item::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 4px;
height: 100%;
background: linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-via));
transform: scaleY(0);
transition: transform 0.3s ease;
border-radius: 0 4px 4px 0;
}
.video-list-item:hover::before {
transform: scaleY(1);
}
.video-list-item:hover {
background: linear-gradient(
135deg,
rgba(255, 255, 255, 0.95),
rgba(249, 250, 251, 0.9)
);
border-color: color-mix(in srgb, var(--brand-primary) 25%, transparent);
transform: translateY(-4px) translateX(4px);
box-shadow:
0 12px 32px color-mix(in srgb, var(--brand-primary) 12%, transparent),
0 4px 12px rgba(0, 0, 0, 0.06);
}
.video-list-item.active {
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 12%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 8%, transparent)
);
border-color: color-mix(in srgb, var(--brand-primary) 40%, transparent);
box-shadow:
0 8px 24px color-mix(in srgb, var(--brand-primary) 20%, transparent),
inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.video-list-item.active::before {
transform: scaleY(1);
background: linear-gradient(135deg, var(--brand-primary), #ec4899);
}
/* 正在播放标识 */
.video-list-item.active::after {
content: '▶';
position: absolute;
top: 8px;
right: 8px;
width: 24px;
height: 24px;
background: linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-via));
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 10px;
color: white;
animation: playingPulse 1.5s ease-in-out infinite;
}
@keyframes playingPulse {
0%,
100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.1);
opacity: 0.8;
}
}
.video-list-thumbnail {
position: relative;
width: 110px;
height: 66px;
flex-shrink: 0;
border-radius: 12px;
overflow: hidden;
background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.video-list-thumbnail img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.4s ease;
}
.video-list-item:hover .video-list-thumbnail img {
transform: scale(1.08);
}
.video-thumbnail-placeholder {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: rgba(255, 255, 255, 0.4);
font-size: 24px;
}
.video-list-index {
position: absolute;
top: 6px;
left: 6px;
width: 22px;
height: 22px;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 90%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 90%, transparent)
);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
font-weight: 700;
color: white;
box-shadow: 0 2px 8px color-mix(in srgb, var(--brand-primary) 40%, transparent);
}
.video-list-duration {
position: absolute;
bottom: 6px;
right: 6px;
padding: 3px 8px;
background: rgba(0, 0, 0, 0.85);
border-radius: 6px;
font-size: 11px;
font-weight: 500;
color: white;
letter-spacing: 0.5px;
}
.video-list-info {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
justify-content: center;
gap: 6px;
}
.video-list-name {
line-height: 1.5;
font-weight: 600 !important;
color: var(--semi-color-text-0) !important;
transition: color 0.3s ease;
}
.video-list-item:hover .video-list-name {
color: var(--brand-primary) !important;
}
.video-list-item.active .video-list-name {
color: var(--brand-primary) !important;
}
.video-list-desc {
line-height: 1.4;
font-size: 12px;
}
/* ===== 提示卡片 ===== */
.video-tips {
margin-top: 8px;
}
.video-tips-card {
border-radius: 20px !important;
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 6%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 6%, transparent),
rgba(236, 72, 153, 0.04)
) !important;
border: 2px solid color-mix(in srgb, var(--brand-primary) 15%, transparent) !important;
position: relative;
overflow: hidden;
transition: all 0.3s ease;
}
.video-tips-card:hover {
border-color: color-mix(in srgb, var(--brand-primary) 25%, transparent) !important;
transform: translateY(-2px);
box-shadow: 0 8px 24px color-mix(in srgb, var(--brand-primary) 10%, transparent);
}
.video-tips-card::before {
content: '';
position: absolute;
top: -50%;
right: -10%;
width: 200px;
height: 200px;
background: radial-gradient(
circle,
color-mix(in srgb, var(--brand-primary) 8%, transparent) 0%,
transparent 70%
);
pointer-events: none;
}
.video-tips-content {
display: flex;
align-items: flex-start;
gap: 18px;
position: relative;
z-index: 1;
}
.video-tips-icon {
font-size: 32px;
line-height: 1;
animation: tipBounce 2s ease-in-out infinite;
}
@keyframes tipBounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(-4px);
}
}
.video-tips-content strong {
color: var(--brand-primary);
font-size: 15px;
}
/* ===== 响应式 ===== */
@media (max-width: 768px) {
.video-tutorial::before,
.video-tutorial::after {
display: none;
}
.video-list {
grid-template-columns: 1fr;
gap: 12px;
}
.video-list-item {
padding: 14px;
border-radius: 14px;
}
.video-list-thumbnail {
width: 90px;
height: 54px;
border-radius: 10px;
}
.video-info {
padding: 20px;
}
.video-info::before {
display: none;
}
.video-title {
font-size: 17px !important;
}
.video-player-card {
border-radius: 18px !important;
}
.video-tips-content {
gap: 14px;
}
.video-tips-icon {
font-size: 26px;
}
}
/* ===== 深色模式 ===== */
html.dark .video-tutorial-loading,
html.dark .video-tutorial-empty {
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 5%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 5%, transparent)
);
border-color: color-mix(in srgb, var(--brand-primary) 15%, transparent);
}
html.dark .video-player-card {
background: var(--semi-color-bg-1);
border-color: color-mix(in srgb, var(--brand-primary) 20%, transparent) !important;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
html.dark .video-info {
background: linear-gradient(
135deg,
rgba(30, 30, 40, 0.8),
rgba(25, 25, 35, 0.6)
);
}
html.dark .video-title {
background: linear-gradient(135deg, #e5e7eb, #d1d5db);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
html.dark .video-meta-item {
background: color-mix(in srgb, var(--brand-primary) 12%, transparent);
}
html.dark .video-meta-item:hover {
background: color-mix(in srgb, var(--brand-primary) 20%, transparent);
}
html.dark .video-list-item {
background: linear-gradient(
135deg,
rgba(30, 30, 40, 0.9),
rgba(25, 25, 35, 0.7)
);
border-color: color-mix(in srgb, var(--brand-primary) 15%, transparent);
}
html.dark .video-list-item:hover {
background: linear-gradient(
135deg,
rgba(40, 40, 55, 0.9),
rgba(35, 35, 50, 0.8)
);
border-color: color-mix(in srgb, var(--brand-primary) 30%, transparent);
box-shadow:
0 12px 32px rgba(0, 0, 0, 0.3),
0 4px 12px rgba(0, 0, 0, 0.2);
}
html.dark .video-list-item.active {
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 18%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 15%, transparent)
);
border-color: color-mix(in srgb, var(--brand-primary) 40%, transparent);
}
html.dark .video-tips-card {
background: linear-gradient(
135deg,
color-mix(in srgb, var(--brand-primary) 10%, transparent),
color-mix(in srgb, var(--brand-gradient-via) 10%, transparent)
) !important;
border-color: color-mix(in srgb, var(--brand-primary) 25%, transparent) !important;
}
html.dark .video-tips-content strong {
color: var(--brand-gradient-from);
}
@@ -0,0 +1,268 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Typography, Card, Empty, Spin, Toast } from '@douyinfe/semi-ui';
import { IconPlayCircle, IconClock, IconFile } from '@douyinfe/semi-icons';
import { API } from '../../../helpers';
import './VideoTutorial.css';
const { Title, Text, Paragraph } = Typography;
const VideoTutorial = () => {
const { t } = useTranslation();
const [videos, setVideos] = useState([]);
const [currentVideo, setCurrentVideo] = useState(null);
const [loading, setLoading] = useState(true);
const [videoError, setVideoError] = useState(false);
const videoRef = useRef(null);
// 获取视频列表
useEffect(() => {
loadVideos();
}, []);
const loadVideos = async () => {
setLoading(true);
try {
const res = await API.get('/api/tutorial/videos');
if (res.data.success && res.data.data) {
setVideos(res.data.data);
if (res.data.data.length > 0) {
setCurrentVideo(res.data.data[0]);
}
}
} catch (error) {
console.error('Failed to load tutorial videos:', error);
Toast.error(t('加载视频失败'));
} finally {
setLoading(false);
}
};
// 格式化时长
const formatDuration = (seconds) => {
if (!seconds) return '--:--';
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, '0')}`;
};
// 格式化文件大小
const formatFileSize = (bytes) => {
if (!bytes) return '--';
if (bytes < 1024 * 1024) {
return `${(bytes / 1024).toFixed(1)} KB`;
}
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
};
// 切换视频
const handleSelectVideo = (video) => {
setCurrentVideo(video);
setVideoError(false);
// 重置视频播放
if (videoRef.current) {
videoRef.current.load();
}
};
// 视频加载错误处理
const handleVideoError = () => {
setVideoError(true);
Toast.error(t('视频加载失败,请刷新页面重试'));
};
// 刷新视频URL
const refreshVideoUrl = async () => {
setVideoError(false);
await loadVideos();
};
if (loading) {
return (
<div className='video-tutorial-loading'>
<Spin size='large' />
<Text type='secondary' style={{ marginTop: 16 }}>
{t('加载视频中...')}
</Text>
</div>
);
}
if (videos.length === 0) {
return (
<div className='video-tutorial-empty'>
<Empty
image={
<IconPlayCircle
size='extra-large'
style={{ fontSize: 64, color: 'var(--semi-color-text-3)' }}
/>
}
title={t('暂无视频教程')}
description={t('管理员还没有上传视频教程,请查看图文教程')}
/>
</div>
);
}
return (
<div className='video-tutorial'>
{/* 视频播放器区域 */}
<div className='video-player-section'>
<Card className='video-player-card'>
{currentVideo && (
<>
<div className='video-player-wrapper'>
{videoError ? (
<div className='video-error'>
<IconPlayCircle size='extra-large' />
<Text type='danger'>{t('视频加载失败')}</Text>
<button
className='video-retry-btn'
onClick={refreshVideoUrl}
>
{t('点击重试')}
</button>
</div>
) : (
<video
ref={videoRef}
key={currentVideo.id}
src={currentVideo.signed_url}
poster={currentVideo.thumbnail_url}
controls
controlsList='nodownload noplaybackrate'
disablePictureInPicture
onContextMenu={(e) => e.preventDefault()}
onError={handleVideoError}
className='video-player'
>
{t('您的浏览器不支持视频播放')}
</video>
)}
</div>
<div className='video-info'>
<Title heading={4} className='video-title'>
{currentVideo.title}
</Title>
{currentVideo.description && (
<Paragraph type='secondary' className='video-description'>
{currentVideo.description}
</Paragraph>
)}
<div className='video-meta'>
{currentVideo.duration > 0 && (
<span className='video-meta-item'>
<IconClock size='small' />
{formatDuration(currentVideo.duration)}
</span>
)}
{currentVideo.file_size > 0 && (
<span className='video-meta-item'>
<IconFile size='small' />
{formatFileSize(currentVideo.file_size)}
</span>
)}
</div>
</div>
</>
)}
</Card>
</div>
{/* 视频列表 */}
{videos.length > 1 && (
<div className='video-list-section'>
<Title heading={5} className='video-list-title'>
{t('视频列表')}
</Title>
<div className='video-list'>
{videos.map((video, index) => (
<div
key={video.id}
className={`video-list-item ${currentVideo?.id === video.id ? 'active' : ''}`}
onClick={() => handleSelectVideo(video)}
>
<div className='video-list-thumbnail'>
{video.thumbnail_url ? (
<img src={video.thumbnail_url} alt={video.title} />
) : (
<div className='video-thumbnail-placeholder'>
<IconPlayCircle size='large' />
</div>
)}
<span className='video-list-index'>{index + 1}</span>
{video.duration > 0 && (
<span className='video-list-duration'>
{formatDuration(video.duration)}
</span>
)}
</div>
<div className='video-list-info'>
<Text
strong
ellipsis={{ showTooltip: true }}
className='video-list-name'
>
{video.title}
</Text>
{video.description && (
<Text
type='tertiary'
size='small'
ellipsis
className='video-list-desc'
>
{video.description}
</Text>
)}
</div>
</div>
))}
</div>
</div>
)}
{/* 提示信息 */}
<div className='video-tips'>
<Card className='video-tips-card'>
<div className='video-tips-content'>
<span className='video-tips-icon'>💡</span>
<div>
<Text strong>{t('观看提示')}</Text>
<Paragraph
type='secondary'
style={{ marginBottom: 0, marginTop: 4 }}
>
{t(
'建议在 WiFi 环境下观看视频教程。如遇视频加载缓慢,请刷新页面重试。',
)}
</Paragraph>
</div>
</div>
</Card>
</div>
</div>
);
};
export default VideoTutorial;
+814
View File
@@ -0,0 +1,814 @@
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useContext, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Link, useNavigate, useSearchParams } from 'react-router-dom';
import {
Typography,
Button,
Card,
Tag,
Toast,
Tabs,
TabPane,
} from '@douyinfe/semi-ui';
import {
IconCopy,
IconTick,
IconArrowRight,
IconKey,
IconCreditCard,
IconCode,
IconSend,
IconSearch,
IconClose,
IconVideo,
IconArticle,
} from '@douyinfe/semi-icons';
import { StatusContext } from '../../context/Status';
import { DEFAULT_LOGIN_REDIRECT } from '../../helpers/data';
import VideoTutorial from './components/VideoTutorial';
import './styles.css';
const { Title, Paragraph, Text } = Typography;
const Tutorial = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const [copiedIndex, setCopiedIndex] = useState(null);
const [statusState] = useContext(StatusContext);
const [activeOS, setActiveOS] = useState('windows');
const [activeTutorialTab, setActiveTutorialTab] = useState('video'); // 默认视频教程
const scrollContainerRef = useRef(null);
// 处理关闭教程
const handleClose = () => {
// 检查是否有来源参数,如果有则返回来源页面,否则返回默认页面
const fromPage = searchParams.get('from');
if (fromPage) {
navigate(`/${fromPage}`);
} else {
navigate(DEFAULT_LOGIN_REDIRECT);
}
};
// 获取后台配置的文档地址
const docsLink =
statusState?.status?.docs_link || 'https://docs.weytoken.com/';
// API 服务器地址(生产环境)
const serverAddress = 'https://api.weytoken.com';
const steps = [
{
key: 'create-key',
title: t('创建密钥'),
icon: <IconKey />,
color: 'var(--brand-gradient-via)',
},
{
key: 'view-models',
title: t('查看可用模型'),
icon: <IconSearch />,
color: 'var(--brand-gradient-to)',
},
{
key: 'recharge',
title: t('充值'),
icon: <IconCreditCard />,
color: 'var(--brand-primary)',
},
{
key: 'install-client',
title: t('安装客户端'),
icon: <IconCode />,
color: 'var(--brand-gradient-from)',
},
{
key: 'start-journey',
title: t('开启之旅'),
icon: <IconSend />,
color: 'var(--brand-primary-hover)',
},
];
// 复制代码
const copyCode = async (code, index) => {
try {
await navigator.clipboard.writeText(code);
setCopiedIndex(index);
Toast.success(t('已复制到剪贴板'));
setTimeout(() => setCopiedIndex(null), 2000);
} catch (err) {
Toast.error(t('复制失败'));
}
};
// 代码块渲染函数:返回 JSX 而非作为内联组件,避免 Tutorial 重渲染时被识别为新的组件类型导致子树重新挂载
const renderCodeBlock = (code, language, index) => (
<div className='tutorial-code-block'>
<div className='tutorial-code-header'>
<Tag size='small' color='cyan'>
{language}
</Tag>
<Button
size='small'
theme='borderless'
icon={copiedIndex === index ? <IconTick /> : <IconCopy />}
onClick={() => copyCode(code, index)}
className='tutorial-copy-btn'
>
{copiedIndex === index ? t('已复制') : t('复制')}
</Button>
</div>
<pre className='tutorial-code-content'>
<code>{code}</code>
</pre>
</div>
);
// 步骤1:创建密钥 - 使用 JSX 变量而非内联组件,避免 Tutorial 重渲染时被识别为新组件类型导致子树重新挂载(连带 scroll 容器重建、滚动位置丢失)
const createKeyStep = (
<div className='tutorial-step-content'>
<div className='tutorial-step-header'>
<div
className='tutorial-step-icon'
style={{
background:
'linear-gradient(135deg, var(--brand-gradient-via), var(--brand-gradient-to))',
}}
>
<IconKey size='large' />
</div>
<div>
<Title heading={3}>{t('第一步:创建 API 密钥')}</Title>
<Paragraph type='secondary'>
{t('API 密钥是调用 AI 服务的凭证,请妥善保管')}
</Paragraph>
</div>
</div>
<Card className='tutorial-card tutorial-card-animated'>
<div className='tutorial-steps-list'>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>1</span>
<span>
{t('点击顶部导航栏的')}
<Link to='/key-management' className='tutorial-link'>
「{t('密钥管理')}」
</Link>
</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>2</span>
<span>{t('点击「创建密钥」按钮')}</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>3</span>
<span>{t('填写密钥名称(如:my-first-key)')}</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>4</span>
<span>{t('选择秘钥分组')}</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>5</span>
<span>{t('点击「提交」完成创建')}</span>
</div>
</div>
</Card>
<Card className='tutorial-card tutorial-warning-card'>
<div className='tutorial-warning-content'>
<div className='tutorial-warning-icon'>⚠️</div>
<div>
<Text strong>{t('重要提示')}</Text>
<Paragraph
type='secondary'
style={{ marginBottom: 0, marginTop: 4 }}
>
{t('密钥只会显示一次,请立即复制保存!格式如:')}
</Paragraph>
<code className='tutorial-key-example'>
sk-xxxxxxxxxxxxxxxxxxxxxxxx
</code>
</div>
</div>
</Card>
<div className='tutorial-action-buttons'>
<Link to='/key-management'>
<Button
type='primary'
theme='solid'
size='large'
icon={<IconKey />}
className='tutorial-action-btn'
>
{t('前往创建密钥')}
</Button>
</Link>
</div>
</div>
);
// 步骤2:查看可用模型
const viewModelsStep = (
<div className='tutorial-step-content'>
<div className='tutorial-step-header'>
<div
className='tutorial-step-icon'
style={{
background:
'linear-gradient(135deg, var(--brand-gradient-to), var(--brand-primary-hover))',
}}
>
<IconSearch size='large' />
</div>
<div>
<Title heading={3}>{t('第二步:查看密钥可用模型')}</Title>
<Paragraph type='secondary'>
{t('创建密钥后,可以查看该密钥有权限使用的模型')}
</Paragraph>
</div>
</div>
<Card className='tutorial-card tutorial-card-animated'>
<div className='tutorial-steps-list'>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>1</span>
<span>
{t('在')}
<Link to='/key-management' className='tutorial-link'>
「{t('密钥管理')}」
</Link>
{t('页面找到刚创建的密钥')}
</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>2</span>
<span>{t('点击密钥卡片右侧的「查看可用模型」按钮')}</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>3</span>
<span>{t('在弹出窗口中查看该密钥可以调用的所有模型')}</span>
</div>
</div>
</Card>
<Card className='tutorial-card tutorial-tip-card'>
<div className='tutorial-tip-content'>
<div className='tutorial-tip-icon'>💡</div>
<div>
<Text strong>{t('小提示')}</Text>
<Paragraph
type='secondary'
style={{ marginBottom: 0, marginTop: 4 }}
>
{t('常用模型推荐:')}
</Paragraph>
<div className='tutorial-model-tags'>
<Tag color='violet' size='large'>
claude-3-5-sonnet
</Tag>
<Tag color='blue' size='large'>
gpt-4o
</Tag>
<Tag color='cyan' size='large'>
gemini-pro
</Tag>
</div>
</div>
</div>
</Card>
</div>
);
// 步骤3:充值
const rechargeStep = (
<div className='tutorial-step-content'>
<div className='tutorial-step-header'>
<div
className='tutorial-step-icon'
style={{
background:
'linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-via))',
}}
>
<IconCreditCard size='large' />
</div>
<div>
<Title heading={3}>{t('第三步:账户充值')}</Title>
<Paragraph type='secondary'>
{t('充值后即可开始使用 AI 服务')}
</Paragraph>
</div>
</div>
<Card className='tutorial-card tutorial-card-animated'>
<div className='tutorial-steps-list'>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>1</span>
<span>
{t('点击页面右上角的')}
<Link
to='/recharge'
className='tutorial-link tutorial-link-orange'
>
「{t('充值')}」
</Link>
{t('按钮')}
</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>2</span>
<span>{t('选择充值金额')}</span>
</div>
<div className='tutorial-step-item'>
<span className='tutorial-step-number'>3</span>
<span>{t('完成支付,余额实时到账')}</span>
</div>
</div>
</Card>
<Card className='tutorial-card tutorial-info-card'>
<div className='tutorial-info-content'>
<div className='tutorial-info-icon'>💰</div>
<div>
<Text strong>{t('计费说明')}</Text>
<Paragraph
type='secondary'
style={{ marginBottom: 0, marginTop: 4 }}
>
{t(
'平台按 Token 消耗计费,不同模型价格不同。可在「模型服务」页面查看详细价格。',
)}
</Paragraph>
</div>
</div>
</Card>
<div className='tutorial-action-buttons'>
<Link to='/recharge'>
<Button
type='warning'
theme='solid'
size='large'
icon={<IconCreditCard />}
className='tutorial-action-btn tutorial-action-btn-orange'
>
{t('前往充值')}
</Button>
</Link>
</div>
</div>
);
// 步骤4:安装客户端
const installClientStep = (
<div className='tutorial-step-content'>
<div className='tutorial-step-header'>
<div
className='tutorial-step-icon'
style={{
background:
'linear-gradient(135deg, var(--brand-gradient-from), var(--brand-gradient-via))',
}}
>
<IconCode size='large' />
</div>
<div>
<Title heading={3}>{t('第四步:安装 Claude Code 客户端')}</Title>
<Paragraph type='secondary'>
{t('Claude Code 是 Anthropic 官方的命令行 AI 编程助手')}
</Paragraph>
</div>
</div>
<Card className='tutorial-card tutorial-card-animated'>
<Title heading={5} style={{ marginBottom: 16 }}>
{t('安装 Claude Code')}
</Title>
{renderCodeBlock(
'npm install -g @anthropic-ai/claude-code',
'bash',
'install-claude',
)}
<Paragraph type='tertiary' style={{ marginTop: 8 }}>
{t('或使用 npx 直接运行:')}
<code>npx @anthropic-ai/claude-code</code>
</Paragraph>
</Card>
<Card className='tutorial-card tutorial-card-animated'>
<Title heading={5} style={{ marginBottom: 16 }}>
{t('配置环境变量')}
</Title>
<Tabs
type='button'
activeKey={activeOS}
onChange={setActiveOS}
className='tutorial-os-tabs'
>
<TabPane
tab={<span className='tutorial-tab-label'>🪟 Windows</span>}
itemKey='windows'
>
<div className='tutorial-tab-content'>
<Paragraph type='secondary'>
{t('在 PowerShell 中执行(永久生效):')}
</Paragraph>
{renderCodeBlock(
`# 永久设置用户环境变量
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', '${serverAddress}', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-你的密钥', 'User')
# 设置后请重新打开终端窗口`,
'powershell',
'env-windows',
)}
<Paragraph type='tertiary' style={{ marginTop: 12 }}>
{t('环境变量将永久保存,重新打开终端后生效')}
</Paragraph>
</div>
</TabPane>
<TabPane
tab={<span className='tutorial-tab-label'>🍎 macOS</span>}
itemKey='macos'
>
<div className='tutorial-tab-content'>
<Paragraph type='secondary'>
{t('在终端中执行(永久生效):')}
</Paragraph>
{renderCodeBlock(
`# 添加到 ~/.zshrc(永久生效)
echo 'export ANTHROPIC_BASE_URL="${serverAddress}"' >> ~/.zshrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-你的密钥"' >> ~/.zshrc
source ~/.zshrc`,
'bash',
'env-macos',
)}
<Paragraph type='tertiary' style={{ marginTop: 12 }}>
{t('如使用 bash 请将 ~/.zshrc 改为 ~/.bash_profile')}
</Paragraph>
</div>
</TabPane>
<TabPane
tab={<span className='tutorial-tab-label'>🐧 Linux</span>}
itemKey='linux'
>
<div className='tutorial-tab-content'>
<Paragraph type='secondary'>
{t('在终端中执行(永久生效):')}
</Paragraph>
{renderCodeBlock(
`# 添加到 ~/.bashrc(永久生效)
echo 'export ANTHROPIC_BASE_URL="${serverAddress}"' >> ~/.bashrc
echo 'export ANTHROPIC_AUTH_TOKEN="sk-你的密钥"' >> ~/.bashrc
source ~/.bashrc`,
'bash',
'env-linux',
)}
<Paragraph type='tertiary' style={{ marginTop: 12 }}>
{t('如使用 zsh 请将 ~/.bashrc 改为 ~/.zshrc')}
</Paragraph>
</div>
</TabPane>
</Tabs>
</Card>
<Card className='tutorial-card tutorial-card-animated'>
<Title heading={5} style={{ marginBottom: 16 }}>
{t('启动使用')}
</Title>
{renderCodeBlock('claude', 'bash', 'start-claude')}
<div className='tutorial-commands-grid'>
<div className='tutorial-command-item'>
<code>/help</code>
<span>{t('查看帮助')}</span>
</div>
<div className='tutorial-command-item'>
<code>/config</code>
<span>{t('配置设置')}</span>
</div>
<div className='tutorial-command-item'>
<code>/clear</code>
<span>{t('清空对话')}</span>
</div>
<div className='tutorial-command-item'>
<code>/exit</code>
<span>{t('退出程序')}</span>
</div>
</div>
</Card>
</div>
);
// 步骤5:开启之旅
const startJourneyStep = (
<div className='tutorial-step-content'>
<div className='tutorial-step-header'>
<div
className='tutorial-step-icon'
style={{
background:
'linear-gradient(135deg, var(--brand-primary-hover), var(--brand-primary))',
}}
>
<IconSend size='large' />
</div>
<div>
<Title heading={3}>{t('第五步:开启 AI 之旅')}</Title>
<Paragraph type='secondary'>
{t('恭喜!您已完成所有准备工作')}
</Paragraph>
</div>
</div>
<div className='tutorial-completion-card'>
<div className='tutorial-completion-icon'>🎉</div>
<Title heading={4}>{t('准备就绪!')}</Title>
<Paragraph>
{t('您已经完成了所有配置,现在可以开始使用 AI 服务了')}
</Paragraph>
<div className='tutorial-completion-actions'>
<Button
type='primary'
theme='solid'
size='large'
icon={<IconTick />}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleClose();
}}
className='tutorial-completion-btn'
>
{t('完成教程')}
</Button>
</div>
</div>
<div className='tutorial-next-steps'>
<Title heading={5} style={{ marginBottom: 20 }}>
{t('后续探索')}
</Title>
<div className='tutorial-explore-grid'>
<Link
to='/market'
className='tutorial-explore-card tutorial-explore-card-purple'
>
<div className='tutorial-explore-icon'>💎</div>
<div className='tutorial-explore-content'>
<Text strong>{t('模型超市')}</Text>
<Paragraph type='secondary' style={{ marginBottom: 0 }}>
{t('查看所有可用模型及价格')}
</Paragraph>
</div>
<IconArrowRight className='tutorial-explore-arrow' />
</Link>
<a
href={docsLink}
target='_blank'
rel='noopener noreferrer'
className='tutorial-explore-card tutorial-explore-card-blue'
>
<div className='tutorial-explore-icon'>📚</div>
<div className='tutorial-explore-content'>
<Text strong>{t('使用文档')}</Text>
<Paragraph type='secondary' style={{ marginBottom: 0 }}>
{t('查看更多使用指南和 API 文档')}
</Paragraph>
</div>
<IconArrowRight className='tutorial-explore-arrow' />
</a>
<Link
to='/experience-center'
className='tutorial-explore-card tutorial-explore-card-green'
>
<div className='tutorial-explore-icon'>🎮</div>
<div className='tutorial-explore-content'>
<Text strong>{t('体验中心')}</Text>
<Paragraph type='secondary' style={{ marginBottom: 0 }}>
{t('在线体验 AI 对话功能')}
</Paragraph>
</div>
<IconArrowRight className='tutorial-explore-arrow' />
</Link>
<Link
to='/user-center'
className='tutorial-explore-card tutorial-explore-card-orange'
>
<div className='tutorial-explore-icon'>📊</div>
<div className='tutorial-explore-content'>
<Text strong>{t('用户中心')}</Text>
<Paragraph type='secondary' style={{ marginBottom: 0 }}>
{t('查看使用统计和调用记录')}
</Paragraph>
</div>
<IconArrowRight className='tutorial-explore-arrow' />
</Link>
</div>
</div>
</div>
);
// 所有步骤数组(直接引用 JSX 变量,保持元素类型稳定,避免重新挂载)
const allStepComponents = [
{
component: createKeyStep,
title: t('创建密钥'),
color: 'var(--brand-gradient-via)',
},
{
component: viewModelsStep,
title: t('查看可用模型'),
color: 'var(--brand-gradient-to)',
},
{
component: rechargeStep,
title: t('充值'),
color: 'var(--brand-primary)',
},
{
component: installClientStep,
title: t('安装客户端'),
color: 'var(--brand-gradient-from)',
},
{
component: startJourneyStep,
title: t('开启之旅'),
color: 'var(--brand-primary-hover)',
},
];
// 图文教程内容 - 滚动浏览模式(使用 JSX 变量而非内联组件,避免状态更新时重新挂载导致滚动位置重置)
const stepsTutorial = (
<div className='tutorial-scroll-wrapper'>
{/* 顶部快速导航 */}
<div className='tutorial-quick-nav'>
<div className='tutorial-quick-nav-inner'>
{steps.map((step, index) => (
<a
key={step.key}
href={`#tutorial-step-${index}`}
className='tutorial-quick-nav-item'
style={{ '--step-color': step.color }}
onClick={(e) => {
e.preventDefault();
const element = document.getElementById(
`tutorial-step-${index}`,
);
if (element && scrollContainerRef.current) {
element.scrollIntoView({
behavior: 'smooth',
block: 'start',
});
}
}}
>
<span className='tutorial-quick-nav-number'>{index + 1}</span>
<span className='tutorial-quick-nav-title'>{step.title}</span>
</a>
))}
</div>
<div className='tutorial-scroll-hint'>
<span className='tutorial-scroll-hint-icon'>↓</span>
<span>{t('向下滚动查看所有步骤')}</span>
</div>
</div>
{/* 可滚动的内容区域 */}
<div className='tutorial-scroll-container' ref={scrollContainerRef}>
<div className='tutorial-all-steps'>
{allStepComponents.map((step, index) => (
<div
key={`step-wrapper-${index}`}
id={`tutorial-step-${index}`}
className='tutorial-step-section'
>
<div className='tutorial-step-divider'>
<div
className='tutorial-step-badge'
style={{
background: `linear-gradient(135deg, ${step.color}, color-mix(in srgb, ${step.color} 85%, transparent))`,
}}
>
{index + 1} / {allStepComponents.length}
</div>
</div>
{step.component}
</div>
))}
</div>
{/* 底部完成提示 */}
<div className='tutorial-scroll-end'>
<div className='tutorial-scroll-end-icon'>🎉</div>
<Paragraph type='secondary'>
{t('恭喜!您已浏览完所有教程内容')}
</Paragraph>
<Button
type='primary'
theme='solid'
icon={<IconTick />}
onClick={handleClose}
>
{t('完成教程')}
</Button>
</div>
</div>
</div>
);
return (
<div className='tutorial-container'>
{/* 头部 */}
<div className='tutorial-header'>
<div className='tutorial-header-content'>
<div className='tutorial-header-badge'>{t('快速上手')}</div>
<Title heading={1} className='tutorial-title'>
{t('新手教程')}
</Title>
<Paragraph type='secondary' className='tutorial-subtitle'>
{t('5 分钟快速上手,开启您的 AI 之旅')}
</Paragraph>
</div>
<Button
type='tertiary'
theme='borderless'
icon={<IconClose />}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleClose();
}}
className='tutorial-close-btn'
size='large'
>
{t('关闭教程')}
</Button>
</div>
{/* 教程类型切换 Tab */}
<div className='tutorial-type-tabs'>
<Tabs
type='button'
activeKey={activeTutorialTab}
onChange={setActiveTutorialTab}
className='tutorial-main-tabs'
>
<TabPane
tab={
<span className='tutorial-tab-label-main'>
<IconVideo /> {t('视频教程')}
</span>
}
itemKey='video'
>
<div className='tutorial-tab-content-wrapper'>
<VideoTutorial />
</div>
</TabPane>
<TabPane
tab={
<span className='tutorial-tab-label-main'>
<IconArticle /> {t('图文教程')}
</span>
}
itemKey='steps'
>
<div className='tutorial-tab-content-wrapper'>{stepsTutorial}</div>
</TabPane>
</Tabs>
</div>
</div>
);
};
export default Tutorial;
File diff suppressed because it is too large Load Diff