替换逻辑更改

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, name: libraryRole.name,
generateText: libraryRole.generateText, generateText: libraryRole.generateText,
imageUrl: libraryRole.imageUrl, imageUrl: libraryRole.imageUrl,
fromDraft: false
}; };
selectRole(updatedRole); selectRole(updatedRole);

View File

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

View File

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

View File

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

View File

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