fix(knowdge-base): 知识库上传提示优化
This commit is contained in:
1 parent
5e7e5a8717
commit
854793f3fe
10 files changed
+181
-23
No files matched your search
@@ -22,8 +22,6 @@ AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4
|
||||
AUTH_JWT_JWKS_URL=http://192.168.100.192:8870/.well-known/jwks
|
||||
|
||||
# Casdoor
|
||||
|
||||
# 共用 IdP(可与生产 Casdoor 同机)
|
||||
CASDOOR_BASE_URL=http://192.168.100.192:8870
|
||||
# 以下为 hxops-dev 应用在 Casdoor 控制台里的 Client ID / Secret(勿与 prod 混用)
|
||||
CASDOOR_CLIENT_ID=758be5fcba2df784fdb4
|
||||
|
||||
@@ -32,7 +32,7 @@ CASDOOR_CLIENT_SECRET=522161bea5bb4f90b63f77c41dc26d223f1244ab
|
||||
CASDOOR_REDIRECT_URI=https://ait.well-trust.com/casdoor-callback
|
||||
CASDOOR_SCOPE=openid profile email
|
||||
CASDOOR_ORGANIZATION=organization_HX
|
||||
# Casdoor Providers → wecom:Name 字段(截图即为 wecom);Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
|
||||
# Casdoor Providers → wecom:Name 字段;Organization=organization_HX,Sub type=Internal,Scope=snsapi_userinfo
|
||||
CASDOOR_WECOM_PROVIDER_HINT=wecom
|
||||
|
||||
# 知识库 Dify 对接
|
||||
|
||||
@@ -628,7 +628,10 @@ defineProps<{
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="kb.showDeleteConfirmDialog"
|
||||
:title="kb.deleteConfirmTitle"
|
||||
:message="kb.deleteConfirmMessage"
|
||||
:confirm-text="kb.deleteConfirmText"
|
||||
:confirm-tone="kb.deleteConfirmTone"
|
||||
@confirm="kb.handleDeleteConfirm"
|
||||
@cancel="kb.closeDeleteConfirmDialog"
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/kb/composables/kb-workspace/kb-workspace.state.ts
|
||||
* 作业面共享响应式状态:各子 composable 通过同一 state 读写,避免重复 ref。
|
||||
* 用途:作业面共享响应式状态;各子 composable 通过同一 state 读写,避免重复 ref。
|
||||
* 依赖:vue-router、vue-i18n、auth、kb.api 类型、kb-workspace.types。
|
||||
* 逻辑:createKbWorkspaceState 产出全部 ref;含公共确认弹窗(删除/上传路径等)辅助方法。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
@@ -57,6 +59,9 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
const showPathUploadHistoryModal = ref(false);
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
const deleteConfirmTitle = ref('');
|
||||
const deleteConfirmText = ref('');
|
||||
const deleteConfirmTone = ref<'danger' | 'primary'>('danger');
|
||||
let pendingDeleteAction: (() => Promise<void> | void) | null = null;
|
||||
const showPathUploadDetails = ref(false);
|
||||
const fileInputRef = ref<HTMLInputElement | null>(null);
|
||||
@@ -114,11 +119,27 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
items: [],
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开公共确认弹窗(删除 / 上传路径等场景复用)。
|
||||
* @param message - 正文
|
||||
* @param onConfirm - 确认回调
|
||||
* @param options.title - 标题;空则用删除默认文案
|
||||
* @param options.confirmText - 确认按钮文案
|
||||
* @param options.confirmTone - danger 删除 / primary 非破坏性确认
|
||||
*/
|
||||
const openDeleteConfirmDialog = (
|
||||
message: string,
|
||||
onConfirm: () => Promise<void> | void,
|
||||
options?: {
|
||||
title?: string;
|
||||
confirmText?: string;
|
||||
confirmTone?: 'danger' | 'primary';
|
||||
},
|
||||
) => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmTitle.value = options?.title || '';
|
||||
deleteConfirmText.value = options?.confirmText || '';
|
||||
deleteConfirmTone.value = options?.confirmTone || 'danger';
|
||||
pendingDeleteAction = onConfirm;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
@@ -126,6 +147,9 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
const closeDeleteConfirmDialog = () => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmMessage.value = '';
|
||||
deleteConfirmTitle.value = '';
|
||||
deleteConfirmText.value = '';
|
||||
deleteConfirmTone.value = 'danger';
|
||||
pendingDeleteAction = null;
|
||||
};
|
||||
|
||||
@@ -170,6 +194,9 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
showPathUploadHistoryModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
deleteConfirmTitle,
|
||||
deleteConfirmText,
|
||||
deleteConfirmTone,
|
||||
showPathUploadDetails,
|
||||
fileInputRef,
|
||||
pathUploadInputRef,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/kb/composables/kb-workspace/useKbWorkspacePathUpload.ts
|
||||
* 路径上传:选文件、分批 job、轮询进度与历史批次操作。
|
||||
* 用途:路径上传编排——选目录、分批 job、轮询进度与历史批次操作。
|
||||
* 依赖:kb.api、kb-path-upload.utils、DeleteConfirmDialog(经 state.openDeleteConfirmDialog)。
|
||||
* 逻辑:优先 showDirectoryPicker 避免浏览器原生目录确认;回退 webkitdirectory;确认后写入待上传清单。
|
||||
*/
|
||||
import type { KbJob } from '../../api/kb.api';
|
||||
import {
|
||||
@@ -169,21 +171,25 @@ export function useKbWorkspacePathUpload(
|
||||
resetPathUploadDraft();
|
||||
};
|
||||
|
||||
const triggerPathUploadSelection = () => {
|
||||
pathUploadInputRef.value?.click();
|
||||
};
|
||||
|
||||
const handlePathFilesSelected = (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = Array.from(input.files || []);
|
||||
if (!files.length) {
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* 将 File 列表合并进待上传清单(按相对路径去重)。
|
||||
* @param files - 目录遍历得到的文件
|
||||
* @param getRelativePath - 取相对路径;缺省用 webkitRelativePath / name
|
||||
*/
|
||||
const appendPathUploadFiles = (
|
||||
files: File[],
|
||||
getRelativePath?: (file: File) => string,
|
||||
) => {
|
||||
if (!files.length) return;
|
||||
const existing = new Set(pathUploadSelectedFiles.value.map((item) => item.displayPath));
|
||||
const nextItems = files.flatMap((file, index) => {
|
||||
const relativePath = (file as File & { webkitRelativePath?: string }).webkitRelativePath || file.name;
|
||||
if (existing.has(relativePath)) return [];
|
||||
const relativePath = (
|
||||
getRelativePath?.(file)
|
||||
|| (file as File & { webkitRelativePath?: string }).webkitRelativePath
|
||||
|| file.name
|
||||
).replace(/\\/g, '/');
|
||||
if (!relativePath || existing.has(relativePath)) return [];
|
||||
existing.add(relativePath);
|
||||
const rootLabel = relativePath.includes('/') ? relativePath.split('/')[0] || file.name : file.name;
|
||||
return [{
|
||||
key: `${Date.now()}-${index}-${relativePath}`,
|
||||
@@ -192,9 +198,111 @@ export function useKbWorkspacePathUpload(
|
||||
rootLabel,
|
||||
}];
|
||||
});
|
||||
if (!nextItems.length) return;
|
||||
pathUploadSelectedFiles.value = [...pathUploadSelectedFiles.value, ...nextItems];
|
||||
pathUploadDraftText.value = pathUploadSelectedFiles.value.map((item) => item.displayPath).join('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
* 递归读取 File System Access API 目录句柄下的全部文件。
|
||||
*/
|
||||
const collectFilesFromDirectoryHandle = async (
|
||||
handle: FileSystemDirectoryHandle,
|
||||
parentPath = '',
|
||||
): Promise<File[]> => {
|
||||
const files: File[] = [];
|
||||
// File System Access API:DirectoryHandle 可异步迭代子项
|
||||
for await (const entry of (handle as any).values() as AsyncIterable<FileSystemHandle>) {
|
||||
const entryPath = parentPath ? `${parentPath}/${entry.name}` : entry.name;
|
||||
if (entry.kind === 'file') {
|
||||
const file = await (entry as FileSystemFileHandle).getFile();
|
||||
Object.defineProperty(file, 'webkitRelativePath', {
|
||||
configurable: true,
|
||||
value: entryPath,
|
||||
});
|
||||
files.push(file);
|
||||
} else if (entry.kind === 'directory') {
|
||||
files.push(...await collectFilesFromDirectoryHandle(entry as FileSystemDirectoryHandle, entryPath));
|
||||
}
|
||||
}
|
||||
return files;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开目录选择器;优先 showDirectoryPicker(无 Windows 原生上传确认),
|
||||
* 不支持时回退隐藏 input[webkitdirectory]。
|
||||
* 选完后用公共 DeleteConfirmDialog 二次确认再写入清单。
|
||||
*/
|
||||
const triggerPathUploadSelection = async () => {
|
||||
const picker = (window as Window & {
|
||||
showDirectoryPicker?: (options?: { mode?: 'read' | 'readwrite' }) => Promise<FileSystemDirectoryHandle>;
|
||||
}).showDirectoryPicker;
|
||||
|
||||
if (typeof picker === 'function') {
|
||||
try {
|
||||
const dirHandle = await picker({ mode: 'read' });
|
||||
const files = await collectFilesFromDirectoryHandle(dirHandle, dirHandle.name);
|
||||
if (!files.length) {
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadEmptyFolder');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
openDeleteConfirmDialog(
|
||||
t('kbWorkspace.pathUploadModal.folderConfirmMessage', {
|
||||
count: files.length,
|
||||
name: dirHandle.name,
|
||||
}),
|
||||
() => {
|
||||
appendPathUploadFiles(files, (file) => (
|
||||
(file as File & { webkitRelativePath?: string }).webkitRelativePath || file.name
|
||||
));
|
||||
},
|
||||
{
|
||||
title: t('kbWorkspace.pathUploadModal.folderConfirmTitle', { count: files.length }),
|
||||
confirmText: t('kbWorkspace.pathUploadModal.folderConfirmAction'),
|
||||
confirmTone: 'primary',
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
// 用户取消选目录不提示
|
||||
if (err instanceof DOMException && err.name === 'AbortError') return;
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadPickFailed');
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pathUploadInputRef.value?.click();
|
||||
};
|
||||
|
||||
/**
|
||||
* 旧版 input[webkitdirectory] 回退:浏览器会先弹原生确认,再进入本回调。
|
||||
* 仍用公共确认弹窗二次确认后写入清单。
|
||||
*/
|
||||
const handlePathFilesSelected = (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const files = Array.from(input.files || []);
|
||||
input.value = '';
|
||||
const firstFile = files[0];
|
||||
if (!firstFile) return;
|
||||
|
||||
const firstRelative = (firstFile as File & { webkitRelativePath?: string }).webkitRelativePath || firstFile.name;
|
||||
const folderName = firstRelative.includes('/') ? (firstRelative.split('/')[0] || firstRelative) : firstRelative;
|
||||
|
||||
openDeleteConfirmDialog(
|
||||
t('kbWorkspace.pathUploadModal.folderConfirmMessage', {
|
||||
count: files.length,
|
||||
name: folderName,
|
||||
}),
|
||||
() => {
|
||||
appendPathUploadFiles(files);
|
||||
},
|
||||
{
|
||||
title: t('kbWorkspace.pathUploadModal.folderConfirmTitle', { count: files.length }),
|
||||
confirmText: t('kbWorkspace.pathUploadModal.folderConfirmAction'),
|
||||
confirmTone: 'primary',
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const removeSelectedPathFile = (key: string) => {
|
||||
|
||||
@@ -277,7 +277,10 @@
|
||||
"selectedRoots": "Selected roots: {paths}",
|
||||
"noRoots": "None",
|
||||
"pickFolderFirst": "Select a local folder before confirming upload.",
|
||||
"confirmUpload": "Confirm upload"
|
||||
"confirmUpload": "Confirm upload",
|
||||
"folderConfirmTitle": "Upload {count} files?",
|
||||
"folderConfirmMessage": "All files under “{name}” will be imported. Continue only if this folder is correct.",
|
||||
"folderConfirmAction": "Upload"
|
||||
},
|
||||
"pathUploadHistoryModal": {
|
||||
"title": "Path upload history",
|
||||
@@ -365,6 +368,8 @@
|
||||
"pathUploadBusy": "Upload in progress, please wait",
|
||||
"selectGroupFirst": "Please select a group first",
|
||||
"selectPathFiles": "Please select at least one local folder or file",
|
||||
"pathUploadEmptyFolder": "The selected folder has no files to upload",
|
||||
"pathUploadPickFailed": "Failed to pick a local folder. Retry or use another browser",
|
||||
"createPathJobFailed": "Failed to create path upload job",
|
||||
"pathStageFailed": "Path file staging failed",
|
||||
"pathUploadDone": "Path files uploaded and clean submitted",
|
||||
|
||||
@@ -277,7 +277,10 @@
|
||||
"selectedRoots": "root ที่เลือก: {paths}",
|
||||
"noRoots": "ไม่มี",
|
||||
"pickFolderFirst": "โปรดเลือกโฟลเดอร์ในเครื่องก่อนยืนยันอัปโหลด",
|
||||
"confirmUpload": "ยืนยันอัปโหลด"
|
||||
"confirmUpload": "ยืนยันอัปโหลด",
|
||||
"folderConfirmTitle": "อัปโหลด {count} ไฟล์หรือไม่?",
|
||||
"folderConfirmMessage": "จะนำเข้าไฟล์ทั้งหมดจาก “{name}” โปรดยืนยันว่าโฟลเดอร์ถูกต้องก่อนดำเนินการต่อ",
|
||||
"folderConfirmAction": "อัปโหลด"
|
||||
},
|
||||
"pathUploadHistoryModal": {
|
||||
"title": "ประวัติ batch อัปโหลด path",
|
||||
@@ -365,6 +368,8 @@
|
||||
"pathUploadBusy": "กำลังอัปโหลด โปรดรอสักครู่",
|
||||
"selectGroupFirst": "โปรดเลือกกลุ่มก่อน",
|
||||
"selectPathFiles": "โปรดเลือกโฟลเดอร์หรือไฟล์ในเครื่องอย่างน้อยหนึ่งรายการ",
|
||||
"pathUploadEmptyFolder": "โฟลเดอร์ที่เลือกไม่มีไฟล์ให้อัปโหลด",
|
||||
"pathUploadPickFailed": "เลือกโฟลเดอร์ในเครื่องไม่สำเร็จ โปรดลองใหม่หรือใช้เบราว์เซอร์อื่น",
|
||||
"createPathJobFailed": "สร้างงานอัปโหลด path ล้มเหลว",
|
||||
"pathStageFailed": "จัดเก็บไฟล์ path ชั่วคราวล้มเหลว",
|
||||
"pathUploadDone": "อัปโหลดไฟล์ path และส่งทำความสะอาดแล้ว",
|
||||
|
||||
@@ -277,7 +277,10 @@
|
||||
"selectedRoots": "已选根路径:{paths}",
|
||||
"noRoots": "暂无",
|
||||
"pickFolderFirst": "请选择本地目录后再确认上传。",
|
||||
"confirmUpload": "确认上传"
|
||||
"confirmUpload": "确认上传",
|
||||
"folderConfirmTitle": "是否上传 {count} 个文件?",
|
||||
"folderConfirmMessage": "将从「{name}」导入所选目录下的全部文件。请确认目录无误后再继续。",
|
||||
"folderConfirmAction": "上传"
|
||||
},
|
||||
"pathUploadHistoryModal": {
|
||||
"title": "上传路径历史批次",
|
||||
@@ -365,6 +368,8 @@
|
||||
"pathUploadBusy": "有文件正在上传请稍等再试~",
|
||||
"selectGroupFirst": "请先选择知识库分组",
|
||||
"selectPathFiles": "请先选择至少一个本地目录或文件",
|
||||
"pathUploadEmptyFolder": "所选目录下没有可上传的文件",
|
||||
"pathUploadPickFailed": "选择本地目录失败,请重试或换用其他浏览器",
|
||||
"createPathJobFailed": "创建上传路径任务失败",
|
||||
"pathStageFailed": "路径文件暂存失败",
|
||||
"pathUploadDone": "路径文件已逐个上传并提交清洗",
|
||||
|
||||
@@ -277,7 +277,10 @@
|
||||
"selectedRoots": "已選根路徑:{paths}",
|
||||
"noRoots": "暫無",
|
||||
"pickFolderFirst": "請選擇本地目錄後再確認上傳。",
|
||||
"confirmUpload": "確認上傳"
|
||||
"confirmUpload": "確認上傳",
|
||||
"folderConfirmTitle": "是否上傳 {count} 個檔案?",
|
||||
"folderConfirmMessage": "將從「{name}」匯入所選目錄下的全部檔案。請確認目錄無誤後再繼續。",
|
||||
"folderConfirmAction": "上傳"
|
||||
},
|
||||
"pathUploadHistoryModal": {
|
||||
"title": "上傳路徑歷史批次",
|
||||
@@ -365,6 +368,8 @@
|
||||
"pathUploadBusy": "有文件正在上傳請稍等再試~",
|
||||
"selectGroupFirst": "請先選擇知識庫分組",
|
||||
"selectPathFiles": "請先選擇至少一個本地目錄或文件",
|
||||
"pathUploadEmptyFolder": "所選目錄下沒有可上傳的檔案",
|
||||
"pathUploadPickFailed": "選擇本地目錄失敗,請重試或改用其他瀏覽器",
|
||||
"createPathJobFailed": "創建上傳路徑任務失敗",
|
||||
"pathStageFailed": "路徑文件暫存失敗",
|
||||
"pathUploadDone": "路徑文件已逐個上傳並提交清洗",
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* shared/components/DeleteConfirmDialog.vue
|
||||
* 通用确认弹窗(默认删除场景,可通过 title / confirmTone 用于其它确认)。
|
||||
* 用途:通用确认弹窗(默认删除;可通过 title / confirmTone / confirmText 用于上传路径等确认)。
|
||||
* 依赖:vue-i18n、dialog-overlay / dialog-panel 设计系统样式。
|
||||
* 逻辑:KbWorkspaceOverlays、ChatViewOverlays、各管理端页面以 v-model 控制显隐。
|
||||
*/
|
||||
|
||||
import { computed, onBeforeUnmount, watch } from 'vue';
|
||||
|
||||
Reference in new issue
Block a user