This commit is contained in:
root 2025-07-11 00:00:12 +08:00
parent 07d5463836
commit e733f91daa
3 changed files with 50 additions and 53 deletions

View File

@ -393,6 +393,31 @@ class TemplateManager:
with open(draft_content_path, 'r', encoding='utf-8') as f:
draft_content = json.load(f)
# Build material lookup tables
materials_lookup = {}
if 'materials' in draft_content:
# Index videos by id
for video in draft_content['materials'].get('videos', []):
video_id = video.get('id', '')
if video_id:
materials_lookup[video_id] = {
'type': 'video',
'path': video.get('path', ''),
'name': video.get('material_name', ''),
'duration': video.get('duration', 0)
}
# Index audios by id
for audio in draft_content['materials'].get('audios', []):
audio_id = audio.get('id', '')
if audio_id:
materials_lookup[audio_id] = {
'type': 'audio',
'path': audio.get('path', ''),
'name': audio.get('name', ''),
'duration': audio.get('duration', 0)
}
# Extract tracks and segments information
tracks = []
if 'tracks' in draft_content:
@ -421,19 +446,36 @@ class TemplateManager:
# Get material reference for resource path
material_id = segment_data.get('material_id', '')
# 参考assets/draft_content.json 根据material_id匹配materials中的videos
resource_path = ''
if material_id:
# TODO: Look up material path from materials list
resource_path = f"material_{material_id}"
material_name = ''
segment_type = segment_data.get('type', 'video')
if material_id and material_id in materials_lookup:
material_info = materials_lookup[material_id]
resource_path = material_info['path']
material_name = material_info['name']
# Auto-detect segment type from material type if not specified
if not segment_data.get('type'):
segment_type = material_info['type']
# Generate segment name based on material name or default
segment_name = segment_data.get('name', '')
if not segment_name:
if material_name:
segment_name = material_name
else:
segment_name = f'片段 {len(track["segments"]) + 1}'
segment = {
'id': segment_data.get('id', ''),
'type': segment_data.get('type', 'video'),
'name': segment_data.get('name', f'随机'),
'type': segment_type,
'name': segment_name,
'start_time': start_time,
'end_time': end_time,
'duration': duration,
'resource_path': resource_path,
'material_name': material_name,
'properties': segment_data.get('properties', {}),
'effects': segment_data.get('effects', [])
}

View File

@ -1,5 +1,5 @@
import React from 'react'
import { Edit, Copy, Trash2, Info } from 'lucide-react'
import { Edit } from 'lucide-react'
interface SegmentContextMenuProps {
isOpen: boolean
@ -15,10 +15,7 @@ export const SegmentContextMenu: React.FC<SegmentContextMenuProps> = ({
isOpen,
position,
onClose,
onEdit,
onCopy,
onDelete,
onInfo
onEdit
}) => {
React.useEffect(() => {
if (isOpen) {
@ -58,48 +55,6 @@ export const SegmentContextMenu: React.FC<SegmentContextMenuProps> = ({
<Edit size={14} />
</button>
{onCopy && (
<button
onClick={() => {
onCopy()
onClose()
}}
className="w-full px-4 py-2 text-left text-sm text-gray-700 hover:bg-gray-100 flex items-center gap-2"
>
<Copy size={14} />
</button>
)}
{onInfo && (
<button
onClick={() => {
onInfo()
onClose()
}}
className="w-full px-4 py-2 text-left text-sm text-gray-700 hover:bg-gray-100 flex items-center gap-2"
>
<Info size={14} />
</button>
)}
{onDelete && (
<>
<hr className="my-1 border-gray-200" />
<button
onClick={() => {
onDelete()
onClose()
}}
className="w-full px-4 py-2 text-left text-sm text-red-600 hover:bg-red-50 flex items-center gap-2"
>
<Trash2 size={14} />
</button>
</>
)}
</div>
)
}

View File

@ -191,7 +191,7 @@ export const TrackTimeline: React.FC<TrackTimelineProps> = ({
key={segment.id}
className={`absolute top-2 bottom-2 rounded-md ${getSegmentColor(segment.type)} ${getSegmentTextColor(segment.type)}
flex items-center px-3 text-sm font-medium cursor-pointer transition-all duration-200
shadow-sm hover:shadow-md transform hover:scale-105 z-10`}
shadow-sm hover:shadow-md transform`}
style={{
left: `${startPercent}%`,
width: `${Math.max(widthPercent, 8)}%`, // Minimum width for visibility