简化角色解析函数,移除数据格式检查并调整角色属性映射,优化代码逻辑。同时,更新角色选择逻辑以使用新的角色数据结构,修复相关的日志输出。

This commit is contained in:
北枳 2025-08-13 20:41:24 +08:00
parent 2ab25bc72c
commit 1871be3d94
3 changed files with 18 additions and 19 deletions

View File

@ -145,18 +145,19 @@ export class RoleEditUseCase {
* @throws {Error}
*/
parseSimilarCharacterList(similarCharacterData: any): RoleEntity[] {
if (!similarCharacterData || !Array.isArray(similarCharacterData.characters)) {
throw new Error('相似角色数据格式错误');
}
// if (!similarCharacterData || !Array.isArray(similarCharacterData.characters)) {
// throw new Error('相似角色数据格式错误');
// }
const characters = [...similarCharacterData.similar_characters, ...similarCharacterData.user_characters];
return similarCharacterData.characters.map((char: any, index: number) => {
return characters.map((char: any, index: number) => {
/** 角色实体对象 */
const roleEntity: RoleEntity = {
id: char.id || `role_${Date.now()}_${index}`,
name: char.name || '',
generateText: char.description || '',
generateText: char.brief || '',
tags: [], // 相似角色接口可能不返回标签,暂时为空
imageUrl: char.image_url || '',
imageUrl: char.avatar || '',
loadingProgress: 100,
disableEdit: false,
updatedAt: Date.now(),

View File

@ -111,8 +111,8 @@ export function CharacterTabContent({
}, [roleData, isInitialized]);
useEffect(() => {
console.log('获取选中项数据', selectedRole);
}, [selectedRole]);
console.log('获取shotSelectionList数据', shotSelectionList);
}, [shotSelectionList]);
useEffect(() => {
console.log('获取角色库数据', userRoleLibrary);
@ -184,8 +184,12 @@ export function CharacterTabContent({
setShowAddToLibrary(false);
// 使用真实的角色数据
const selectedRole = userRoleLibrary[index];
if (selectedRole) {
const role = userRoleLibrary[index];
if (role) {
selectRole({
...role,
name: selectedRole?.name || ''
});
handleStartReplaceCharacter();
}
};

View File

@ -158,23 +158,22 @@ export function ReplacePanel({
whileHover={{ scale: 1.02 }}
whileTap={{ scale: 0.98 }}
>
{shot.videoUrl && (
{shot.videoUrl && shot.videoUrl.length > 0 && (
<video
ref={el => {
if (el) videoRefs.current[shot.id] = el;
}}
src={shot.videoUrl}
src={shot.videoUrl[0]}
className="w-full h-full object-cover"
loop
muted
playsInline
/>
)}
{!shot.videoUrl && (
{(!shot.videoUrl || shot.videoUrl.length === 0) && (
<>
<img
src={shot.sketchUrl}
alt={`Shot ${shot.id}`}
className="w-full h-full object-cover"
/>
<div className="absolute inset-0 bg-black/50 flex items-center justify-center">
@ -182,11 +181,6 @@ export function ReplacePanel({
</div>
</>
)}
{selectedShots.includes(shot.id) && (
<div className="absolute top-2 right-2">
<Check className="w-4 h-4 text-blue-500" />
</div>
)}
</motion.div>
))}
</div>