2052 lines
81 KiB
Vue
2052 lines
81 KiB
Vue
<script setup lang="ts">
|
|
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import Uppy from '@uppy/core'
|
|
import Dashboard from '@uppy/dashboard'
|
|
import XHRUpload from '@uppy/xhr-upload'
|
|
import '@uppy/core/dist/style.min.css'
|
|
import '@uppy/dashboard/dist/style.min.css'
|
|
|
|
import DifyHealthDialog from '@/components/DifyHealthDialog.vue'
|
|
import DifySettingsDialog from '@/components/DifySettingsDialog.vue'
|
|
import LocaleSwitcher from '@/components/LocaleSwitcher.vue'
|
|
import StatusPill from '@/components/StatusPill.vue'
|
|
import ToastStack from '@/components/ToastStack.vue'
|
|
import { authState, clearSession } from '@/lib/auth'
|
|
import { apiFetch } from '@/lib/api'
|
|
import { localeCode, useI18n } from '@/lib/i18n'
|
|
|
|
type Department = {
|
|
id: number
|
|
name: string
|
|
description?: string | null
|
|
knowledge_base_count?: number
|
|
}
|
|
|
|
type Group = {
|
|
id: number
|
|
name: string
|
|
description?: string | null
|
|
dify_dataset_id?: string | null
|
|
document_count?: number
|
|
department_id: number | null
|
|
department_name?: string | null
|
|
}
|
|
|
|
type UserBrief = {
|
|
id: number
|
|
username: string
|
|
full_name?: string | null
|
|
}
|
|
|
|
type CurrentVersion = {
|
|
id: number
|
|
version_no: number
|
|
source_filename: string
|
|
source_ext: string
|
|
file_size: number
|
|
convert_status: string
|
|
sync_status: string
|
|
uploaded_at: string
|
|
uploaded_by?: UserBrief | null
|
|
failed_reason?: string | null
|
|
}
|
|
|
|
type FileRow = {
|
|
id: number
|
|
title: string
|
|
version_count: number
|
|
current_version: CurrentVersion | null
|
|
}
|
|
|
|
type UploadResponse = {
|
|
created?: Array<unknown>
|
|
duplicates?: Array<{ filename?: string; reason?: string }>
|
|
}
|
|
|
|
type DifyDiffRow = {
|
|
key: string
|
|
status: 'matched' | 'local_only' | 'dify_only' | 'attention'
|
|
display_name: string
|
|
knowledge_base?: {
|
|
group_id?: number | null
|
|
name?: string | null
|
|
dataset_id?: string | null
|
|
} | null
|
|
local?: {
|
|
document_id: number
|
|
title: string
|
|
source_ext?: string | null
|
|
convert_status: string
|
|
sync_status: string
|
|
remote_document_id?: string | null
|
|
} | null
|
|
remote?: {
|
|
document_id: string
|
|
name: string
|
|
indexing_status?: string | null
|
|
display_status?: string | null
|
|
enabled: boolean
|
|
} | null
|
|
}
|
|
|
|
type DashboardSummary = {
|
|
knowledge_base_count: number
|
|
file_count: number
|
|
running_count: number
|
|
}
|
|
|
|
type UploadRejection = {
|
|
name: string
|
|
reason: string
|
|
}
|
|
|
|
const router = useRouter()
|
|
const { locale, t } = useI18n()
|
|
|
|
const departments = ref<Department[]>([])
|
|
const selectedDepartmentId = ref<number | null>(null)
|
|
const groups = ref<Group[]>([])
|
|
const selectedGroupId = ref<number | null>(null)
|
|
const files = ref<FileRow[]>([])
|
|
const selectedIds = ref<number[]>([])
|
|
const loading = ref(false)
|
|
const filterBusy = ref(false)
|
|
const actionBusy = ref(false)
|
|
const error = ref('')
|
|
const userMenuOpen = ref(false)
|
|
const healthDialogOpen = ref(false)
|
|
const toasts = ref<Array<{ id: number; tone?: 'success' | 'error'; message: string }>>([])
|
|
const uploaderHost = ref<HTMLElement | null>(null)
|
|
const uploadFileInput = ref<HTMLInputElement | null>(null)
|
|
const uploadFolderInput = ref<HTMLInputElement | null>(null)
|
|
const groupInlineForm = reactive({
|
|
name: '',
|
|
description: ''
|
|
})
|
|
const dashboardSummary = reactive<DashboardSummary>({
|
|
knowledge_base_count: 0,
|
|
file_count: 0,
|
|
running_count: 0
|
|
})
|
|
const uploadRejections = ref<UploadRejection[]>([])
|
|
const groupDialog = reactive({
|
|
open: false,
|
|
mode: 'create' as 'create' | 'edit',
|
|
groupId: null as number | null,
|
|
name: '',
|
|
description: '',
|
|
departmentId: null as number | null,
|
|
})
|
|
const uploadDialog = reactive({
|
|
open: false
|
|
})
|
|
const groupDeleteDialog = reactive({
|
|
open: false,
|
|
group: null as Group | null,
|
|
deleteDify: false
|
|
})
|
|
const diffViewer = reactive({
|
|
open: false,
|
|
loading: false,
|
|
queried: false,
|
|
scope: 'knowledge_base' as 'knowledge_base' | 'global',
|
|
searchField: 'file_name' as 'file_name' | 'knowledge_base',
|
|
page: 1,
|
|
qInput: '',
|
|
qFilter: '',
|
|
summary: {
|
|
matched: 0,
|
|
local_only: 0,
|
|
dify_only: 0,
|
|
attention: 0
|
|
},
|
|
rows: [] as DifyDiffRow[]
|
|
})
|
|
const previewDialog = reactive({
|
|
open: false,
|
|
loading: false,
|
|
mode: 'text' as 'text' | 'pdf' | 'image' | 'unsupported',
|
|
title: '',
|
|
subtitle: '',
|
|
text: '',
|
|
url: ''
|
|
})
|
|
const settingsDialogOpen = ref(false)
|
|
const documentDeleteDialog = reactive({
|
|
open: false,
|
|
row: null as FileRow | null,
|
|
deleteDify: false
|
|
})
|
|
|
|
const filters = reactive({
|
|
q: '',
|
|
status: '',
|
|
sync_status: '',
|
|
file_type: '',
|
|
uploaded_from: '',
|
|
uploaded_to: ''
|
|
})
|
|
|
|
let pollTimer: number | undefined
|
|
let uppy: Uppy | null = null
|
|
const filePage = ref(1)
|
|
const filePageSize = ref(50)
|
|
const pageSelectAllInput = ref<HTMLInputElement | null>(null)
|
|
const filePageSizeOptions = [20, 50, 100]
|
|
|
|
const isAdmin = computed(() => ['admin', 'super_admin'].includes(authState.user?.role || ''))
|
|
const isSuperAdmin = computed(() => authState.user?.role === 'super_admin')
|
|
const canManagePermissions = computed(() => isAdmin.value)
|
|
const canManageKnowledgeBases = computed(() => isAdmin.value)
|
|
const canManageSettings = computed(() => isAdmin.value)
|
|
const hasDepartments = computed(() => departments.value.length > 0)
|
|
const hasGroups = computed(() => groups.value.length > 0)
|
|
const selectedGroup = computed(() => groups.value.find((item) => item.id === selectedGroupId.value) || null)
|
|
const selectedDepartment = computed(() => departments.value.find((item) => item.id === selectedDepartmentId.value) || null)
|
|
const currentUserLabel = computed(() => authState.user?.full_name || authState.user?.username || t('common.unknown'))
|
|
const workspaceHeaderTitle = computed(() => t('login.productName'))
|
|
const workspaceHeaderEyebrow = computed(() => '')
|
|
const selectedGroupFileCount = computed(() => selectedGroup.value?.document_count ?? files.value.length)
|
|
const selectedCount = computed(() => selectedIds.value.length)
|
|
const isGlobalDiff = computed(() => diffViewer.scope === 'global')
|
|
const diffPageSize = 20
|
|
const diffSearchPlaceholder = computed(() => {
|
|
if (!isGlobalDiff.value) return t('workspace.diffSearchPlaceholder')
|
|
return diffViewer.searchField === 'knowledge_base'
|
|
? t('workspace.diffSearchByKnowledgeBasePlaceholder')
|
|
: t('workspace.diffSearchByFileNamePlaceholder')
|
|
})
|
|
const filteredDiffRows = computed(() => {
|
|
const term = diffViewer.qFilter.trim().toLowerCase()
|
|
if (!term) return diffViewer.rows
|
|
return diffViewer.rows.filter((row) => {
|
|
if (isGlobalDiff.value && diffViewer.searchField === 'knowledge_base') {
|
|
return (row.knowledge_base?.name || '').toLowerCase().includes(term)
|
|
}
|
|
return [row.display_name, row.local?.title, row.remote?.name].some((value) => value?.toLowerCase().includes(term))
|
|
})
|
|
})
|
|
const diffSearchActive = computed(() => diffViewer.qFilter.trim().length > 0)
|
|
const diffIssueRows = computed(() =>
|
|
filteredDiffRows.value.filter((row) => row.status !== 'matched').sort((left, right) => left.display_name.localeCompare(right.display_name))
|
|
)
|
|
const visibleDiffRows = computed(() => {
|
|
const rows = diffSearchActive.value ? filteredDiffRows.value : diffIssueRows.value
|
|
return [...rows].sort((left, right) => left.display_name.localeCompare(right.display_name))
|
|
})
|
|
const diffCountSummary = computed(() => ({
|
|
matched: diffViewer.rows.filter((row) => row.status === 'matched').length,
|
|
local_only: diffViewer.rows.filter((row) => row.status !== 'matched' && row.status !== 'dify_only').length,
|
|
dify_only: diffViewer.rows.filter((row) => row.status === 'dify_only').length
|
|
}))
|
|
const diffPageCount = computed(() => Math.max(1, Math.ceil(visibleDiffRows.value.length / diffPageSize)))
|
|
const pagedDiffRows = computed(() => {
|
|
const start = (diffViewer.page - 1) * diffPageSize
|
|
return visibleDiffRows.value.slice(start, start + diffPageSize)
|
|
})
|
|
const diffReady = computed(() => diffViewer.loading || diffViewer.queried)
|
|
const diffAligned = computed(
|
|
() => diffViewer.queried && !diffViewer.loading && diffViewer.rows.filter((row) => row.status !== 'matched').length === 0 && diffCountSummary.value.matched > 0
|
|
)
|
|
const hasPagedDiffResults = computed(() => diffViewer.queried && !diffViewer.loading && diffPageCount.value > 1)
|
|
const hasRunningItems = computed(() =>
|
|
files.value.some((item) => {
|
|
const version = item.current_version
|
|
if (!version) return false
|
|
return ['queued', 'running'].includes(version.convert_status) || version.sync_status === 'syncing'
|
|
})
|
|
)
|
|
const filePageCount = computed(() => Math.max(1, Math.ceil(files.value.length / filePageSize.value)))
|
|
const filePageStart = computed(() => (files.value.length === 0 ? 0 : (filePage.value - 1) * filePageSize.value))
|
|
const pagedFiles = computed(() => files.value.slice(filePageStart.value, filePageStart.value + filePageSize.value))
|
|
const filePageEnd = computed(() => Math.min(filePageStart.value + pagedFiles.value.length, files.value.length))
|
|
const currentPageIds = computed(() => pagedFiles.value.map((item) => item.id))
|
|
const isCurrentPageSelected = computed(
|
|
() => currentPageIds.value.length > 0 && currentPageIds.value.every((id) => selectedIds.value.includes(id))
|
|
)
|
|
const isCurrentPagePartiallySelected = computed(
|
|
() => currentPageIds.value.some((id) => selectedIds.value.includes(id)) && !isCurrentPageSelected.value
|
|
)
|
|
|
|
function pushToast(message: string, tone: 'success' | 'error' = 'success') {
|
|
const id = Date.now() + Math.floor(Math.random() * 1000)
|
|
toasts.value.push({ id, tone, message })
|
|
window.setTimeout(() => {
|
|
toasts.value = toasts.value.filter((item) => item.id !== id)
|
|
}, 3000)
|
|
}
|
|
|
|
function clearUploadRejections() {
|
|
uploadRejections.value = []
|
|
}
|
|
|
|
function appendUploadRejection(name: string, reason: string) {
|
|
if (!name) return
|
|
const dedupeKey = `${name}::${reason}`
|
|
if (uploadRejections.value.some((item) => `${item.name}::${item.reason}` === dedupeKey)) {
|
|
return
|
|
}
|
|
uploadRejections.value = [...uploadRejections.value, { name, reason }]
|
|
}
|
|
|
|
const conversionOptions = computed(() => [
|
|
{ value: '', label: t('workspace.allConversionStates') },
|
|
{ value: 'queued', label: t('status.queued') },
|
|
{ value: 'running', label: t('status.running') },
|
|
{ value: 'success', label: t('status.success') },
|
|
{ value: 'failed', label: t('status.failed') }
|
|
])
|
|
|
|
const syncOptions = computed(() => [
|
|
{ value: '', label: t('workspace.allSyncStates') },
|
|
{ value: 'unsynced', label: t('status.unsynced') },
|
|
{ value: 'syncing', label: t('status.syncing') },
|
|
{ value: 'synced', label: t('status.synced') },
|
|
{ value: 'sync_failed', label: t('status.sync_failed') }
|
|
])
|
|
|
|
const uppyCoreLocale = computed(() => {
|
|
if (locale.value === 'en') return undefined
|
|
return {
|
|
pluralize: () => 0,
|
|
strings: {
|
|
addBulkFilesFailed: {
|
|
0: '添加 %{smart_count} 个文件失败,发生内部错误',
|
|
1: '添加 %{smart_count} 个文件失败,发生内部错误'
|
|
},
|
|
youCanOnlyUploadX: {
|
|
0: '最多只能上传 %{smart_count} 个文件',
|
|
1: '最多只能上传 %{smart_count} 个文件'
|
|
},
|
|
youHaveToAtLeastSelectX: {
|
|
0: '至少需要选择 %{smart_count} 个文件',
|
|
1: '至少需要选择 %{smart_count} 个文件'
|
|
},
|
|
youCanOnlyUploadFileTypes: '仅支持上传:%{types}',
|
|
noMoreFilesAllowed: '不能再添加更多文件',
|
|
failedToUpload: '上传 %{file} 失败',
|
|
loading: '加载中…',
|
|
addedNumFiles: '已添加 %{numFiles} 个文件',
|
|
missingRequiredMetaField: '缺少必填字段',
|
|
pleaseWait: '请稍候'
|
|
}
|
|
}
|
|
})
|
|
|
|
const uppyDashboardLocale = computed(() => {
|
|
if (locale.value === 'en') return undefined
|
|
return {
|
|
strings: {
|
|
dashboardTitle: '上传面板',
|
|
myDevice: '本机文件',
|
|
dropPasteFiles: '把文件拖到这里,或 %{browseFiles}',
|
|
browseFiles: '浏览文件',
|
|
dropHint: '把文件拖到这里',
|
|
uploadComplete: '上传完成',
|
|
uploadPaused: '上传已暂停',
|
|
resumeUpload: '继续上传',
|
|
pauseUpload: '暂停上传',
|
|
retryUpload: '重试上传',
|
|
cancelUpload: '取消上传',
|
|
error: '错误',
|
|
addMoreFiles: '继续添加文件',
|
|
addMore: '继续添加',
|
|
xFilesSelected: {
|
|
0: '已选择 %{smart_count} 个文件',
|
|
1: '已选择 %{smart_count} 个文件'
|
|
},
|
|
uploadingXFiles: {
|
|
0: '正在上传 %{smart_count} 个文件',
|
|
1: '正在上传 %{smart_count} 个文件'
|
|
},
|
|
processingXFiles: {
|
|
0: '正在处理 %{smart_count} 个文件',
|
|
1: '正在处理 %{smart_count} 个文件'
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
function logout() {
|
|
clearSession()
|
|
router.push('/login')
|
|
}
|
|
|
|
function closeMenus() {
|
|
userMenuOpen.value = false
|
|
}
|
|
|
|
function formatSize(size: number) {
|
|
if (size < 1024) return `${size} B`
|
|
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`
|
|
return `${(size / 1024 / 1024).toFixed(1)} MB`
|
|
}
|
|
|
|
function formatDate(value: string) {
|
|
return new Date(value).toLocaleString(localeCode(locale.value))
|
|
}
|
|
|
|
function extractDownloadFilename(disposition: string) {
|
|
if (!disposition) return ''
|
|
const utf8Match = disposition.match(/filename\*\s*=\s*UTF-8''([^;]+)/i)
|
|
if (utf8Match?.[1]) {
|
|
try {
|
|
return decodeURIComponent(utf8Match[1].trim())
|
|
} catch {
|
|
return utf8Match[1].trim()
|
|
}
|
|
}
|
|
const quotedMatch = disposition.match(/filename\s*=\s*"([^"]+)"/i)
|
|
if (quotedMatch?.[1]) return quotedMatch[1].trim()
|
|
const plainMatch = disposition.match(/filename\s*=\s*([^;]+)/i)
|
|
if (plainMatch?.[1]) return plainMatch[1].trim()
|
|
return ''
|
|
}
|
|
|
|
function triggerBlobDownload(blob: Blob, filename: string) {
|
|
const url = URL.createObjectURL(blob)
|
|
const link = document.createElement('a')
|
|
link.href = url
|
|
link.download = filename
|
|
link.style.display = 'none'
|
|
document.body.appendChild(link)
|
|
link.click()
|
|
link.remove()
|
|
window.setTimeout(() => URL.revokeObjectURL(url), 0)
|
|
}
|
|
|
|
function formatDateParts(value: string) {
|
|
const date = new Date(value)
|
|
return {
|
|
day: date.toLocaleDateString(localeCode(locale.value)),
|
|
time: date.toLocaleTimeString(localeCode(locale.value), {
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
second: '2-digit',
|
|
hour12: false,
|
|
}),
|
|
}
|
|
}
|
|
|
|
function truncateTitle(value: string, limit = 10) {
|
|
if (!value) return ''
|
|
return value.length > limit ? `${value.slice(0, limit)}...` : value
|
|
}
|
|
|
|
function uploaderLabel(version: CurrentVersion | null) {
|
|
if (!version?.uploaded_by) return t('common.unknown')
|
|
return version.uploaded_by.full_name || version.uploaded_by.username
|
|
}
|
|
|
|
function revokePreviewUrl() {
|
|
if (previewDialog.url) {
|
|
URL.revokeObjectURL(previewDialog.url)
|
|
previewDialog.url = ''
|
|
}
|
|
}
|
|
|
|
function previewAvailable(row: FileRow, kind: 'source' | 'md') {
|
|
if (kind === 'md') return row.current_version?.convert_status === 'success'
|
|
return row.current_version?.source_ext?.toLowerCase() === '.pdf'
|
|
}
|
|
|
|
function canPush(version: CurrentVersion | null) {
|
|
if (!version) return false
|
|
return version.convert_status === 'success' && !['synced', 'syncing'].includes(version.sync_status)
|
|
}
|
|
|
|
function diffStatusLabel(status: DifyDiffRow['status']) {
|
|
const labels: Record<DifyDiffRow['status'], string> = {
|
|
matched: t('workspace.diffMatched'),
|
|
local_only: t('workspace.diffLocalOnly'),
|
|
dify_only: t('workspace.diffDifyOnly'),
|
|
attention: t('workspace.diffAttention')
|
|
}
|
|
return labels[status]
|
|
}
|
|
|
|
function diffStatusClass(status: DifyDiffRow['status']) {
|
|
const classes: Record<DifyDiffRow['status'], string> = {
|
|
matched: 'bg-emerald-100 text-emerald-700',
|
|
local_only: 'bg-sky-100 text-sky-700',
|
|
dify_only: 'bg-violet-100 text-violet-700',
|
|
attention: 'bg-amber-100 text-amber-700'
|
|
}
|
|
return classes[status]
|
|
}
|
|
|
|
function diffRowSideLabel(row: DifyDiffRow) {
|
|
if (row.status === 'matched') return t('workspace.diffMatched')
|
|
return row.status === 'dify_only' ? t('workspace.diffDifyOnly') : t('workspace.diffLocalOnly')
|
|
}
|
|
|
|
function remoteStatusLabel(row: DifyDiffRow) {
|
|
return row.remote?.display_status || row.remote?.indexing_status || t('common.none')
|
|
}
|
|
|
|
function diffActionLabel(row: DifyDiffRow) {
|
|
return row.status === 'dify_only' ? t('workspace.syncCurrent') : t('workspace.syncToDify')
|
|
}
|
|
|
|
function diffActionHidden(row: DifyDiffRow) {
|
|
return row.status === 'matched'
|
|
}
|
|
|
|
function diffFileLabel(row: DifyDiffRow) {
|
|
if (row.local) {
|
|
const ext = row.local.source_ext || ''
|
|
return row.local.title.endsWith(ext) ? row.local.title : `${row.local.title}${ext}`
|
|
}
|
|
return row.remote?.name || row.display_name
|
|
}
|
|
|
|
function resetDiffViewerState() {
|
|
diffViewer.page = 1
|
|
diffViewer.searchField = 'file_name'
|
|
diffViewer.qInput = ''
|
|
diffViewer.qFilter = ''
|
|
diffViewer.queried = false
|
|
diffViewer.rows = []
|
|
diffViewer.summary = { matched: 0, local_only: 0, dify_only: 0, attention: 0 }
|
|
}
|
|
|
|
function applyDiffSearch() {
|
|
diffViewer.qFilter = diffViewer.qInput.trim()
|
|
diffViewer.page = 1
|
|
}
|
|
|
|
function openCreateGroupDialog() {
|
|
if (!hasDepartments.value) {
|
|
pushToast(t('admin.createDepartmentFirst'), 'error')
|
|
return
|
|
}
|
|
groupDialog.open = true
|
|
groupDialog.mode = 'create'
|
|
groupDialog.groupId = null
|
|
groupDialog.name = ''
|
|
groupDialog.description = ''
|
|
groupDialog.departmentId = selectedDepartmentId.value || departments.value[0]?.id || null
|
|
}
|
|
|
|
function openEditGroupDialog(group: Group) {
|
|
groupDialog.open = true
|
|
groupDialog.mode = 'edit'
|
|
groupDialog.groupId = group.id
|
|
groupDialog.name = group.name
|
|
groupDialog.description = group.description || ''
|
|
groupDialog.departmentId = group.department_id
|
|
}
|
|
|
|
function closeGroupDialog() {
|
|
groupDialog.open = false
|
|
}
|
|
|
|
function closeUploadDialog() {
|
|
uploadDialog.open = false
|
|
}
|
|
|
|
function openDeleteGroupDialog(group: Group) {
|
|
groupDeleteDialog.open = true
|
|
groupDeleteDialog.group = group
|
|
groupDeleteDialog.deleteDify = false
|
|
}
|
|
|
|
function closeDeleteGroupDialog() {
|
|
groupDeleteDialog.open = false
|
|
groupDeleteDialog.group = null
|
|
groupDeleteDialog.deleteDify = false
|
|
}
|
|
|
|
function closeDiffViewer() {
|
|
diffViewer.open = false
|
|
resetDiffViewerState()
|
|
}
|
|
|
|
function closePreviewDialog() {
|
|
revokePreviewUrl()
|
|
previewDialog.open = false
|
|
previewDialog.loading = false
|
|
previewDialog.mode = 'text'
|
|
previewDialog.title = ''
|
|
previewDialog.subtitle = ''
|
|
previewDialog.text = ''
|
|
}
|
|
|
|
function openDeleteDocumentDialog(row: FileRow) {
|
|
documentDeleteDialog.open = true
|
|
documentDeleteDialog.row = row
|
|
documentDeleteDialog.deleteDify = false
|
|
}
|
|
|
|
function closeDeleteDocumentDialog() {
|
|
documentDeleteDialog.open = false
|
|
documentDeleteDialog.row = null
|
|
documentDeleteDialog.deleteDify = false
|
|
}
|
|
|
|
async function loadDashboardSummary() {
|
|
const suffix = selectedDepartmentId.value ? `?department_id=${selectedDepartmentId.value}` : ''
|
|
const data = await apiFetch(`/api/groups/summary${suffix}`)
|
|
dashboardSummary.knowledge_base_count = data.knowledge_base_count
|
|
dashboardSummary.file_count = data.file_count
|
|
dashboardSummary.running_count = data.running_count
|
|
}
|
|
|
|
async function loadDepartments() {
|
|
const data = await apiFetch('/api/departments')
|
|
departments.value = data.data || []
|
|
if (!departments.value.some((item) => item.id === selectedDepartmentId.value)) {
|
|
const preferredDepartmentId = authState.user?.primary_department_id ?? null
|
|
selectedDepartmentId.value =
|
|
departments.value.find((item) => item.id === preferredDepartmentId)?.id ??
|
|
departments.value[0]?.id ??
|
|
null
|
|
}
|
|
}
|
|
|
|
async function loadDifyDiff() {
|
|
if (diffViewer.scope === 'knowledge_base' && !selectedGroupId.value) {
|
|
diffViewer.rows = []
|
|
diffViewer.summary = { matched: 0, local_only: 0, dify_only: 0, attention: 0 }
|
|
diffViewer.queried = false
|
|
return
|
|
}
|
|
diffViewer.loading = true
|
|
try {
|
|
const endpoint =
|
|
diffViewer.scope === 'global'
|
|
? `/api/groups/dify-diff-global${selectedDepartmentId.value ? `?department_id=${selectedDepartmentId.value}` : ''}`
|
|
: `/api/groups/${selectedGroupId.value}/dify-diff`
|
|
const data = await apiFetch(endpoint)
|
|
diffViewer.rows = data.rows
|
|
diffViewer.summary = data.summary
|
|
diffViewer.queried = true
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToLoadDifyDiff')
|
|
} finally {
|
|
diffViewer.loading = false
|
|
}
|
|
}
|
|
|
|
async function runDiffScan() {
|
|
diffViewer.qFilter = ''
|
|
diffViewer.page = 1
|
|
await loadDifyDiff()
|
|
}
|
|
|
|
async function openDiffViewer(scope: 'knowledge_base' | 'global') {
|
|
if (scope === 'knowledge_base' && !selectedGroupId.value) return
|
|
diffViewer.scope = scope
|
|
diffViewer.open = true
|
|
resetDiffViewerState()
|
|
}
|
|
|
|
function diffActionAvailable(row: DifyDiffRow) {
|
|
if (row.status === 'matched') return false
|
|
if (row.status === 'dify_only') {
|
|
return Boolean(row.remote?.document_id && row.knowledge_base?.dataset_id && (row.knowledge_base?.group_id || row.knowledge_base?.name))
|
|
}
|
|
return !!row.local?.document_id
|
|
}
|
|
|
|
async function triggerDiffAction(row: DifyDiffRow) {
|
|
if (!diffActionAvailable(row)) {
|
|
error.value = t('workspace.syncCurrentUnavailable')
|
|
return
|
|
}
|
|
if (row.status === 'dify_only' && row.remote?.document_id && row.knowledge_base?.dataset_id) {
|
|
actionBusy.value = true
|
|
error.value = ''
|
|
try {
|
|
const result = await apiFetch('/api/groups/import-dify-document', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
group_id: row.knowledge_base?.group_id ?? selectedGroupId.value,
|
|
department_id: selectedDepartmentId.value,
|
|
dataset_id: row.knowledge_base.dataset_id,
|
|
remote_document_id: row.remote.document_id,
|
|
knowledge_base_name: row.knowledge_base?.name || selectedGroup.value?.name || null
|
|
})
|
|
})
|
|
if (result.group_id) {
|
|
selectedGroupId.value = result.group_id
|
|
}
|
|
pushToast(t('workspace.syncCurrentImported'))
|
|
await loadGroups()
|
|
await loadFiles({ silent: true })
|
|
await loadDashboardSummary()
|
|
await loadDifyDiff()
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToImportFromDify')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
return
|
|
}
|
|
if (!row.local) {
|
|
error.value = t('workspace.syncCurrentUnavailable')
|
|
return
|
|
}
|
|
await triggerSync(row.local.document_id)
|
|
await loadDifyDiff()
|
|
}
|
|
|
|
async function refreshWorkspace() {
|
|
await loadDepartments()
|
|
await loadGroups()
|
|
await loadFiles()
|
|
await loadDashboardSummary()
|
|
}
|
|
|
|
async function loadGroups() {
|
|
const suffix = selectedDepartmentId.value ? `?department_id=${selectedDepartmentId.value}` : ''
|
|
const data = await apiFetch(`/api/groups${suffix}`)
|
|
groups.value = data.data
|
|
const currentExists = groups.value.some((item) => item.id === selectedGroupId.value)
|
|
if (!currentExists) {
|
|
selectedGroupId.value = groups.value[0]?.id ?? null
|
|
}
|
|
}
|
|
|
|
function markDocumentsSyncing(documentIds: number[]) {
|
|
if (documentIds.length === 0) return
|
|
const targets = new Set(documentIds)
|
|
files.value = files.value.map((item) => {
|
|
if (!targets.has(item.id) || !item.current_version) return item
|
|
return {
|
|
...item,
|
|
current_version: {
|
|
...item.current_version,
|
|
sync_status: 'syncing'
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
async function loadFiles(options: { silent?: boolean; resetPage?: boolean } = {}) {
|
|
const { silent = false, resetPage = false } = options
|
|
if (!selectedGroupId.value) {
|
|
files.value = []
|
|
selectedIds.value = []
|
|
filePage.value = 1
|
|
return
|
|
}
|
|
if (!silent) {
|
|
loading.value = true
|
|
}
|
|
error.value = ''
|
|
try {
|
|
const query = new URLSearchParams()
|
|
Object.entries(filters).forEach(([key, value]) => {
|
|
if (value) query.set(key, value)
|
|
})
|
|
const suffix = query.toString() ? `?${query.toString()}` : ''
|
|
const data = await apiFetch(`/api/groups/${selectedGroupId.value}/files${suffix}`)
|
|
files.value = data.data
|
|
selectedIds.value = selectedIds.value.filter((id) => files.value.some((item) => item.id === id))
|
|
filePage.value = resetPage ? 1 : Math.min(filePage.value, Math.max(1, Math.ceil(files.value.length / filePageSize.value)))
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToLoadFiles')
|
|
} finally {
|
|
if (!silent) {
|
|
loading.value = false
|
|
}
|
|
}
|
|
}
|
|
|
|
async function createGroup() {
|
|
if (!groupInlineForm.name.trim()) {
|
|
error.value = t('workspace.groupNameRequired')
|
|
return
|
|
}
|
|
if (!selectedDepartmentId.value) {
|
|
error.value = t('workspace.departmentRequired')
|
|
return
|
|
}
|
|
actionBusy.value = true
|
|
error.value = ''
|
|
try {
|
|
const created = await apiFetch('/api/groups', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
name: groupInlineForm.name.trim(),
|
|
description: groupInlineForm.description.trim() || null,
|
|
department_id: selectedDepartmentId.value
|
|
})
|
|
})
|
|
groupInlineForm.name = ''
|
|
groupInlineForm.description = ''
|
|
pushToast(t('admin.groupCreated'))
|
|
await loadGroups()
|
|
selectedGroupId.value = created.id
|
|
await loadFiles()
|
|
await loadDashboardSummary()
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToCreateGroup')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function submitGroupDialog() {
|
|
if (!groupDialog.name.trim()) {
|
|
error.value = t('workspace.groupNameRequired')
|
|
return
|
|
}
|
|
if (!groupDialog.departmentId) {
|
|
error.value = t('workspace.departmentRequired')
|
|
return
|
|
}
|
|
actionBusy.value = true
|
|
error.value = ''
|
|
try {
|
|
if (groupDialog.mode === 'create') {
|
|
const created = await apiFetch('/api/groups', {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
name: groupDialog.name.trim(),
|
|
description: groupDialog.description.trim() || null,
|
|
department_id: groupDialog.departmentId
|
|
})
|
|
})
|
|
pushToast(t('admin.groupCreated'))
|
|
await loadGroups()
|
|
selectedGroupId.value = created.id
|
|
} else {
|
|
const target = groups.value.find((item) => item.id === groupDialog.groupId)
|
|
if (!target) throw new Error(t('workspace.failedToLoadFiles'))
|
|
const nameChanged = groupDialog.name.trim() !== target.name
|
|
const renameDify = nameChanged && !!target.dify_dataset_id ? window.confirm(t('admin.renameDifyPrompt')) : false
|
|
await apiFetch(`/api/groups/${target.id}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify({
|
|
name: groupDialog.name.trim(),
|
|
description: groupDialog.description.trim() || null,
|
|
department_id: groupDialog.departmentId,
|
|
rename_dify: renameDify
|
|
})
|
|
})
|
|
pushToast(t('admin.groupUpdated'))
|
|
await loadGroups()
|
|
selectedGroupId.value = target.id
|
|
}
|
|
closeGroupDialog()
|
|
await loadFiles()
|
|
await loadDashboardSummary()
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t(groupDialog.mode === 'create' ? 'workspace.failedToCreateGroup' : 'workspace.failedToSaveGroup')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function confirmDeleteGroup() {
|
|
const group = groupDeleteDialog.group
|
|
if (!group) return
|
|
actionBusy.value = true
|
|
error.value = ''
|
|
try {
|
|
await apiFetch(`/api/groups/${group.id}?delete_dify=${groupDeleteDialog.deleteDify}`, { method: 'DELETE' })
|
|
pushToast(t('workspace.groupDeleted'))
|
|
await loadGroups()
|
|
await loadFiles()
|
|
await loadDashboardSummary()
|
|
closeDeleteGroupDialog()
|
|
} catch (err) {
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToDeleteGroup')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
function updatePageSelectAllState() {
|
|
if (!pageSelectAllInput.value) return
|
|
pageSelectAllInput.value.indeterminate = isCurrentPagePartiallySelected.value
|
|
}
|
|
|
|
function selectAll() {
|
|
if (isCurrentPageSelected.value) {
|
|
selectedIds.value = selectedIds.value.filter((id) => !currentPageIds.value.includes(id))
|
|
return
|
|
}
|
|
selectedIds.value = [...new Set([...selectedIds.value, ...currentPageIds.value])]
|
|
}
|
|
|
|
function syncUppyMeta() {
|
|
if (!uppy) return
|
|
uppy.setMeta({
|
|
group_id: selectedGroupId.value ? String(selectedGroupId.value) : ''
|
|
})
|
|
}
|
|
|
|
function destroyUploader() {
|
|
uppy?.destroy()
|
|
uppy = null
|
|
if (uploaderHost.value) {
|
|
uploaderHost.value.innerHTML = ''
|
|
}
|
|
}
|
|
|
|
function mountUploader() {
|
|
if (!uploaderHost.value || uppy) return
|
|
|
|
uppy = new Uppy({
|
|
autoProceed: false,
|
|
infoTimeout: 3000,
|
|
restrictions: {
|
|
maxNumberOfFiles: 500,
|
|
allowedFileTypes: ['.doc', '.docx', '.pdf', '.xls', '.xlsx', '.csv', '.ppt', '.pptx']
|
|
},
|
|
locale: uppyCoreLocale.value,
|
|
onBeforeUpload: (pendingFiles) => {
|
|
if (!selectedGroupId.value) {
|
|
pushToast(t('workspace.selectGroupBeforeUploading'), 'error')
|
|
return false
|
|
}
|
|
syncUppyMeta()
|
|
return pendingFiles
|
|
}
|
|
})
|
|
|
|
uppy.use(Dashboard, {
|
|
target: uploaderHost.value,
|
|
inline: true,
|
|
height: 220,
|
|
note: t('workspace.uploadNote'),
|
|
locale: uppyDashboardLocale.value,
|
|
proudlyDisplayPoweredByUppy: false,
|
|
showProgressDetails: true,
|
|
hideUploadButton: false,
|
|
doneButtonHandler: null
|
|
})
|
|
|
|
uppy.use(XHRUpload, {
|
|
endpoint: '/api/files/upload',
|
|
method: 'post',
|
|
formData: true,
|
|
bundle: true,
|
|
fieldName: 'files',
|
|
headers: authState.token ? { Authorization: `Bearer ${authState.token}` } : {},
|
|
allowedMetaFields: ['group_id']
|
|
})
|
|
|
|
uppy.on('upload', () => {
|
|
syncUppyMeta()
|
|
})
|
|
|
|
uppy.on('restriction-failed', (file, uppyError) => {
|
|
appendUploadRejection(file?.name || t('workspace.unknownFile'), uppyError.message || t('workspace.uploadFailed'))
|
|
})
|
|
|
|
uppy.on('complete', (result) => {
|
|
const successful = result.successful || []
|
|
const body = successful.find((file) => file.response?.body)?.response?.body as UploadResponse | undefined
|
|
const createdCount = body?.created?.length ?? successful.length
|
|
const duplicateCount = body?.duplicates?.length ?? 0
|
|
const duplicateNames = (body?.duplicates || [])
|
|
.map((item) => item.filename)
|
|
.filter((item): item is string => Boolean(item))
|
|
.slice(0, 3)
|
|
.join(', ')
|
|
|
|
pushToast(
|
|
t('workspace.uploadQueued', {
|
|
created: createdCount,
|
|
duplicates: duplicateCount,
|
|
suffix: duplicateNames ? t('workspace.duplicateSuffix', { names: duplicateNames }) : ''
|
|
}),
|
|
'success'
|
|
)
|
|
void Promise.all([loadGroups(), loadFiles({ silent: true }), loadDashboardSummary()])
|
|
uppy?.clear()
|
|
})
|
|
|
|
uppy.on('upload-error', (_file, uppyError, response) => {
|
|
const detail =
|
|
typeof response?.body === 'object' && response?.body !== null ? (response.body as { detail?: string }).detail : ''
|
|
pushToast(detail || uppyError.message || t('workspace.uploadFailed'), 'error')
|
|
})
|
|
|
|
uppy.on('error', (uppyError) => {
|
|
pushToast(uppyError.message || t('workspace.uploadFailed'), 'error')
|
|
})
|
|
|
|
syncUppyMeta()
|
|
}
|
|
|
|
async function openUploadDialog() {
|
|
if (!hasDepartments.value) {
|
|
pushToast(t('admin.createDepartmentFirst'), 'error')
|
|
return
|
|
}
|
|
if (!selectedGroupId.value) {
|
|
pushToast(t('workspace.selectGroupBeforeUploading'), 'error')
|
|
return
|
|
}
|
|
clearUploadRejections()
|
|
uploadDialog.open = true
|
|
await nextTick()
|
|
mountUploader()
|
|
}
|
|
|
|
function addFilesToUploader(entries: Array<{ file: File; name: string }>) {
|
|
if (!uppy) return
|
|
for (const entry of entries) {
|
|
try {
|
|
uppy.addFile({
|
|
name: entry.name,
|
|
type: entry.file.type,
|
|
data: entry.file,
|
|
})
|
|
} catch (uppyError) {
|
|
appendUploadRejection(
|
|
entry.name,
|
|
uppyError instanceof Error ? uppyError.message : t('workspace.uploadFailed')
|
|
)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
function handleFileSelection(event: Event) {
|
|
const input = event.target as HTMLInputElement
|
|
addFilesToUploader(Array.from(input.files || []).map((file) => ({ file, name: file.name })))
|
|
input.value = ''
|
|
}
|
|
|
|
function handleFolderSelection(event: Event) {
|
|
const input = event.target as HTMLInputElement
|
|
addFilesToUploader(
|
|
Array.from(input.files || []).map((file) => ({
|
|
file,
|
|
name: (file as File & { webkitRelativePath?: string }).webkitRelativePath || file.name,
|
|
}))
|
|
)
|
|
input.value = ''
|
|
}
|
|
|
|
async function openPreview(row: FileRow, kind: 'source' | 'md') {
|
|
revokePreviewUrl()
|
|
previewDialog.open = true
|
|
previewDialog.loading = true
|
|
previewDialog.title = row.title
|
|
previewDialog.subtitle = kind === 'md' ? t('workspace.previewMarkdown') : t('workspace.previewOriginal')
|
|
previewDialog.text = ''
|
|
try {
|
|
const response = await fetch(`/api/files/${row.id}/download?kind=${kind}`, {
|
|
headers: { Authorization: `Bearer ${authState.token}` }
|
|
})
|
|
if (!response.ok) {
|
|
throw new Error(await response.text())
|
|
}
|
|
const blob = await response.blob()
|
|
const disposition = response.headers.get('content-disposition') || ''
|
|
const filename = extractDownloadFilename(disposition) || row.current_version?.source_filename || row.title
|
|
previewDialog.subtitle = filename
|
|
if (kind === 'md' || blob.type.startsWith('text/') || /\.(md|txt|csv)$/i.test(filename)) {
|
|
previewDialog.mode = 'text'
|
|
previewDialog.text = await blob.text()
|
|
} else if (blob.type.startsWith('image/') || /\.(png|jpg|jpeg|gif|webp|bmp|svg)$/i.test(filename)) {
|
|
previewDialog.mode = 'image'
|
|
previewDialog.url = URL.createObjectURL(blob)
|
|
} else if (blob.type === 'application/pdf' || /\.pdf$/i.test(filename)) {
|
|
previewDialog.mode = 'pdf'
|
|
previewDialog.url = URL.createObjectURL(blob)
|
|
} else {
|
|
previewDialog.mode = 'unsupported'
|
|
previewDialog.url = URL.createObjectURL(blob)
|
|
previewDialog.text = t('workspace.previewUnsupported')
|
|
}
|
|
} catch (err) {
|
|
previewDialog.mode = 'unsupported'
|
|
previewDialog.text = err instanceof Error ? err.message : t('workspace.previewFailed')
|
|
} finally {
|
|
previewDialog.loading = false
|
|
}
|
|
}
|
|
|
|
async function triggerSync(documentId: number) {
|
|
actionBusy.value = true
|
|
try {
|
|
await apiFetch(`/api/files/${documentId}/sync-dify`, { method: 'POST' })
|
|
markDocumentsSyncing([documentId])
|
|
pushToast(t('workspace.syncQueued'), 'success')
|
|
await Promise.all([loadFiles({ silent: true }), loadGroups(), loadDashboardSummary()])
|
|
} catch (err) {
|
|
pushToast(err instanceof Error ? err.message : t('workspace.failedToQueueSync'), 'error')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function triggerRetry(documentId: number) {
|
|
actionBusy.value = true
|
|
try {
|
|
await apiFetch(`/api/files/${documentId}/retry-convert`, { method: 'POST' })
|
|
pushToast(t('workspace.retryQueued'), 'success')
|
|
await loadFiles()
|
|
} catch (err) {
|
|
pushToast(err instanceof Error ? err.message : t('workspace.failedToQueueRetry'), 'error')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function batchSync() {
|
|
if (!hasDepartments.value) {
|
|
pushToast(t('admin.createDepartmentFirst'), 'error')
|
|
return
|
|
}
|
|
if (selectedIds.value.length === 0) return
|
|
actionBusy.value = true
|
|
try {
|
|
const syncingIds = [...selectedIds.value]
|
|
await apiFetch('/api/files/sync-dify-batch', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ document_ids: selectedIds.value })
|
|
})
|
|
markDocumentsSyncing(syncingIds)
|
|
await Promise.all([loadFiles({ silent: true }), loadGroups(), loadDashboardSummary()])
|
|
pushToast(t('workspace.batchSyncQueued', { count: syncingIds.length }), 'success')
|
|
} catch (err) {
|
|
pushToast(err instanceof Error ? err.message : t('workspace.failedToQueueBatchSync'), 'error')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function batchDownload(kind: 'source' | 'md') {
|
|
if (!hasDepartments.value) {
|
|
pushToast(t('admin.createDepartmentFirst'), 'error')
|
|
return
|
|
}
|
|
if (selectedIds.value.length === 0) return
|
|
error.value = ''
|
|
const response = await fetch('/api/files/download-batch', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${authState.token}`
|
|
},
|
|
body: JSON.stringify({ document_ids: selectedIds.value, kind })
|
|
})
|
|
if (!response.ok) {
|
|
error.value = await response.text()
|
|
return
|
|
}
|
|
const blob = await response.blob()
|
|
const disposition = response.headers.get('content-disposition') || ''
|
|
const today = new Date()
|
|
const fallbackDate = `${today.getFullYear()}${String(today.getMonth() + 1).padStart(2, '0')}${String(today.getDate()).padStart(2, '0')}`
|
|
triggerBlobDownload(blob, extractDownloadFilename(disposition) || `鏂囦欢涓嬭浇_${fallbackDate}.zip`)
|
|
}
|
|
|
|
async function confirmDeleteDocument() {
|
|
const row = documentDeleteDialog.row
|
|
if (!row) return
|
|
const deleteDify = documentDeleteDialog.deleteDify
|
|
const previousFiles = files.value
|
|
const previousSelectedIds = [...selectedIds.value]
|
|
const previousGroups = groups.value.map((item) => ({ ...item }))
|
|
const previousSummary = { ...dashboardSummary }
|
|
const wasRunning =
|
|
row.current_version != null &&
|
|
(['queued', 'running'].includes(row.current_version.convert_status) || row.current_version.sync_status === 'syncing')
|
|
|
|
closeDeleteDocumentDialog()
|
|
actionBusy.value = true
|
|
error.value = ''
|
|
|
|
files.value = files.value.filter((item) => item.id !== row.id)
|
|
selectedIds.value = selectedIds.value.filter((id) => id !== row.id)
|
|
|
|
const group = groups.value.find((item) => item.id === selectedGroupId.value)
|
|
if (group && typeof group.document_count === 'number') {
|
|
group.document_count = Math.max(0, group.document_count - 1)
|
|
}
|
|
dashboardSummary.file_count = Math.max(0, dashboardSummary.file_count - 1)
|
|
if (wasRunning) {
|
|
dashboardSummary.running_count = Math.max(0, dashboardSummary.running_count - 1)
|
|
}
|
|
|
|
try {
|
|
await apiFetch(`/api/files/${row.id}?delete_dify=${deleteDify}`, { method: 'DELETE' })
|
|
pushToast(t('workspace.documentDeleteQueued'))
|
|
await Promise.all([loadGroups(), loadFiles(), loadDashboardSummary()])
|
|
} catch (err) {
|
|
files.value = previousFiles
|
|
selectedIds.value = previousSelectedIds
|
|
groups.value = previousGroups
|
|
dashboardSummary.knowledge_base_count = previousSummary.knowledge_base_count
|
|
dashboardSummary.file_count = previousSummary.file_count
|
|
dashboardSummary.running_count = previousSummary.running_count
|
|
error.value = err instanceof Error ? err.message : t('workspace.failedToDeleteDocument')
|
|
pushToast(error.value, 'error')
|
|
} finally {
|
|
actionBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function downloadSingle(documentId: number, kind: 'source' | 'md') {
|
|
error.value = ''
|
|
const response = await fetch(`/api/files/${documentId}/download?kind=${kind}`, {
|
|
headers: { Authorization: `Bearer ${authState.token}` }
|
|
})
|
|
if (!response.ok) {
|
|
error.value = await response.text()
|
|
return
|
|
}
|
|
const blob = await response.blob()
|
|
const disposition = response.headers.get('content-disposition') || ''
|
|
triggerBlobDownload(blob, extractDownloadFilename(disposition) || `download.${kind === 'md' ? 'md' : 'bin'}`)
|
|
}
|
|
|
|
function applyFilters() {
|
|
filterBusy.value = true
|
|
void loadFiles({ silent: true, resetPage: true }).finally(() => {
|
|
filterBusy.value = false
|
|
})
|
|
}
|
|
|
|
function resetFilters() {
|
|
filters.q = ''
|
|
filters.status = ''
|
|
filters.sync_status = ''
|
|
filters.uploaded_from = ''
|
|
filters.uploaded_to = ''
|
|
filterBusy.value = true
|
|
void loadFiles({ silent: true, resetPage: true }).finally(() => {
|
|
filterBusy.value = false
|
|
})
|
|
}
|
|
|
|
function setupPolling() {
|
|
window.clearInterval(pollTimer)
|
|
pollTimer = window.setInterval(() => {
|
|
if (hasRunningItems.value) {
|
|
void Promise.all([loadFiles({ silent: true }), loadGroups(), loadDashboardSummary()])
|
|
}
|
|
}, 5000)
|
|
}
|
|
|
|
onMounted(async () => {
|
|
await refreshWorkspace()
|
|
setupPolling()
|
|
})
|
|
|
|
watch(selectedDepartmentId, async () => {
|
|
diffViewer.open = false
|
|
await loadGroups()
|
|
await loadFiles({ resetPage: true })
|
|
await loadDashboardSummary()
|
|
})
|
|
|
|
watch(selectedGroupId, async () => {
|
|
syncUppyMeta()
|
|
diffViewer.open = false
|
|
await loadFiles({ resetPage: true })
|
|
if (uploadDialog.open) {
|
|
await nextTick()
|
|
destroyUploader()
|
|
mountUploader()
|
|
}
|
|
})
|
|
|
|
watch(hasRunningItems, () => {
|
|
setupPolling()
|
|
})
|
|
|
|
watch([filePageCount, filePageSize], () => {
|
|
if (filePage.value > filePageCount.value) {
|
|
filePage.value = filePageCount.value
|
|
}
|
|
})
|
|
|
|
watch([selectedIds, pagedFiles], () => {
|
|
updatePageSelectAllState()
|
|
}, { deep: true, immediate: true })
|
|
|
|
watch(
|
|
() => diffViewer.searchField,
|
|
() => {
|
|
diffViewer.qInput = ''
|
|
diffViewer.qFilter = ''
|
|
diffViewer.page = 1
|
|
}
|
|
)
|
|
|
|
watch(diffIssueRows, () => {
|
|
if (diffViewer.page > diffPageCount.value) {
|
|
diffViewer.page = diffPageCount.value
|
|
}
|
|
})
|
|
|
|
watch(locale, async () => {
|
|
if (uploadDialog.open) {
|
|
await nextTick()
|
|
destroyUploader()
|
|
mountUploader()
|
|
}
|
|
})
|
|
|
|
watch(
|
|
() => `${locale.value}:${workspaceHeaderTitle.value}`,
|
|
() => {
|
|
document.title = workspaceHeaderTitle.value
|
|
},
|
|
{ immediate: true }
|
|
)
|
|
|
|
watch(
|
|
() => uploadDialog.open,
|
|
async (isOpen) => {
|
|
if (isOpen) {
|
|
await nextTick()
|
|
mountUploader()
|
|
syncUppyMeta()
|
|
return
|
|
}
|
|
destroyUploader()
|
|
}
|
|
)
|
|
|
|
onBeforeUnmount(() => {
|
|
window.clearInterval(pollTimer)
|
|
revokePreviewUrl()
|
|
destroyUploader()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<main class="min-h-screen px-4 py-6 md:px-8" @click="closeMenus">
|
|
<ToastStack :toasts="toasts" />
|
|
<div class="mx-auto flex max-w-[1680px] flex-col gap-6">
|
|
<header class="panel relative z-20 overflow-visible flex flex-col gap-4 px-6 py-4 xl:flex-row xl:items-center xl:justify-between">
|
|
<div>
|
|
<p v-if="workspaceHeaderEyebrow" class="text-xs font-semibold uppercase tracking-[0.32em] text-surge">
|
|
{{ workspaceHeaderEyebrow }}
|
|
</p>
|
|
<h1 class="text-3xl font-bold text-ink" :class="workspaceHeaderEyebrow ? 'mt-2' : ''">{{ workspaceHeaderTitle }}</h1>
|
|
</div>
|
|
<div class="flex flex-wrap items-center justify-end gap-3">
|
|
<LocaleSwitcher />
|
|
<button v-if="canManagePermissions" class="btn-ghost" @click="router.push('/admin')">
|
|
{{ t('workspace.adminConsole') }}
|
|
</button>
|
|
<div class="user-menu" tabindex="0" @click.stop>
|
|
<button class="user-menu-trigger" type="button" @click="userMenuOpen = !userMenuOpen">
|
|
<span class="user-menu-name" :title="currentUserLabel">{{ currentUserLabel }}</span>
|
|
<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.8" class="user-menu-icon">
|
|
<path d="m5 7 5 5 5-5" stroke-linecap="round" stroke-linejoin="round" />
|
|
</svg>
|
|
</button>
|
|
<div v-if="userMenuOpen" class="user-menu-panel min-w-[180px]">
|
|
<button v-if="canManageSettings" class="menu-item" @click="settingsDialogOpen = true">
|
|
{{ t('admin.openDifySettings') }}
|
|
</button>
|
|
<button v-if="canManageSettings" class="menu-item" @click="healthDialogOpen = true">
|
|
{{ t('admin.difyHealth') }}
|
|
</button>
|
|
<button class="menu-item" @click="logout">{{ t('common.signOut') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="grid gap-6 lg:grid-cols-[300px_minmax(0,1fr)]">
|
|
<aside class="panel overflow-hidden p-0">
|
|
<div class="flex h-full min-h-[720px] flex-col">
|
|
<div class="border-b border-slate-100 px-5 py-4">
|
|
<div class="flex items-center justify-between gap-3">
|
|
<div class="flex items-center gap-3">
|
|
<p class="text-sm font-semibold text-ink">{{ t('workspace.groupsTitle') }}</p>
|
|
<span class="tag bg-mist text-dusk">{{ groups.length }}</span>
|
|
</div>
|
|
<button
|
|
v-if="canManageKnowledgeBases && hasGroups"
|
|
class="btn-ghost shrink-0 whitespace-nowrap px-3 py-2 text-xs"
|
|
:disabled="actionBusy || !hasDepartments"
|
|
@click="openCreateGroupDialog"
|
|
>
|
|
{{ t('workspace.addGroup') }}
|
|
</button>
|
|
</div>
|
|
<div class="mt-4">
|
|
<select v-if="hasDepartments" v-model="selectedDepartmentId" class="input">
|
|
<option v-for="department in departments" :key="department.id" :value="department.id">
|
|
{{ department.name }}
|
|
</option>
|
|
</select>
|
|
<input
|
|
v-else
|
|
class="input"
|
|
:value="t('admin.noDepartmentPlaceholder')"
|
|
disabled
|
|
readonly
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div v-if="canManageKnowledgeBases && !hasGroups" class="border-b border-slate-100 px-4 py-4">
|
|
<div class="rounded-3xl border border-slate-200 bg-mist/60 p-4">
|
|
<p class="text-sm font-semibold text-ink">{{ t('workspace.createGroupPanel') }}</p>
|
|
<p v-if="!hasDepartments" class="mt-3 rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">
|
|
{{ t('admin.createDepartmentFirst') }}
|
|
</p>
|
|
<div v-else class="mt-3 space-y-3">
|
|
<select v-if="hasDepartments" v-model="selectedDepartmentId" class="input">
|
|
<option v-for="department in departments" :key="department.id" :value="department.id">
|
|
{{ department.name }}
|
|
</option>
|
|
</select>
|
|
<input
|
|
v-else
|
|
class="input"
|
|
:value="t('admin.noDepartmentPlaceholder')"
|
|
disabled
|
|
readonly
|
|
/>
|
|
<input v-model="groupInlineForm.name" class="input" :placeholder="t('admin.groupName')" />
|
|
<textarea
|
|
v-model="groupInlineForm.description"
|
|
class="input min-h-[92px] resize-none"
|
|
:placeholder="t('admin.groupDescription')"
|
|
></textarea>
|
|
<button class="btn-primary w-full" :disabled="actionBusy" @click="createGroup">{{ t('admin.createGroup') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex-1 overflow-y-auto px-4 py-4">
|
|
<div class="space-y-2.5">
|
|
<div v-for="group in groups" :key="group.id" class="group-card relative">
|
|
<button
|
|
class="w-full rounded-2xl border px-4 py-3 text-left transition"
|
|
:class="
|
|
selectedGroupId === group.id
|
|
? 'border-ink bg-ink text-white shadow-soft'
|
|
: 'border-slate-200 bg-white/80 text-ink hover:-translate-y-0.5 hover:border-surge hover:bg-white'
|
|
"
|
|
@click="selectedGroupId = group.id"
|
|
>
|
|
<div class="flex min-w-0 items-center gap-3 pr-14">
|
|
<span class="truncate text-[15px] font-semibold leading-6">{{ group.name }}</span>
|
|
</div>
|
|
<span
|
|
class="group-card-status-dot absolute right-4 top-1/2 inline-flex h-2.5 w-2.5 -translate-y-1/2 rounded-full transition"
|
|
:class="group.dify_dataset_id ? 'bg-emerald-400' : 'bg-slate-300'"
|
|
></span>
|
|
</button>
|
|
<div
|
|
v-if="canManageKnowledgeBases"
|
|
class="group-card-actions absolute right-2 top-1/2 z-10 flex -translate-y-1/2 items-center gap-1 rounded-full bg-white/96 p-1 shadow-soft"
|
|
>
|
|
<button
|
|
class="icon-btn text-ink"
|
|
:aria-label="t('workspace.editGroup')"
|
|
:title="t('workspace.editGroup')"
|
|
:disabled="actionBusy"
|
|
@click.stop="openEditGroupDialog(group)"
|
|
>
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" class="h-4 w-4">
|
|
<path d="M12 20h9" stroke-linecap="round" stroke-linejoin="round" />
|
|
<path
|
|
d="m16.5 3.5 4 4L8 20l-5 1 1-5 12.5-12.5Z"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
/>
|
|
</svg>
|
|
</button>
|
|
<button
|
|
class="icon-btn text-rose-600 hover:border-rose-200 hover:text-rose-700"
|
|
:aria-label="t('workspace.deleteGroup')"
|
|
:title="t('workspace.deleteGroup')"
|
|
:disabled="actionBusy"
|
|
@click.stop="openDeleteGroupDialog(group)"
|
|
>
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" class="h-4 w-4">
|
|
<path d="M3 6h18" stroke-linecap="round" />
|
|
<path d="M8 6V4.8A1.8 1.8 0 0 1 9.8 3h4.4A1.8 1.8 0 0 1 16 4.8V6" stroke-linecap="round" />
|
|
<path d="m6 6 1 14a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-14" stroke-linecap="round" stroke-linejoin="round" />
|
|
<path d="M10 11v6M14 11v6" stroke-linecap="round" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p v-if="groups.length === 0" class="rounded-2xl border border-dashed border-slate-200 px-4 py-6 text-sm text-dusk">
|
|
{{ t('workspace.noGroupsYet') }}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<section class="space-y-4">
|
|
<div class="grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(420px,0.85fr)]">
|
|
<div class="panel px-5 py-4">
|
|
<div class="flex flex-wrap items-start justify-between gap-4">
|
|
<div class="min-w-0 flex-1">
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.currentGroup') }}</p>
|
|
<div class="mt-2 flex flex-wrap items-center gap-3">
|
|
<h2 class="truncate text-[1.7rem] font-bold leading-tight text-ink">
|
|
{{ selectedGroup?.name || t('workspace.selectGroup') }}
|
|
</h2>
|
|
<span
|
|
class="tag px-3 py-1.5 text-sm"
|
|
:class="selectedGroup?.dify_dataset_id ? 'bg-emerald-100 text-emerald-700' : 'bg-slate-100 text-slate-600'"
|
|
>
|
|
{{ selectedGroup?.dify_dataset_id ? t('workspace.difyLinkedStatus') : t('workspace.difyUnlinkedStatus') }}
|
|
</span>
|
|
<span class="tag bg-mist px-3 py-1.5 text-sm text-dusk">
|
|
{{ t('workspace.documents') }} {{ selectedGroupFileCount }}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<button class="btn-ghost" :disabled="!selectedGroupId" @click="openDiffViewer('knowledge_base')">
|
|
{{ t('workspace.viewCurrentDifyDiff') }}
|
|
</button>
|
|
</div>
|
|
<div class="mt-4 flex flex-wrap items-center gap-3">
|
|
<button class="btn-ghost" :disabled="!selectedGroupId || !hasDepartments" @click="openUploadDialog">
|
|
{{ t('workspace.batchUpload') }}
|
|
</button>
|
|
<button class="btn-ghost" :disabled="selectedCount === 0 || actionBusy || !hasDepartments" @click="batchSync">
|
|
{{ t('workspace.batchSyncToDify') }}
|
|
</button>
|
|
<button class="btn-ghost" :disabled="selectedCount === 0 || !hasDepartments" @click="batchDownload('source')">
|
|
{{ t('workspace.downloadOriginals') }}
|
|
</button>
|
|
<button class="btn-ghost" :disabled="selectedCount === 0 || !hasDepartments" @click="batchDownload('md')">
|
|
{{ t('workspace.downloadMarkdown') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel px-5 py-4">
|
|
<div class="flex flex-wrap items-center justify-between gap-4">
|
|
<div>
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.allKnowledgeBases') }}</p>
|
|
</div>
|
|
<button class="btn-ghost" :disabled="actionBusy" @click="openDiffViewer('global')">
|
|
{{ t('workspace.viewGlobalDifyDiff') }}
|
|
</button>
|
|
</div>
|
|
<div class="mt-4 flex flex-wrap items-center gap-2">
|
|
<div class="rounded-2xl border border-slate-100 bg-mist/60 px-3 py-2">
|
|
<p class="text-[10px] uppercase tracking-[0.2em] text-dusk">{{ t('workspace.knowledgeBaseCount') }}</p>
|
|
<p class="mt-1 text-lg font-bold text-ink">{{ dashboardSummary.knowledge_base_count }}</p>
|
|
</div>
|
|
<div class="rounded-2xl border border-slate-100 bg-mist/60 px-3 py-2">
|
|
<p class="text-[10px] uppercase tracking-[0.2em] text-dusk">{{ t('workspace.totalFiles') }}</p>
|
|
<p class="mt-1 text-lg font-bold text-ink">{{ dashboardSummary.file_count }}</p>
|
|
</div>
|
|
<div class="rounded-2xl border border-slate-100 bg-mist/60 px-3 py-2">
|
|
<p class="text-[10px] uppercase tracking-[0.2em] text-dusk">{{ t('workspace.runningFiles') }}</p>
|
|
<p class="mt-1 text-lg font-bold text-ink">{{ dashboardSummary.running_count }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel overflow-hidden">
|
|
<div class="border-b border-slate-100 px-6 py-4">
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<input v-model="filters.q" class="input min-w-[180px] flex-[1_1_220px]" :placeholder="t('workspace.searchTitle')" />
|
|
<select v-model="filters.status" class="input min-w-[180px] flex-[1_1_180px]">
|
|
<option v-for="option in conversionOptions" :key="option.value || 'all'" :value="option.value">{{ option.label }}</option>
|
|
</select>
|
|
<select v-model="filters.sync_status" class="input min-w-[180px] flex-[1_1_180px]">
|
|
<option v-for="option in syncOptions" :key="option.value || 'all'" :value="option.value">{{ option.label }}</option>
|
|
</select>
|
|
<div class="date-range-shell min-w-[280px] flex-[1_1_280px]">
|
|
<input v-model="filters.uploaded_from" class="date-range-input" type="date" />
|
|
<span class="date-range-divider">-</span>
|
|
<input v-model="filters.uploaded_to" class="date-range-input" type="date" />
|
|
</div>
|
|
<button class="btn-ghost" :disabled="filterBusy || loading" @click="applyFilters">{{ t('workspace.applyFilters') }}</button>
|
|
<button class="btn-ghost" :disabled="filterBusy || loading" @click="resetFilters">{{ t('workspace.clearFilters') }}</button>
|
|
</div>
|
|
<p v-if="error" class="mt-4 rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
|
|
{{ error }}
|
|
</p>
|
|
</div>
|
|
<div class="overflow-x-auto">
|
|
<table class="file-table min-w-[1280px] text-left text-sm">
|
|
<colgroup>
|
|
<col style="width: 44px" />
|
|
<col style="width: 48px" />
|
|
<col style="width: 156px" />
|
|
<col style="width: 88px" />
|
|
<col style="width: 96px" />
|
|
<col style="width: 120px" />
|
|
<col style="width: 120px" />
|
|
<col style="width: 128px" />
|
|
<col style="width: 120px" />
|
|
<col style="width: 420px" />
|
|
</colgroup>
|
|
<thead class="bg-mist/60 text-dusk">
|
|
<tr>
|
|
<th class="px-4 py-3">
|
|
<input ref="pageSelectAllInput" :checked="isCurrentPageSelected" type="checkbox" @change="selectAll" />
|
|
</th>
|
|
<th class="px-4 py-3">#</th>
|
|
<th class="px-4 py-3">{{ t('workspace.titleColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.formatColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.sizeColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.statusColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.difySyncColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.uploadedAtColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.uploaderColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.actionsColumn') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-if="loading && files.length === 0">
|
|
<td colspan="10" class="px-4 py-10 text-center text-dusk">{{ t('workspace.loadingFiles') }}</td>
|
|
</tr>
|
|
<tr v-for="(row, index) in pagedFiles" :key="row.id" class="border-t border-slate-100">
|
|
<td class="px-4 py-4 align-middle">
|
|
<input v-model="selectedIds" :value="row.id" type="checkbox" />
|
|
</td>
|
|
<td class="px-4 py-4 align-middle">{{ filePageStart + index + 1 }}</td>
|
|
<td class="px-4 py-4 align-middle">
|
|
<button
|
|
v-if="previewAvailable(row, 'md')"
|
|
class="file-title-link"
|
|
:title="row.title"
|
|
@click="openPreview(row, 'md')"
|
|
>
|
|
{{ truncateTitle(row.title) }}
|
|
</button>
|
|
<p v-else class="file-title-text" :title="row.title">{{ truncateTitle(row.title) }}</p>
|
|
</td>
|
|
<td class="px-4 py-4 align-middle whitespace-nowrap">{{ row.current_version?.source_ext || '-' }}</td>
|
|
<td class="px-4 py-4 align-middle whitespace-nowrap">{{ row.current_version ? formatSize(row.current_version.file_size) : '-' }}</td>
|
|
<td class="px-4 py-4 align-middle">
|
|
<StatusPill :status="row.current_version?.convert_status || 'queued'" />
|
|
</td>
|
|
<td class="px-4 py-4 align-middle">
|
|
<StatusPill :status="row.current_version?.sync_status || 'unsynced'" kind="sync" />
|
|
</td>
|
|
<td class="px-4 py-4 align-middle whitespace-nowrap">
|
|
<div v-if="row.current_version?.uploaded_at" class="datetime-stack">
|
|
<span>{{ formatDateParts(row.current_version.uploaded_at).day }}</span>
|
|
<span class="datetime-subtle">{{ formatDateParts(row.current_version.uploaded_at).time }}</span>
|
|
</div>
|
|
<span v-else>-</span>
|
|
</td>
|
|
<td class="px-4 py-4 align-middle" :title="uploaderLabel(row.current_version)">
|
|
<span class="block truncate">{{ uploaderLabel(row.current_version) }}</span>
|
|
</td>
|
|
<td class="px-4 py-4 align-middle">
|
|
<div class="table-actions">
|
|
<button
|
|
v-if="previewAvailable(row, 'source')"
|
|
class="btn-ghost table-action-btn"
|
|
@click="openPreview(row, 'source')"
|
|
>
|
|
{{ t('workspace.previewOriginal') }}
|
|
</button>
|
|
<button class="btn-ghost table-action-btn" @click="downloadSingle(row.id, 'source')">{{ t('workspace.downloadOriginal') }}</button>
|
|
<button class="btn-ghost table-action-btn" @click="downloadSingle(row.id, 'md')">{{ t('workspace.downloadMd') }}</button>
|
|
<button class="btn-ghost table-action-btn" :disabled="!canPush(row.current_version) || actionBusy" @click="triggerSync(row.id)">
|
|
{{ t('workspace.syncToDify') }}
|
|
</button>
|
|
<button
|
|
class="btn-ghost table-action-btn text-rose-600 hover:border-rose-200 hover:text-rose-700"
|
|
:disabled="actionBusy"
|
|
@click="openDeleteDocumentDialog(row)"
|
|
>
|
|
{{ t('workspace.delete') }}
|
|
</button>
|
|
</div>
|
|
<p v-if="row.current_version?.failed_reason" class="mt-2 max-w-xs text-xs text-rose-700">
|
|
{{ row.current_version.failed_reason }}
|
|
</p>
|
|
</td>
|
|
</tr>
|
|
<tr v-if="!loading && files.length === 0">
|
|
<td colspan="10" class="px-4 py-12 text-center text-dusk">{{ t('workspace.noDocumentsFound') }}</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div v-if="files.length" class="flex flex-wrap items-center justify-between gap-4 border-t border-slate-100 px-6 py-4">
|
|
<p class="text-sm text-dusk">
|
|
{{ t('workspace.paginationSummary', { start: filePageStart + 1, end: filePageEnd, total: files.length }) }}
|
|
</p>
|
|
<div class="flex flex-wrap items-center gap-3">
|
|
<label class="text-sm font-medium text-dusk" for="file-page-size">{{ t('workspace.rowsPerPage') }}</label>
|
|
<select id="file-page-size" v-model.number="filePageSize" class="input !w-auto min-w-[110px] py-2" @change="filePage = 1">
|
|
<option v-for="size in filePageSizeOptions" :key="size" :value="size">{{ t('workspace.rowsPerPageOption', { size }) }}</option>
|
|
</select>
|
|
<button class="btn-ghost" :disabled="filePage === 1" @click="filePage = Math.max(1, filePage - 1)">{{ t('workspace.prevPage') }}</button>
|
|
<span class="text-sm font-medium text-ink">{{ t('workspace.pageIndicator', { page: filePage, total: filePageCount }) }}</span>
|
|
<button class="btn-ghost" :disabled="filePage >= filePageCount" @click="filePage = Math.min(filePageCount, filePage + 1)">{{ t('workspace.nextPage') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<input ref="uploadFileInput" class="hidden" type="file" multiple @change="handleFileSelection" />
|
|
<input ref="uploadFolderInput" class="hidden" type="file" webkitdirectory multiple @change="handleFolderSelection" />
|
|
|
|
<div
|
|
v-if="uploadDialog.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
|
@click="closeUploadDialog"
|
|
>
|
|
<div class="panel w-full max-w-5xl px-6 py-6" @click.stop>
|
|
<div class="flex flex-wrap items-start justify-between gap-4">
|
|
<div>
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.batchUpload') }}</p>
|
|
<h3 class="mt-2 text-2xl font-bold text-ink">{{ t('workspace.uploadDialogTitle') }}</h3>
|
|
<p class="mt-2 text-sm text-dusk">{{ selectedGroup?.name || t('workspace.selectGroupBeforeUploading') }}</p>
|
|
</div>
|
|
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="closeUploadDialog" aria-label="Close">
|
|
<svg aria-hidden="true" class="h-5 w-5" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
|
<path d="M5 5l10 10M15 5L5 15" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
<div class="mt-5 flex flex-wrap gap-3">
|
|
<button class="btn-ghost" @click="uploadFileInput?.click()">{{ t('workspace.uploadFiles') }}</button>
|
|
<button class="btn-ghost" @click="uploadFolderInput?.click()">{{ t('workspace.uploadFolder') }}</button>
|
|
</div>
|
|
<p class="mt-4 text-sm text-dusk">{{ t('workspace.uploadProgressHint') }}</p>
|
|
<div class="mt-4" ref="uploaderHost"></div>
|
|
<div v-if="uploadRejections.length" class="mt-4 rounded-3xl border border-amber-200 bg-amber-50/90 p-4">
|
|
<div class="flex flex-wrap items-start justify-between gap-3">
|
|
<div>
|
|
<p class="text-sm font-semibold text-amber-900">{{ t('workspace.uploadRejectedListTitle', { count: uploadRejections.length }) }}</p>
|
|
<p class="mt-1 text-xs text-amber-800">{{ t('workspace.uploadRejectedListHint') }}</p>
|
|
</div>
|
|
<button class="btn-ghost px-3 py-2 text-xs" @click="clearUploadRejections">{{ t('common.clear') }}</button>
|
|
</div>
|
|
<div class="mt-3 max-h-44 overflow-auto rounded-2xl border border-amber-200 bg-white/80">
|
|
<div
|
|
v-for="item in uploadRejections"
|
|
:key="item.name + '-' + item.reason"
|
|
class="flex flex-wrap items-start justify-between gap-3 border-b border-amber-100 px-4 py-3 last:border-b-0"
|
|
>
|
|
<div class="min-w-0 flex-1">
|
|
<p class="truncate text-sm font-medium text-ink" :title="item.name">{{ item.name }}</p>
|
|
<p class="mt-1 text-xs text-amber-900">{{ item.reason }}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="previewDialog.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
|
@click="closePreviewDialog"
|
|
>
|
|
<div class="panel w-full max-w-5xl px-6 py-6" @click.stop>
|
|
<div class="flex flex-wrap items-start justify-between gap-4">
|
|
<div>
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.previewDialogEyebrow') }}</p>
|
|
<h3 class="mt-2 text-2xl font-bold text-ink">{{ previewDialog.title }}</h3>
|
|
<p class="mt-2 text-sm text-dusk">{{ previewDialog.subtitle }}</p>
|
|
</div>
|
|
<button class="btn-ghost px-3 py-2" @click="closePreviewDialog">{{ t('common.cancel') }}</button>
|
|
</div>
|
|
<div class="mt-5 rounded-3xl border border-slate-200 bg-white/90 p-4">
|
|
<div v-if="previewDialog.loading" class="py-16 text-center text-dusk">{{ t('common.loading') }}</div>
|
|
<pre v-else-if="previewDialog.mode === 'text'" class="max-h-[60vh] overflow-auto whitespace-pre-wrap text-sm leading-7 text-ink">{{ previewDialog.text }}</pre>
|
|
<img v-else-if="previewDialog.mode === 'image'" :src="previewDialog.url" :alt="previewDialog.title" class="mx-auto max-h-[60vh] rounded-2xl object-contain" />
|
|
<iframe v-else-if="previewDialog.mode === 'pdf'" :src="previewDialog.url" class="h-[70vh] w-full rounded-2xl border border-slate-200"></iframe>
|
|
<div v-else class="space-y-4 py-10 text-center">
|
|
<p class="text-sm text-dusk">{{ previewDialog.text }}</p>
|
|
<a v-if="previewDialog.url" class="btn-ghost" :href="previewDialog.url" :download="previewDialog.subtitle">{{ t('workspace.downloadOriginal') }}</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="documentDeleteDialog.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/40 px-4 py-8 backdrop-blur-sm"
|
|
@click="closeDeleteDocumentDialog"
|
|
>
|
|
<div class="panel w-full max-w-lg px-6 py-6" @click.stop>
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.documentsTableTitle') }}</p>
|
|
<h3 class="mt-2 text-2xl font-bold text-ink">{{ t('workspace.delete') }}</h3>
|
|
<p class="mt-2 text-sm leading-7 text-dusk">
|
|
{{ t('workspace.deleteDocumentPrompt', { name: documentDeleteDialog.row?.title || '' }) }}
|
|
</p>
|
|
</div>
|
|
<button class="btn-ghost dialog-static-btn flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="closeDeleteDocumentDialog" aria-label="Close">
|
|
<svg aria-hidden="true" class="h-5 w-5" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
|
<path d="M5 5l10 10M15 5L5 15" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
|
|
<label
|
|
v-if="documentDeleteDialog.row?.current_version?.sync_status && documentDeleteDialog.row.current_version.sync_status !== 'unsynced'"
|
|
class="mt-5 flex items-start gap-3 rounded-3xl border border-slate-200 bg-mist/60 px-4 py-4 text-sm text-ink"
|
|
>
|
|
<input v-model="documentDeleteDialog.deleteDify" class="mt-1 h-4 w-4 accent-surge" type="checkbox" />
|
|
<span>
|
|
<span class="font-semibold">{{ t('workspace.deleteDocumentSyncDify') }}</span>
|
|
<span class="mt-1 block text-dusk">{{ t('workspace.deleteDocumentSyncDifyHint') }}</span>
|
|
</span>
|
|
</label>
|
|
|
|
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
|
<button class="btn-ghost dialog-static-btn" @click="closeDeleteDocumentDialog">{{ t('common.cancel') }}</button>
|
|
<button class="btn-primary dialog-static-btn" :disabled="actionBusy" @click="confirmDeleteDocument">{{ t('workspace.delete') }}</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="groupDialog.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
|
@click="closeGroupDialog"
|
|
>
|
|
<div class="panel w-full max-w-xl px-6 py-6" @click.stop>
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-surge">{{ t('workspace.groupsTitle') }}</p>
|
|
<h3 class="mt-2 text-2xl font-bold text-ink">
|
|
{{ groupDialog.mode === 'create' ? t('workspace.createGroupDialogTitle') : t('workspace.editGroupDialogTitle') }}
|
|
</h3>
|
|
</div>
|
|
<button class="btn-ghost px-3 py-2" @click="closeGroupDialog">{{ t('common.cancel') }}</button>
|
|
</div>
|
|
<div class="mt-5 space-y-4">
|
|
<select v-if="hasDepartments" v-model="groupDialog.departmentId" class="input">
|
|
<option v-for="department in departments" :key="department.id" :value="department.id">
|
|
{{ department.name }}
|
|
</option>
|
|
</select>
|
|
<input
|
|
v-else
|
|
class="input"
|
|
:value="t('admin.noDepartmentPlaceholder')"
|
|
disabled
|
|
readonly
|
|
/>
|
|
<input v-model="groupDialog.name" class="input" :placeholder="t('admin.groupName')" />
|
|
<textarea
|
|
v-model="groupDialog.description"
|
|
class="input min-h-[140px] resize-none"
|
|
:placeholder="t('admin.groupDescription')"
|
|
></textarea>
|
|
</div>
|
|
<div class="mt-5 flex flex-wrap justify-end gap-3">
|
|
<button class="btn-ghost" @click="closeGroupDialog">{{ t('common.cancel') }}</button>
|
|
<button class="btn-primary" :disabled="actionBusy || !hasDepartments" @click="submitGroupDialog">
|
|
{{ groupDialog.mode === 'create' ? t('admin.createGroup') : t('common.save') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="groupDeleteDialog.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/40 px-4 py-8 backdrop-blur-sm"
|
|
@click="closeDeleteGroupDialog"
|
|
>
|
|
<div class="panel w-full max-w-lg px-6 py-6" @click.stop>
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<p class="text-sm leading-7 text-dusk">
|
|
{{ t('workspace.deleteGroupPromptLocal', { name: groupDeleteDialog.group?.name || '' }) }}
|
|
</p>
|
|
</div>
|
|
<button class="btn-ghost dialog-static-btn flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="closeDeleteGroupDialog" aria-label="Close">
|
|
<svg aria-hidden="true" class="h-5 w-5" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
|
<path d="M5 5l10 10M15 5L5 15" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
|
|
<label
|
|
v-if="groupDeleteDialog.group?.dify_dataset_id"
|
|
class="mt-5 flex items-start gap-3 rounded-3xl border border-slate-200 bg-mist/60 px-4 py-4 text-sm text-ink"
|
|
>
|
|
<input v-model="groupDeleteDialog.deleteDify" class="mt-1 h-4 w-4 accent-surge" type="checkbox" />
|
|
<span>
|
|
<span class="font-semibold">{{ t('workspace.deleteGroupSyncDify') }}</span>
|
|
<span class="mt-1 block text-dusk">{{ t('workspace.deleteGroupSyncDifyHint') }}</span>
|
|
</span>
|
|
</label>
|
|
|
|
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
|
<button class="btn-ghost dialog-static-btn" @click="closeDeleteGroupDialog">{{ t('common.cancel') }}</button>
|
|
<button class="btn-primary dialog-static-btn" :disabled="actionBusy" @click="confirmDeleteGroup">
|
|
{{ t('workspace.confirmDeleteGroup') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div
|
|
v-if="diffViewer.open"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
|
@click="closeDiffViewer"
|
|
>
|
|
<div class="panel flex max-h-[90vh] w-full max-w-5xl flex-col px-6 py-6" @click.stop>
|
|
<div class="flex items-start justify-between gap-4">
|
|
<div>
|
|
<h3 class="text-2xl font-bold text-ink">
|
|
{{ isGlobalDiff ? t('workspace.globalDiffDialogTitle') : selectedGroup?.name || t('workspace.selectGroup') }}
|
|
</h3>
|
|
</div>
|
|
<div class="flex items-center gap-3">
|
|
<button class="btn-ghost px-4 py-2.5 text-sm" :disabled="diffViewer.loading" @click="runDiffScan">
|
|
{{ t('workspace.queryDiff') }}
|
|
</button>
|
|
<button
|
|
class="btn-ghost flex h-14 w-14 items-center justify-center rounded-2xl px-0"
|
|
@click="closeDiffViewer"
|
|
aria-label="Close"
|
|
>
|
|
<svg aria-hidden="true" class="h-5 w-5" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
|
|
<path d="M5 5l10 10M15 5L5 15" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-5 grid gap-3 md:grid-cols-3">
|
|
<div class="rounded-3xl border border-slate-100 bg-mist/60 p-4">
|
|
<p class="text-xs uppercase tracking-[0.22em] text-dusk">{{ t('workspace.diffMatched') }}</p>
|
|
<p class="mt-2 text-3xl font-bold text-ink">{{ diffCountSummary.matched }}</p>
|
|
</div>
|
|
<div class="rounded-3xl border border-slate-100 bg-mist/60 p-4">
|
|
<p class="text-xs uppercase tracking-[0.22em] text-dusk">{{ t('workspace.diffLocalOnly') }}</p>
|
|
<p class="mt-2 text-3xl font-bold text-ink">{{ diffCountSummary.local_only }}</p>
|
|
</div>
|
|
<div class="rounded-3xl border border-slate-100 bg-mist/60 p-4">
|
|
<p class="text-xs uppercase tracking-[0.22em] text-dusk">{{ t('workspace.diffDifyOnly') }}</p>
|
|
<p class="mt-2 text-3xl font-bold text-ink">{{ diffCountSummary.dify_only }}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-5 flex-1 overflow-hidden rounded-3xl border border-slate-200 bg-white/90">
|
|
<div class="max-h-[52vh] overflow-x-auto overflow-y-scroll">
|
|
<template v-if="!diffReady">
|
|
<div class="px-4 py-16 text-center text-dusk">{{ t('workspace.diffQueryPrompt') }}</div>
|
|
</template>
|
|
<template v-else-if="diffViewer.loading">
|
|
<div class="px-4 py-10 text-center text-dusk">{{ t('common.loading') }}</div>
|
|
</template>
|
|
<template v-else>
|
|
<div class="px-4 py-4">
|
|
<div class="grid gap-3" :class="isGlobalDiff ? 'md:grid-cols-[180px_minmax(0,1fr)_120px]' : 'md:grid-cols-[minmax(0,1fr)_120px]'">
|
|
<select v-if="isGlobalDiff" v-model="diffViewer.searchField" class="input">
|
|
<option value="knowledge_base">{{ t('workspace.diffSearchByKnowledgeBase') }}</option>
|
|
<option value="file_name">{{ t('workspace.diffSearchByFileName') }}</option>
|
|
</select>
|
|
<input
|
|
v-model="diffViewer.qInput"
|
|
class="input w-full"
|
|
:placeholder="diffSearchPlaceholder"
|
|
@keyup.enter="applyDiffSearch"
|
|
/>
|
|
<button class="btn-ghost" @click="applyDiffSearch">{{ t('workspace.applyFilters') }}</button>
|
|
</div>
|
|
</div>
|
|
<div v-if="diffAligned && !diffSearchActive" class="px-4 pb-16 pt-8 text-center">
|
|
<p class="text-lg font-semibold text-ink">{{ t('workspace.diffAllAligned') }}</p>
|
|
</div>
|
|
<div v-else-if="visibleDiffRows.length === 0" class="px-4 pb-10 pt-6 text-center text-dusk">
|
|
{{ t('workspace.diffEmpty') }}
|
|
</div>
|
|
<table v-else class="file-table diff-table min-w-[960px] w-full table-fixed text-left text-sm">
|
|
<caption class="sr-only">{{ t('workspace.diffDialogTitle') }}</caption>
|
|
<colgroup>
|
|
<col style="width: 50%" />
|
|
<col style="width: 20%" />
|
|
<col style="width: 30%" />
|
|
</colgroup>
|
|
<thead class="sticky top-0 z-10 bg-mist/90 text-dusk backdrop-blur">
|
|
<tr>
|
|
<th class="px-4 py-3">{{ t('workspace.fileNameColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.diffStateColumn') }}</th>
|
|
<th class="px-4 py-3">{{ t('workspace.actionsColumn') }}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr v-for="row in pagedDiffRows" :key="row.key" class="border-t border-slate-100 align-middle">
|
|
<td class="px-4 py-4 font-semibold text-ink">
|
|
<div class="min-w-0">
|
|
<p v-if="isGlobalDiff" class="mb-1 text-xs font-semibold uppercase tracking-[0.18em] text-dusk">
|
|
{{ row.knowledge_base?.name || '-' }}
|
|
</p>
|
|
<p class="truncate" :title="diffFileLabel(row)">{{ diffFileLabel(row) }}</p>
|
|
</div>
|
|
</td>
|
|
<td class="px-4 py-4">
|
|
<span class="tag" :class="row.status === 'dify_only' ? 'bg-violet-100 text-violet-700' : row.status === 'matched' ? 'bg-emerald-100 text-emerald-700' : 'bg-sky-100 text-sky-700'">
|
|
{{ diffRowSideLabel(row) }}
|
|
</span>
|
|
</td>
|
|
<td class="px-4 py-4">
|
|
<button
|
|
v-if="!diffActionHidden(row)"
|
|
class="btn-ghost px-3 py-2"
|
|
:disabled="actionBusy || !diffActionAvailable(row)"
|
|
:title="diffActionAvailable(row) ? '' : t('workspace.syncCurrentUnavailable')"
|
|
@click="triggerDiffAction(row)"
|
|
>
|
|
{{ diffActionLabel(row) }}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</template>
|
|
</div>
|
|
<div
|
|
v-if="diffReady && !diffViewer.loading"
|
|
class="flex min-h-[64px] flex-wrap items-center justify-between gap-3 border-t border-slate-100 px-4 py-3"
|
|
>
|
|
<p class="text-sm text-dusk">
|
|
<template v-if="hasPagedDiffResults">
|
|
{{ t('workspace.diffPaginationSummary', { shown: pagedDiffRows.length, total: visibleDiffRows.length }) }}
|
|
</template>
|
|
</p>
|
|
<div v-if="hasPagedDiffResults" class="flex items-center gap-2">
|
|
<button class="btn-ghost px-3 py-2" :disabled="diffViewer.page <= 1" @click="diffViewer.page -= 1">
|
|
{{ t('workspace.prevPage') }}
|
|
</button>
|
|
<span class="text-sm font-medium text-ink">
|
|
{{ t('workspace.pageIndicator', { page: diffViewer.page, total: diffPageCount }) }}
|
|
</span>
|
|
<button class="btn-ghost px-3 py-2" :disabled="diffViewer.page >= diffPageCount" @click="diffViewer.page += 1">
|
|
{{ t('workspace.nextPage') }}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<DifySettingsDialog
|
|
:open="settingsDialogOpen"
|
|
@close="settingsDialogOpen = false"
|
|
@saved="pushToast($event)"
|
|
@error="pushToast($event, 'error')"
|
|
/>
|
|
|
|
<DifyHealthDialog
|
|
:open="healthDialogOpen"
|
|
@close="healthDialogOpen = false"
|
|
@toast="pushToast($event)"
|
|
@error="pushToast($event, 'error')"
|
|
/>
|
|
</div>
|
|
</main>
|
|
</template>
|