替换逻辑更改

This commit is contained in:
海龙 2025-08-13 19:38:59 +08:00
parent 5dfa836b2e
commit 34fc5981d4
5 changed files with 46 additions and 15 deletions

View File

@ -304,6 +304,7 @@ export const useRoleServiceHook = (): UseRoleService => {
name: libraryRole.name,
generateText: libraryRole.generateText,
imageUrl: libraryRole.imageUrl,
fromDraft: false
};
selectRole(updatedRole);

View File

@ -41,19 +41,21 @@ interface UseRoleShotService {
clearShotSelection: () => void;
/** 设置选中的角色 */
setSelectedRole: (role: RoleEntity) => void;
/** 设置草稿箱角色列表 */
setDraftRoleList: (roleList: RoleEntity[]) => void;
}
/**
* Hook
*
*/
export const useRoleShotServiceHook = (projectId: string,selectRole?:RoleEntity): UseRoleShotService => {
export const useRoleShotServiceHook = (projectId: string,selectRole?:RoleEntity,roleList?:RoleEntity[]): UseRoleShotService => {
// 响应式状态
const [shotSelectionList, setShotSelectionList] = useState<ExtendedVideoSegmentEntity[]>([]);
const [selectedRoleId, setSelectedRoleId] = useState<string | null>(null);
const [selectedRole, setSelectedRole] = useState<RoleEntity | null>(selectRole || null);
const [isReplacing, setIsReplacing] = useState<boolean>(false); // 全局替换状态
const [draftRoleList, setDraftRoleList] = useState<RoleEntity[]>(roleList || []);
// 计算属性
/**
*
@ -172,17 +174,23 @@ export const useRoleShotServiceHook = (projectId: string,selectRole?:RoleEntity)
}
];
const newDraftRoleList = draftRoleList.filter(role =>{
if(role.name===selectedRole.name){
role.fromDraft = true
}
return role.fromDraft
});
console.log('newDraftRoleList', newDraftRoleList)
// 循环调用接口,为每个选中的分镜单独调用
shotSelectionList.forEach(async (shot) => {
try {
(selectedRole as any).shot = shot;
// 调用应用角色到分镜接口(不等待完成)
applyRoleToShots({
project_id: projectId,
shot_id: shot.id, // 单个分镜ID
character_replacements: characterReplacements,
wait_for_completion: false, // 不等待完成,异步处理
character_draft: JSON.stringify(selectedRole)
character_draft: JSON.stringify(newDraftRoleList)
}).then(response => {
if (response.successful) {
console.log(`分镜 ${shot.id} 角色替换成功:`, response.data);
@ -236,7 +244,8 @@ export const useRoleShotServiceHook = (projectId: string,selectRole?:RoleEntity)
toggleShotSelection,
applyRoleToSelectedShots,
clearShotSelection,
setSelectedRole
setSelectedRole,
setDraftRoleList
};
};

View File

@ -40,6 +40,8 @@ export interface RoleEntity extends BaseEntity {
tags: TagValueObject[];
/** 角色图片URL */
imageUrl: string;
/**来源于草稿箱 */
fromDraft: boolean;
}
/**

View File

@ -72,7 +72,8 @@ export class RoleEditUseCase {
imageUrl: char.image_path || '', // 使用API返回的图片路径
loadingProgress: 100, // 默认加载完成
disableEdit: false, // 默认允许编辑
updatedAt: Date.now()
updatedAt: Date.now(),
fromDraft: false
};
return roleEntity;
@ -90,12 +91,24 @@ export class RoleEditUseCase {
// if (!Array.isArray(projectRoleData)) {
// throw new Error('项目角色数据格式错误');
// }
let draftRoleList:Record<string,RoleEntity> = {};
// 如果草稿箱有数据,则返回草稿箱数据
if(projectRoleData.character_draft){
const roleList = JSON.parse(projectRoleData.character_draft);
if(projectRoleData.character_draft){
const roleEntity: RoleEntity[] = JSON.parse(projectRoleData.character_draft);
return roleEntity;
for(const role of roleList){
draftRoleList[role.name] = role;
}
}
return projectRoleData.characters.map((char, index) => {
if(draftRoleList[char.character_name]){
return {
...draftRoleList[char.character_name],
fromDraft: true,
id: `role_${index + 1}`,
updatedAt: Date.now(),
};
}
/** 角色实体对象 */
const roleEntity: RoleEntity = {
id: `role_${index + 1}`,
@ -116,7 +129,8 @@ export class RoleEditUseCase {
imageUrl: char.image_path || '',
loadingProgress: 100,
disableEdit: false,
updatedAt: Date.now()
updatedAt: Date.now(),
fromDraft: false
};
return roleEntity;
@ -145,7 +159,8 @@ export class RoleEditUseCase {
imageUrl: char.image_url || '',
loadingProgress: 100,
disableEdit: false,
updatedAt: Date.now()
updatedAt: Date.now(),
fromDraft: false
};
return roleEntity;
@ -238,7 +253,8 @@ export class RoleEditUseCase {
imageUrl: characterData.image_url || '',
loadingProgress: 100,
disableEdit: false,
updatedAt: Date.now()
updatedAt: Date.now(),
fromDraft: false
};
return roleEntity;
} catch (error) {
@ -361,7 +377,8 @@ export class RoleEditUseCase {
imageUrl: imageUrl, // 使用传入的图片地址
loadingProgress: 100, // 加载完成
disableEdit: false, // 允许编辑
updatedAt: Date.now()
updatedAt: Date.now(),
fromDraft: false
};
return mockRole;

View File

@ -55,13 +55,15 @@ export const useEditData = (tabType: string, originalText?: string) => {
toggleShotSelection,
applyRoleToSelectedShots,
clearShotSelection,
setSelectedRole
} = useRoleShotServiceHook(projectId, selectedRole || undefined);
setSelectedRole,
setDraftRoleList
} = useRoleShotServiceHook(projectId, selectedRole || undefined,roleList || undefined);
useEffect(() => {
console.log('useEditData-----selectedRole', selectedRole);
if(selectedRole){
setSelectedRole(selectedRole);
setDraftRoleList(roleList || []);
}
}, [selectedRole]);