init
This commit is contained in:
commit
fe636432d0
154 files changed
+30381
No files matched your search
@@ -0,0 +1,13 @@
|
||||
FROM node:22-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:alpine
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document Cleaning</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
resolver 127.0.0.11 ipv6=off valid=10s;
|
||||
client_max_body_size 200m;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
set $api_upstream api:8000;
|
||||
proxy_pass http://$api_upstream$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /storage/ {
|
||||
set $api_upstream api:8000;
|
||||
proxy_pass http://$api_upstream$request_uri;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Expires "0" always;
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Expires "0" always;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
Generated
+2668
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "document-cleaning-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uppy/core": "^4.5.2",
|
||||
"@uppy/dashboard": "^4.4.2",
|
||||
"@uppy/xhr-upload": "^4.3.3",
|
||||
"vue": "^3.5.25",
|
||||
"vue-router": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.10.1",
|
||||
"@vitejs/plugin-vue": "^6.0.2",
|
||||
"@vue/tsconfig": "^0.8.1",
|
||||
"autoprefixer": "^10.4.24",
|
||||
"postcss": "^8.5.6",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "~5.9.3",
|
||||
"vite": "^8.0.0-beta.13",
|
||||
"vue-tsc": "^3.1.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div class="app-shell">
|
||||
<router-view />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,359 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
|
||||
import { apiFetch } from '@/lib/api'
|
||||
import { localeCode, useI18n } from '@/lib/i18n'
|
||||
|
||||
type WatchdogTask = {
|
||||
id: string
|
||||
name: string
|
||||
runtime_seconds?: number | null
|
||||
delivery_info?: {
|
||||
routing_key?: string | null
|
||||
} | null
|
||||
}
|
||||
|
||||
type WatchdogAction = {
|
||||
type: string
|
||||
at?: string | null
|
||||
reason?: string | null
|
||||
}
|
||||
|
||||
type WatchdogSnapshot = {
|
||||
available?: boolean
|
||||
status?: string
|
||||
checked_at?: string | null
|
||||
last_restart_at?: string | null
|
||||
worker?: {
|
||||
online?: boolean
|
||||
command?: string | null
|
||||
concurrency?: number | null
|
||||
} | null
|
||||
api?: {
|
||||
configured?: boolean
|
||||
reachable?: boolean
|
||||
base_url?: string | null
|
||||
dataset_count?: number | null
|
||||
error?: string | null
|
||||
} | null
|
||||
queue_lengths?: Record<string, number>
|
||||
shared_postgres?: {
|
||||
available?: boolean
|
||||
max_connections?: number | null
|
||||
active_connections?: number | null
|
||||
usage_ratio?: number | null
|
||||
error?: string | null
|
||||
} | null
|
||||
active_tasks?: WatchdogTask[]
|
||||
reserved_tasks?: WatchdogTask[]
|
||||
actions?: WatchdogAction[]
|
||||
issues?: string[]
|
||||
} | null
|
||||
|
||||
type LocalSyncHealth = {
|
||||
timeout_seconds: number
|
||||
syncing_versions: number
|
||||
sync_failed_versions: number
|
||||
active_sync_jobs: number
|
||||
stale_candidates: number
|
||||
active_jobs: Array<{ id: string }>
|
||||
recent_failures: Array<{ id: string }>
|
||||
stale_versions: Array<{
|
||||
document_id: number
|
||||
version_id: number
|
||||
age_seconds: number
|
||||
reason: string
|
||||
}>
|
||||
}
|
||||
|
||||
type DifyHealthPayload = {
|
||||
dify_base_url: string
|
||||
dify_api_configured: boolean
|
||||
watchdog_snapshot: WatchdogSnapshot
|
||||
local_sync_health: LocalSyncHealth
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
toast: [message: string]
|
||||
error: [message: string]
|
||||
}>()
|
||||
|
||||
const { locale, t } = useI18n()
|
||||
|
||||
const loading = ref(false)
|
||||
const recoveryBusy = ref(false)
|
||||
const payload = ref<DifyHealthPayload | null>(null)
|
||||
|
||||
const snapshot = computed(() => payload.value?.watchdog_snapshot || null)
|
||||
const localHealth = computed<LocalSyncHealth>(() => {
|
||||
return (
|
||||
payload.value?.local_sync_health || {
|
||||
timeout_seconds: 0,
|
||||
syncing_versions: 0,
|
||||
sync_failed_versions: 0,
|
||||
active_sync_jobs: 0,
|
||||
stale_candidates: 0,
|
||||
active_jobs: [],
|
||||
recent_failures: [],
|
||||
stale_versions: [],
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const queueEntries = computed(() => Object.entries(snapshot.value?.queue_lengths || {}))
|
||||
const totalPending = computed(() => queueEntries.value.reduce((sum, [, count]) => sum + count, 0))
|
||||
const activeTasks = computed(() => snapshot.value?.active_tasks || [])
|
||||
const watchdogIssues = computed(() => snapshot.value?.issues || [])
|
||||
const watchdogActions = computed(() => snapshot.value?.actions || [])
|
||||
const sharedPostgres = computed(() => snapshot.value?.shared_postgres || null)
|
||||
const sharedPostgresUsagePercent = computed(() => {
|
||||
const ratio = sharedPostgres.value?.usage_ratio
|
||||
if (typeof ratio !== 'number' || Number.isNaN(ratio)) return null
|
||||
return Math.round(ratio * 100)
|
||||
})
|
||||
const sharedPostgresUsageLabel = computed(() => {
|
||||
if (!sharedPostgres.value?.available) return t('admin.sharedPostgresUnavailable')
|
||||
if (sharedPostgresUsagePercent.value === null) return '--'
|
||||
return `${sharedPostgresUsagePercent.value}%`
|
||||
})
|
||||
const sharedPostgresUsageHint = computed(() => {
|
||||
if (!sharedPostgres.value?.available) return sharedPostgres.value?.error || t('common.none')
|
||||
return `${sharedPostgres.value?.active_connections ?? '--'} / ${sharedPostgres.value?.max_connections ?? '--'}`
|
||||
})
|
||||
|
||||
const healthGuide = computed(() => {
|
||||
if (locale.value === 'zh') {
|
||||
return [
|
||||
{ label: 'Watchdog 状态', text: '表示服务器自动巡检和自愈最近一次执行的结果。' },
|
||||
{ label: 'Dify API', text: '表示当前系统能否访问 Dify 接口。' },
|
||||
{ label: 'Worker 并发', text: '表示 Dify 后台当前最多能同时处理多少个任务。' },
|
||||
{ label: '待处理队列', text: '表示 Dify 队列里还未被消费的任务总量。' },
|
||||
{ label: '卡住同步', text: '表示本地已经卡住、等待回收的同步记录数量。' },
|
||||
{ label: '本地同步健康', text: '表示本地同步中、失败和卡住候选的汇总情况。' },
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ label: 'Watchdog Status', text: 'Latest self-healing result from the watchdog.' },
|
||||
{ label: 'Dify API', text: 'Whether this system can reach the Dify API.' },
|
||||
{ label: 'Worker Concurrency', text: 'How many Dify background jobs can run at the same time.' },
|
||||
{ label: 'Pending Queue', text: 'How many jobs are still waiting inside Dify queues.' },
|
||||
{ label: 'Stuck Syncs', text: 'How many local sync records are stuck and waiting to be reclaimed.' },
|
||||
{ label: 'Local Sync Health', text: 'Overview of local syncing, failures, and stale candidates.' },
|
||||
]
|
||||
})
|
||||
|
||||
function close() {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function formatDate(value?: string | null) {
|
||||
if (!value) return t('common.none')
|
||||
return new Date(value).toLocaleString(localeCode(locale.value))
|
||||
}
|
||||
|
||||
function formatRuntime(seconds?: number | null) {
|
||||
if (!seconds || seconds < 1) return '0s'
|
||||
if (seconds < 60) return `${seconds}s`
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const remain = seconds % 60
|
||||
return `${minutes}m ${remain}s`
|
||||
}
|
||||
|
||||
function statusLabel(status?: string | null) {
|
||||
switch (status) {
|
||||
case 'ok':
|
||||
return t('admin.statusOk')
|
||||
case 'restarted':
|
||||
return t('admin.statusRestarted')
|
||||
case 'warning':
|
||||
return t('admin.statusWarning')
|
||||
default:
|
||||
return t('admin.healthUnavailable')
|
||||
}
|
||||
}
|
||||
|
||||
async function loadHealth() {
|
||||
loading.value = true
|
||||
try {
|
||||
payload.value = await apiFetch('/api/admin/dify-health')
|
||||
} catch (err) {
|
||||
emit('error', err instanceof Error ? err.message : t('admin.failedToLoadDifyHealth'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function recoverStuckSyncs() {
|
||||
recoveryBusy.value = true
|
||||
try {
|
||||
const result = await apiFetch('/api/admin/recover-stale-syncs', { method: 'POST' })
|
||||
const message =
|
||||
result.recovered_versions > 0
|
||||
? t('admin.staleSyncRecovered', { count: result.recovered_versions })
|
||||
: t('admin.noStaleSyncsFound')
|
||||
emit('toast', message)
|
||||
await loadHealth()
|
||||
} catch (err) {
|
||||
emit('error', err instanceof Error ? err.message : t('admin.failedToRecoverStaleSyncs'))
|
||||
} finally {
|
||||
recoveryBusy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
void loadHealth()
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="close"
|
||||
>
|
||||
<div class="panel w-full max-w-6xl 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('admin.difyHealth') }}</p>
|
||||
<h3 class="mt-2 text-2xl font-bold text-ink">{{ t('admin.difyHealthTitle') }}</h3>
|
||||
<p class="mt-2 text-sm text-dusk">{{ t('admin.difyHealthHint') }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button class="btn-ghost" :disabled="recoveryBusy" @click="recoverStuckSyncs">{{ t('admin.recoverStaleSyncs') }}</button>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="close" 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 v-if="loading" class="py-16 text-center text-dusk">{{ t('common.loading') }}</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="mt-5 grid gap-4 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.7fr)]">
|
||||
<div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-6">
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.healthStatus') }}</p>
|
||||
<span class="tag mt-3 inline-flex" :class="snapshot?.status === 'ok' ? 'bg-emerald-100 text-emerald-700' : snapshot?.status === 'restarted' ? 'bg-amber-100 text-amber-700' : 'bg-rose-100 text-rose-700'">
|
||||
{{ statusLabel(snapshot?.status) }}
|
||||
</span>
|
||||
<p class="mt-3 text-xs text-dusk">{{ t('admin.lastCheckedAt') }}: {{ formatDate(snapshot?.checked_at) }}</p>
|
||||
</div>
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.difyApi') }}</p>
|
||||
<p class="mt-3 text-2xl font-semibold text-ink">{{ snapshot?.api?.reachable ? t('common.yes') : t('common.no') }}</p>
|
||||
<p class="mt-3 break-all text-xs text-dusk">{{ payload?.dify_base_url || t('common.none') }}</p>
|
||||
</div>
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.workerConcurrency') }}</p>
|
||||
<p class="mt-3 text-2xl font-semibold text-ink">{{ snapshot?.worker?.concurrency ?? '--' }}</p>
|
||||
<p class="mt-3 text-xs text-dusk">{{ t('admin.lastRestartAt') }}: {{ formatDate(snapshot?.last_restart_at) }}</p>
|
||||
</div>
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.sharedPostgresUsage') }}</p>
|
||||
<p class="mt-3 text-2xl font-semibold text-ink">{{ sharedPostgresUsageLabel }}</p>
|
||||
<p class="mt-3 break-all text-xs text-dusk">{{ sharedPostgresUsageHint }}</p>
|
||||
</div>
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.pendingQueue') }}</p>
|
||||
<p class="mt-3 text-2xl font-semibold text-ink">{{ totalPending }}</p>
|
||||
<p class="mt-3 text-xs text-dusk">{{ queueEntries.map(([name, count]) => `${name}:${count}`).join(' · ') || t('common.none') }}</p>
|
||||
</div>
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.staleCandidates') }}</p>
|
||||
<p class="mt-3 text-2xl font-semibold text-ink">{{ localHealth.stale_candidates }}</p>
|
||||
<p class="mt-3 text-xs text-dusk">{{ t('admin.activeSyncJobs') }}: {{ localHealth.active_sync_jobs }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-3xl border border-slate-200 bg-mist/40 px-5 py-5">
|
||||
<p class="rounded-2xl border border-slate-200 bg-white px-3 py-3 text-sm text-dusk">
|
||||
{{ t('admin.recoverStaleSyncsHint') }}
|
||||
</p>
|
||||
<p class="mt-5 text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.watchdogIssues') }}</p>
|
||||
<div class="mt-3 space-y-2">
|
||||
<p v-if="watchdogIssues.length === 0" class="text-sm text-dusk">{{ t('admin.noWatchdogIssues') }}</p>
|
||||
<p v-for="issue in watchdogIssues" :key="issue" class="rounded-2xl border border-slate-200 bg-white px-3 py-3 text-sm text-ink">
|
||||
{{ issue }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p class="mt-5 text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.watchdogActions') }}</p>
|
||||
<div class="mt-3 space-y-2">
|
||||
<p v-if="watchdogActions.length === 0" class="text-sm text-dusk">{{ t('admin.noWatchdogActions') }}</p>
|
||||
<div
|
||||
v-for="action in watchdogActions.slice(0, 5)"
|
||||
:key="`${action.type}-${action.at}`"
|
||||
class="rounded-2xl border border-slate-200 bg-white px-3 py-3 text-sm text-ink"
|
||||
>
|
||||
<p class="font-medium">{{ action.type }}</p>
|
||||
<p v-if="action.reason" class="mt-1 text-xs text-dusk">{{ action.reason }}</p>
|
||||
<p v-if="action.at" class="mt-1 text-xs text-dusk">{{ formatDate(action.at) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-5 py-5">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.activeTasks') }}</p>
|
||||
<span class="text-xs text-dusk">{{ activeTasks.length }}</span>
|
||||
</div>
|
||||
<div class="mt-4 space-y-3">
|
||||
<p v-if="activeTasks.length === 0" class="text-sm text-dusk">{{ t('admin.noneRunning') }}</p>
|
||||
<div v-for="task in activeTasks.slice(0, 6)" :key="task.id" class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<p class="font-medium text-ink">{{ task.name }}</p>
|
||||
<p class="mt-1 text-xs text-dusk">{{ t('admin.routingKey') }}: {{ task.delivery_info?.routing_key || t('common.none') }}</p>
|
||||
</div>
|
||||
<span class="tag bg-sky-100 text-sky-700">{{ formatRuntime(task.runtime_seconds) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-3xl border border-slate-200 bg-white px-5 py-5">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.localSyncHealth') }}</p>
|
||||
<span class="text-xs text-dusk">{{ t('admin.timeoutSeconds') }}: {{ localHealth.timeout_seconds }}</span>
|
||||
</div>
|
||||
<div class="mt-4 grid gap-3 sm:grid-cols-3">
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('status.syncing') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ localHealth.syncing_versions }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('status.sync_failed') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ localHealth.sync_failed_versions }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('admin.staleCandidates') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ localHealth.stale_candidates }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 grid gap-3 md:grid-cols-2 xl:grid-cols-3">
|
||||
<div v-for="item in healthGuide" :key="item.label" class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="font-semibold text-ink">{{ item.label }}</p>
|
||||
<p class="mt-2 text-sm leading-6 text-dusk">{{ item.text }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,281 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
|
||||
import { apiFetch } from '@/lib/api'
|
||||
import { useI18n } from '@/lib/i18n'
|
||||
|
||||
type DifyModelOption = {
|
||||
provider: string
|
||||
model: string
|
||||
label: string
|
||||
}
|
||||
|
||||
type DifyModelCatalog = {
|
||||
embedding_models: DifyModelOption[]
|
||||
rerank_models: DifyModelOption[]
|
||||
automatic_defaults: {
|
||||
embedding_model_provider?: string | null
|
||||
embedding_model?: string | null
|
||||
reranking_model_provider?: string | null
|
||||
reranking_model?: string | null
|
||||
}
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
saved: [message: string]
|
||||
error: [message: string]
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const errorMessage = ref('')
|
||||
|
||||
const settings = reactive({
|
||||
dify_permission: 'all_team_members',
|
||||
indexing_technique: 'high_quality',
|
||||
search_method: 'hybrid_search',
|
||||
doc_form: 'text_model',
|
||||
embedding_model_provider: '',
|
||||
embedding_model: '',
|
||||
reranking_model_provider: '',
|
||||
reranking_model: '',
|
||||
top_k: 5,
|
||||
score_threshold_enabled: true,
|
||||
score_threshold: 0.35
|
||||
})
|
||||
|
||||
const difyModels = reactive<DifyModelCatalog>({
|
||||
embedding_models: [],
|
||||
rerank_models: [],
|
||||
automatic_defaults: {
|
||||
embedding_model_provider: '',
|
||||
embedding_model: '',
|
||||
reranking_model_provider: '',
|
||||
reranking_model: ''
|
||||
}
|
||||
})
|
||||
|
||||
function close() {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function modelValue(provider?: string | null, model?: string | null) {
|
||||
return provider && model ? `${provider}::${model}` : ''
|
||||
}
|
||||
|
||||
function applyModelValue(value: string, kind: 'embedding' | 'rerank') {
|
||||
const [provider = '', model = ''] = value.split('::')
|
||||
if (kind === 'embedding') {
|
||||
settings.embedding_model_provider = provider
|
||||
settings.embedding_model = model
|
||||
return
|
||||
}
|
||||
settings.reranking_model_provider = provider
|
||||
settings.reranking_model = model
|
||||
}
|
||||
|
||||
const embeddingOptions = computed(() => [
|
||||
{ value: '', label: t('admin.automaticChoice') },
|
||||
...difyModels.embedding_models.map((item) => ({
|
||||
value: modelValue(item.provider, item.model),
|
||||
label: item.label
|
||||
}))
|
||||
])
|
||||
|
||||
const rerankOptions = computed(() => [
|
||||
{ value: '', label: t('admin.automaticChoice') },
|
||||
...difyModels.rerank_models.map((item) => ({
|
||||
value: modelValue(item.provider, item.model),
|
||||
label: item.label
|
||||
}))
|
||||
])
|
||||
|
||||
const selectedEmbeddingValue = computed({
|
||||
get: () => modelValue(settings.embedding_model_provider, settings.embedding_model),
|
||||
set: (value: string) => applyModelValue(value, 'embedding')
|
||||
})
|
||||
|
||||
const selectedRerankValue = computed({
|
||||
get: () => modelValue(settings.reranking_model_provider, settings.reranking_model),
|
||||
set: (value: string) => applyModelValue(value, 'rerank')
|
||||
})
|
||||
|
||||
function resolveModelLabel(kind: 'embedding' | 'rerank', provider?: string | null, model?: string | null) {
|
||||
const collection = kind === 'embedding' ? difyModels.embedding_models : difyModels.rerank_models
|
||||
const matched = collection.find((item) => item.provider === provider && item.model === model)
|
||||
if (matched) return matched.label
|
||||
return provider && model ? `${provider} / ${model}` : t('admin.automaticChoice')
|
||||
}
|
||||
|
||||
const automaticEmbeddingLabel = computed(() =>
|
||||
resolveModelLabel(
|
||||
'embedding',
|
||||
difyModels.automatic_defaults.embedding_model_provider,
|
||||
difyModels.automatic_defaults.embedding_model
|
||||
)
|
||||
)
|
||||
|
||||
const automaticRerankLabel = computed(() =>
|
||||
resolveModelLabel(
|
||||
'rerank',
|
||||
difyModels.automatic_defaults.reranking_model_provider,
|
||||
difyModels.automatic_defaults.reranking_model
|
||||
)
|
||||
)
|
||||
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
const [settingsData, difyModelsData] = await Promise.all([
|
||||
apiFetch('/api/admin/settings'),
|
||||
apiFetch('/api/admin/dify-models')
|
||||
])
|
||||
Object.assign(settings, settingsData)
|
||||
Object.assign(difyModels, difyModelsData)
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : t('admin.failedToLoadAdminData')
|
||||
errorMessage.value = message
|
||||
emit('error', message)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSettings() {
|
||||
saving.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
await apiFetch('/api/admin/settings', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(settings)
|
||||
})
|
||||
emit('saved', t('admin.difyDefaultsSaved'))
|
||||
close()
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : t('admin.failedToSaveSettings')
|
||||
errorMessage.value = message
|
||||
emit('error', message)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
(open) => {
|
||||
if (open) {
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="close"
|
||||
>
|
||||
<div class="panel w-full max-w-5xl px-6 py-6" @click.stop>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold text-ink">{{ t('admin.settingsDialogTitle') }}</h3>
|
||||
<p class="mt-2 max-w-3xl text-sm leading-6 text-dusk">{{ t('admin.automaticSummary') }}</p>
|
||||
</div>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="close" 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>
|
||||
|
||||
<p v-if="errorMessage" class="mt-4 rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
|
||||
<div v-if="loading" class="py-16 text-center text-dusk">{{ t('common.loading') }}</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="mt-5 grid gap-4 rounded-3xl border border-slate-100 bg-mist/40 p-4 md:grid-cols-2">
|
||||
<div class="rounded-2xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.embeddingModel') }}</p>
|
||||
<p class="mt-2 text-sm text-ink">{{ t('admin.currentAutomaticEmbedding', { value: automaticEmbeddingLabel }) }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-white px-4 py-4">
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.18em] text-dusk">{{ t('admin.rerankModel') }}</p>
|
||||
<p class="mt-2 text-sm text-ink">{{ t('admin.currentAutomaticRerank', { value: automaticRerankLabel }) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.difyPermission') }}</span>
|
||||
<select v-model="settings.dify_permission" class="input">
|
||||
<option value="all_team_members">all_team_members</option>
|
||||
<option value="only_me">only_me</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.indexingTechnique') }}</span>
|
||||
<select v-model="settings.indexing_technique" class="input">
|
||||
<option value="high_quality">high_quality</option>
|
||||
<option value="economy">economy</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.searchMethod') }}</span>
|
||||
<select v-model="settings.search_method" class="input">
|
||||
<option value="hybrid_search">hybrid_search</option>
|
||||
<option value="semantic_search">semantic_search</option>
|
||||
<option value="full_text_search">full_text_search</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.docForm') }}</span>
|
||||
<select v-model="settings.doc_form" class="input">
|
||||
<option value="text_model">text_model</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.embeddingModel') }}</span>
|
||||
<select v-model="selectedEmbeddingValue" class="input">
|
||||
<option v-for="option in embeddingOptions" :key="option.value || 'auto-embedding'" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.rerankModel') }}</span>
|
||||
<select v-model="selectedRerankValue" class="input" :disabled="settings.search_method !== 'hybrid_search'">
|
||||
<option v-for="option in rerankOptions" :key="option.value || 'auto-rerank'" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.topK') }}</span>
|
||||
<input v-model.number="settings.top_k" class="input" type="number" min="1" />
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.scoreThreshold') }}</span>
|
||||
<input v-model.number="settings.score_threshold" class="input" type="number" min="0" max="1" step="0.05" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="mt-4 inline-flex items-center gap-2 text-sm text-dusk">
|
||||
<input v-model="settings.score_threshold_enabled" type="checkbox" />
|
||||
{{ t('admin.enableScoreThreshold') }}
|
||||
</label>
|
||||
|
||||
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
||||
<button class="btn-ghost" @click="close">{{ t('common.cancel') }}</button>
|
||||
<button class="btn-primary" :disabled="saving" @click="saveSettings">{{ t('common.save') }}</button>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n, type Locale } from '@/lib/i18n'
|
||||
|
||||
const { locale, setLocale, t } = useI18n()
|
||||
|
||||
const options: Array<{ value: Locale; label: string }> = [
|
||||
{ value: 'en', label: 'EN' },
|
||||
{ value: 'zh', label: '中文' }
|
||||
]
|
||||
|
||||
function handleLocaleChange(event: Event) {
|
||||
const target = event.target as HTMLSelectElement
|
||||
setLocale(target.value as Locale)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<label class="select-shell">
|
||||
<span class="select-label">{{ t('common.language') }}</span>
|
||||
<select class="select-control" :value="locale" @change="handleLocaleChange">
|
||||
<option v-for="option in options" :key="option.value" :value="option.value">
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useI18n } from '@/lib/i18n'
|
||||
|
||||
const props = defineProps<{
|
||||
status: string
|
||||
kind?: 'convert' | 'sync'
|
||||
}>()
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const klass = computed(() => {
|
||||
const status = props.status || 'unknown'
|
||||
if (status === 'success' || status === 'synced') return 'bg-emerald-100 text-emerald-700'
|
||||
if (status === 'running' || status === 'syncing') return 'bg-sky-100 text-sky-700'
|
||||
if (status === 'failed' || status === 'sync_failed') return 'bg-rose-100 text-rose-700'
|
||||
if (status === 'queued' || status === 'unsynced' || status === 'stale') return 'bg-slate-100 text-slate-700'
|
||||
return 'bg-slate-100 text-slate-700'
|
||||
})
|
||||
|
||||
const label = computed(() => {
|
||||
return t(`status.${props.status === 'stale' ? 'unsynced' : props.status}`)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span class="tag" :class="klass">{{ label }}</span>
|
||||
</template>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
defineProps<{
|
||||
toasts: Array<{
|
||||
id: number
|
||||
tone?: 'success' | 'error'
|
||||
message: string
|
||||
}>
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pointer-events-none fixed left-1/2 top-20 z-[70] flex w-[min(34rem,calc(100vw-2rem))] -translate-x-1/2 flex-col gap-3">
|
||||
<transition-group name="toast">
|
||||
<div
|
||||
v-for="toast in toasts"
|
||||
:key="toast.id"
|
||||
class="rounded-2xl border px-4 py-3 text-center text-sm shadow-soft backdrop-blur-xl"
|
||||
:class="
|
||||
toast.tone === 'error'
|
||||
? 'border-rose-200 bg-rose-50/95 text-rose-700'
|
||||
: 'border-emerald-200 bg-emerald-50/95 text-emerald-700'
|
||||
"
|
||||
>
|
||||
{{ toast.message }}
|
||||
</div>
|
||||
</transition-group>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
import { authState, clearSession } from './auth'
|
||||
|
||||
type RequestOptions = RequestInit & {
|
||||
skipAuth?: boolean
|
||||
}
|
||||
|
||||
export async function apiFetch(path: string, options: RequestOptions = {}) {
|
||||
const headers = new Headers(options.headers || {})
|
||||
if (!options.skipAuth && authState.token) {
|
||||
headers.set('Authorization', `Bearer ${authState.token}`)
|
||||
}
|
||||
if (!(options.body instanceof FormData) && !headers.has('Content-Type')) {
|
||||
headers.set('Content-Type', 'application/json')
|
||||
}
|
||||
const response = await fetch(path, { ...options, headers })
|
||||
if (response.status === 401) {
|
||||
clearSession()
|
||||
window.location.href = '/login'
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
if (!response.ok) {
|
||||
let detail = response.statusText
|
||||
try {
|
||||
const data = await response.json()
|
||||
detail = data.detail || JSON.stringify(data)
|
||||
} catch {
|
||||
detail = await response.text()
|
||||
}
|
||||
throw new Error(detail)
|
||||
}
|
||||
if (response.status === 204) {
|
||||
return null
|
||||
}
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
if (contentType.includes('application/json')) {
|
||||
return response.json()
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
export async function downloadBlob(path: string, options: RequestOptions = {}, filename?: string) {
|
||||
const headers = new Headers(options.headers || {})
|
||||
if (authState.token) {
|
||||
headers.set('Authorization', `Bearer ${authState.token}`)
|
||||
}
|
||||
const response = await fetch(path, { ...options, headers })
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text())
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const disposition = response.headers.get('content-disposition') || ''
|
||||
const utf8Match = disposition.match(/filename\*\s*=\s*UTF-8''([^;]+)/i)
|
||||
const quotedMatch = disposition.match(/filename\s*=\s*"([^"]+)"/i)
|
||||
const plainMatch = disposition.match(/filename\s*=\s*([^;]+)/i)
|
||||
const resolvedFilename =
|
||||
filename ||
|
||||
(utf8Match?.[1]
|
||||
? (() => {
|
||||
try {
|
||||
return decodeURIComponent(utf8Match[1].trim())
|
||||
} catch {
|
||||
return utf8Match[1].trim()
|
||||
}
|
||||
})()
|
||||
: quotedMatch?.[1] || plainMatch?.[1]?.trim()) ||
|
||||
'download.bin'
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = resolvedFilename
|
||||
link.style.display = 'none'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { reactive } from 'vue'
|
||||
|
||||
type SessionUser = {
|
||||
id: number
|
||||
username: string
|
||||
full_name?: string | null
|
||||
role: string
|
||||
accessible_group_ids?: number[]
|
||||
primary_department_id?: number | null
|
||||
primary_department_name?: string | null
|
||||
accessible_department_ids?: number[]
|
||||
}
|
||||
|
||||
type SessionState = {
|
||||
token: string
|
||||
user: SessionUser | null
|
||||
}
|
||||
|
||||
const storedToken = localStorage.getItem('dc_token') || ''
|
||||
const storedUser = localStorage.getItem('dc_user')
|
||||
|
||||
export const authState = reactive<SessionState>({
|
||||
token: storedToken,
|
||||
user: storedUser ? JSON.parse(storedUser) : null
|
||||
})
|
||||
|
||||
export function setSession(token: string, user: SessionUser) {
|
||||
authState.token = token
|
||||
authState.user = user
|
||||
localStorage.setItem('dc_token', token)
|
||||
localStorage.setItem('dc_user', JSON.stringify(user))
|
||||
}
|
||||
|
||||
export function clearSession() {
|
||||
authState.token = ''
|
||||
authState.user = null
|
||||
localStorage.removeItem('dc_token')
|
||||
localStorage.removeItem('dc_user')
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import './style.css'
|
||||
|
||||
createApp(App).use(router).mount('#app')
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { authState } from '@/lib/auth'
|
||||
import LoginView from '@/views/LoginView.vue'
|
||||
import WorkspaceView from '@/views/WorkspaceView.vue'
|
||||
import AdminView from '@/views/AdminView.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/workspace'
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
component: LoginView,
|
||||
meta: { guestOnly: true }
|
||||
},
|
||||
{
|
||||
path: '/workspace',
|
||||
component: WorkspaceView,
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
component: AdminView,
|
||||
meta: { requiresAuth: true, adminOnly: true }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
if (to.meta.requiresAuth && !authState.token) {
|
||||
return '/login'
|
||||
}
|
||||
if (to.meta.guestOnly && authState.token) {
|
||||
return '/workspace'
|
||||
}
|
||||
if (to.meta.adminOnly && !['super_admin', 'admin'].includes(authState.user?.role || '')) {
|
||||
return '/workspace'
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,395 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=Noto+Sans+SC:wght@400;500;700&display=swap');
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
color: #122033;
|
||||
background:
|
||||
radial-gradient(circle at 12% 14%, rgba(21, 115, 255, 0.18), transparent 30%),
|
||||
radial-gradient(circle at 86% 18%, rgba(255, 113, 71, 0.12), transparent 24%),
|
||||
radial-gradient(circle at 78% 88%, rgba(31, 195, 154, 0.14), transparent 28%),
|
||||
linear-gradient(180deg, #f6f8fc 0%, #ecf1f7 100%);
|
||||
font-family: 'Space Grotesk', 'Noto Sans SC', sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
color: #122033;
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: '';
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
background-image:
|
||||
linear-gradient(rgba(18, 32, 51, 0.035) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(18, 32, 51, 0.035) 1px, transparent 1px);
|
||||
background-size: 32px 32px;
|
||||
mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.22));
|
||||
}
|
||||
|
||||
body::after {
|
||||
content: '';
|
||||
position: fixed;
|
||||
right: -10rem;
|
||||
top: 8rem;
|
||||
width: 28rem;
|
||||
height: 28rem;
|
||||
border-radius: 9999px;
|
||||
pointer-events: none;
|
||||
background: radial-gradient(circle, rgba(21, 115, 255, 0.18) 0%, rgba(21, 115, 255, 0) 70%);
|
||||
filter: blur(8px);
|
||||
}
|
||||
|
||||
#app {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.panel {
|
||||
@apply rounded-panel border border-slate-300/90 bg-white/80 shadow-soft backdrop-blur-xl;
|
||||
position: relative;
|
||||
box-shadow:
|
||||
0 18px 50px rgba(18, 32, 51, 0.1),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.72);
|
||||
}
|
||||
|
||||
.panel::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0 0 auto 0;
|
||||
height: 3px;
|
||||
background: linear-gradient(90deg, rgba(21, 115, 255, 0.92), rgba(31, 195, 154, 0.72), rgba(255, 113, 71, 0.72));
|
||||
}
|
||||
|
||||
.input {
|
||||
@apply w-full rounded-2xl border border-slate-300 bg-white px-4 py-3 text-sm text-ink outline-none transition focus:border-surge focus:ring-4 focus:ring-surge/10;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7),
|
||||
0 1px 2px rgba(18, 32, 51, 0.04);
|
||||
}
|
||||
|
||||
.btn {
|
||||
@apply inline-flex items-center justify-center gap-2 rounded-2xl px-4 py-2.5 text-sm font-medium transition;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
@apply btn border border-transparent bg-ink text-white hover:-translate-y-0.5 hover:bg-slate-800;
|
||||
box-shadow: 0 12px 24px rgba(18, 32, 51, 0.18);
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
@apply btn border border-slate-300 bg-white text-ink hover:-translate-y-0.5 hover:border-surge hover:text-surge;
|
||||
box-shadow:
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7),
|
||||
0 1px 2px rgba(18, 32, 51, 0.05);
|
||||
}
|
||||
|
||||
.dialog-static-btn,
|
||||
.dialog-static-btn:hover,
|
||||
.dialog-static-btn:focus-visible,
|
||||
.dialog-static-btn:active {
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
.dialog-static-btn {
|
||||
transition:
|
||||
border-color 140ms ease,
|
||||
color 140ms ease,
|
||||
background-color 140ms ease,
|
||||
box-shadow 140ms ease !important;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
@apply inline-flex h-8 w-8 items-center justify-center rounded-full border border-slate-300 bg-white transition hover:-translate-y-0.5 hover:border-surge hover:text-surge disabled:cursor-not-allowed disabled:opacity-60;
|
||||
}
|
||||
|
||||
.group-card .group-card-actions {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition:
|
||||
opacity 160ms ease,
|
||||
transform 160ms ease,
|
||||
border-color 180ms ease,
|
||||
background-color 180ms ease,
|
||||
color 180ms ease;
|
||||
transform: translateY(-50%) scale(0.96);
|
||||
}
|
||||
|
||||
.group-card .group-card-status-dot {
|
||||
opacity: 1;
|
||||
transition: opacity 160ms ease;
|
||||
}
|
||||
|
||||
.group-card:hover .group-card-actions,
|
||||
.group-card .group-card-actions:focus-within {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transform: translateY(-50%) scale(1);
|
||||
}
|
||||
|
||||
.group-card:hover .group-card-status-dot {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@media (hover: none) {
|
||||
.group-card .group-card-actions {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transform: translateY(-50%) scale(1);
|
||||
}
|
||||
|
||||
.group-card .group-card-status-dot {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.tag {
|
||||
@apply inline-flex items-center rounded-full px-2.5 py-1 text-xs font-semibold;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.select-shell {
|
||||
@apply inline-flex items-center gap-2 rounded-2xl border border-slate-300 bg-white px-3 py-2 text-sm shadow-soft backdrop-blur-xl;
|
||||
}
|
||||
|
||||
.select-label {
|
||||
@apply text-xs font-semibold uppercase tracking-[0.18em] text-dusk;
|
||||
}
|
||||
|
||||
.select-control {
|
||||
@apply rounded-xl border-0 bg-transparent py-1 pl-1 pr-7 text-sm font-semibold text-ink outline-none;
|
||||
}
|
||||
|
||||
.menu-shell {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.menu-trigger {
|
||||
@apply inline-flex cursor-pointer items-center gap-2 rounded-full px-3 py-2 text-sm font-semibold text-ink transition hover:bg-white/80 hover:text-surge;
|
||||
list-style: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.menu-trigger::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-trigger-icon {
|
||||
@apply h-4 w-4 text-dusk transition;
|
||||
}
|
||||
|
||||
.menu-shell[open] .menu-trigger {
|
||||
@apply border-surge text-surge;
|
||||
}
|
||||
|
||||
.menu-shell[open] .menu-trigger-icon {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.menu-popover {
|
||||
@apply absolute right-0 top-[calc(100%+0.5rem)] z-40 rounded-2xl border border-slate-200 bg-white/95 p-1 shadow-soft backdrop-blur-xl;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
@apply flex w-full items-center justify-center rounded-xl px-4 py-2 text-center text-sm font-medium text-ink transition hover:bg-mist hover:text-surge;
|
||||
}
|
||||
|
||||
.user-menu {
|
||||
@apply relative inline-flex items-center outline-none;
|
||||
}
|
||||
|
||||
.user-menu::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: -0.5rem;
|
||||
right: -0.5rem;
|
||||
top: 100%;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
.user-menu-trigger {
|
||||
@apply inline-flex items-center gap-1 rounded-xl px-1.5 py-1 text-[15px] font-semibold text-ink transition;
|
||||
}
|
||||
|
||||
.user-menu:hover .user-menu-trigger,
|
||||
.user-menu:focus-within .user-menu-trigger {
|
||||
@apply text-surge;
|
||||
}
|
||||
|
||||
.user-menu-panel {
|
||||
@apply absolute left-1/2 top-[calc(100%+0.45rem)] z-50 min-w-[132px] rounded-2xl border border-slate-300 bg-white p-1 shadow-soft backdrop-blur-xl;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
visibility: hidden;
|
||||
transform: translate(-50%, 4px);
|
||||
transition:
|
||||
opacity 160ms ease,
|
||||
transform 160ms ease;
|
||||
}
|
||||
|
||||
.user-menu:hover .user-menu-panel,
|
||||
.user-menu:focus-within .user-menu-panel {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
visibility: visible;
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
|
||||
.user-menu-name {
|
||||
@apply max-w-[156px] truncate text-[15px] font-semibold text-current;
|
||||
}
|
||||
|
||||
.user-menu-icon {
|
||||
@apply h-3.5 w-3.5 text-dusk transition;
|
||||
}
|
||||
|
||||
.user-menu:hover .user-menu-icon,
|
||||
.user-menu:focus-within .user-menu-icon {
|
||||
@apply text-surge;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.date-range-shell {
|
||||
@apply flex items-center rounded-2xl border border-slate-300 bg-white px-3 py-2;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
.date-range-input {
|
||||
@apply min-w-0 flex-1 border-0 bg-transparent px-1 py-1 text-sm text-ink outline-none;
|
||||
}
|
||||
|
||||
.date-range-divider {
|
||||
@apply px-2 text-sm font-semibold text-dusk;
|
||||
}
|
||||
|
||||
.file-title-link {
|
||||
@apply block max-w-[8em] truncate text-left font-semibold text-surge underline decoration-surge/80 underline-offset-4 transition hover:text-blue-700;
|
||||
}
|
||||
|
||||
.file-title-text {
|
||||
@apply block max-w-[8em] truncate font-semibold text-ink;
|
||||
}
|
||||
|
||||
.datetime-stack {
|
||||
@apply flex flex-col leading-tight text-ink;
|
||||
}
|
||||
|
||||
.datetime-subtle {
|
||||
@apply mt-1 text-xs text-dusk;
|
||||
}
|
||||
|
||||
.table-actions {
|
||||
@apply flex flex-nowrap items-center gap-2 overflow-x-auto;
|
||||
}
|
||||
|
||||
.table-actions .btn-ghost {
|
||||
transform: none !important;
|
||||
transition:
|
||||
border-color 140ms ease,
|
||||
color 140ms ease,
|
||||
background-color 140ms ease,
|
||||
box-shadow 140ms ease !important;
|
||||
}
|
||||
|
||||
.table-actions .btn-ghost:hover,
|
||||
.table-actions .btn-ghost:focus-visible,
|
||||
.table-actions .btn-ghost:active {
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
.table-action-btn {
|
||||
@apply shrink-0 whitespace-nowrap justify-center rounded-xl px-3 py-2 text-xs;
|
||||
transform: none !important;
|
||||
transition:
|
||||
border-color 140ms ease,
|
||||
color 140ms ease,
|
||||
background-color 140ms ease,
|
||||
box-shadow 140ms ease;
|
||||
}
|
||||
|
||||
.table-action-btn:hover,
|
||||
.table-action-btn:focus-visible {
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
.status-toggle {
|
||||
@apply inline-flex min-w-[132px] items-center justify-center gap-3 rounded-full border px-3 py-2 text-sm font-medium transition;
|
||||
}
|
||||
|
||||
.status-toggle:disabled {
|
||||
@apply cursor-not-allowed opacity-60;
|
||||
}
|
||||
|
||||
.status-toggle-track {
|
||||
@apply relative h-6 w-11 rounded-full border border-transparent transition;
|
||||
}
|
||||
|
||||
.status-toggle-thumb {
|
||||
@apply absolute left-0.5 top-0.5 rounded-full bg-white shadow-sm transition;
|
||||
height: 1.125rem;
|
||||
width: 1.125rem;
|
||||
}
|
||||
|
||||
.status-toggle-label {
|
||||
@apply whitespace-nowrap;
|
||||
}
|
||||
|
||||
.status-toggle--on {
|
||||
@apply border-emerald-200 bg-emerald-50 text-emerald-700;
|
||||
}
|
||||
|
||||
.status-toggle--on .status-toggle-track {
|
||||
@apply bg-emerald-500;
|
||||
}
|
||||
|
||||
.status-toggle--on .status-toggle-thumb {
|
||||
transform: translateX(1.25rem);
|
||||
}
|
||||
|
||||
.status-toggle--off {
|
||||
@apply border-slate-200 bg-slate-100 text-slate-600;
|
||||
}
|
||||
|
||||
.status-toggle--off .status-toggle-track {
|
||||
@apply bg-slate-300;
|
||||
}
|
||||
|
||||
.uppy-compact .uppy-Dashboard-inner,
|
||||
.uppy-compact .uppy-Dashboard-innerWrap {
|
||||
min-height: 220px !important;
|
||||
}
|
||||
|
||||
.uppy-compact .uppy-Dashboard-inner {
|
||||
width: 100% !important;
|
||||
border: 1px dashed rgba(148, 163, 184, 0.45);
|
||||
border-radius: 1.5rem;
|
||||
background: linear-gradient(180deg, rgba(248, 250, 252, 0.82), rgba(255, 255, 255, 0.94));
|
||||
}
|
||||
|
||||
.file-table {
|
||||
table-layout: auto;
|
||||
}
|
||||
|
||||
.diff-table {
|
||||
table-layout: fixed;
|
||||
min-width: 960px;
|
||||
}
|
||||
|
||||
.file-table th,
|
||||
.file-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
@@ -0,0 +1,769 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import DifyHealthDialog from '@/components/DifyHealthDialog.vue'
|
||||
import DifySettingsDialog from '@/components/DifySettingsDialog.vue'
|
||||
import LocaleSwitcher from '@/components/LocaleSwitcher.vue'
|
||||
import ToastStack from '@/components/ToastStack.vue'
|
||||
import { apiFetch } from '@/lib/api'
|
||||
import { authState, clearSession } from '@/lib/auth'
|
||||
import { useI18n } from '@/lib/i18n'
|
||||
|
||||
type DepartmentRow = {
|
||||
id: number
|
||||
name: string
|
||||
description?: string | null
|
||||
user_count?: number
|
||||
knowledge_base_count?: number
|
||||
}
|
||||
|
||||
type UserRow = {
|
||||
id: number
|
||||
username: string
|
||||
full_name?: string | null
|
||||
role: string
|
||||
is_primary_super_admin?: boolean
|
||||
is_active: boolean
|
||||
primary_department_id: number | null
|
||||
primary_department_name?: string | null
|
||||
accessible_department_ids: number[]
|
||||
extra_department_ids: number[]
|
||||
}
|
||||
|
||||
type EditableUser = {
|
||||
id: number | null
|
||||
username: string
|
||||
full_name: string
|
||||
password: string
|
||||
role: string
|
||||
is_active: boolean
|
||||
primary_department_id: number | null
|
||||
extra_department_ids: number[]
|
||||
}
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const users = ref<UserRow[]>([])
|
||||
const departments = ref<DepartmentRow[]>([])
|
||||
const settingsDialogOpen = ref(false)
|
||||
const healthDialogOpen = ref(false)
|
||||
const userMenuOpen = ref(false)
|
||||
const togglingUserId = ref<number | null>(null)
|
||||
const toasts = ref<Array<{ id: number; tone?: 'success' | 'error'; message: string }>>([])
|
||||
|
||||
const departmentDialog = reactive({
|
||||
open: false,
|
||||
mode: 'create' as 'create' | 'edit',
|
||||
id: null as number | null,
|
||||
name: '',
|
||||
description: '',
|
||||
})
|
||||
|
||||
const departmentDeleteDialog = reactive({
|
||||
open: false,
|
||||
id: null as number | null,
|
||||
name: '',
|
||||
user_count: 0,
|
||||
knowledge_base_count: 0,
|
||||
target_department_id: null as number | null,
|
||||
})
|
||||
|
||||
const userDialog = reactive({
|
||||
open: false,
|
||||
mode: 'create' as 'create' | 'edit',
|
||||
})
|
||||
|
||||
const userDeleteDialog = reactive({
|
||||
open: false,
|
||||
id: null as number | null,
|
||||
username: '',
|
||||
})
|
||||
|
||||
const editableUser = reactive<EditableUser>({
|
||||
id: null,
|
||||
username: '',
|
||||
full_name: '',
|
||||
password: '',
|
||||
role: 'user',
|
||||
is_active: true,
|
||||
primary_department_id: null,
|
||||
extra_department_ids: [],
|
||||
})
|
||||
|
||||
const isAdmin = computed(() => ['super_admin', 'admin'].includes(authState.user?.role || ''))
|
||||
const currentUserLabel = computed(() => authState.user?.full_name || authState.user?.username || t('common.unknown'))
|
||||
const currentUserId = computed(() => authState.user?.id ?? null)
|
||||
const sortedUsers = computed(() => [...users.value].sort((left, right) => left.username.localeCompare(right.username)))
|
||||
const departmentOptions = computed(() => departments.value.map((item) => ({ value: item.id, label: item.name })))
|
||||
const hasDepartments = computed(() => departments.value.length > 0)
|
||||
const departmentDeleteOptions = computed(() =>
|
||||
departments.value.filter((item) => item.id !== departmentDeleteDialog.id).map((item) => ({ value: item.id, label: item.name })),
|
||||
)
|
||||
const departmentDeleteNeedsMigration = computed(
|
||||
() => departmentDeleteDialog.user_count > 0 || departmentDeleteDialog.knowledge_base_count > 0,
|
||||
)
|
||||
const roleOptions = computed(() => [
|
||||
{ value: 'admin', label: t('roles.admin') },
|
||||
{ value: 'user', label: t('roles.user') },
|
||||
])
|
||||
|
||||
const userDepartmentIds = computed(() => {
|
||||
const ids = [editableUser.primary_department_id, ...editableUser.extra_department_ids].filter(
|
||||
(value): value is number => value !== null,
|
||||
)
|
||||
return [...new Set(ids)]
|
||||
})
|
||||
|
||||
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 logout() {
|
||||
clearSession()
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
function closeMenus() {
|
||||
userMenuOpen.value = false
|
||||
}
|
||||
|
||||
function resetDepartmentDialog() {
|
||||
departmentDialog.open = false
|
||||
departmentDialog.mode = 'create'
|
||||
departmentDialog.id = null
|
||||
departmentDialog.name = ''
|
||||
departmentDialog.description = ''
|
||||
}
|
||||
|
||||
function resetDepartmentDeleteDialog() {
|
||||
departmentDeleteDialog.open = false
|
||||
departmentDeleteDialog.id = null
|
||||
departmentDeleteDialog.name = ''
|
||||
departmentDeleteDialog.user_count = 0
|
||||
departmentDeleteDialog.knowledge_base_count = 0
|
||||
departmentDeleteDialog.target_department_id = null
|
||||
}
|
||||
|
||||
function resetUserDialog() {
|
||||
userDialog.open = false
|
||||
userDialog.mode = 'create'
|
||||
editableUser.id = null
|
||||
editableUser.username = ''
|
||||
editableUser.full_name = ''
|
||||
editableUser.password = ''
|
||||
editableUser.role = 'user'
|
||||
editableUser.is_active = true
|
||||
editableUser.primary_department_id = departments.value[0]?.id ?? null
|
||||
editableUser.extra_department_ids = []
|
||||
}
|
||||
|
||||
function resetUserDeleteDialog() {
|
||||
userDeleteDialog.open = false
|
||||
userDeleteDialog.id = null
|
||||
userDeleteDialog.username = ''
|
||||
}
|
||||
|
||||
function setUserDepartmentIds(departmentIds: number[]) {
|
||||
const uniqueIds = [...new Set(departmentIds)]
|
||||
editableUser.primary_department_id = uniqueIds[0] ?? null
|
||||
editableUser.extra_department_ids = uniqueIds.slice(1)
|
||||
}
|
||||
|
||||
function normalizeExtraDepartments(primaryDepartmentId: number | null, departmentIds: number[]) {
|
||||
if (!primaryDepartmentId) return [...new Set(departmentIds)]
|
||||
return [...new Set(departmentIds)].filter((item) => item !== primaryDepartmentId)
|
||||
}
|
||||
|
||||
function openCreateDepartmentDialog() {
|
||||
resetDepartmentDialog()
|
||||
departmentDialog.open = true
|
||||
departmentDialog.mode = 'create'
|
||||
}
|
||||
|
||||
function openEditDepartmentDialog(row: DepartmentRow) {
|
||||
departmentDialog.open = true
|
||||
departmentDialog.mode = 'edit'
|
||||
departmentDialog.id = row.id
|
||||
departmentDialog.name = row.name
|
||||
departmentDialog.description = row.description || ''
|
||||
}
|
||||
|
||||
function openDeleteDepartmentDialog(row: DepartmentRow) {
|
||||
departmentDeleteDialog.open = true
|
||||
departmentDeleteDialog.id = row.id
|
||||
departmentDeleteDialog.name = row.name
|
||||
departmentDeleteDialog.user_count = row.user_count ?? 0
|
||||
departmentDeleteDialog.knowledge_base_count = row.knowledge_base_count ?? 0
|
||||
departmentDeleteDialog.target_department_id = departments.value.find((item) => item.id !== row.id)?.id ?? null
|
||||
}
|
||||
|
||||
function openCreateUserDialog() {
|
||||
if (!hasDepartments.value) {
|
||||
pushToast(t('admin.createDepartmentFirst'), 'error')
|
||||
return
|
||||
}
|
||||
resetUserDialog()
|
||||
userDialog.open = true
|
||||
userDialog.mode = 'create'
|
||||
}
|
||||
|
||||
function openEditUserDialog(row: UserRow) {
|
||||
userDialog.open = true
|
||||
userDialog.mode = 'edit'
|
||||
editableUser.id = row.id
|
||||
editableUser.username = row.username
|
||||
editableUser.full_name = row.full_name || ''
|
||||
editableUser.password = ''
|
||||
editableUser.role = row.is_primary_super_admin ? 'super_admin' : row.role
|
||||
editableUser.is_active = row.is_active
|
||||
setUserDepartmentIds(row.accessible_department_ids)
|
||||
}
|
||||
|
||||
function canDeleteUser(row: UserRow) {
|
||||
return row.username !== 'admin' && !row.is_primary_super_admin && row.id !== currentUserId.value
|
||||
}
|
||||
|
||||
function openDeleteUserDialog(row: UserRow) {
|
||||
if (!canDeleteUser(row)) return
|
||||
userDeleteDialog.open = true
|
||||
userDeleteDialog.id = row.id
|
||||
userDeleteDialog.username = row.username
|
||||
}
|
||||
|
||||
function toggleUserDepartment(departmentId: number, checked: boolean) {
|
||||
const nextIds = [...userDepartmentIds.value]
|
||||
if (checked) {
|
||||
if (!nextIds.includes(departmentId)) nextIds.push(departmentId)
|
||||
} else {
|
||||
const index = nextIds.indexOf(departmentId)
|
||||
if (index >= 0) nextIds.splice(index, 1)
|
||||
}
|
||||
setUserDepartmentIds(nextIds)
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const [departmentData, userData] = await Promise.all([
|
||||
apiFetch('/api/admin/departments'),
|
||||
apiFetch('/api/admin/users'),
|
||||
])
|
||||
departments.value = departmentData.data || []
|
||||
users.value = userData.data || []
|
||||
if (!editableUser.primary_department_id) {
|
||||
editableUser.primary_department_id = departments.value[0]?.id ?? null
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('admin.failedToLoadAdminData')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function saveDepartment() {
|
||||
error.value = ''
|
||||
try {
|
||||
const payload = {
|
||||
name: departmentDialog.name.trim(),
|
||||
description: departmentDialog.description.trim() || null,
|
||||
}
|
||||
if (departmentDialog.mode === 'create') {
|
||||
await apiFetch('/api/admin/departments', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
pushToast(t('admin.departmentCreated'))
|
||||
} else {
|
||||
await apiFetch(`/api/admin/departments/${departmentDialog.id}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
pushToast(t('admin.departmentUpdated'))
|
||||
}
|
||||
resetDepartmentDialog()
|
||||
await loadAll()
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('admin.failedToSaveDepartment')
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDepartment() {
|
||||
error.value = ''
|
||||
if (!departmentDeleteDialog.id) return
|
||||
if (departmentDeleteNeedsMigration.value && !departmentDeleteDialog.target_department_id) {
|
||||
error.value = t('admin.deleteDepartmentTargetRequired')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await apiFetch(`/api/admin/departments/${departmentDeleteDialog.id}`, {
|
||||
method: 'DELETE',
|
||||
body: JSON.stringify({
|
||||
target_department_id: departmentDeleteNeedsMigration.value ? departmentDeleteDialog.target_department_id : null,
|
||||
}),
|
||||
})
|
||||
pushToast(departmentDeleteNeedsMigration.value ? t('admin.departmentDeletedWithMigration') : t('admin.departmentDeleted'))
|
||||
resetDepartmentDeleteDialog()
|
||||
await loadAll()
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('admin.failedToDeleteDepartment')
|
||||
}
|
||||
}
|
||||
|
||||
async function saveUser() {
|
||||
error.value = ''
|
||||
if (userDepartmentIds.value.length === 0) {
|
||||
error.value = t('admin.primaryDepartmentRequired')
|
||||
return
|
||||
}
|
||||
const orderedDepartmentIds = userDepartmentIds.value
|
||||
const payload = {
|
||||
username: editableUser.username.trim(),
|
||||
password: editableUser.password || undefined,
|
||||
full_name: editableUser.full_name.trim() || null,
|
||||
role: editableUser.role,
|
||||
is_active: editableUser.is_active,
|
||||
primary_department_id: orderedDepartmentIds[0] ?? null,
|
||||
accessible_department_ids: normalizeExtraDepartments(orderedDepartmentIds[0] ?? null, orderedDepartmentIds.slice(1)),
|
||||
}
|
||||
try {
|
||||
if (userDialog.mode === 'create') {
|
||||
await apiFetch('/api/admin/users', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
...payload,
|
||||
password: editableUser.password,
|
||||
}),
|
||||
})
|
||||
pushToast(t('admin.userCreated'))
|
||||
} else {
|
||||
await apiFetch(`/api/admin/users/${editableUser.id}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
pushToast(t('admin.userSaved', { username: editableUser.username }))
|
||||
}
|
||||
resetUserDialog()
|
||||
await loadAll()
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t(userDialog.mode === 'create' ? 'admin.failedToCreateUser' : 'admin.failedToUpdateUser')
|
||||
}
|
||||
}
|
||||
|
||||
function departmentSummary(user: UserRow) {
|
||||
const names = departments.value
|
||||
.filter((item) => user.accessible_department_ids.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
return names.join('、') || t('common.none')
|
||||
}
|
||||
|
||||
function extraDepartmentSummary(user: UserRow) {
|
||||
const names = departments.value
|
||||
.filter((item) => user.extra_department_ids.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
return names.join('、') || t('common.none')
|
||||
}
|
||||
|
||||
function departmentPermissionSummary(user: UserRow) {
|
||||
const names = departments.value
|
||||
.filter((item) => user.accessible_department_ids.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
return names.join('、') || t('common.none')
|
||||
}
|
||||
|
||||
function renderDepartmentPermissionSummary(user: UserRow) {
|
||||
const names = departments.value
|
||||
.filter((item) => user.accessible_department_ids.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
return names.join('、') || t('common.none')
|
||||
}
|
||||
|
||||
async function toggleUserActive(user: UserRow) {
|
||||
if (user.username === 'admin' || user.is_primary_super_admin || togglingUserId.value === user.id) return
|
||||
error.value = ''
|
||||
togglingUserId.value = user.id
|
||||
try {
|
||||
await apiFetch(`/api/admin/users/${user.id}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({
|
||||
is_active: !user.is_active,
|
||||
}),
|
||||
})
|
||||
user.is_active = !user.is_active
|
||||
pushToast(t('admin.userStatusUpdated'))
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('admin.failedToToggleUserStatus')
|
||||
} finally {
|
||||
togglingUserId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteUser() {
|
||||
error.value = ''
|
||||
if (!userDeleteDialog.id) return
|
||||
try {
|
||||
await apiFetch(`/api/admin/users/${userDeleteDialog.id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
pushToast(t('admin.userDeleted'))
|
||||
resetUserDeleteDialog()
|
||||
await loadAll()
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('admin.failedToDeleteUser')
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => t('admin.permissionsPageTitle'),
|
||||
(value) => {
|
||||
document.title = value
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
if (!isAdmin.value) {
|
||||
router.push('/workspace')
|
||||
return
|
||||
}
|
||||
void loadAll()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="min-h-screen px-4 py-6 md:px-8" @click="closeMenus">
|
||||
<ToastStack :toasts="toasts" />
|
||||
|
||||
<div class="mx-auto max-w-[1680px] space-y-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>
|
||||
<h1 class="text-3xl font-bold text-ink">{{ t('admin.permissionsPageTitle') }}</h1>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-end gap-3">
|
||||
<LocaleSwitcher />
|
||||
<button class="btn-ghost" @click="router.push('/workspace')">{{ t('admin.backToWorkspace') }}</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 class="menu-item" @click="settingsDialogOpen = true">{{ t('admin.openDifySettings') }}</button>
|
||||
<button class="menu-item" @click="healthDialogOpen = true">{{ t('admin.difyHealth') }}</button>
|
||||
<button class="menu-item" @click="logout">{{ t('common.signOut') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<p v-if="error" class="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">{{ error }}</p>
|
||||
|
||||
<section class="grid gap-6 xl:grid-cols-[360px_minmax(0,1fr)]">
|
||||
<div class="panel px-5 py-5">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold text-ink">{{ t('admin.departmentsTitle') }}</h2>
|
||||
</div>
|
||||
<button class="btn-ghost" @click="openCreateDepartmentDialog">{{ t('admin.createDepartment') }}</button>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 space-y-3">
|
||||
<article v-for="department in departments" :key="department.id" class="rounded-3xl border border-slate-200 bg-white px-4 py-4">
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<p class="truncate text-base font-semibold text-ink">{{ department.name }}</p>
|
||||
<p v-if="department.description" class="mt-1 text-sm text-dusk">{{ department.description }}</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button class="btn-ghost px-3 py-2" @click="openEditDepartmentDialog(department)">{{ t('common.edit') }}</button>
|
||||
<button class="btn-ghost px-3 py-2" @click="openDeleteDepartmentDialog(department)">{{ t('workspace.delete') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 grid grid-cols-2 gap-3">
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('admin.userCount') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ department.user_count ?? 0 }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('admin.groups') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ department.knowledge_base_count ?? 0 }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel px-5 py-5">
|
||||
<div class="flex flex-wrap items-center justify-end gap-3">
|
||||
<button class="btn-ghost" :disabled="!hasDepartments" @click="openCreateUserDialog">{{ t('admin.createUser') }}</button>
|
||||
</div>
|
||||
|
||||
<p v-if="!hasDepartments" class="mt-4 rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-800">
|
||||
{{ t('admin.createDepartmentFirst') }}
|
||||
</p>
|
||||
|
||||
<div class="mt-5 overflow-hidden rounded-3xl border border-slate-200 bg-white">
|
||||
<table class="file-table w-full min-w-[920px] text-left text-sm">
|
||||
<thead class="bg-mist/70 text-dusk">
|
||||
<tr>
|
||||
<th class="px-4 py-3">{{ t('admin.username') }}</th>
|
||||
<th class="px-4 py-3">{{ t('admin.fullName') }}</th>
|
||||
<th class="px-4 py-3">{{ t('admin.role') }}</th>
|
||||
<th class="px-4 py-3">{{ t('admin.departmentPermissions') }}</th>
|
||||
<th class="px-4 py-3">{{ t('admin.active') }}</th>
|
||||
<th class="px-4 py-3">{{ t('admin.action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="user in sortedUsers" :key="user.id" class="border-t border-slate-100">
|
||||
<td class="px-4 py-4 font-semibold text-ink">{{ user.username }}</td>
|
||||
<td class="px-4 py-4 text-ink">{{ user.full_name || '-' }}</td>
|
||||
<td class="px-4 py-4 text-ink">{{ t(`roles.${user.role}`) }}</td>
|
||||
<td class="px-4 py-4 text-dusk">{{ renderDepartmentPermissionSummary(user) }}</td>
|
||||
<td class="px-4 py-4">
|
||||
<button
|
||||
class="status-toggle"
|
||||
:class="user.is_active ? 'status-toggle--on' : 'status-toggle--off'"
|
||||
:disabled="user.username === 'admin' || user.is_primary_super_admin || togglingUserId === user.id"
|
||||
@click="toggleUserActive(user)"
|
||||
>
|
||||
<span class="status-toggle-track" aria-hidden="true">
|
||||
<span class="status-toggle-thumb"></span>
|
||||
</span>
|
||||
<span class="status-toggle-label">
|
||||
{{ user.is_active ? t('admin.enabled') : t('admin.disabled') }}
|
||||
</span>
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-4 py-4">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button class="btn-ghost px-3 py-2" @click="openEditUserDialog(user)">{{ t('common.edit') }}</button>
|
||||
<button
|
||||
v-if="canDeleteUser(user)"
|
||||
class="btn-ghost px-3 py-2"
|
||||
@click="openDeleteUserDialog(user)"
|
||||
>
|
||||
{{ t('workspace.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-if="!loading && sortedUsers.length === 0">
|
||||
<td colspan="6" class="px-4 py-10 text-center text-dusk">{{ t('admin.noUsers') }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div
|
||||
v-if="departmentDialog.open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="resetDepartmentDialog"
|
||||
>
|
||||
<div class="panel w-full max-w-xl px-6 py-6" @click.stop>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold text-ink">
|
||||
{{ departmentDialog.mode === 'create' ? t('admin.createDepartment') : t('admin.editDepartment') }}
|
||||
</h3>
|
||||
</div>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="resetDepartmentDialog" 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 space-y-4">
|
||||
<input v-model="departmentDialog.name" class="input" :placeholder="t('admin.departmentName')" />
|
||||
<textarea v-model="departmentDialog.description" class="input min-h-[140px] resize-none" :placeholder="t('admin.departmentDescription')"></textarea>
|
||||
</div>
|
||||
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
||||
<button class="btn-ghost" @click="resetDepartmentDialog">{{ t('common.cancel') }}</button>
|
||||
<button class="btn-primary" @click="saveDepartment">{{ t('common.save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="departmentDeleteDialog.open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="resetDepartmentDeleteDialog"
|
||||
>
|
||||
<div class="panel w-full max-w-xl px-6 py-6" @click.stop>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold text-ink">{{ t('admin.deleteDepartment') }}</h3>
|
||||
<p class="mt-2 text-sm text-dusk">{{ departmentDeleteDialog.name }}</p>
|
||||
</div>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="resetDepartmentDeleteDialog" 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 grid grid-cols-2 gap-3">
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('admin.userCount') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ departmentDeleteDialog.user_count }}</p>
|
||||
</div>
|
||||
<div class="rounded-2xl border border-slate-200 bg-mist/40 px-3 py-3">
|
||||
<p class="text-xs text-dusk">{{ t('admin.groups') }}</p>
|
||||
<p class="mt-2 text-xl font-semibold text-ink">{{ departmentDeleteDialog.knowledge_base_count }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="departmentDeleteNeedsMigration" class="mt-5 rounded-3xl border border-amber-200 bg-amber-50 px-4 py-4">
|
||||
<p class="text-sm font-semibold text-amber-900">{{ t('admin.deleteDepartmentNeedsMigration') }}</p>
|
||||
<p class="mt-2 text-sm text-amber-800">{{ t('admin.deleteDepartmentNeedsMigrationHint') }}</p>
|
||||
<select v-model="departmentDeleteDialog.target_department_id" class="input mt-4">
|
||||
<option :value="null">{{ t('admin.selectMigrationDepartment') }}</option>
|
||||
<option v-for="option in departmentDeleteOptions" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<p v-else class="mt-5 rounded-3xl border border-slate-200 bg-mist/40 px-4 py-4 text-sm text-dusk">
|
||||
{{ t('admin.deleteDepartmentEmptyHint') }}
|
||||
</p>
|
||||
|
||||
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
||||
<button class="btn-ghost" @click="resetDepartmentDeleteDialog">{{ t('common.cancel') }}</button>
|
||||
<button
|
||||
class="btn-primary"
|
||||
:disabled="departmentDeleteNeedsMigration && !departmentDeleteDialog.target_department_id"
|
||||
@click="deleteDepartment"
|
||||
>
|
||||
{{ t('admin.deleteDepartment') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="userDialog.open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="resetUserDialog"
|
||||
>
|
||||
<div class="panel w-full max-w-3xl px-6 py-6" @click.stop>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold text-ink">
|
||||
{{ userDialog.mode === 'create' ? t('admin.createUser') : t('admin.editUser') }}
|
||||
</h3>
|
||||
</div>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="resetUserDialog" 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 grid gap-4 md:grid-cols-2">
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.username') }}</span>
|
||||
<input v-model="editableUser.username" class="input" :disabled="userDialog.mode === 'edit'" />
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.fullName') }}</span>
|
||||
<input v-model="editableUser.full_name" class="input" />
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.password') }}</span>
|
||||
<input v-model="editableUser.password" class="input" type="password" :placeholder="userDialog.mode === 'edit' ? t('admin.passwordOptional') : t('admin.password')" />
|
||||
</label>
|
||||
<label class="space-y-2">
|
||||
<span class="text-sm font-medium text-dusk">{{ t('admin.role') }}</span>
|
||||
<select v-model="editableUser.role" class="input" :disabled="editableUser.username === 'admin'">
|
||||
<option v-if="editableUser.username === 'admin'" value="super_admin">{{ t('roles.super_admin') }}</option>
|
||||
<option v-for="option in roleOptions" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="mt-5 rounded-3xl border border-slate-200 bg-mist/40 px-4 py-4">
|
||||
<p class="text-sm font-semibold text-ink">{{ t('admin.departmentPermissions') }}</p>
|
||||
<p class="mt-2 text-sm text-dusk">{{ t('admin.departmentAccessHint') }}</p>
|
||||
<div v-if="hasDepartments" class="mt-4 grid gap-2 md:grid-cols-2">
|
||||
<label
|
||||
v-for="department in departments"
|
||||
:key="department.id"
|
||||
class="flex items-center gap-3 rounded-2xl border border-slate-200 bg-white px-3 py-3 text-sm text-ink"
|
||||
>
|
||||
<input
|
||||
class="h-4 w-4 accent-surge"
|
||||
type="checkbox"
|
||||
:checked="userDepartmentIds.includes(department.id)"
|
||||
@change="toggleUserDepartment(department.id, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span class="truncate">{{ department.name }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<input
|
||||
v-else
|
||||
class="input mt-4"
|
||||
:value="t('admin.noDepartmentPlaceholder')"
|
||||
disabled
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex flex-wrap justify-end gap-3">
|
||||
<button class="btn-ghost" @click="resetUserDialog">{{ t('common.cancel') }}</button>
|
||||
<button class="btn-primary" @click="saveUser">{{ t('common.save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="userDeleteDialog.open"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center bg-slate-950/35 px-4 py-8 backdrop-blur-sm"
|
||||
@click="resetUserDeleteDialog"
|
||||
>
|
||||
<div class="panel w-full max-w-lg px-6 py-6" @click.stop>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-2xl font-bold text-ink">{{ t('admin.deleteUser') }}</h3>
|
||||
<p class="mt-2 text-sm text-dusk">{{ t('admin.deleteUserPrompt', { username: userDeleteDialog.username }) }}</p>
|
||||
</div>
|
||||
<button class="btn-ghost flex h-12 w-12 items-center justify-center rounded-2xl px-0" @click="resetUserDeleteDialog" 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-6 flex flex-wrap justify-end gap-3">
|
||||
<button class="btn-ghost" @click="resetUserDeleteDialog">{{ t('common.cancel') }}</button>
|
||||
<button class="btn-primary" @click="deleteUser">{{ t('workspace.delete') }}</button>
|
||||
</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>
|
||||
@@ -0,0 +1,100 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import LocaleSwitcher from '@/components/LocaleSwitcher.vue'
|
||||
import { setSession } from '@/lib/auth'
|
||||
import { apiFetch } from '@/lib/api'
|
||||
import { useI18n } from '@/lib/i18n'
|
||||
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const username = ref('admin')
|
||||
const password = ref('admin123456')
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
const cards = computed(() => [
|
||||
{
|
||||
title: t('login.cards.batchUploadTitle'),
|
||||
body: t('login.cards.batchUploadBody')
|
||||
},
|
||||
{
|
||||
title: t('login.cards.queuedConversionTitle'),
|
||||
body: t('login.cards.queuedConversionBody')
|
||||
},
|
||||
{
|
||||
title: t('login.cards.difyMappingTitle'),
|
||||
body: t('login.cards.difyMappingBody')
|
||||
}
|
||||
])
|
||||
|
||||
async function submit() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await apiFetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ username: username.value, password: password.value }),
|
||||
skipAuth: true
|
||||
})
|
||||
setSession(data.access_token, data.user)
|
||||
router.push('/workspace')
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : t('login.loginFailed')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="min-h-screen px-6 py-10 md:px-10">
|
||||
<div class="mx-auto max-w-6xl">
|
||||
<div class="mb-6 flex justify-end">
|
||||
<LocaleSwitcher />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mx-auto grid min-h-[calc(100vh-8rem)] max-w-6xl gap-8 lg:grid-cols-[1.15fr_0.85fr]">
|
||||
<section class="panel relative overflow-hidden px-8 py-10 md:px-12">
|
||||
<div class="absolute inset-x-0 top-0 h-1.5 bg-gradient-to-r from-surge via-cyan-400 to-mint"></div>
|
||||
<p class="text-sm font-semibold uppercase tracking-[0.32em] text-surge">{{ t('login.productName') }}</p>
|
||||
<h1 class="mt-6 max-w-xl text-4xl font-bold leading-tight text-ink md:text-6xl">
|
||||
{{ t('login.heading') }}
|
||||
</h1>
|
||||
<p class="mt-6 max-w-2xl text-base leading-8 text-dusk md:text-lg">
|
||||
{{ t('login.description') }}
|
||||
</p>
|
||||
<div class="mt-10 grid gap-4 md:grid-cols-3">
|
||||
<div v-for="card in cards" :key="card.title" class="rounded-3xl border border-slate-200 bg-mist/80 p-5">
|
||||
<p class="text-sm font-semibold text-ink">{{ card.title }}</p>
|
||||
<p class="mt-2 text-sm leading-6 text-dusk">{{ card.body }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel flex items-center px-8 py-10 md:px-10">
|
||||
<form class="w-full space-y-5" @submit.prevent="submit">
|
||||
<div>
|
||||
<p class="text-sm font-semibold uppercase tracking-[0.24em] text-dusk">{{ t('login.signInLabel') }}</p>
|
||||
<h2 class="mt-3 text-3xl font-bold text-ink">{{ t('login.enterWorkspace') }}</h2>
|
||||
</div>
|
||||
<label class="block space-y-2">
|
||||
<span class="text-sm text-dusk">{{ t('login.username') }}</span>
|
||||
<input v-model="username" class="input" placeholder="admin" />
|
||||
</label>
|
||||
<label class="block space-y-2">
|
||||
<span class="text-sm text-dusk">{{ t('login.password') }}</span>
|
||||
<input v-model="password" class="input" type="password" :placeholder="t('login.passwordPlaceholder')" />
|
||||
</label>
|
||||
<p v-if="error" class="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700">
|
||||
{{ error }}
|
||||
</p>
|
||||
<button class="btn-primary w-full py-3 text-base" :disabled="loading">
|
||||
{{ loading ? t('login.signingIn') : t('login.signInContinue') }}
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
File diff suppressed because it is too large.
Load diff
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
ink: '#122033',
|
||||
mist: '#f3f7fb',
|
||||
surge: '#1573ff',
|
||||
mint: '#1fc39a',
|
||||
ember: '#ff7147',
|
||||
dusk: '#5c6b82'
|
||||
},
|
||||
boxShadow: {
|
||||
soft: '0 16px 40px rgba(18, 32, 51, 0.08)'
|
||||
},
|
||||
borderRadius: {
|
||||
panel: '1.5rem'
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "@vue/tsconfig/tsconfig.dom.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"types": ["vite/client"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"composite": true,
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("vite").UserConfig;
|
||||
export default _default;
|
||||
@@ -0,0 +1,24 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import path from 'node:path';
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src')
|
||||
}
|
||||
},
|
||||
server: {
|
||||
port: 5174,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/storage': {
|
||||
target: 'http://127.0.0.1:8000',
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import path from 'node:path'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src')
|
||||
}
|
||||
},
|
||||
server: {
|
||||
port: 5174,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/storage': {
|
||||
target: 'http://127.0.0.1:8000',
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user