/*
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 .
For commercial licensing, please contact support@quantumnous.com
*/
import { Trans } from 'react-i18next';
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import { writeClipboardText } from '../../helpers/clipboard';
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 '@/components/ui';
import {
IconCopy,
IconTick,
IconArrowRight,
IconKey,
IconCreditCard,
IconCode,
IconSend,
IconSearch,
IconClose,
IconVideo,
IconArticle,
} from '@/components/ui/icons';
import { StatusContext } from '../../context/Status';
import { DEFAULT_LOGIN_REDIRECT } from '../../helpers/data';
import { isMiniProgramWebView } from '../../helpers/miniProgram';
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: ,
color: 'var(--brand-gradient-via)',
},
{
key: 'view-models',
title: t('查看可用模型'),
icon: ,
color: 'var(--brand-gradient-to)',
},
{
key: 'recharge',
title: t('充值'),
icon: ,
color: 'var(--brand-primary)',
},
{
key: 'install-client',
title: t('安装客户端'),
icon: ,
color: 'var(--brand-gradient-from)',
},
{
key: 'start-journey',
title: t('开启之旅'),
icon: ,
color: 'var(--brand-primary-hover)',
},
];
// 复制代码
const copyCode = async (code, index) => {
try {
await writeClipboardText(code);
setCopiedIndex(index);
Toast.success(t('已复制到剪贴板'));
setTimeout(() => setCopiedIndex(null), 2000);
} catch (err) {
Toast.error(t('复制失败'));
}
};
// 代码块渲染函数:返回 JSX 而非作为内联组件,避免 Tutorial 重渲染时被识别为新的组件类型导致子树重新挂载
const renderCodeBlock = (code, language, index) => (