[
...(d?.characters||[]).map(c=>c.uuid+'|'+(c.avatar_url||c.image_url)),
...(d?.scenes||[]).map(s=>s.uuid+'|'+s.image_url),
...(d?.props||[]).map(p=>p.uuid+'|'+p.image_url),
...(d?.creatures||[]).map(c=>c.uuid+'|'+c.image_url),
].join(',');
if (imgKey(data) !== imgKey(assets)) assets = data;
} else {
artifactData = data;
}
}
}
"
@genvia:open-artifact.window="
const { type, data } = $event.detail;
// 实体类型(角色、场景、道具、生物)统一跳转到资产面板,不缓存到 _cache
if (type === 'character' || type === 'scene' || type === 'prop' || type === 'creature') {
// 触发切换到资产面板
window.dispatchEvent(new CustomEvent('artifact-panel-switch', { detail: { step: 'assets' } }));
} else if (type && data != null) {
const labels = {
drama_outline: window.i18n?.t('ui.artifact.story_outline.100'),
script: window.i18n?.t('ui.artifact.story_script.113'),
storyboard: window.i18n?.t('ui.artifact.story_storyboard.120'),
};
_cache[type] = { data, title: data?.title || data?.name || labels[type] || type };
}
"
@storyboard-edit-open="window.dispatchEvent(new CustomEvent('genvia:storyboard-editor-request', { detail: $event.detail }))"
@artifact-panel-switch.window="
const step = $event.detail.step;
const labels = {
drama_outline: window.i18n?.t('ui.artifact.story_outline.100'),
script: window.i18n?.t('ui.artifact.story_script.113'),
storyboard: window.i18n?.t('ui.artifact.story_storyboard.120'),
assets: window.i18n?.t('ui.artifact.assets_materials.126'),
video: window.i18n?.t('ui.artifact.video_production.127'),
};
// 切换面板时关闭分镜编辑器(真正状态在 drama.js,通过 window 事件通知)
window.dispatchEvent(new CustomEvent('genvia:storyboard-editor-close'));
if (step === 'assets') {
artifactTitle = window.i18n?.t('ui.artifact.assets_materials.126');
{
const cached = (_cache['assets'] || (window._genviaArtifactCache || {})['assets']);
if (cached) {
// 有缓存,直接使用
assets = cached.data;
artifactData = cached.data;
artifactType = 'assets';
assetsLoading = false;
} else {
// 无缓存,设置加载状态,不显示空数据
artifactType = 'assets';
artifactData = null;
assetsLoading = true;
}
// 从多个来源获取 dramaId(优先从缓存)
const dramaId = _cache['drama_outline']?.data?.drama_id
|| _cache['script']?.data?.drama_id
|| window.SessionManager?.getCurrentDramaId?.();
if (dramaId && !window._testAgentMode && !cached) {
const fetcher = window.AuthManager?.fetchWithAuth?.bind(window.AuthManager) || fetch;
fetcher('/api/entities/?drama_id=' + dramaId)
.then(r => r.json())
.then(data => {
const d = { characters: data.characters || [], scenes: data.scenes || [], props: data.props || [], creatures: data.creatures || [] };
window._genviaArtifactCache = window._genviaArtifactCache || {};
window._genviaArtifactCache['assets'] = { data: d, title: window.i18n?.t('ui.artifact.assets_materials.126') };
assetsLoading = false;
window.dispatchEvent(new CustomEvent('genvia:artifact-available', { detail: { type: 'assets', data: d, title: window.i18n?.t('ui.artifact.assets_materials.126') } }));
}).catch(e => {
console.error('[artifact-panel] fetch assets failed:', e);
assetsLoading = false;
});
} else if (!cached) {
// 没有 dramaId 或测试模式,显示空状态
assetsLoading = false;
const empty = defaultAssets();
assets = empty;
artifactData = empty;
}
}
} else if (_cache[step] || (window._genviaArtifactCache || {})[step]) {
const entry = _cache[step] || window._genviaArtifactCache[step];
artifactType = step;
artifactData = entry.data;
artifactTitle = entry.title || labels[step] || step;
} else {
// issue #691:_cache 未命中但 session 元数据确认工件存在时,按 artifact_id lazy-fetch
artifactType = step;
artifactData = null;
artifactTitle = labels[step] || step;
const artifactId = (window._genviaArtifactIds || {})[step];
if (artifactId && !window._testAgentMode && ['drama_outline', 'script', 'storyboard'].includes(step)) {
const fetcher = window.AuthManager?.fetchWithAuth?.bind(window.AuthManager) || fetch;
fetcher('/api/workspace/preview/' + artifactId)
.then(r => r.ok ? r.json() : null)
.then(resp => {
if (!resp || !resp.content) return;
const data = resp.content;
window._genviaArtifactCache = window._genviaArtifactCache || {};
window._genviaArtifactCache[step] = { data, title: resp.title || labels[step] };
window.dispatchEvent(new CustomEvent('genvia:artifact-available', {
detail: { type: step, artifactId, data, title: resp.title || labels[step] }
}));
})
.catch(e => console.warn('[artifact-panel] lazy-fetch failed:', step, e));
}
}
"
>