Initial import of weiyuan frontend
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user