Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
video msg
bulaienaofutuojiesenzhang8a3b3922fcac
diff --git a/src/app/i18n/locales/en/publish.json b/src/app/i18n/locales/en/publish.jsonindex d501fc87..ff0e3634 100644--- a/src/app/i18n/locales/en/publish.json+++ b/src/app/i18n/locales/en/publish.json@@ -73,7 +73,14 @@},"preview": {"title": "Preview",- "emptyDescription": "See your work preview here"+ "emptyDescription": "See your work preview here",+ "videoInfo": {+ "filename": "Filename",+ "format": "Format",+ "resolution": "Resolution",+ "size": "Size",+ "duration": "Duration"+ }},"draft": {"selectDraft": "Select Draft",diff --git a/src/app/i18n/locales/zh-CN/publish.json b/src/app/i18n/locales/zh-CN/publish.jsonindex b6ec7b82..3e26e158 100644--- a/src/app/i18n/locales/zh-CN/publish.json+++ b/src/app/i18n/locales/zh-CN/publish.json@@ -73,7 +73,14 @@},"preview": {"title": "预览",- "emptyDescription": "在这里看到你的作品预览"+ "emptyDescription": "在这里看到你的作品预览",+ "videoInfo": {+ "filename": "文件名",+ "format": "格式",+ "resolution": "分辨率",+ "size": "大小",+ "duration": "时长"+ }},"draft": {"selectDraft": "选择草稿",diff --git a/src/components/PublishDialog/compoents/PublishDialogPreview.example.tsx b/src/components/PublishDialog/compoents/PublishDialogPreview.example.tsxnew file mode 100644index 00000000..d0e4d673--- /dev/null+++ b/src/components/PublishDialog/compoents/PublishDialogPreview.example.tsx@@ -0,0 +1,78 @@+import React from 'react';+import PublishDialogPreview from './PublishDialogPreview';++// 示例:展示视频预览功能+const PublishDialogPreviewExample = () => {+ return (+ <div style={{ padding: '20px', maxWidth: '800px' }}>+ <h2>作品预览组件示例</h2>+ <p>这个组件现在支持显示视频的详细信息:</p>++ <ul>+ <li>✅ <strong>文件名</strong> - 显示视频文件的原始文件名</li>+ <li>✅ <strong>格式</strong> - 自动从文件名提取并显示文件格式(如 MP4、MOV 等)</li>+ <li>✅ <strong>分辨率</strong> - 显示视频的宽度和高度(如 1920x1080)</li>+ <li>✅ <strong>文件大小</strong> - 自动格式化显示文件大小(如 1.5 MB、2.3 GB)</li>+ <li>✅ <strong>时长</strong> - 格式化显示视频时长(如 2:30、1:05:45)</li>+ </ul>++ <div style={{ border: '1px solid #ddd', borderRadius: '8px', padding: '16px', marginTop: '20px' }}>+ <h3>功能特点</h3>+ <ul>+ <li><strong>多语言支持</strong>:支持中英文标签显示</li>+ <li><strong>智能格式化</strong>:文件大小和时长自动格式化</li>+ <li><strong>响应式设计</strong>:适配不同屏幕尺寸</li>+ <li><strong>优雅的UI</strong>:半透明背景,清晰的标签和值显示</li>+ </ul>+ </div>++ <div style={{ border: '1px solid #ddd', borderRadius: '8px', padding: '16px', marginTop: '20px' }}>+ <h3>数据来源</h3>+ <p>视频信息来自 <code>IVideoFile</code> 接口:</p>+ <pre style={{ background: '#f5f5f5', padding: '10px', borderRadius: '4px', overflow: 'auto' }}>+{`interface IVideoFile {+ filename: string; // 文件名+ width: number; // 视频宽度+ height: number; // 视频高度+ size: number; // 文件大小(字节)+ duration: number; // 视频时长(秒)+ videoUrl: string; // 视频URL+ cover: IImgFile; // 封面图片+}`}+ </pre>+ </div>++ <div style={{ border: '1px solid #ddd', borderRadius: '8px', padding: '16px', marginTop: '20px' }}>+ <h3>格式化示例</h3>+ <ul>+ <li><strong>文件大小</strong>:+ <ul>+ <li>1024 bytes → "1 KB"</li>+ <li>1048576 bytes → "1 MB"</li>+ <li>1073741824 bytes → "1 GB"</li>+ </ul>+ </li>+ <li><strong>时长</strong>:+ <ul>+ <li>65 seconds → "1:05"</li>+ <li>3665 seconds → "1:01:05"</li>+ <li>120 seconds → "2:00"</li>+ </ul>+ </li>+ </ul>+ </div>++ <div style={{ border: '1px solid #ddd', borderRadius: '8px', padding: '16px', marginTop: '20px' }}>+ <h3>样式特点</h3>+ <ul>+ <li>半透明黑色背景 (rgba(0, 0, 0, 0.8))</li>+ <li>白色文字,标签为浅灰色</li>+ <li>圆角底部设计,与视频播放器完美融合</li>+ <li>响应式布局,标签和值左右对齐</li>+ </ul>+ </div>+ </div>+ );+};++export default PublishDialogPreviewExample;diff --git a/src/components/PublishDialog/compoents/PublishDialogPreview.test.tsx b/src/components/PublishDialog/compoents/PublishDialogPreview.test.tsxnew file mode 100644index 00000000..4ffa709e--- /dev/null+++ b/src/components/PublishDialog/compoents/PublishDialogPreview.test.tsx@@ -0,0 +1,77 @@+import React from 'react';+import { render, screen } from '@testing-library/react';+import PublishDialogPreview from './PublishDialogPreview';++// Mock the dependencies+jest.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ }),+}));++jest.mock('@/components/PublishDialog/usePublishDialog', () => ({+ usePublishDialog: () => ({+ expandedPubItem: {+ params: {+ video: {+ filename: 'test-video.mp4',+ width: 1920,+ height: 1080,+ size: 1048576, // 1MB+ duration: 120, // 2 minutes+ videoUrl: 'https://example.com/video.mp4',+ cover: {+ imgUrl: 'https://example.com/cover.jpg'+ }+ }+ }+ }+ }),+}));++// Mock Swiper components+jest.mock('swiper/react', () => ({+ Swiper: ({ children }: { children: React.ReactNode }) => <div data-testid="swiper">{children}</div>,+ SwiperSlide: ({ children }: { children: React.ReactNode }) => <div data-testid="swiper-slide">{children}</div>,+}));++jest.mock('swiper/modules', () => ({+ Navigation: {},+ Pagination: {},+}));++describe('PublishDialogPreview', () => {+ it('renders video information correctly', () => {+ render(<PublishDialogPreview />);++ // Check if video info labels are present+ expect(screen.getByText('preview.videoInfo.filename:')).toBeInTheDocument();+ expect(screen.getByText('preview.videoInfo.format:')).toBeInTheDocument();+ expect(screen.getByText('preview.videoInfo.resolution:')).toBeInTheDocument();+ expect(screen.getByText('preview.videoInfo.size:')).toBeInTheDocument();+ expect(screen.getByText('preview.videoInfo.duration:')).toBeInTheDocument();++ // Check if video info values are present+ expect(screen.getByText('test-video.mp4')).toBeInTheDocument();+ expect(screen.getByText('MP4')).toBeInTheDocument();+ expect(screen.getByText('1920x1080')).toBeInTheDocument();+ expect(screen.getByText('1 MB')).toBeInTheDocument();+ expect(screen.getByText('2:00')).toBeInTheDocument();+ });++ it('formats file size correctly', () => {+ // Test the formatFileSize function indirectly through the component+ render(<PublishDialogPreview />);++ // Check if 1MB is formatted as "1 MB"+ expect(screen.getByText('1 MB')).toBeInTheDocument();+ });++ it('formats duration correctly', () => {+ // Test the formatDuration function indirectly through the component+ render(<PublishDialogPreview />);++ // Check if 120 seconds is formatted as "2:00"+ expect(screen.getByText('2:00')).toBeInTheDocument();+ });+});diff --git a/src/components/PublishDialog/compoents/PublishDialogPreview.tsx b/src/components/PublishDialog/compoents/PublishDialogPreview.tsxindex 713b9e18..c2ab69bb 100644--- a/src/components/PublishDialog/compoents/PublishDialogPreview.tsx+++ b/src/components/PublishDialog/compoents/PublishDialogPreview.tsx@@ -9,6 +9,28 @@ import { useTranslation } from "react-i18next";import "swiper/css";import "swiper/css/pagination";+// 格式化文件大小+const formatFileSize = (bytes: number): string => {+ if (bytes === 0) return '0 Bytes';+ const k = 1024;+ const sizes = ['Bytes', 'KB', 'MB', 'GB'];+ const i = Math.floor(Math.log(bytes) / Math.log(k));+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];+};++// 格式化时长+const formatDuration = (seconds: number): string => {+ const hours = Math.floor(seconds / 3600);+ const minutes = Math.floor((seconds % 3600) / 60);+ const secs = Math.floor(seconds % 60);++ if (hours > 0) {+ return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;+ } else {+ return `${minutes}:${secs.toString().padStart(2, '0')}`;+ }+};+export interface IPublishDialogPreviewRef {}export interface IPublishDialogPreviewProps {}@@ -56,6 +78,48 @@ const PublishDialogPreview = memo(controlsposter={expandedPubItem.params.video?.cover.imgUrl}/>+ {/* 视频信息显示 */}+ <div className="publishDialogPreview-video-info">+ <div className="publishDialogPreview-video-info-item">+ <span className="publishDialogPreview-video-info-label">{t('preview.videoInfo.filename' as any)}:</span>+ <span className="publishDialogPreview-video-info-value">+ {expandedPubItem.params.video?.filename || 'Unknown'}+ </span>+ </div>+ <div className="publishDialogPreview-video-info-item">+ <span className="publishDialogPreview-video-info-label">{t('preview.videoInfo.format' as any)}:</span>+ <span className="publishDialogPreview-video-info-value">+ {expandedPubItem.params.video?.filename?.split('.').pop()?.toUpperCase() || 'Unknown'}+ </span>+ </div>+ <div className="publishDialogPreview-video-info-item">+ <span className="publishDialogPreview-video-info-label">{t('preview.videoInfo.resolution' as any)}:</span>+ <span className="publishDialogPreview-video-info-value">+ {expandedPubItem.params.video?.width && expandedPubItem.params.video?.height+ ? `${expandedPubItem.params.video.width}x${expandedPubItem.params.video.height}`+ : 'Unknown'+ }+ </span>+ </div>+ <div className="publishDialogPreview-video-info-item">+ <span className="publishDialogPreview-video-info-label">{t('preview.videoInfo.size' as any)}:</span>+ <span className="publishDialogPreview-video-info-value">+ {expandedPubItem.params.video?.size+ ? formatFileSize(expandedPubItem.params.video.size)+ : 'Unknown'+ }+ </span>+ </div>+ <div className="publishDialogPreview-video-info-item">+ <span className="publishDialogPreview-video-info-label">{t('preview.videoInfo.duration' as any)}:</span>+ <span className="publishDialogPreview-video-info-value">+ {expandedPubItem.params.video?.duration+ ? formatDuration(expandedPubItem.params.video.duration)+ : 'Unknown'+ }+ </span>+ </div>+ </div></div></div>) : (diff --git a/src/components/PublishDialog/publishDialog.module.scss b/src/components/PublishDialog/publishDialog.module.scssindex ac3e3fa8..49880d04 100644--- a/src/components/PublishDialog/publishDialog.module.scss+++ b/src/components/PublishDialog/publishDialog.module.scss@@ -205,6 +205,34 @@ $assistantWidth: 330px;border-radius: 0;}}+ &-video-info {+ background: rgba(0, 0, 0, 0.8);+ color: white;+ padding: 12px 16px;+ border-radius: 0 0 30px 30px;+ font-size: 12px;+ &-item {+ display: flex;+ justify-content: space-between;+ align-items: center;+ margin-bottom: 4px;+ &:last-child {+ margin-bottom: 0;+ }+ }+ &-label {+ font-weight: 500;+ color: #ccc;+ min-width: 60px;+ }+ &-value {+ color: white;+ font-weight: 400;+ text-align: right;+ flex: 1;+ margin-left: 8px;+ }+ }}.publishDialogPreview-wrapper {text-align: left;