feat(chat): 完善固资预览与下载权限
This commit is contained in:
1 parent
6ce0942fef
commit
bf18a7ef1d
19 files changed
+1163
-86
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* features/chat/composables/useChatSourceFiles.ts
|
||||
* 检索来源 / 源文件链接解析与预览。
|
||||
*/
|
||||
@@ -204,6 +204,8 @@ export interface UseChatSourceFilesOptions {
|
||||
export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceFilesOptions) {
|
||||
const filePreviewVisible = ref(false);
|
||||
const previewFile = ref<{ name: string; url: string; actualExt?: string } | null>(null);
|
||||
const previewFiles = ref<Array<{ name: string; url: string; actualExt?: string }>>([]);
|
||||
const currentPreviewIndex = ref(0);
|
||||
|
||||
const getSourceTitle = (item: Record<string, unknown>) =>
|
||||
String(item?.document_name || item?.title || item?.source || 'Untitled Source');
|
||||
@@ -398,6 +400,8 @@ export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceF
|
||||
window.location.href = resolvedFile.url;
|
||||
return;
|
||||
}
|
||||
previewFiles.value = [resolvedFile];
|
||||
currentPreviewIndex.value = 0;
|
||||
previewFile.value = resolvedFile;
|
||||
filePreviewVisible.value = true;
|
||||
} catch (error: unknown) {
|
||||
@@ -406,6 +410,55 @@ export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceF
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开多文件预览组,并支持在同一弹窗内切换。
|
||||
* AI 触发时机:当后端一次返回同资产的多张图片,需要在当前系统内左右切换查看时调用。
|
||||
* 核心逻辑:先解析每个文件的可预览 URL,再把文件列表和初始索引写入共享弹窗状态。
|
||||
* 参数与输出约束:files 必须至少有 1 个可预览项;initialIndex 会被钳制到合法范围。
|
||||
*/
|
||||
const openPreviewGallery = async (files: SourceFileLink[], initialIndex = 0) => {
|
||||
const normalizedFiles = Array.isArray(files) ? files : [];
|
||||
if (!normalizedFiles.length) {
|
||||
msg.warning(t('chat.previewUnavailable'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const resolvedFiles = await Promise.all(normalizedFiles.map((file) => resolveSourceLink(file)));
|
||||
if (!resolvedFiles.length) {
|
||||
msg.warning(t('chat.previewUnavailable'));
|
||||
return;
|
||||
}
|
||||
const safeIndex = Math.min(Math.max(initialIndex, 0), resolvedFiles.length - 1);
|
||||
const initialFile = resolvedFiles[safeIndex] || resolvedFiles[0];
|
||||
if (!initialFile) {
|
||||
msg.warning(t('chat.previewUnavailable'));
|
||||
return;
|
||||
}
|
||||
if (shouldBypassEmbeddedPreview(initialFile)) {
|
||||
window.location.href = initialFile.url;
|
||||
return;
|
||||
}
|
||||
previewFiles.value = resolvedFiles;
|
||||
currentPreviewIndex.value = safeIndex;
|
||||
previewFile.value = initialFile;
|
||||
filePreviewVisible.value = true;
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : t('chat.previewUnavailable');
|
||||
msg.warning(message);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换当前预览中的文件索引。
|
||||
* 用途:供 FilePreviewModal 在多图模式下切换上一张、下一张或缩略图点击时回写当前文件。
|
||||
*/
|
||||
const setPreviewFileIndex = (nextIndex: number) => {
|
||||
if (!previewFiles.value.length) return;
|
||||
const safeIndex = Math.min(Math.max(nextIndex, 0), previewFiles.value.length - 1);
|
||||
currentPreviewIndex.value = safeIndex;
|
||||
previewFile.value = previewFiles.value[safeIndex] || null;
|
||||
};
|
||||
|
||||
const parsePlmPreviewLink = (href: string): SourceFileLink | null => {
|
||||
const rawHref = (href || '').trim();
|
||||
if (!rawHref.startsWith('#plm-preview?')) return null;
|
||||
@@ -419,6 +472,8 @@ export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceF
|
||||
return {
|
||||
filePreviewVisible,
|
||||
previewFile,
|
||||
previewFiles,
|
||||
currentPreviewIndex,
|
||||
getSourceTitle,
|
||||
getSourceMeta,
|
||||
getSourceBrief,
|
||||
@@ -427,6 +482,8 @@ export function useChatSourceFiles({ agentId, t, msg, isMobile }: UseChatSourceF
|
||||
getDisplayRetrieverResources,
|
||||
shouldExpandSourceDetails,
|
||||
openPreview,
|
||||
openPreviewGallery,
|
||||
setPreviewFileIndex,
|
||||
parsePlmPreviewLink,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user