Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
增加视频播放器
DESKTOP-ZTS2NQJNA0a2038ee5fab
diff --git a/src/components/VideoPlayer/index.tsx b/src/components/VideoPlayer/index.tsxnew file mode 100644index 00000000..3c6ddd2d--- /dev/null+++ b/src/components/VideoPlayer/index.tsx@@ -0,0 +1,46 @@+import React, { useState, useRef, useEffect } from 'react';+import { Modal } from 'antd';+import styles from './videoPlayer.module.scss';++interface VideoPlayerProps {+ videoUrl: string;+ visible: boolean;+ onClose: () => void;+ title?: string;+}++const VideoPlayer: React.FC<VideoPlayerProps> = ({ videoUrl, visible, onClose, title }) => {+ const videoRef = useRef<HTMLVideoElement>(null);++ useEffect(() => {+ // 当模态框关闭时暂停视频+ if (!visible && videoRef.current) {+ videoRef.current.pause();+ }+ }, [visible]);++ return (+ <Modal+ title={title || '视频播放'}+ open={visible}+ onCancel={onClose}+ footer={null}+ width={800}+ centered+ destroyOnClose+ className={styles.videoModal}+ >+ <div className={styles.videoContainer}>+ <video+ ref={videoRef}+ src={videoUrl}+ controls+ autoPlay+ className={styles.videoPlayer}+ />+ </div>+ </Modal>+ );+};++export default VideoPlayer;\ No newline at end of filediff --git a/src/components/VideoPlayer/videoPlayer.module.scss b/src/components/VideoPlayer/videoPlayer.module.scssnew file mode 100644index 00000000..68acf062--- /dev/null+++ b/src/components/VideoPlayer/videoPlayer.module.scss@@ -0,0 +1,47 @@+.videoModal {+ :global {+ .ant-modal-content {+ background-color: #000;+ border-radius: 8px;+ overflow: hidden;+ }++ .ant-modal-header {+ background-color: #000;+ border-bottom: 1px solid #333;++ .ant-modal-title {+ color: #fff;+ }+ }++ .ant-modal-close {+ color: #fff;++ &:hover {+ color: #a66ae4;+ }+ }++ .ant-modal-body {+ padding: 0;+ }+ }+}++.videoContainer {+ width: 100%;+ height: 0;+ padding-bottom: 56.25%; /* 16:9 宽高比 */+ position: relative;+}++.videoPlayer {+ position: absolute;+ top: 0;+ left: 0;+ width: 100%;+ height: 100%;+ object-fit: contain;+ background-color: #000;+}\ No newline at end of filediff --git a/src/views/task/popTask.tsx b/src/views/task/popTask.tsxindex 16765deb..856742c3 100644--- a/src/views/task/popTask.tsx+++ b/src/views/task/popTask.tsx@@ -99,7 +99,7 @@ export default function Page() {<div className={styles.taskList}>{taskList.map((task) => (- <Card key={task.id} className={styles.taskCard}>+ <Card key={task._id} className={styles.taskCard}><div className={styles.taskCardContent}><div className={styles.taskImageContainer}><imgdiff --git a/src/views/task/videoTask.tsx b/src/views/task/videoTask.tsxindex e65edad8..477edfa6 100644--- a/src/views/task/videoTask.tsx+++ b/src/views/task/videoTask.tsx@@ -20,6 +20,7 @@ import {CopyOutlined,} from '@ant-design/icons';import dayjs from 'dayjs';+import VideoPlayer from '@/components/VideoPlayer';// 导入平台图标import KwaiIcon from '@/assets/svgs/account/ks.svg';@@ -49,6 +50,17 @@ export default function Page() {const Ref_TaskInfo = useRef<TaskInfoRef>(null);+ // 添加视频播放状态+ const [videoPlayback, setVideoPlayback] = useState<{+ visible: boolean;+ url: string;+ title: string;+ }>({+ visible: false,+ url: '',+ title: '',+ });+async function getTaskList(isLoadMore = false) {setLoading(true);try {@@ -133,19 +145,49 @@ export default function Page() {);};+ // 打开视频播放器+ const openVideoPlayer = (task: Task<TaskVideo>, e: React.MouseEvent) => {+ e.stopPropagation();+ if (task.dataInfo?.videoUrl) {+ setVideoPlayback({+ visible: true,+ url: `${FILE_BASE_URL}${task.dataInfo.videoUrl}`,+ title: task.title || '视频播放',+ });+ } else {+ message.info('该任务暂无视频');+ }+ };++ // 关闭视频播放器+ const closeVideoPlayer = () => {+ setVideoPlayback((prev) => ({ ...prev, visible: false }));+ };+return (<div className={styles.videoTaskContainer}><TaskInfo ref={Ref_TaskInfo} />++ {/* 添加视频播放组件 */}+ <VideoPlayer+ videoUrl={videoPlayback.url}+ visible={videoPlayback.visible}+ onClose={closeVideoPlayer}+ title={videoPlayback.title}+ /><div className={styles.taskList}>{taskList.map((task) => (<Card- key={task.id}+ key={task._id}className={styles.taskCard}styles={{ body: { padding: 0 } }}><div className={styles.taskCardContent}>- <div className={styles.taskImageContainer}>+ <div+ className={styles.taskImageContainer}+ onClick={(e) => openVideoPlayer(task, e)}+ ><imgsrc={`${FILE_BASE_URL}${task.imageUrl}`}alt={task.title}