fix
This commit is contained in:
parent
07d5463836
commit
e733f91daa
|
|
@ -393,6 +393,31 @@ class TemplateManager:
|
||||||
with open(draft_content_path, 'r', encoding='utf-8') as f:
|
with open(draft_content_path, 'r', encoding='utf-8') as f:
|
||||||
draft_content = json.load(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
|
# Extract tracks and segments information
|
||||||
tracks = []
|
tracks = []
|
||||||
if 'tracks' in draft_content:
|
if 'tracks' in draft_content:
|
||||||
|
|
@ -421,19 +446,36 @@ class TemplateManager:
|
||||||
|
|
||||||
# Get material reference for resource path
|
# Get material reference for resource path
|
||||||
material_id = segment_data.get('material_id', '')
|
material_id = segment_data.get('material_id', '')
|
||||||
|
# 参考assets/draft_content.json 根据material_id匹配materials中的videos
|
||||||
resource_path = ''
|
resource_path = ''
|
||||||
if material_id:
|
material_name = ''
|
||||||
# TODO: Look up material path from materials list
|
segment_type = segment_data.get('type', 'video')
|
||||||
resource_path = f"material_{material_id}"
|
|
||||||
|
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 = {
|
segment = {
|
||||||
'id': segment_data.get('id', ''),
|
'id': segment_data.get('id', ''),
|
||||||
'type': segment_data.get('type', 'video'),
|
'type': segment_type,
|
||||||
'name': segment_data.get('name', f'随机'),
|
'name': segment_name,
|
||||||
'start_time': start_time,
|
'start_time': start_time,
|
||||||
'end_time': end_time,
|
'end_time': end_time,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'resource_path': resource_path,
|
'resource_path': resource_path,
|
||||||
|
'material_name': material_name,
|
||||||
'properties': segment_data.get('properties', {}),
|
'properties': segment_data.get('properties', {}),
|
||||||
'effects': segment_data.get('effects', [])
|
'effects': segment_data.get('effects', [])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Edit, Copy, Trash2, Info } from 'lucide-react'
|
import { Edit } from 'lucide-react'
|
||||||
|
|
||||||
interface SegmentContextMenuProps {
|
interface SegmentContextMenuProps {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
|
|
@ -15,10 +15,7 @@ export const SegmentContextMenu: React.FC<SegmentContextMenuProps> = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
position,
|
position,
|
||||||
onClose,
|
onClose,
|
||||||
onEdit,
|
onEdit
|
||||||
onCopy,
|
|
||||||
onDelete,
|
|
||||||
onInfo
|
|
||||||
}) => {
|
}) => {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
|
|
@ -58,48 +55,6 @@ export const SegmentContextMenu: React.FC<SegmentContextMenuProps> = ({
|
||||||
<Edit size={14} />
|
<Edit size={14} />
|
||||||
重命名
|
重命名
|
||||||
</button>
|
</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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ export const TrackTimeline: React.FC<TrackTimelineProps> = ({
|
||||||
key={segment.id}
|
key={segment.id}
|
||||||
className={`absolute top-2 bottom-2 rounded-md ${getSegmentColor(segment.type)} ${getSegmentTextColor(segment.type)}
|
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
|
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={{
|
style={{
|
||||||
left: `${startPercent}%`,
|
left: `${startPercent}%`,
|
||||||
width: `${Math.max(widthPercent, 8)}%`, // Minimum width for visibility
|
width: `${Math.max(widthPercent, 8)}%`, // Minimum width for visibility
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue