refactor(frontend): 前端重构 V3
This commit is contained in:
1 parent
8d8b40812d
commit
ec97ea8787
80 files changed
+6887
-3733
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,534 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/schedules/components/ScheduleCreateEditModal.vue
|
||||
* 定时任务创建/编辑弹窗。
|
||||
*/
|
||||
import { ChevronDown, ChevronUp, Plus } from 'lucide-vue-next';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="admin.showScheduleCreateModal" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-3xl">
|
||||
<div class="flex items-center justify-between border-b border-subtle px-8 py-6">
|
||||
<h3 class="text-2xl font-bold tracking-tight text-primary">{{ admin.scheduleEditingId ? $t('admin.schedule.form.editTitle') : $t('admin.schedule.form.createTitle') }}</h3>
|
||||
<button
|
||||
class="rounded-full p-2 text-muted transition hover-surface-soft hover:text-secondary"
|
||||
@click="admin.showScheduleCreateModal = false"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div class="max-h-[72vh] space-y-5 overflow-y-auto px-8 py-6">
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.name') }}</label>
|
||||
<input v-model="admin.scheduleCreateForm.name" class="input-field !text-sm !leading-5" :placeholder="$t('admin.schedule.form.namePlaceholder')" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.owner') }}</label>
|
||||
<div class="relative">
|
||||
<input
|
||||
v-model="admin.scheduleOwnerQuery"
|
||||
type="text"
|
||||
class="input-field !text-sm !leading-5"
|
||||
:placeholder="admin.users.length === 0 ? $t('admin.schedule.form.noUsers') : $t('admin.schedule.form.selectOwner')"
|
||||
:disabled="admin.users.length === 0"
|
||||
@focus="admin.scheduleOwnerDropdownOpen = true"
|
||||
@input="admin.handleScheduleOwnerInput"
|
||||
@blur="admin.scheduleCloseOwnerDropdown"
|
||||
/>
|
||||
<div
|
||||
v-if="admin.scheduleOwnerDropdownOpen && admin.users.length > 0"
|
||||
class="admin-dropdown max-h-60 w-full overflow-y-auto"
|
||||
>
|
||||
<button
|
||||
v-for="u in admin.filteredOwnerUsers"
|
||||
:key="u.id"
|
||||
type="button"
|
||||
class="flex w-full items-center gap-3 px-3 py-2 text-left text-sm transition hover:bg-surface-soft"
|
||||
:class="admin.scheduleCreateForm.owner_user_id === u.id ? 'bg-blue-50/50' : ''"
|
||||
@mousedown.prevent="admin.selectScheduleOwner(u.id)"
|
||||
>
|
||||
<span class="text-secondary">{{ u.real_name || u.username }}{{ u.employee_id ? '(' + u.employee_id + ')' : '' }}</span>
|
||||
</button>
|
||||
<div v-if="admin.filteredOwnerUsers.length === 0" class="px-3 py-2 text-sm text-muted">
|
||||
{{ $t('admin.wecom.noData') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- SQL Config Panel -->
|
||||
<div class="rounded-2xl border border-default bg-surface-soft/40 p-4">
|
||||
<div class="mb-3 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<h4 class="text-base font-bold text-primary shrink-0">{{ $t('admin.schedule.form.dataSourceConfig') }}</h4>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<div
|
||||
class="segment-control segment-control--fit segment-control--sm shrink-0"
|
||||
role="radiogroup"
|
||||
:aria-label="$t('admin.schedule.form.dataSourceConfig')"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCreateForm.data_source_type === 'database'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCreateForm.data_source_type === 'database' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCreateForm.data_source_type = 'database'"
|
||||
>{{ $t('admin.schedule.form.databaseDirect') }}</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCreateForm.data_source_type === 'external_api'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCreateForm.data_source_type === 'external_api' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCreateForm.data_source_type = 'external_api'"
|
||||
>{{ $t('admin.schedule.form.externalApi') }}</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary btn-sm inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="admin.scheduleTestLoading || !admin.scheduleEditingId"
|
||||
@click="admin.handleTestScheduleSql"
|
||||
>
|
||||
{{ admin.scheduleTestLoading ? $t('admin.schedule.form.querying') : $t('admin.schedule.form.testQuery') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary btn-sm inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap"
|
||||
@click="admin.scheduleConfigCollapsed = !admin.scheduleConfigCollapsed"
|
||||
>
|
||||
<ChevronDown v-if="admin.scheduleConfigCollapsed" class="h-3.5 w-3.5 shrink-0" />
|
||||
<ChevronUp v-else class="h-3.5 w-3.5 shrink-0" />
|
||||
{{ admin.scheduleConfigCollapsed ? $t('admin.schedule.form.expandConfig') : $t('admin.schedule.form.collapseConfig') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="!admin.scheduleConfigCollapsed" class="space-y-3">
|
||||
<!-- 数据库直联模式 -->
|
||||
<template v-if="admin.scheduleCreateForm.data_source_type === 'database'">
|
||||
<!-- 数据源配置 -->
|
||||
<details class="rounded-xl border border-default bg-surface" open>
|
||||
<summary class="cursor-pointer px-4 py-2.5 text-sm font-semibold text-secondary hover:bg-surface-soft rounded-xl">{{ $t('admin.schedule.form.dataSourceSection') }}</summary>
|
||||
<div class="space-y-3 px-4 pb-4 pt-2">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsDbType') }}</label>
|
||||
<select v-model="admin.scheduleSqlEditForm.ds_db_type" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200">
|
||||
<option value="sqlserver">SQL Server</option>
|
||||
<option value="postgresql">PostgreSQL</option>
|
||||
<option value="mysql">MySQL</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsHost') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_host" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" :placeholder="$t('admin.schedule.form.dsHostPlaceholder')" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-4 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsPort') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_port" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" placeholder="1433" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsDatabase') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_database" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" :placeholder="$t('admin.schedule.form.dsDatabasePlaceholder')" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsUsername') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_username" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" placeholder="sa" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsPassword') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_password" type="password" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" :placeholder="$t('admin.schedule.form.dsPasswordPlaceholder')" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="admin.scheduleSqlEditForm.ds_db_type === 'sqlserver'" class="grid grid-cols-3 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsDriver') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.ds_driver" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" placeholder="SQL Server" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsEncrypt') }}</label>
|
||||
<select v-model="admin.scheduleSqlEditForm.ds_encrypt" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200">
|
||||
<option value="">{{ $t('admin.schedule.form.defaultNo') }}</option>
|
||||
<option value="yes">yes</option>
|
||||
<option value="no">no</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.dsTrustCert') }}</label>
|
||||
<select v-model="admin.scheduleSqlEditForm.ds_trust_cert" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200">
|
||||
<option value="">{{ $t('admin.schedule.form.defaultYes') }}</option>
|
||||
<option value="yes">yes</option>
|
||||
<option value="no">no</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs text-muted">{{ $t('admin.schedule.form.envVarHint', { token: $t('admin.schedule.form.envVarToken') }) }}</p>
|
||||
</div>
|
||||
</details>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.baseFetchSql') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.base_fetch_sql"
|
||||
class="w-full min-h-[160px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.fetchWhereConditions') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.fetch_where_conditions"
|
||||
class="w-full min-h-[80px] rounded-xl border border-amber-200 bg-amber-50/30 p-3 text-xs leading-relaxed text-secondary font-mono focus:border-amber-300 focus:outline-none focus:ring-1 focus:ring-amber-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.fetchOrderBy') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.fetch_order_by" class="w-full input-field px-3 py-2 text-xs font-mono text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.detailSql') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.detail_sql"
|
||||
class="w-full min-h-[120px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.writebackSql') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.writeback_sql"
|
||||
class="w-full min-h-[48px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.rowIdKey') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.row_id_key" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.logPrefix') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.log_prefix" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden">
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.aliasOrder') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.alias_order_str" class="w-full input-field px-3 py-2 text-xs font-mono text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.detailAliasOrder') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.detail_alias_order_str" class="w-full input-field px-3 py-2 text-xs font-mono text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.headerLabels') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.header_labels_str"
|
||||
class="w-full min-h-[100px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 外部API模式 -->
|
||||
<template v-if="admin.scheduleCreateForm.data_source_type === 'external_api'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.apiUrl') }}</label>
|
||||
<input v-model="admin.scheduleSqlEditForm.api_url" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" placeholder="https://api.example.com/endpoint" />
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.apiMethod') }}</label>
|
||||
<select v-model="admin.scheduleSqlEditForm.api_method" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200">
|
||||
<option value="POST">POST</option>
|
||||
<option value="GET">GET</option>
|
||||
<option value="PUT">PUT</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.apiTimeoutSeconds') }}</label>
|
||||
<input type="number" :value="120" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" disabled />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.apiHeaders') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.api_headers_str"
|
||||
class="w-full min-h-[60px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.apiBodyTemplate') }}</label>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.api_body_template"
|
||||
class="w-full min-h-[80px] input-field p-3 text-xs leading-relaxed text-secondary font-mono focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200 resize-y"
|
||||
></textarea>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-if="admin.scheduleTestResult" class="mt-4 rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4">
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h4 class="text-sm font-bold text-emerald-900">{{ $t('admin.schedule.testRun.queryResult') }}</h4>
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-xs text-emerald-600">{{ $t('admin.schedule.testRun.resultSummary', { total: admin.scheduleTestResult.total, showing: admin.scheduleTestResult.showing }) }}</span>
|
||||
<button class="rounded-full p-1 text-emerald-400 transition hover:bg-emerald-100 hover:text-emerald-600" @click="admin.scheduleTestResult = null">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-2 overflow-x-auto rounded-xl border border-emerald-200 bg-surface">
|
||||
<table class="w-full text-xs">
|
||||
<thead class="bg-emerald-50">
|
||||
<tr>
|
||||
<th v-for="col in admin.scheduleTestResult.columns" :key="col" class="whitespace-nowrap px-3 py-2 text-left font-semibold text-emerald-800">{{ col }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, ri) in admin.scheduleTestResult.rows" :key="ri" class="border-t border-emerald-100">
|
||||
<td v-for="col in admin.scheduleTestResult.columns" :key="col" class="whitespace-nowrap px-3 py-1.5 text-secondary">{{ row[col] }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<details class="mt-2">
|
||||
<summary class="cursor-pointer text-xs font-semibold text-emerald-700 hover:text-emerald-900">{{ $t('admin.schedule.testRun.viewGeneratedSql') }}</summary>
|
||||
<pre class="admin-pre-block admin-pre-block--sql">{{ admin.scheduleTestResult.sql }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.agentLabel') }}</label>
|
||||
<div class="relative">
|
||||
<select v-model="admin.scheduleCreateForm.dify_agent_id" class="input-field appearance-none pr-10 !text-sm !leading-5" :disabled="admin.agents.length === 0">
|
||||
<option :value="null">{{ admin.agents.length === 0 ? $t('admin.schedule.form.noAgents') : $t('admin.schedule.form.agentDisabled') }}</option>
|
||||
<option v-for="a in admin.agents" :key="a.id" :value="a.id">{{ a.name }}{{ $t('admin.schedule.form.agentOptionId', { id: a.dify_app_id?.slice(0, 8) || a.id }) }}</option>
|
||||
</select>
|
||||
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
|
||||
<svg class="h-4 w-4 text-muted" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z" clip-rule="evenodd"/></svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.waitSeconds') }}</label>
|
||||
<input v-model.number="admin.scheduleCreateForm.wait_seconds" type="number" min="0" class="input-field !text-sm !leading-5" placeholder="300" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-emerald-200 bg-emerald-50/40 p-4">
|
||||
<label class="flex items-center gap-2 text-sm font-semibold text-secondary">
|
||||
<input v-model="admin.scheduleCreateForm.kb_sync_enabled" type="checkbox" class="h-4 w-4 rounded border-default text-emerald-600 focus:ring-emerald-300" />
|
||||
{{ $t('admin.schedule.form.kbSyncEnabled') }}
|
||||
</label>
|
||||
<p class="mt-1 text-xs text-muted">{{ $t('admin.schedule.form.kbSyncHint') }}</p>
|
||||
<div v-if="admin.scheduleCreateForm.kb_sync_enabled" class="mt-3">
|
||||
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.kbGroup') }}</label>
|
||||
<select v-model="admin.scheduleCreateForm.kb_group_id" class="input-field !text-sm !leading-5" :disabled="admin.kbGroups.length === 0">
|
||||
<option :value="null">{{ admin.kbGroups.length === 0 ? $t('admin.schedule.form.noKbGroups') : $t('admin.schedule.form.selectKbGroup') }}</option>
|
||||
<option v-for="group in admin.kbGroups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="admin.scheduleCreateForm.dify_agent_id" class="rounded-2xl border border-indigo-200 bg-indigo-50/40 p-4">
|
||||
<div class="mb-2">
|
||||
<label class="block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.difySystemPrompt') }}</label>
|
||||
<p class="mt-1 text-xs text-muted">{{ $t('admin.schedule.form.difySystemPromptHint') }}</p>
|
||||
</div>
|
||||
<textarea
|
||||
v-model="admin.scheduleSqlEditForm.dify_system_prompt"
|
||||
class="input-field min-h-[140px] p-3 text-sm font-mono resize-y border-indigo-200"
|
||||
:placeholder="$t('admin.schedule.form.difySystemPromptPlaceholder')"
|
||||
></textarea>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-default bg-surface-soft/40 p-4">
|
||||
<div class="mb-3">
|
||||
<h4 class="text-base font-bold text-primary">{{ $t('admin.schedule.form.cronTitle') }}</h4>
|
||||
<p class="text-sm text-muted">{{ $t('admin.schedule.form.cronHint') }}</p>
|
||||
</div>
|
||||
<div
|
||||
class="segment-control segment-control--cols-4 segment-control--sm"
|
||||
role="radiogroup"
|
||||
:aria-label="$t('admin.schedule.form.cronTitle')"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'every_minutes'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'every_minutes' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'every_minutes'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.everyMinutes') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'hourly'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'hourly' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'hourly'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.hourly') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'daily'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'daily' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'daily'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.daily') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
:aria-checked="admin.scheduleCronDesigner.mode === 'weekly'"
|
||||
class="segment-item"
|
||||
:class="admin.scheduleCronDesigner.mode === 'weekly' ? 'segment-item--active' : ''"
|
||||
@click="admin.scheduleCronDesigner.mode = 'weekly'"
|
||||
>
|
||||
{{ $t('admin.schedule.form.weekly') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-1 gap-3 md:grid-cols-3">
|
||||
<template v-if="admin.scheduleCronDesigner.mode === 'every_minutes'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minuteInterval') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.every_minutes" type="number" min="1" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="admin.scheduleCronDesigner.mode === 'hourly'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minuteOfHour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.hourly_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="admin.scheduleCronDesigner.mode === 'daily'">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.hour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.daily_hour" type="number" min="0" max="23" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minute') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.daily_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.weekday') }}</label>
|
||||
<select v-model.number="admin.scheduleCronDesigner.weekly_day" class="input-field !text-sm !leading-5">
|
||||
<option v-for="d in admin.weeklyDayOptions" :key="d.value" :value="d.value">{{ d.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.hour') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.weekly_hour" type="number" min="0" max="23" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.minute') }}</label>
|
||||
<input v-model.number="admin.scheduleCronDesigner.weekly_minute" type="number" min="0" max="59" class="input-field !text-sm !leading-5" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<div class="mt-4 rounded-xl border border-dashed border-default bg-surface-soft px-4 py-3 text-xs text-secondary">
|
||||
{{ $t('admin.schedule.form.cronPreview') }}:<span class="font-mono text-primary">{{ admin.scheduleCronPreview }}</span>
|
||||
<span v-if="admin.scheduleNextRunPreview" class="ml-4">{{ $t('admin.schedule.form.nextRun') }}:<span class="font-medium text-primary">{{ admin.formatDateTime(admin.scheduleNextRunPreview.toISOString()) }}</span></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-field px-3 py-2.5">
|
||||
<div class="flex flex-col gap-2 md:flex-row md:items-center">
|
||||
<label class="inline-flex shrink-0 items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="admin.scheduleCreateForm.notify_enabled" type="checkbox" class="h-4 w-4 rounded text-blue-600" />
|
||||
{{ $t('admin.schedule.form.notifyEnabled') }}
|
||||
</label>
|
||||
<div v-if="admin.scheduleCreateForm.notify_enabled" class="relative flex-1">
|
||||
<div
|
||||
class="min-h-[38px] input-field px-3 py-2 text-sm flex flex-wrap gap-1.5 items-center focus-within:border-blue-300 focus-within:ring-1 focus-within:ring-blue-200"
|
||||
>
|
||||
<span
|
||||
v-for="uid in admin.scheduleCreateForm.notify_user_ids_json"
|
||||
:key="uid"
|
||||
class="inline-flex items-center gap-1 rounded-lg bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700"
|
||||
>
|
||||
{{ admin.getUserName(uid) }}
|
||||
<button
|
||||
type="button"
|
||||
class="ml-0.5 text-blue-400 hover:text-blue-600"
|
||||
@click.stop="admin.removeNotifyUser(uid)"
|
||||
>✕</button>
|
||||
</span>
|
||||
<input
|
||||
v-model="admin.scheduleNotifyUserQuery"
|
||||
type="text"
|
||||
class="min-w-[120px] flex-1 border-0 bg-transparent p-0 text-sm text-secondary outline-none focus:ring-0"
|
||||
:placeholder="$t('admin.schedule.form.selectNotifyUsers')"
|
||||
@focus="admin.scheduleNotifyDropdownOpen = true"
|
||||
@input="admin.scheduleNotifyDropdownOpen = true"
|
||||
@blur="admin.scheduleCloseNotifyDropdown"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="admin.scheduleNotifyDropdownOpen"
|
||||
class="admin-dropdown max-h-60 w-full overflow-y-auto"
|
||||
>
|
||||
<button
|
||||
v-for="u in admin.filteredNotifyUsers"
|
||||
:key="u.id"
|
||||
type="button"
|
||||
class="flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left text-sm transition hover:bg-surface-soft"
|
||||
:class="admin.scheduleCreateForm.notify_user_ids_json.includes(u.id) ? 'bg-blue-50/50' : ''"
|
||||
@mousedown.prevent="admin.toggleNotifyUser(u.id)"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="pointer-events-none h-3.5 w-3.5 rounded text-blue-600"
|
||||
:checked="admin.scheduleCreateForm.notify_user_ids_json.includes(u.id)"
|
||||
tabindex="-1"
|
||||
readonly
|
||||
/>
|
||||
<span class="text-secondary">{{ u.real_name || u.username }}{{ u.employee_id ? '(' + u.employee_id + ')' : '' }}</span>
|
||||
</button>
|
||||
<div v-if="admin.filteredNotifyUsers.length === 0" class="px-3 py-2 text-sm text-muted">
|
||||
{{ $t('admin.wecom.noData') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border border-default bg-surface-soft/40 px-4 py-3">
|
||||
<label class="inline-flex cursor-pointer items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="admin.scheduleCreateForm.enabled" type="checkbox" class="admin-checkbox" />
|
||||
{{ $t('admin.schedule.form.enableOnCreate') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-modal-footer admin-modal-footer--muted justify-end gap-3 px-8 py-5">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary"
|
||||
@click="admin.showScheduleCreateModal = false"
|
||||
>
|
||||
{{ $t('admin.schedule.form.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary inline-flex items-center gap-2 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="admin.scheduleCreateSaving || !admin.scheduleCreateForm.name || !admin.scheduleCreateForm.owner_user_id"
|
||||
@click="admin.createSchedule"
|
||||
>
|
||||
<Plus class="h-4 w-4 shrink-0" />
|
||||
{{ admin.scheduleCreateSaving ? $t('admin.schedule.form.saving') : (admin.scheduleEditingId ? $t('admin.schedule.form.saveChanges') : $t('admin.schedule.form.createSchedule')) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/components/ScheduleOverviewPanel.vue
|
||||
* 定时任务概览模式:统计卡片与任务卡片网格。
|
||||
* 依赖:schedules.context、lucide-vue-next。
|
||||
* 逻辑:inject admin;展示 schedules 列表与快捷操作。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { Edit3, FlaskConical, Plus, Power, PowerOff, Rocket, Settings2, Trash2 } from 'lucide-vue-next';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="admin-panel-lg p-6 shadow-sm">
|
||||
<div class="mb-5 grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="admin-stat-tile px-4 py-3">
|
||||
<div class="text-xl font-bold text-primary">{{ admin.schedules.length }}</div>
|
||||
<div class="text-sm text-muted">{{ $t('admin.schedule.stats.total') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3">
|
||||
<div class="text-xl font-bold text-primary">{{ admin.scheduleEnabledCount }}</div>
|
||||
<div class="text-sm text-muted">{{ $t('admin.schedule.stats.enabled') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3">
|
||||
<div class="text-xl font-bold text-primary">{{ admin.scheduleDisabledCount }}</div>
|
||||
<div class="text-sm text-muted">{{ $t('admin.schedule.stats.disabled') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3">
|
||||
<div class="text-xl font-bold text-primary">{{ admin.scheduleRunningCount }}</div>
|
||||
<div class="text-sm text-muted">{{ $t('admin.schedule.stats.running') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-panel p-4">
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h4 class="text-lg font-bold text-primary">{{ $t('admin.schedule.sectionOverview') }}</h4>
|
||||
<span class="text-xs text-muted">{{ $t('admin.schedule.switchByCard') }}</span>
|
||||
</div>
|
||||
<div v-if="admin.scheduleLoading" class="py-8 text-center text-sm text-muted">{{ $t('admin.schedule.loading') }}</div>
|
||||
<div v-else class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3 auto-rows-fr">
|
||||
<div class="admin-panel p-4 transition-colors hover:border-brand-300 h-full min-h-[260px] flex flex-col">
|
||||
<div class="mb-3 flex items-center gap-2">
|
||||
<div class="flex h-8 w-8 items-center justify-center rounded-xl bg-brand-50 text-brand-600">
|
||||
<Settings2 class="h-4 w-4" />
|
||||
</div>
|
||||
<div class="font-semibold text-primary">{{ $t('admin.schedule.addTitle') }}</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ $t('admin.schedule.addHint') }}
|
||||
</div>
|
||||
<div class="mt-auto pt-3">
|
||||
<button
|
||||
@click="admin.openScheduleCreateModal"
|
||||
class="inline-flex w-full items-center justify-center gap-2 rounded-xl bg-brand-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ $t('admin.schedule.addButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="s in admin.schedules"
|
||||
:key="s.id"
|
||||
class="flex h-full min-h-[260px] flex-col admin-panel p-4 transition hover:border-blue-200 hover:bg-surface-soft"
|
||||
>
|
||||
<button class="w-full text-left" @click="admin.openScheduleRunSubmenu(s.id)">
|
||||
<div class="min-h-[96px]">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="truncate text-base font-semibold text-primary">{{ s.name }}</div>
|
||||
<span class="inline-flex shrink-0 items-center whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="s.enabled ? 'bg-emerald-100 text-emerald-700' : 'bg-surface-strong text-secondary'">
|
||||
{{ s.enabled ? $t('admin.schedule.enabled') : $t('admin.schedule.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-muted">{{ $t('admin.schedule.scheduleNo') }}:{{ s.schedule_no }}</div>
|
||||
<div class="mt-1 text-sm text-muted">Cron:{{ s.cron_expr }}</div>
|
||||
<div
|
||||
v-if="s.schedule_type === 'platform_app' && s.platform_api_path"
|
||||
class="mt-1 text-sm text-muted"
|
||||
>
|
||||
{{ $t('admin.schedule.config') }}:{{ s.platform_api_path }}
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-muted">{{ $t('admin.schedule.owner') }}:{{ s.owner_username || s.owner_user_id }}</div>
|
||||
</div>
|
||||
</button>
|
||||
<div class="mt-auto pt-3">
|
||||
<div class="mb-1 text-sm text-muted">
|
||||
{{ $t('admin.schedule.lastRun') }}:{{ admin.formatDateTime(s.last_run_at) }}
|
||||
</div>
|
||||
<div class="mb-3 text-sm text-muted">
|
||||
{{ $t('admin.schedule.nextRun') }}:{{ admin.formatDateTime(s.next_run_at) }}
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-2 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click.stop="admin.openScheduleEditModal(s)"
|
||||
>
|
||||
<Edit3 class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.edit') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!s.enabled"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-emerald-200 px-3 py-2 text-xs font-medium text-emerald-700 transition-colors hover:bg-emerald-50"
|
||||
@click.stop="admin.setScheduleEnabled(s.id, true)"
|
||||
>
|
||||
<Power class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.start') }}
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-amber-200 px-3 py-2 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-50"
|
||||
@click.stop="admin.setScheduleEnabled(s.id, false)"
|
||||
>
|
||||
<PowerOff class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.pause') }}
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-blue-200 px-3 py-2 text-xs font-medium text-blue-700 transition-colors hover:bg-blue-50"
|
||||
@click.stop="admin.runScheduleNow(s.id)"
|
||||
>
|
||||
<Rocket class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.run') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="s.platform_api_path && s.data_source_type !== 'external_api'"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-violet-200 px-3 py-2 text-xs font-medium text-violet-700 transition-colors hover:bg-violet-50"
|
||||
@click.stop="admin.openTestRunDialog(s)"
|
||||
>
|
||||
<FlaskConical class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.test') }}
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50"
|
||||
@click.stop="admin.deleteSchedule(s)"
|
||||
>
|
||||
<Trash2 class="h-3.5 w-3.5" />
|
||||
{{ $t('admin.schedule.actions.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="admin.schedules.length === 0" class="rounded-xl border border-dashed border-default px-4 py-6 text-center text-sm text-muted">
|
||||
{{ $t('admin.schedule.emptyList') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/components/SchedulePageHeader.vue
|
||||
* 定时任务页顶栏:返回、标题、刷新。
|
||||
* 依赖:schedules.context、lucide-vue-next。
|
||||
* 逻辑:inject admin 上下文;概览/工作台模式切换标题与返回按钮。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { ArrowLeft, RefreshCw, Settings2 } from 'lucide-vue-next';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="admin-panel-lg px-7 py-6 shadow-sm">
|
||||
<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
||||
<div class="flex items-start gap-4">
|
||||
<button
|
||||
v-if="admin.scheduleViewMode === 'workbench'"
|
||||
class="inline-flex h-14 w-14 items-center justify-center admin-panel text-muted transition hover:bg-surface-soft hover:text-secondary"
|
||||
@click="admin.backToScheduleOverview"
|
||||
>
|
||||
<ArrowLeft class="h-7 w-7" />
|
||||
</button>
|
||||
<div class="flex h-14 w-14 items-center justify-center rounded-2xl bg-blue-50 text-blue-600">
|
||||
<Settings2 class="h-7 w-7" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold tracking-tight text-primary">
|
||||
{{ admin.scheduleViewMode === 'overview' ? $t('admin.schedule.overviewTitle') : $t('admin.schedule.workbenchTitle') }}
|
||||
</h2>
|
||||
<p class="mt-1.5 text-sm text-muted">
|
||||
{{ admin.scheduleViewMode === 'overview' ? $t('admin.schedule.overviewSubtitle') : $t('admin.schedule.workbenchSubtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="inline-flex items-center gap-2 admin-panel px-5 py-2.5 text-sm font-semibold text-secondary transition hover:bg-surface-soft"
|
||||
@click="admin.loadSchedules"
|
||||
>
|
||||
<RefreshCw class="h-5 w-5" />
|
||||
{{ $t('admin.schedule.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,183 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/schedules/components/ScheduleTestRunDialog.vue
|
||||
* 定时任务试运行弹窗。
|
||||
*/
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="admin.showTestRunDialog" class="admin-modal-overlay items-center">
|
||||
<div class="admin-modal-panel max-w-4xl max-h-[90vh] overflow-y-auto">
|
||||
<div class="admin-modal-header sticky top-0 z-10 px-6 py-4 rounded-t-3xl">
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-primary">{{ $t('admin.schedule.testRun.title', { name: admin.testRunSchedule?.name }) }}</h3>
|
||||
<p class="text-xs text-muted mt-0.5">{{ $t('admin.schedule.testRun.subtitle') }}</p>
|
||||
</div>
|
||||
<button @click="admin.showTestRunDialog = false" class="rounded-xl border border-default px-3 py-1.5 text-sm text-muted hover:bg-surface-soft">{{ $t('admin.schedule.testRun.close') }}</button>
|
||||
</div>
|
||||
<div class="p-6 space-y-4">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.testRun.baseFetchSqlReadonly') }}</label>
|
||||
<textarea
|
||||
:value="admin.testRunBaseFetchSql"
|
||||
readonly
|
||||
class="w-full min-h-[120px] rounded-xl border border-default bg-surface-soft p-3 text-xs leading-relaxed text-muted font-mono resize-y cursor-default"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.fetchWhereConditions') }}</label>
|
||||
<textarea
|
||||
v-model="admin.testRunWhere"
|
||||
class="w-full min-h-[80px] rounded-xl border border-amber-200 bg-amber-50/30 p-3 text-xs leading-relaxed text-secondary font-mono focus:border-amber-300 focus:outline-none focus:ring-1 focus:ring-amber-200 resize-y"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.form.fetchOrderBy') }}</label>
|
||||
<input v-model="admin.testRunOrderBy" class="w-full input-field px-3 py-2 text-xs font-mono text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-semibold text-muted uppercase">{{ $t('admin.schedule.testRun.limitRows') }}</label>
|
||||
<input type="number" v-model.number="admin.testRunLimit" min="1" max="10" class="w-full input-field px-3 py-2 text-sm text-secondary focus:border-blue-300 focus:outline-none focus:ring-1 focus:ring-blue-200" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-xl border border-emerald-200 bg-emerald-50/40 px-4 py-3">
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input
|
||||
v-model="admin.testRunKbSync"
|
||||
type="checkbox"
|
||||
class="h-4 w-4 rounded border-default text-emerald-600 focus:ring-emerald-300"
|
||||
:disabled="!admin.testRunKbSyncAvailable"
|
||||
/>
|
||||
{{ $t('admin.schedule.testRun.writeToKb') }}
|
||||
</label>
|
||||
<p class="mt-1 text-xs text-muted">
|
||||
{{ admin.testRunKbSyncAvailable ? $t('admin.schedule.testRun.writeToKbHint') : $t('admin.schedule.testRun.noKbGroupHint') }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
class="inline-flex items-center gap-1.5 rounded-xl bg-violet-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-violet-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="admin.testRunLoading"
|
||||
@click="admin.handleTestRun"
|
||||
>
|
||||
{{ admin.testRunLoading ? $t('admin.schedule.testRun.running') : $t('admin.schedule.testRun.start') }}
|
||||
</button>
|
||||
<span v-if="admin.testRunLoading" class="text-xs text-muted">{{ $t('admin.schedule.testRun.waitingHint') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="admin.testRunResult" class="space-y-4 mt-2">
|
||||
<div class="flex items-center gap-4 rounded-xl border border-default bg-surface-soft/50 px-4 py-3">
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-primary">{{ admin.testRunResult.total_count }}</div>
|
||||
<div class="text-[10px] text-muted">{{ $t('admin.schedule.testRun.total') }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-emerald-600">{{ admin.testRunResult.success_count }}</div>
|
||||
<div class="text-[10px] text-muted">{{ $t('admin.schedule.testRun.success') }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-rose-600">{{ admin.testRunResult.failed_count }}</div>
|
||||
<div class="text-[10px] text-muted">{{ $t('admin.schedule.testRun.failed') }}</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold text-amber-600">{{ admin.testRunResult.skipped_count }}</div>
|
||||
<div class="text-[10px] text-muted">{{ $t('admin.schedule.testRun.skipped') }}</div>
|
||||
</div>
|
||||
<div class="ml-auto text-xs text-muted">
|
||||
{{ $t('admin.schedule.testRun.limitSummary', { limit: admin.testRunResult.limit, agentId: admin.testRunResult.dify_agent_id || $t('admin.schedule.testRun.noAgent') }) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="admin.testRunResult.dify_execution_snapshot"
|
||||
class="rounded-xl border border-indigo-200 bg-indigo-50/50 p-3"
|
||||
>
|
||||
<h4 class="mb-2 text-sm font-bold text-indigo-900">{{ $t('admin.schedule.difySnapshot.title') }}</h4>
|
||||
<div v-if="admin.testRunResult.dify_execution_snapshot.dify_enabled" class="space-y-2 text-xs text-secondary">
|
||||
<div>
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.difySnapshot.agent') }}:</span>
|
||||
{{ admin.testRunResult.dify_execution_snapshot.dify_agent_name || '-' }}
|
||||
{{ $t('admin.schedule.difySnapshot.agentId', { id: admin.testRunResult.dify_execution_snapshot.dify_agent_id ?? '-' }) }}
|
||||
</div>
|
||||
<div>
|
||||
<span class="mb-1 block font-semibold text-muted">{{ $t('admin.schedule.difySnapshot.systemPrompt') }}:</span>
|
||||
<pre
|
||||
v-if="admin.testRunResult.dify_execution_snapshot.dify_system_prompt"
|
||||
class="max-h-[200px] overflow-auto whitespace-pre-wrap rounded-lg border border-indigo-100 bg-surface p-3 font-mono text-[11px] text-primary"
|
||||
>{{ admin.testRunResult.dify_execution_snapshot.dify_system_prompt }}</pre>
|
||||
<span v-else class="text-muted">{{ $t('admin.schedule.difySnapshot.notConfigured') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="text-xs text-muted">{{ $t('admin.schedule.difySnapshot.notEnabledTest') }}</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h4 class="text-sm font-bold text-secondary mb-2">{{ $t('admin.schedule.testRun.stepLogs') }}</h4>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="(log, li) in admin.testRunResult.step_logs"
|
||||
:key="li"
|
||||
class="rounded-xl border p-3"
|
||||
:class="log.status === 'failed' ? 'border-rose-200 bg-rose-50/40' : 'border-default bg-surface'"
|
||||
>
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold"
|
||||
:class="(admin.stepStatusMap[log.status] || admin.stepStatusMap.success || { cls: 'bg-surface-soft text-secondary' }).cls"
|
||||
>
|
||||
{{ (admin.stepStatusMap[log.status] || { label: log.status }).label }}
|
||||
</span>
|
||||
<span class="text-xs font-semibold text-secondary">{{ admin.stepLabelMap[log.step] || log.step }}</span>
|
||||
<span v-if="log.row_id" class="text-[10px] text-muted">row_id={{ log.row_id }}</span>
|
||||
<span v-if="log.duration_ms != null" class="text-[10px] text-muted">{{ log.duration_ms }}ms</span>
|
||||
</div>
|
||||
<details v-if="log.detail" class="mt-1">
|
||||
<summary class="cursor-pointer text-[10px] font-semibold text-muted hover:text-secondary">{{ $t('admin.schedule.viewDetail') }}</summary>
|
||||
<pre class="admin-pre-block">{{ JSON.stringify(log.detail, null, 2) }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details>
|
||||
<summary class="cursor-pointer text-xs font-semibold text-muted hover:text-secondary">{{ $t('admin.schedule.testRun.viewSql') }}</summary>
|
||||
<pre class="admin-pre-block admin-pre-block--sql">{{ admin.testRunResult.sql }}</pre>
|
||||
</details>
|
||||
|
||||
<details v-if="admin.testRunResult.errors && admin.testRunResult.errors.length > 0">
|
||||
<summary class="cursor-pointer text-xs font-semibold text-rose-600 hover:text-rose-800">{{ $t('admin.schedule.testRun.errors', { count: admin.testRunResult.errors.length }) }}</summary>
|
||||
<pre class="mt-1 whitespace-pre-wrap rounded-lg bg-rose-50 p-3 text-xs text-rose-700 font-mono">{{ admin.testRunResult.errors.join('\n') }}</pre>
|
||||
</details>
|
||||
|
||||
<div
|
||||
v-if="admin.testRunKbSyncAttempted"
|
||||
class="rounded-xl border px-4 py-3 text-xs text-secondary"
|
||||
:class="admin.testRunResult.kb_sync_status === 'success' ? 'border-emerald-200 bg-emerald-50/40' : admin.testRunResult.kb_sync_status === 'failed' ? 'border-rose-200 bg-rose-50/40' : 'border-amber-200 bg-amber-50/40'"
|
||||
>
|
||||
<div class="font-bold" :class="admin.testRunResult.kb_sync_status === 'success' ? 'text-emerald-800' : admin.testRunResult.kb_sync_status === 'failed' ? 'text-rose-800' : 'text-amber-800'">
|
||||
{{ $t('admin.schedule.kbSync.title') }}
|
||||
</div>
|
||||
<div v-if="admin.testRunResult.kb_sync_status" class="mt-1">
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.status') }}:</span>
|
||||
{{ admin.testRunResult.kb_sync_status }}
|
||||
</div>
|
||||
<div v-else class="mt-1 text-amber-700">
|
||||
{{ $t('admin.schedule.testRun.kbSyncNoStatus') }}
|
||||
</div>
|
||||
<div v-if="admin.testRunResult.kb_document_id" class="mt-1">
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.document') }}:</span>
|
||||
{{ admin.testRunResult.kb_document_id }}
|
||||
</div>
|
||||
<div v-if="admin.testRunResult.kb_sync_error" class="mt-1 text-rose-600">
|
||||
{{ admin.testRunResult.kb_sync_error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/components/ScheduleWorkbenchPanel.vue
|
||||
* 定时任务工作台模式:侧边任务列表与运行记录表格。
|
||||
* 依赖:schedules.context、lucide-vue-next。
|
||||
* 逻辑:inject admin;筛选/查询运行记录、展开日志详情。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
ChevronDown, ChevronUp, Download, Edit3, Eye, FlaskConical, Power, PowerOff, Rocket, Trash2,
|
||||
} from 'lucide-vue-next';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-6">
|
||||
<div class="grid grid-cols-2 gap-3 admin-panel-lg p-4 shadow-sm md:grid-cols-4 xl:grid-cols-7">
|
||||
<div class="col-span-2 admin-stat-tile px-4 py-3 xl:col-span-3">
|
||||
<div class="truncate text-base font-semibold text-primary">{{ admin.selectedSchedule?.name || $t('admin.schedule.noSelection') }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ $t('admin.schedule.selectedHint', { time: admin.selectedScheduleLatestRunAt }) }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3 text-center">
|
||||
<div class="text-base font-semibold text-primary">{{ admin.selectedScheduleRuns.length }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ $t('admin.schedule.runBatches') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3 text-center">
|
||||
<div class="text-base font-semibold text-primary">{{ admin.selectedScheduleRunMetrics.total }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ $t('admin.schedule.totalProcessed') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3 text-center">
|
||||
<div class="text-base font-semibold text-emerald-700">{{ admin.selectedScheduleRunMetrics.success }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ $t('admin.schedule.totalSuccess') }}</div>
|
||||
</div>
|
||||
<div class="admin-stat-tile px-4 py-3 text-center">
|
||||
<div class="text-base font-semibold text-rose-600">{{ admin.selectedScheduleRunMetrics.failed }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ $t('admin.schedule.totalFailed') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-panel-lg p-6 shadow-sm">
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-[320px_minmax(0,1fr)]">
|
||||
<div class="admin-panel-lg p-6 shadow-sm">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h4 class="text-lg font-semibold text-primary">{{ $t('admin.schedule.listTitle') }}</h4>
|
||||
<span class="text-xs text-muted">{{ $t('admin.schedule.switchByCard') }}</span>
|
||||
</div>
|
||||
<div class="space-y-3">
|
||||
<button
|
||||
v-for="s in admin.schedules"
|
||||
:key="`workbench-${s.id}`"
|
||||
class="w-full rounded-2xl border px-4 py-4 text-left transition-all"
|
||||
:class="admin.selectedScheduleId === s.id ? 'border-blue-300 bg-blue-50/60' : 'border-default bg-surface hover:border-blue-200 hover:bg-surface-soft'"
|
||||
@click="admin.viewScheduleRuns(s.id)"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-semibold text-primary">{{ s.name }}</div>
|
||||
<div class="mt-0.5 text-xs text-muted">{{ s.schedule_no }}</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default p-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
:title="$t('admin.schedule.actions.edit')"
|
||||
@click.stop="admin.openScheduleEditModal(s)"
|
||||
>
|
||||
<Edit3 class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="!s.enabled"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-emerald-200 p-1.5 text-xs font-medium text-emerald-700 transition-colors hover:bg-emerald-50"
|
||||
:title="$t('admin.schedule.actions.start')"
|
||||
@click.stop="admin.setScheduleEnabled(s.id, true)"
|
||||
>
|
||||
<Power class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="inline-flex items-center justify-center rounded-xl border border-amber-200 p-1.5 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-50"
|
||||
:title="$t('admin.schedule.actions.pause')"
|
||||
@click.stop="admin.setScheduleEnabled(s.id, false)"
|
||||
>
|
||||
<PowerOff class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex items-center justify-center rounded-xl border border-blue-200 p-1.5 text-xs font-medium text-blue-700 transition-colors hover:bg-blue-50"
|
||||
:title="$t('admin.schedule.actions.run')"
|
||||
@click.stop="admin.runScheduleNow(s.id)"
|
||||
>
|
||||
<Rocket class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
v-if="s.platform_api_path && s.data_source_type !== 'external_api'"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-violet-200 p-1.5 text-xs font-medium text-violet-700 transition-colors hover:bg-violet-50"
|
||||
:title="$t('admin.schedule.actions.test')"
|
||||
@click.stop="admin.openTestRunDialog(s)"
|
||||
>
|
||||
<FlaskConical class="h-3 w-3" />
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex items-center justify-center rounded-xl border border-rose-200 p-1.5 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50"
|
||||
:title="$t('admin.schedule.actions.delete')"
|
||||
@click.stop="admin.deleteSchedule(s)"
|
||||
>
|
||||
<Trash2 class="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<span class="inline-flex shrink-0 items-center whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="s.enabled ? 'bg-emerald-100 text-emerald-700' : 'bg-surface-strong text-secondary'">
|
||||
{{ s.enabled ? $t('admin.schedule.enabled') : $t('admin.schedule.disabled') }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div v-if="admin.selectedSchedule" class="admin-panel p-4">
|
||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ $t('admin.schedule.recordsTitle', { name: admin.selectedSchedule.name }) }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">{{ $t('admin.schedule.recordsSubtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="mb-3 flex flex-wrap items-center gap-2 text-xs">
|
||||
<label class="text-muted">{{ $t('admin.schedule.filterStart') }}</label>
|
||||
<input type="datetime-local" step="1" v-model="admin.scheduleRunStartedAfter" class="!min-w-0 !w-[170px] !py-1 !px-2 !text-xs rounded-lg border border-default" />
|
||||
<label class="text-muted">{{ $t('admin.schedule.filterEnd') }}</label>
|
||||
<input type="datetime-local" step="1" v-model="admin.scheduleRunStartedBefore" class="!min-w-0 !w-[170px] !py-1 !px-2 !text-xs rounded-lg border border-default" />
|
||||
<select v-model="admin.scheduleRunStatusFilter" class="!min-w-0 !w-[90px] !py-1 !px-2 !text-xs rounded-lg border border-default">
|
||||
<option v-for="opt in admin.scheduleRunStatusOptions" :key="opt.value" :value="opt.value">
|
||||
{{ opt.label }}
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
class="inline-flex items-center rounded-lg bg-brand-600 px-2.5 py-1 text-xs font-medium text-white hover:bg-brand-700"
|
||||
@click="admin.viewScheduleRuns(admin.selectedSchedule.id)"
|
||||
>
|
||||
{{ $t('admin.schedule.query') }}
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex items-center rounded-lg border border-default px-2.5 py-1 text-xs font-medium text-secondary hover:bg-surface-soft"
|
||||
@click="admin.resetScheduleRunFilters(); admin.viewScheduleRuns(admin.selectedSchedule.id)"
|
||||
>
|
||||
{{ $t('admin.schedule.reset') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="admin-table-wrap max-h-[calc(100vh-20rem)] rounded-xl border border-subtle scrollbar-thin">
|
||||
<table class="admin-table min-w-[1270px] table-fixed text-xs">
|
||||
<colgroup>
|
||||
<col
|
||||
v-for="col in admin.scheduleRunColumnDefs"
|
||||
:key="col.key"
|
||||
:style="{ width: `${col.width}px` }"
|
||||
/>
|
||||
</colgroup>
|
||||
<thead class="sticky top-0 z-10 admin-table-sticky-head">
|
||||
<tr class="text-muted">
|
||||
<th
|
||||
v-for="(col, colIndex) in admin.scheduleRunColumnDefs"
|
||||
:key="col.key"
|
||||
class="group relative whitespace-nowrap admin-table-sticky-head px-4 py-3 text-xs font-semibold uppercase select-none"
|
||||
>
|
||||
<span class="whitespace-nowrap">{{ col.label }}</span>
|
||||
<span
|
||||
class="absolute inset-y-0 -right-1 z-10 w-2 cursor-col-resize"
|
||||
@mousedown.prevent="admin.startScheduleColResize(colIndex, $event)"
|
||||
:title="$t('admin.schedule.resizeColumn', { label: col.label })"
|
||||
></span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="admin.scheduleRunsLoading">
|
||||
<td colspan="10" class="px-4 py-8 text-center text-sm text-muted">{{ $t('admin.schedule.queryingRuns') }}</td>
|
||||
</tr>
|
||||
<tr v-else-if="admin.filteredScheduleRuns.length === 0">
|
||||
<td colspan="10" class="px-4 py-8 text-center text-sm text-muted">{{ $t('admin.schedule.noRunRecords') }}</td>
|
||||
</tr>
|
||||
<tr
|
||||
v-else
|
||||
v-for="r in admin.filteredScheduleRuns"
|
||||
:key="r.id"
|
||||
class="text-secondary transition"
|
||||
>
|
||||
<td class="whitespace-nowrap px-4 py-2.5" :title="r.run_no">{{ r.run_no }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5" :title="admin.formatDateTime(r.started_at)">{{ admin.formatDateTime(r.started_at) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5" :title="admin.formatDateTime(r.finished_at)">{{ admin.formatDateTime(r.finished_at) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">
|
||||
<span class="inline-flex shrink-0 items-center whitespace-nowrap rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="admin.getScheduleRunStatusBadge(r.status).cls">
|
||||
{{ admin.getScheduleRunStatusBadge(r.status).label }}
|
||||
</span>
|
||||
<span v-if="r.error_message" class="ml-1 text-xs text-muted" :title="r.error_message">...</span>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">{{ r.total_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">{{ r.success_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">{{ r.failed_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">
|
||||
<span v-if="r.wecom_notified" class="inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-xs text-emerald-600">
|
||||
<svg class="h-3.5 w-3.5 shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" /></svg>
|
||||
{{ $t('admin.schedule.notified') }}
|
||||
</span>
|
||||
<span v-else-if="r.wecom_notify_error" class="whitespace-nowrap text-xs text-amber-500" :title="r.wecom_notify_error">{{ $t('admin.schedule.notifyError') }}</span>
|
||||
<span v-else class="text-xs text-muted">-</span>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">
|
||||
<div class="flex items-center">
|
||||
<a
|
||||
v-if="r.total_count > 0"
|
||||
href="#"
|
||||
@click.prevent="admin.downloadScheduleExcel(r.id)"
|
||||
class="inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-lg border border-default px-2 py-1 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
<Download class="h-3 w-3 shrink-0" />
|
||||
{{ $t('admin.schedule.download') }}
|
||||
</a>
|
||||
<span v-if="r.total_count === 0" class="text-muted">-</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-2.5">
|
||||
<div class="flex items-center">
|
||||
<button
|
||||
v-if="(r.step_logs && r.step_logs.length > 0) || r.dify_execution_snapshot || r.kb_sync_status"
|
||||
@click="admin.expandedScheduleRunId = admin.expandedScheduleRunId === r.id ? null : r.id"
|
||||
class="inline-flex shrink-0 items-center gap-1 whitespace-nowrap rounded-lg border border-blue-200 px-2 py-1 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-50"
|
||||
>
|
||||
<Eye class="h-3 w-3 shrink-0" />
|
||||
{{ $t('admin.schedule.log') }}
|
||||
<ChevronDown v-if="admin.expandedScheduleRunId !== r.id" class="h-3 w-3 shrink-0" />
|
||||
<ChevronUp v-else class="h-3 w-3 shrink-0" />
|
||||
</button>
|
||||
<span v-else class="text-muted">-</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr
|
||||
v-if="admin.expandedScheduleRun"
|
||||
:key="'expanded-' + admin.expandedScheduleRunId"
|
||||
>
|
||||
<td colspan="10" class="px-4 py-3 bg-surface-soft/60">
|
||||
<div class="space-y-3">
|
||||
<div
|
||||
v-if="admin.expandedScheduleRun.kb_sync_status"
|
||||
class="rounded-xl border border-emerald-200 bg-emerald-50/50 p-3 text-xs text-secondary"
|
||||
>
|
||||
<div class="font-bold text-emerald-800">{{ $t('admin.schedule.kbSync.title') }}</div>
|
||||
<div class="mt-1">
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.status') }}:</span>
|
||||
{{ admin.expandedScheduleRun.kb_sync_status }}
|
||||
</div>
|
||||
<div v-if="admin.expandedScheduleRun.kb_document_id" class="mt-1">
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.document') }}:</span>
|
||||
{{ admin.expandedScheduleRun.kb_document_id }}
|
||||
</div>
|
||||
<div v-if="admin.expandedScheduleRun.kb_sync_error" class="mt-1 text-rose-600">
|
||||
{{ admin.expandedScheduleRun.kb_sync_error }}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="admin.expandedScheduleRun.dify_execution_snapshot"
|
||||
class="rounded-xl border border-indigo-200 bg-indigo-50/50 p-3"
|
||||
>
|
||||
<div class="mb-2 flex items-center justify-between">
|
||||
<h5 class="text-xs font-bold uppercase text-indigo-800">{{ $t('admin.schedule.difySnapshot.title') }}</h5>
|
||||
<span class="text-[10px] text-indigo-600/80">
|
||||
{{ admin.expandedScheduleRun.dify_execution_snapshot.captured_at || '-' }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="admin.expandedScheduleRun.dify_execution_snapshot.dify_enabled" class="space-y-2 text-xs text-secondary">
|
||||
<div>
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.difySnapshot.agent') }}:</span>
|
||||
{{ admin.expandedScheduleRun.dify_execution_snapshot.dify_agent_name || '-' }}
|
||||
<span class="text-muted">{{ $t('admin.schedule.difySnapshot.agentId', { id: admin.expandedScheduleRun.dify_execution_snapshot.dify_agent_id ?? '-' }) }}</span>
|
||||
</div>
|
||||
<div v-if="admin.expandedScheduleRun.dify_execution_snapshot.dify_app_id">
|
||||
<span class="font-semibold text-muted">{{ $t('admin.schedule.difySnapshot.difyAppId') }}:</span>
|
||||
{{ admin.expandedScheduleRun.dify_execution_snapshot.dify_app_id }}
|
||||
</div>
|
||||
<div>
|
||||
<span class="mb-1 block font-semibold text-muted">{{ $t('admin.schedule.difySnapshot.systemPrompt') }}:</span>
|
||||
<pre
|
||||
v-if="admin.expandedScheduleRun.dify_execution_snapshot.dify_system_prompt"
|
||||
class="max-h-[240px] overflow-auto whitespace-pre-wrap rounded-lg border border-indigo-100 bg-surface p-3 font-mono text-[11px] leading-relaxed text-primary"
|
||||
>{{ admin.expandedScheduleRun.dify_execution_snapshot.dify_system_prompt }}</pre>
|
||||
<span v-else class="text-muted">{{ $t('admin.schedule.difySnapshot.notConfiguredUseDefault') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="text-xs text-muted">{{ $t('admin.schedule.difySnapshot.notEnabledRun') }}</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<h5 class="text-xs font-bold text-secondary uppercase">{{ $t('admin.schedule.runLogs') }}</h5>
|
||||
<span class="text-xs text-muted">{{ $t('admin.schedule.stepsCount', { count: admin.expandedScheduleRun.step_logs?.length || 0 }) }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-for="(log, li) in admin.expandedScheduleRun.step_logs || []"
|
||||
:key="li"
|
||||
class="rounded-xl border p-3"
|
||||
:class="log.status === 'failed' ? 'border-rose-200 bg-rose-50/40' : 'border-default bg-surface'"
|
||||
>
|
||||
<div class="flex items-center gap-2 mb-1">
|
||||
<span class="inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-bold"
|
||||
:class="(admin.stepStatusMap[log.status] || admin.stepStatusMap.success || { cls: 'bg-surface-soft text-secondary' }).cls">
|
||||
{{ (admin.stepStatusMap[log.status] || { label: log.status }).label }}
|
||||
</span>
|
||||
<span class="text-xs font-semibold text-secondary">{{ admin.stepLabelMap[log.step] || log.step }}</span>
|
||||
<span v-if="log.row_id" class="text-[10px] text-muted">row_id={{ log.row_id }}</span>
|
||||
<span v-if="log.duration_ms != null" class="text-[10px] text-muted">{{ log.duration_ms }}ms</span>
|
||||
</div>
|
||||
<details v-if="log.detail" class="mt-1">
|
||||
<summary class="cursor-pointer text-[10px] font-semibold text-muted hover:text-secondary">{{ $t('admin.schedule.viewDetail') }}</summary>
|
||||
<pre class="admin-pre-block">{{ JSON.stringify(log.detail, null, 2) }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="rounded-2xl border border-dashed border-default bg-surface px-4 py-10 text-center text-sm text-muted">
|
||||
{{ $t('admin.schedule.noSelectionHint') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/schedules/components/SchedulesPageOverlays.vue
|
||||
* 定时任务页弹窗层:试运行、创建/编辑、删除确认。
|
||||
*/
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { useSchedulesAdminContext } from '../composables/schedules.context';
|
||||
import ScheduleCreateEditModal from './ScheduleCreateEditModal.vue';
|
||||
import ScheduleTestRunDialog from './ScheduleTestRunDialog.vue';
|
||||
|
||||
const admin = useSchedulesAdminContext();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ScheduleTestRunDialog />
|
||||
<ScheduleCreateEditModal />
|
||||
<DeleteConfirmDialog
|
||||
v-model="admin.showDeleteConfirmDialog"
|
||||
:title="admin.deleteConfirmTitle"
|
||||
:message="admin.deleteConfirmMessage"
|
||||
@cancel="admin.closeDeleteConfirm"
|
||||
@confirm="admin.confirmDelete"
|
||||
/>
|
||||
</template>
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/schedule-admin.state.ts
|
||||
* 定时任务管理页共享 ref 与删除确认弹窗状态。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import type { ScheduleRun, ScheduleTask, TestScheduleRunResult } from '@/features/admin/api/schedule.api';
|
||||
import type { AdminAgentOption, AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import type { KbGroup } from '@/features/kb/api/kb.api';
|
||||
import {
|
||||
createDefaultCronDesigner,
|
||||
createDefaultScheduleCreateForm,
|
||||
createDefaultScheduleSqlEditForm,
|
||||
} from '../../types/schedule-admin.types';
|
||||
|
||||
export function createScheduleAdminState() {
|
||||
const agents = ref<AdminAgentOption[]>([]);
|
||||
const users = ref<AdminUserRow[]>([]);
|
||||
const kbGroups = ref<KbGroup[]>([]);
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmTitle = ref('');
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
const openDeleteConfirm = (
|
||||
message: string,
|
||||
onConfirm: () => Promise<void> | void,
|
||||
title = '',
|
||||
): void => {
|
||||
deleteConfirmTitle.value = title;
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = onConfirm;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmTitle.value = '';
|
||||
deleteConfirmMessage.value = '';
|
||||
deleteConfirmAction = null;
|
||||
};
|
||||
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
if (!deleteConfirmAction) return;
|
||||
try {
|
||||
await deleteConfirmAction();
|
||||
} finally {
|
||||
closeDeleteConfirm();
|
||||
}
|
||||
};
|
||||
|
||||
const schedules = ref<ScheduleTask[]>([]);
|
||||
const schedulesLoaded = ref(false);
|
||||
void schedulesLoaded;
|
||||
const selectedScheduleRuns = ref<ScheduleRun[]>([]);
|
||||
const scheduleLoading = ref(false);
|
||||
const scheduleRunsLoading = ref(false);
|
||||
const selectedScheduleId = ref<number | null>(null);
|
||||
const scheduleRunStatusFilter = ref<'all' | string>('all');
|
||||
const scheduleRunStartedAfter = ref('');
|
||||
const scheduleRunStartedBefore = ref('');
|
||||
const scheduleRunColumnDefs = ref([
|
||||
{ key: 'run_no', label: '', width: 280, min: 60 },
|
||||
{ key: 'started_at', label: '', width: 190, min: 60 },
|
||||
{ key: 'finished_at', label: '', width: 190, min: 60 },
|
||||
{ key: 'status', label: '', width: 130, min: 50 },
|
||||
{ key: 'total_count', label: '', width: 70, min: 40 },
|
||||
{ key: 'success_count', label: '', width: 70, min: 40 },
|
||||
{ key: 'failed_count', label: '', width: 70, min: 40 },
|
||||
{ key: 'wecom_notified', label: '', width: 100, min: 80 },
|
||||
{ key: 'detail', label: '', width: 100, min: 80 },
|
||||
{ key: 'log', label: '', width: 100, min: 80 },
|
||||
]);
|
||||
const resizingScheduleCol = ref<{ index: number; startX: number; startWidth: number } | null>(null);
|
||||
|
||||
const scheduleViewMode = ref<'overview' | 'workbench'>('overview');
|
||||
const showScheduleCreateModal = ref(false);
|
||||
const scheduleCreateSaving = ref(false);
|
||||
const scheduleEditingId = ref<number | null>(null);
|
||||
const scheduleCreateForm = ref(createDefaultScheduleCreateForm());
|
||||
const scheduleConfigCollapsed = ref(true);
|
||||
const scheduleCronDesigner = ref(createDefaultCronDesigner());
|
||||
|
||||
const expandedScheduleRunId = ref<number | null>(null);
|
||||
|
||||
const showTestRunDialog = ref(false);
|
||||
const testRunSchedule = ref<ScheduleTask | null>(null);
|
||||
const testRunWhere = ref('');
|
||||
const testRunOrderBy = ref('');
|
||||
const testRunBaseFetchSql = ref('');
|
||||
const testRunLimit = ref(3);
|
||||
const testRunKbSync = ref(false);
|
||||
const testRunKbSyncAttempted = ref(false);
|
||||
const testRunLoading = ref(false);
|
||||
const testRunResult = ref<TestScheduleRunResult | null>(null);
|
||||
|
||||
const scheduleSqlEditForm = ref(createDefaultScheduleSqlEditForm());
|
||||
const scheduleSqlSaving = ref(false);
|
||||
void scheduleSqlSaving;
|
||||
const scheduleTestLoading = ref(false);
|
||||
const scheduleTestResult = ref<{ total: number; showing: number; columns: string[]; rows: any[]; sql: string } | null>(null);
|
||||
|
||||
const scheduleNotifyDropdownOpen = ref(false);
|
||||
const scheduleNotifyUserQuery = ref('');
|
||||
const scheduleOwnerDropdownOpen = ref(false);
|
||||
const scheduleOwnerQuery = ref('');
|
||||
|
||||
return {
|
||||
agents,
|
||||
users,
|
||||
kbGroups,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmTitle,
|
||||
deleteConfirmMessage,
|
||||
openDeleteConfirm,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
schedules,
|
||||
schedulesLoaded,
|
||||
selectedScheduleRuns,
|
||||
scheduleLoading,
|
||||
scheduleRunsLoading,
|
||||
selectedScheduleId,
|
||||
scheduleRunStatusFilter,
|
||||
scheduleRunStartedAfter,
|
||||
scheduleRunStartedBefore,
|
||||
scheduleRunColumnDefs,
|
||||
resizingScheduleCol,
|
||||
scheduleViewMode,
|
||||
showScheduleCreateModal,
|
||||
scheduleCreateSaving,
|
||||
scheduleEditingId,
|
||||
scheduleCreateForm,
|
||||
scheduleConfigCollapsed,
|
||||
scheduleCronDesigner,
|
||||
expandedScheduleRunId,
|
||||
showTestRunDialog,
|
||||
testRunSchedule,
|
||||
testRunWhere,
|
||||
testRunOrderBy,
|
||||
testRunBaseFetchSql,
|
||||
testRunLimit,
|
||||
testRunKbSync,
|
||||
testRunKbSyncAttempted,
|
||||
testRunLoading,
|
||||
testRunResult,
|
||||
scheduleSqlEditForm,
|
||||
scheduleSqlSaving,
|
||||
scheduleTestLoading,
|
||||
scheduleTestResult,
|
||||
scheduleNotifyDropdownOpen,
|
||||
scheduleNotifyUserQuery,
|
||||
scheduleOwnerDropdownOpen,
|
||||
scheduleOwnerQuery,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminState = ReturnType<typeof createScheduleAdminState>;
|
||||
+359
@@ -0,0 +1,359 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminForm.ts
|
||||
* 创建/编辑弹窗:Cron 设计器、负责人/通知人、SQL 配置与提交。
|
||||
*/
|
||||
import { computed, watch } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import {
|
||||
createAdminSchedule,
|
||||
getAdminScheduleTaskConfig,
|
||||
testAdminScheduleSql,
|
||||
updateAdminSchedule,
|
||||
type ScheduleTask,
|
||||
} from '@/features/admin/api/schedule.api';
|
||||
import type { AdminUserRow } from '@/features/admin/types/admin.types';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
createDefaultCronDesigner,
|
||||
createDefaultScheduleCreateForm,
|
||||
createDefaultScheduleSqlEditForm,
|
||||
} from '../../types/schedule-admin.types';
|
||||
import { buildScheduleConfigPayload } from '../../utils/schedule-form-payload.utils';
|
||||
import {
|
||||
buildCronExprFromDesigner,
|
||||
computeNextRunPreview,
|
||||
parseCronExprToDesigner,
|
||||
} from '../../utils/schedule-cron.utils';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
import type { ScheduleAdminLookups } from './useScheduleAdminLookups';
|
||||
import type { ScheduleAdminList } from './useScheduleAdminList';
|
||||
import type { ScheduleAdminRuns } from './useScheduleAdminRuns';
|
||||
|
||||
export function useScheduleAdminForm(
|
||||
state: ScheduleAdminState,
|
||||
lookups: Pick<ScheduleAdminLookups, 'loadAgents' | 'loadUsers' | 'loadKbGroups'>,
|
||||
list: Pick<ScheduleAdminList, 'loadSchedules'>,
|
||||
runs: Pick<ScheduleAdminRuns, 'viewScheduleRuns'>,
|
||||
t: ComposerTranslation,
|
||||
) {
|
||||
const msg = useMessage();
|
||||
const {
|
||||
users,
|
||||
showScheduleCreateModal,
|
||||
scheduleCreateSaving,
|
||||
scheduleEditingId,
|
||||
scheduleCreateForm,
|
||||
scheduleConfigCollapsed,
|
||||
scheduleCronDesigner,
|
||||
scheduleSqlEditForm,
|
||||
scheduleTestLoading,
|
||||
scheduleTestResult,
|
||||
scheduleNotifyDropdownOpen,
|
||||
scheduleNotifyUserQuery,
|
||||
scheduleOwnerDropdownOpen,
|
||||
scheduleOwnerQuery,
|
||||
} = state;
|
||||
|
||||
let scheduleNotifyCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
let scheduleOwnerCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const weeklyDayOptions = computed(() => [
|
||||
{ value: 1, label: t('admin.schedule.weekday.mon') },
|
||||
{ value: 2, label: t('admin.schedule.weekday.tue') },
|
||||
{ value: 3, label: t('admin.schedule.weekday.wed') },
|
||||
{ value: 4, label: t('admin.schedule.weekday.thu') },
|
||||
{ value: 5, label: t('admin.schedule.weekday.fri') },
|
||||
{ value: 6, label: t('admin.schedule.weekday.sat') },
|
||||
{ value: 0, label: t('admin.schedule.weekday.sun') },
|
||||
]);
|
||||
|
||||
const scheduleCronPreview = computed(() => buildCronExprFromDesigner(scheduleCronDesigner.value));
|
||||
const scheduleNextRunPreview = computed(() => computeNextRunPreview(scheduleCronPreview.value));
|
||||
|
||||
const formatUserOptionLabel = (u: AdminUserRow) =>
|
||||
`${u.real_name || u.username}${u.employee_id ? `(${u.employee_id})` : ''}`;
|
||||
|
||||
const filteredNotifyUsers = computed(() => {
|
||||
const keyword = scheduleNotifyUserQuery.value.trim().toLowerCase();
|
||||
return users.value.filter((u) => {
|
||||
if (!keyword) return true;
|
||||
return [u.real_name, u.username, u.employee_id, String(u.id)]
|
||||
.filter(Boolean)
|
||||
.some((val) => String(val).toLowerCase().includes(keyword));
|
||||
});
|
||||
});
|
||||
|
||||
const filteredOwnerUsers = computed(() => {
|
||||
const keyword = scheduleOwnerQuery.value.trim().toLowerCase();
|
||||
return users.value.filter((u) => {
|
||||
if (!keyword) return true;
|
||||
return [u.real_name, u.username, u.employee_id, String(u.id)]
|
||||
.filter(Boolean)
|
||||
.some((val) => String(val).toLowerCase().includes(keyword));
|
||||
});
|
||||
});
|
||||
|
||||
const syncScheduleOwnerQuery = (): void => {
|
||||
const ownerId = scheduleCreateForm.value.owner_user_id;
|
||||
if (!ownerId) {
|
||||
scheduleOwnerQuery.value = '';
|
||||
return;
|
||||
}
|
||||
const u = users.value.find((x) => x.id === ownerId);
|
||||
scheduleOwnerQuery.value = u ? formatUserOptionLabel(u) : String(ownerId);
|
||||
};
|
||||
|
||||
const resetScheduleCreateForm = () => {
|
||||
scheduleEditingId.value = null;
|
||||
scheduleCreateForm.value = createDefaultScheduleCreateForm();
|
||||
scheduleSqlEditForm.value = createDefaultScheduleSqlEditForm();
|
||||
scheduleTestResult.value = null;
|
||||
scheduleNotifyUserQuery.value = '';
|
||||
scheduleNotifyDropdownOpen.value = false;
|
||||
scheduleOwnerQuery.value = '';
|
||||
scheduleOwnerDropdownOpen.value = false;
|
||||
scheduleCronDesigner.value = createDefaultCronDesigner();
|
||||
};
|
||||
|
||||
const openScheduleCreateModal = async () => {
|
||||
resetScheduleCreateForm();
|
||||
scheduleConfigCollapsed.value = true;
|
||||
await Promise.all([lookups.loadAgents(), lookups.loadUsers(), lookups.loadKbGroups()]);
|
||||
showScheduleCreateModal.value = true;
|
||||
};
|
||||
|
||||
const openScheduleEditModal = async (task: ScheduleTask) => {
|
||||
await Promise.all([lookups.loadAgents(), lookups.loadUsers(), lookups.loadKbGroups()]);
|
||||
scheduleConfigCollapsed.value = true;
|
||||
scheduleNotifyUserQuery.value = '';
|
||||
scheduleNotifyDropdownOpen.value = false;
|
||||
scheduleOwnerDropdownOpen.value = false;
|
||||
scheduleEditingId.value = task.id;
|
||||
scheduleCreateForm.value = {
|
||||
name: task.name || '',
|
||||
platform_api_path: task.platform_api_path || '',
|
||||
dify_agent_id: task.dify_agent_id || null,
|
||||
owner_user_id: task.owner_user_id || null,
|
||||
wait_seconds: task.wait_seconds || 0,
|
||||
notify_enabled: !!task.notify_enabled,
|
||||
notify_user_ids_json: task.notify_user_ids_json || [],
|
||||
kb_sync_enabled: !!task.kb_sync_enabled,
|
||||
kb_group_id: task.kb_group_id || null,
|
||||
enabled: !!task.enabled,
|
||||
data_source_type: (task.data_source_type || 'database') as 'database' | 'external_api',
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await getAdminScheduleTaskConfig(task.id);
|
||||
const cfg = result.config;
|
||||
scheduleCreateForm.value.data_source_type = (result.data_source_type || 'database') as 'database' | 'external_api';
|
||||
if (cfg) {
|
||||
scheduleSqlEditForm.value = {
|
||||
base_fetch_sql: cfg.base_fetch_sql || '',
|
||||
fetch_where_conditions: cfg.fetch_where_conditions || '',
|
||||
fetch_order_by: cfg.fetch_order_by || '',
|
||||
detail_sql: cfg.detail_sql || '',
|
||||
writeback_sql: cfg.writeback_sql || '',
|
||||
row_id_key: cfg.row_id_key || 'id',
|
||||
log_prefix: cfg.log_prefix || '',
|
||||
alias_order_str: (cfg.alias_order || []).join(','),
|
||||
detail_alias_order_str: (cfg.detail_alias_order || []).join(','),
|
||||
header_labels_str: cfg.header_labels ? JSON.stringify(cfg.header_labels, null, 2) : '{}',
|
||||
ds_db_type: cfg.data_source?.db_type || 'sqlserver',
|
||||
ds_host: cfg.data_source?.host || '',
|
||||
ds_port: cfg.data_source?.port || '',
|
||||
ds_database: cfg.data_source?.database || '',
|
||||
ds_username: cfg.data_source?.username || '',
|
||||
ds_password: cfg.data_source?.password || '',
|
||||
ds_driver: cfg.data_source?.driver || '',
|
||||
ds_encrypt: cfg.data_source?.encrypt || '',
|
||||
ds_trust_cert: cfg.data_source?.trust_cert || '',
|
||||
api_url: cfg.external_api?.url || '',
|
||||
api_method: cfg.external_api?.method || 'POST',
|
||||
api_headers_str: cfg.external_api?.headers ? JSON.stringify(cfg.external_api.headers, null, 2) : '{}',
|
||||
api_body_template: cfg.external_api?.body_template || '',
|
||||
dify_system_prompt: cfg.dify_system_prompt || '',
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
scheduleSqlEditForm.value = createDefaultScheduleSqlEditForm();
|
||||
}
|
||||
|
||||
scheduleTestResult.value = null;
|
||||
scheduleCronDesigner.value = parseCronExprToDesigner(task.cron_expr);
|
||||
syncScheduleOwnerQuery();
|
||||
showScheduleCreateModal.value = true;
|
||||
};
|
||||
|
||||
const scheduleCloseNotifyDropdown = (): void => {
|
||||
if (scheduleNotifyCloseTimer) clearTimeout(scheduleNotifyCloseTimer);
|
||||
scheduleNotifyCloseTimer = setTimeout(() => {
|
||||
scheduleNotifyDropdownOpen.value = false;
|
||||
}, 150);
|
||||
};
|
||||
|
||||
const selectScheduleOwner = (id: number): void => {
|
||||
const u = users.value.find((x) => x.id === id);
|
||||
if (!u) return;
|
||||
scheduleCreateForm.value.owner_user_id = id;
|
||||
scheduleOwnerQuery.value = formatUserOptionLabel(u);
|
||||
scheduleOwnerDropdownOpen.value = false;
|
||||
};
|
||||
|
||||
const handleScheduleOwnerInput = (): void => {
|
||||
scheduleOwnerDropdownOpen.value = true;
|
||||
const ownerId = scheduleCreateForm.value.owner_user_id;
|
||||
if (!ownerId) return;
|
||||
const u = users.value.find((x) => x.id === ownerId);
|
||||
const currentLabel = u ? formatUserOptionLabel(u) : '';
|
||||
if (scheduleOwnerQuery.value.trim() !== currentLabel) {
|
||||
scheduleCreateForm.value.owner_user_id = null;
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleCloseOwnerDropdown = (): void => {
|
||||
if (scheduleOwnerCloseTimer) clearTimeout(scheduleOwnerCloseTimer);
|
||||
scheduleOwnerCloseTimer = setTimeout(() => {
|
||||
scheduleOwnerDropdownOpen.value = false;
|
||||
}, 150);
|
||||
};
|
||||
|
||||
watch(() => scheduleCreateForm.value.dify_agent_id, (agentId) => {
|
||||
if (!agentId) {
|
||||
scheduleSqlEditForm.value.dify_system_prompt = '';
|
||||
}
|
||||
});
|
||||
|
||||
const getUserName = (uid: number) => {
|
||||
const u = users.value.find((x) => x.id === uid);
|
||||
return u ? (u.real_name || u.username) : String(uid);
|
||||
};
|
||||
|
||||
const toggleNotifyUser = (uid: number) => {
|
||||
const notifyList = scheduleCreateForm.value.notify_user_ids_json;
|
||||
if (notifyList.includes(uid)) {
|
||||
scheduleCreateForm.value.notify_user_ids_json = notifyList.filter((id: number) => id !== uid);
|
||||
} else {
|
||||
scheduleCreateForm.value.notify_user_ids_json = [...notifyList, uid];
|
||||
}
|
||||
};
|
||||
|
||||
const removeNotifyUser = (uid: number) => {
|
||||
scheduleCreateForm.value.notify_user_ids_json = scheduleCreateForm.value.notify_user_ids_json.filter((id: number) => id !== uid);
|
||||
};
|
||||
|
||||
const handleTestScheduleSql = async () => {
|
||||
const taskId = scheduleEditingId.value;
|
||||
if (!taskId) return;
|
||||
|
||||
scheduleTestLoading.value = true;
|
||||
scheduleTestResult.value = null;
|
||||
try {
|
||||
const result = await testAdminScheduleSql(taskId, {
|
||||
fetch_where_conditions: scheduleSqlEditForm.value.fetch_where_conditions,
|
||||
fetch_order_by: scheduleSqlEditForm.value.fetch_order_by,
|
||||
limit: 10,
|
||||
});
|
||||
scheduleTestResult.value = result;
|
||||
} catch (e: any) {
|
||||
msg.error(`${t('admin.schedule.msg.testQueryFailed')}: ${e?.message || e}`);
|
||||
} finally {
|
||||
scheduleTestLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const createSchedule = async () => {
|
||||
if (!scheduleCreateForm.value.name || !scheduleCreateForm.value.owner_user_id) return;
|
||||
|
||||
const dst = scheduleCreateForm.value.data_source_type;
|
||||
const hasAgent = !!scheduleCreateForm.value.dify_agent_id;
|
||||
const hasSql = dst === 'database' && !!scheduleSqlEditForm.value.base_fetch_sql.trim();
|
||||
const hasApi = dst === 'external_api' && !!scheduleSqlEditForm.value.api_url.trim();
|
||||
if (!hasAgent && !hasSql && !hasApi) {
|
||||
msg.error(t('admin.schedule.msg.configRequired'));
|
||||
return;
|
||||
}
|
||||
|
||||
let headerLabels: Record<string, string> = {};
|
||||
try {
|
||||
headerLabels = JSON.parse(scheduleSqlEditForm.value.header_labels_str || '{}');
|
||||
} catch {
|
||||
msg.error(t('admin.schedule.msg.headerLabelsJsonInvalid'));
|
||||
return;
|
||||
}
|
||||
let apiHeaders: Record<string, string> = {};
|
||||
if (dst === 'external_api') {
|
||||
try {
|
||||
apiHeaders = JSON.parse(scheduleSqlEditForm.value.api_headers_str || '{}');
|
||||
} catch {
|
||||
msg.error(t('admin.schedule.msg.apiHeadersJsonInvalid'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let configPayload: Record<string, unknown>;
|
||||
configPayload = buildScheduleConfigPayload(
|
||||
scheduleSqlEditForm.value,
|
||||
hasAgent,
|
||||
headerLabels,
|
||||
apiHeaders,
|
||||
);
|
||||
|
||||
scheduleCreateSaving.value = true;
|
||||
try {
|
||||
const payload: Record<string, unknown> = {
|
||||
name: scheduleCreateForm.value.name,
|
||||
schedule_type: 'platform_app',
|
||||
owner_user_id: scheduleCreateForm.value.owner_user_id,
|
||||
cron_expr: scheduleCronPreview.value,
|
||||
wait_seconds: Math.max(0, Number(scheduleCreateForm.value.wait_seconds || 0)),
|
||||
dify_agent_id: scheduleCreateForm.value.dify_agent_id || undefined,
|
||||
notify_user_ids_json: scheduleCreateForm.value.notify_enabled ? scheduleCreateForm.value.notify_user_ids_json : [],
|
||||
notify_enabled: scheduleCreateForm.value.notify_enabled,
|
||||
kb_sync_enabled: scheduleCreateForm.value.kb_sync_enabled,
|
||||
kb_group_id: scheduleCreateForm.value.kb_sync_enabled ? scheduleCreateForm.value.kb_group_id : null,
|
||||
enabled: scheduleCreateForm.value.enabled,
|
||||
data_source_type: dst,
|
||||
config: configPayload,
|
||||
};
|
||||
let resultData: { id?: number; schedule?: { id?: number } } | null = null;
|
||||
if (scheduleEditingId.value) {
|
||||
resultData = await updateAdminSchedule(scheduleEditingId.value, payload) as { id?: number; schedule?: { id?: number } };
|
||||
} else {
|
||||
resultData = await createAdminSchedule(payload) as { id?: number; schedule?: { id?: number } };
|
||||
}
|
||||
const createdId = resultData?.id ?? resultData?.schedule?.id ?? null;
|
||||
const targetId = scheduleEditingId.value || createdId;
|
||||
showScheduleCreateModal.value = false;
|
||||
await list.loadSchedules();
|
||||
if (targetId) {
|
||||
await runs.viewScheduleRuns(targetId);
|
||||
}
|
||||
} catch (err: any) {
|
||||
msg.error(err?.message || t('common.errorOccurred'));
|
||||
} finally {
|
||||
scheduleCreateSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
weeklyDayOptions,
|
||||
scheduleCronPreview,
|
||||
scheduleNextRunPreview,
|
||||
filteredNotifyUsers,
|
||||
filteredOwnerUsers,
|
||||
openScheduleCreateModal,
|
||||
openScheduleEditModal,
|
||||
scheduleCloseNotifyDropdown,
|
||||
selectScheduleOwner,
|
||||
handleScheduleOwnerInput,
|
||||
scheduleCloseOwnerDropdown,
|
||||
getUserName,
|
||||
toggleNotifyUser,
|
||||
removeNotifyUser,
|
||||
handleTestScheduleSql,
|
||||
createSchedule,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminForm = ReturnType<typeof useScheduleAdminForm>;
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminList.ts
|
||||
* 任务列表加载、概览统计、启停/立即执行/删除与视图切换。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import {
|
||||
deleteAdminSchedule,
|
||||
listAdminSchedules,
|
||||
runAdminSchedule,
|
||||
toggleAdminSchedule,
|
||||
type ScheduleTask,
|
||||
} from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
import type { ScheduleAdminRuns } from './useScheduleAdminRuns';
|
||||
|
||||
export function useScheduleAdminList(
|
||||
state: ScheduleAdminState,
|
||||
runs: Pick<ScheduleAdminRuns, 'viewScheduleRuns'>,
|
||||
t: ComposerTranslation,
|
||||
) {
|
||||
const msg = useMessage();
|
||||
const {
|
||||
schedules,
|
||||
scheduleLoading,
|
||||
selectedScheduleId,
|
||||
selectedScheduleRuns,
|
||||
scheduleViewMode,
|
||||
openDeleteConfirm,
|
||||
} = state;
|
||||
|
||||
const scheduleEnabledCount = computed(() => schedules.value.filter((item) => item.enabled).length);
|
||||
const scheduleDisabledCount = computed(() => schedules.value.filter((item) => !item.enabled).length);
|
||||
const scheduleRunningCount = computed(() => schedules.value.filter((item) => item.last_status === 'running').length);
|
||||
|
||||
const loadSchedules = async () => {
|
||||
scheduleLoading.value = true;
|
||||
try {
|
||||
schedules.value = await listAdminSchedules();
|
||||
if (schedules.value.length === 0) {
|
||||
selectedScheduleId.value = null;
|
||||
selectedScheduleRuns.value = [];
|
||||
scheduleViewMode.value = 'overview';
|
||||
return;
|
||||
}
|
||||
const exists = selectedScheduleId.value && schedules.value.some((item) => item.id === selectedScheduleId.value);
|
||||
const nextScheduleId = exists && selectedScheduleId.value ? selectedScheduleId.value : schedules.value[0]?.id ?? null;
|
||||
if (!exists && nextScheduleId) {
|
||||
selectedScheduleId.value = nextScheduleId;
|
||||
}
|
||||
if (scheduleViewMode.value === 'workbench' && nextScheduleId) {
|
||||
await runs.viewScheduleRuns(nextScheduleId);
|
||||
}
|
||||
} finally {
|
||||
scheduleLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const loadAll = async (): Promise<void> => {
|
||||
await loadSchedules();
|
||||
};
|
||||
|
||||
const openScheduleRunSubmenu = async (taskId: number) => {
|
||||
scheduleViewMode.value = 'workbench';
|
||||
await runs.viewScheduleRuns(taskId);
|
||||
};
|
||||
|
||||
const backToScheduleOverview = () => {
|
||||
scheduleViewMode.value = 'overview';
|
||||
};
|
||||
|
||||
const runScheduleNow = async (taskId: number) => {
|
||||
try {
|
||||
await runAdminSchedule(taskId);
|
||||
} catch (err: any) {
|
||||
msg.error(err?.message || t('admin.schedule.msg.runNowFailed'));
|
||||
return;
|
||||
}
|
||||
await runs.viewScheduleRuns(taskId);
|
||||
await loadSchedules();
|
||||
|
||||
const pollInterval = setInterval(async () => {
|
||||
await runs.viewScheduleRuns(taskId);
|
||||
await loadSchedules();
|
||||
const target = schedules.value.find((s: ScheduleTask) => s.id === taskId);
|
||||
if (target && target.last_status && target.last_status !== 'running') {
|
||||
clearInterval(pollInterval);
|
||||
}
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
const setScheduleEnabled = async (taskId: number, enabled: boolean) => {
|
||||
try {
|
||||
await toggleAdminSchedule(taskId, enabled);
|
||||
await loadSchedules();
|
||||
} catch (err: any) {
|
||||
msg.error(err?.message || t('common.errorOccurred'));
|
||||
}
|
||||
};
|
||||
|
||||
const deleteSchedule = (task: ScheduleTask) => {
|
||||
openDeleteConfirm(
|
||||
t('admin.schedule.deleteConfirmMessage', { name: task.name }),
|
||||
async () => {
|
||||
try {
|
||||
await deleteAdminSchedule(task.id);
|
||||
} catch (err: any) {
|
||||
msg.error(err?.message || t('admin.schedule.msg.deleteFailed'));
|
||||
return;
|
||||
}
|
||||
if (selectedScheduleId.value === task.id) {
|
||||
selectedScheduleId.value = null;
|
||||
selectedScheduleRuns.value = [];
|
||||
}
|
||||
await loadSchedules();
|
||||
},
|
||||
t('admin.schedule.deleteDialogTitle'),
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
scheduleEnabledCount,
|
||||
scheduleDisabledCount,
|
||||
scheduleRunningCount,
|
||||
loadSchedules,
|
||||
loadAll,
|
||||
openScheduleRunSubmenu,
|
||||
backToScheduleOverview,
|
||||
runScheduleNow,
|
||||
setScheduleEnabled,
|
||||
deleteSchedule,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminList = ReturnType<typeof useScheduleAdminList>;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminLookups.ts
|
||||
* 定时任务表单依赖的下拉数据:Agent、用户、知识库分组。
|
||||
*/
|
||||
import { listAdminAgents, listAdminUsers } from '@/features/admin/api/admin.api';
|
||||
import { getKbGroups } from '@/features/kb/api/kb.api';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
|
||||
export function useScheduleAdminLookups(state: ScheduleAdminState) {
|
||||
const { agents, users, kbGroups } = state;
|
||||
|
||||
const loadAgents = async (): Promise<void> => {
|
||||
try {
|
||||
agents.value = await listAdminAgents();
|
||||
} catch (e) {
|
||||
console.error('Failed to load agents', e);
|
||||
agents.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadUsers = async (): Promise<void> => {
|
||||
try {
|
||||
users.value = await listAdminUsers();
|
||||
} catch (e) {
|
||||
console.error('Error loading users:', e);
|
||||
users.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadKbGroups = async (): Promise<void> => {
|
||||
try {
|
||||
kbGroups.value = await getKbGroups();
|
||||
} catch (e) {
|
||||
console.error('Failed to load kb groups', e);
|
||||
kbGroups.value = [];
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
loadAgents,
|
||||
loadUsers,
|
||||
loadKbGroups,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminLookups = ReturnType<typeof useScheduleAdminLookups>;
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminRuns.ts
|
||||
* 执行批次列表:筛选、列宽、展开详情、Excel 下载与指标派生。
|
||||
*/
|
||||
import { computed, watch, type Ref } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import { listAdminScheduleRuns } from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { formatDateTime } from '../../utils/schedule-format.utils';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
|
||||
export function useScheduleAdminRuns(
|
||||
state: ScheduleAdminState,
|
||||
t: ComposerTranslation,
|
||||
locale: Ref<string>,
|
||||
) {
|
||||
const msg = useMessage();
|
||||
const {
|
||||
schedules,
|
||||
selectedScheduleRuns,
|
||||
scheduleRunsLoading,
|
||||
selectedScheduleId,
|
||||
scheduleRunStatusFilter,
|
||||
scheduleRunStartedAfter,
|
||||
scheduleRunStartedBefore,
|
||||
scheduleRunColumnDefs,
|
||||
resizingScheduleCol,
|
||||
expandedScheduleRunId,
|
||||
} = state;
|
||||
|
||||
const syncScheduleRunColumnLabels = () => {
|
||||
const keyToI18n: Record<string, string> = {
|
||||
run_no: 'runNo',
|
||||
started_at: 'startedAt',
|
||||
finished_at: 'finishedAt',
|
||||
status: 'status',
|
||||
total_count: 'totalCount',
|
||||
success_count: 'successCount',
|
||||
failed_count: 'failedCount',
|
||||
wecom_notified: 'wecomNotified',
|
||||
detail: 'detail',
|
||||
log: 'log',
|
||||
};
|
||||
scheduleRunColumnDefs.value.forEach((col) => {
|
||||
const i18nKey = keyToI18n[col.key];
|
||||
if (i18nKey) col.label = t(`admin.schedule.columns.${i18nKey}`);
|
||||
});
|
||||
};
|
||||
watch(locale, syncScheduleRunColumnLabels, { immediate: true });
|
||||
|
||||
const onScheduleColResizeMove = (event: MouseEvent) => {
|
||||
const resizeState = resizingScheduleCol.value;
|
||||
if (!resizeState) return;
|
||||
const def = scheduleRunColumnDefs.value[resizeState.index];
|
||||
if (!def) return;
|
||||
const delta = event.clientX - resizeState.startX;
|
||||
def.width = Math.max(def.min, resizeState.startWidth + delta);
|
||||
};
|
||||
|
||||
const stopScheduleColResize = () => {
|
||||
if (!resizingScheduleCol.value) return;
|
||||
resizingScheduleCol.value = null;
|
||||
window.removeEventListener('mousemove', onScheduleColResizeMove);
|
||||
window.removeEventListener('mouseup', stopScheduleColResize);
|
||||
};
|
||||
|
||||
const startScheduleColResize = (index: number, event: MouseEvent) => {
|
||||
const def = scheduleRunColumnDefs.value[index];
|
||||
if (!def) return;
|
||||
resizingScheduleCol.value = {
|
||||
index,
|
||||
startX: event.clientX,
|
||||
startWidth: def.width,
|
||||
};
|
||||
window.addEventListener('mousemove', onScheduleColResizeMove);
|
||||
window.addEventListener('mouseup', stopScheduleColResize);
|
||||
};
|
||||
|
||||
const selectedSchedule = computed(() =>
|
||||
schedules.value.find((item) => item.id === selectedScheduleId.value) || null,
|
||||
);
|
||||
|
||||
const scheduleRunStatusOptions = computed(() => [
|
||||
{ value: 'all', label: t('admin.schedule.status.all') },
|
||||
{ value: 'success', label: t('admin.schedule.status.success') },
|
||||
{ value: 'partial_failed', label: t('admin.schedule.status.partialFailed') },
|
||||
{ value: 'failed', label: t('admin.schedule.status.failed') },
|
||||
{ value: 'running', label: t('admin.schedule.status.running') },
|
||||
]);
|
||||
|
||||
const getScheduleRunStatusBadge = (status: string) => {
|
||||
const map: Record<string, { cls: string; label: string }> = {
|
||||
success: { cls: 'bg-emerald-100 text-emerald-700', label: t('admin.schedule.status.success') },
|
||||
partial_failed: { cls: 'bg-blue-100 text-blue-700', label: t('admin.schedule.status.partialFailed') },
|
||||
failed: { cls: 'bg-rose-100 text-rose-700', label: t('admin.schedule.status.failed') },
|
||||
running: { cls: 'bg-amber-100 text-amber-700', label: t('admin.schedule.status.running') },
|
||||
queued: { cls: 'bg-surface-soft text-secondary', label: t('admin.schedule.status.queued') },
|
||||
};
|
||||
return map[status] || { cls: 'bg-surface-soft text-secondary', label: status };
|
||||
};
|
||||
|
||||
const filteredScheduleRuns = computed(() => {
|
||||
if (scheduleRunStatusFilter.value === 'all') return selectedScheduleRuns.value;
|
||||
return selectedScheduleRuns.value.filter((item) => item.status === scheduleRunStatusFilter.value);
|
||||
});
|
||||
|
||||
const expandedScheduleRun = computed(() => {
|
||||
if (!expandedScheduleRunId.value) return null;
|
||||
return filteredScheduleRuns.value.find((x) => x.id === expandedScheduleRunId.value) || null;
|
||||
});
|
||||
|
||||
const stepLabelMap: Record<string, string> = {
|
||||
fetch_srm: t('admin.schedule.step.fetchSrm'),
|
||||
call_dify: t('admin.schedule.step.callDify'),
|
||||
writeback_srm: t('admin.schedule.step.writebackSrm'),
|
||||
call_internal_api: t('admin.schedule.step.callInternalApi'),
|
||||
pre_dify: t('admin.schedule.step.preDify'),
|
||||
};
|
||||
const stepStatusMap: Record<string, { cls: string; label: string }> = {
|
||||
success: { cls: 'bg-emerald-100 text-emerald-700', label: t('admin.schedule.status.success') },
|
||||
failed: { cls: 'bg-rose-100 text-rose-700', label: t('admin.schedule.status.failed') },
|
||||
};
|
||||
|
||||
const selectedScheduleRunMetrics = computed(() => {
|
||||
const runs = selectedScheduleRuns.value;
|
||||
return runs.reduce(
|
||||
(acc, item) => {
|
||||
acc.total += item.total_count || 0;
|
||||
acc.success += item.success_count || 0;
|
||||
acc.failed += item.failed_count || 0;
|
||||
return acc;
|
||||
},
|
||||
{ total: 0, success: 0, failed: 0 },
|
||||
);
|
||||
});
|
||||
|
||||
const selectedScheduleLatestRunAt = computed(() => {
|
||||
const raw = selectedScheduleRuns.value[0]?.started_at || selectedSchedule.value?.last_run_at;
|
||||
return raw ? formatDateTime(raw) : '-';
|
||||
});
|
||||
|
||||
const todayStart = () => {
|
||||
const d = new Date();
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}T00:00:00`;
|
||||
};
|
||||
const todayEnd = () => {
|
||||
const d = new Date();
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}T23:59:59`;
|
||||
};
|
||||
|
||||
const resetScheduleRunFilters = () => {
|
||||
scheduleRunStatusFilter.value = 'all';
|
||||
scheduleRunStartedAfter.value = todayStart();
|
||||
scheduleRunStartedBefore.value = todayEnd();
|
||||
};
|
||||
|
||||
const viewScheduleRuns = async (taskId: number) => {
|
||||
selectedScheduleId.value = taskId;
|
||||
scheduleRunsLoading.value = true;
|
||||
if (!scheduleRunStartedAfter.value && !scheduleRunStartedBefore.value) {
|
||||
resetScheduleRunFilters();
|
||||
}
|
||||
try {
|
||||
const params: { status?: string; started_after?: string; started_before?: string } = {};
|
||||
if (scheduleRunStatusFilter.value !== 'all') params.status = scheduleRunStatusFilter.value;
|
||||
if (scheduleRunStartedAfter.value) {
|
||||
params.started_after = new Date(scheduleRunStartedAfter.value).toISOString();
|
||||
}
|
||||
if (scheduleRunStartedBefore.value) {
|
||||
params.started_before = new Date(scheduleRunStartedBefore.value).toISOString();
|
||||
}
|
||||
selectedScheduleRuns.value = await listAdminScheduleRuns(taskId, params);
|
||||
} finally {
|
||||
scheduleRunsLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const downloadScheduleExcel = async (runId: number) => {
|
||||
const res = await fetch(`/api/admin/schedule-runs/${runId}/excel`, { headers: getAuthHeaders() });
|
||||
if (!res.ok) {
|
||||
msg.error(t('admin.schedule.msg.downloadExcelFailed'));
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
const disposition = res.headers.get('content-disposition');
|
||||
a.download = disposition?.match(/filename\*?=(?:UTF-8'')?["']?([^;"'\n]+)/)?.[1] || 'result.xlsx';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
return {
|
||||
selectedSchedule,
|
||||
scheduleRunStatusOptions,
|
||||
getScheduleRunStatusBadge,
|
||||
filteredScheduleRuns,
|
||||
expandedScheduleRun,
|
||||
stepLabelMap,
|
||||
stepStatusMap,
|
||||
selectedScheduleRunMetrics,
|
||||
selectedScheduleLatestRunAt,
|
||||
resetScheduleRunFilters,
|
||||
viewScheduleRuns,
|
||||
downloadScheduleExcel,
|
||||
startScheduleColResize,
|
||||
formatDateTime,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminRuns = ReturnType<typeof useScheduleAdminRuns>;
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminTestRun.ts
|
||||
* 定时任务试运行弹窗:加载配置、提交试跑、刷新列表。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import type { ComposerTranslation } from 'vue-i18n';
|
||||
import {
|
||||
getAdminSchedule,
|
||||
getAdminScheduleTaskConfig,
|
||||
testAdminScheduleRun,
|
||||
type ScheduleTask,
|
||||
} from '@/features/admin/api/schedule.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { ScheduleAdminState } from './schedule-admin.state';
|
||||
import type { ScheduleAdminList } from './useScheduleAdminList';
|
||||
import type { ScheduleAdminRuns } from './useScheduleAdminRuns';
|
||||
|
||||
export function useScheduleAdminTestRun(
|
||||
state: ScheduleAdminState,
|
||||
list: Pick<ScheduleAdminList, 'loadSchedules'>,
|
||||
runs: Pick<ScheduleAdminRuns, 'viewScheduleRuns'>,
|
||||
t: ComposerTranslation,
|
||||
) {
|
||||
const msg = useMessage();
|
||||
const {
|
||||
showTestRunDialog,
|
||||
testRunSchedule,
|
||||
testRunWhere,
|
||||
testRunOrderBy,
|
||||
testRunBaseFetchSql,
|
||||
testRunLimit,
|
||||
testRunKbSync,
|
||||
testRunKbSyncAttempted,
|
||||
testRunLoading,
|
||||
testRunResult,
|
||||
} = state;
|
||||
|
||||
const testRunKbSyncAvailable = computed(
|
||||
() => !!(testRunSchedule.value?.kb_group_id),
|
||||
);
|
||||
|
||||
const openTestRunDialog = async (s: ScheduleTask) => {
|
||||
let freshTask = s;
|
||||
try {
|
||||
freshTask = await getAdminSchedule(s.id);
|
||||
} catch {
|
||||
// 列表数据兜底
|
||||
}
|
||||
testRunSchedule.value = freshTask;
|
||||
try {
|
||||
const result = await getAdminScheduleTaskConfig(s.id);
|
||||
const cfg = result.config;
|
||||
testRunWhere.value = cfg?.fetch_where_conditions || '';
|
||||
testRunOrderBy.value = cfg?.fetch_order_by || '';
|
||||
testRunBaseFetchSql.value = cfg?.base_fetch_sql || '';
|
||||
} catch {
|
||||
testRunWhere.value = '';
|
||||
testRunOrderBy.value = '';
|
||||
testRunBaseFetchSql.value = '';
|
||||
}
|
||||
testRunLimit.value = 3;
|
||||
testRunKbSync.value = !!(freshTask.kb_group_id && freshTask.kb_sync_enabled);
|
||||
testRunKbSyncAttempted.value = false;
|
||||
testRunResult.value = null;
|
||||
testRunLoading.value = false;
|
||||
showTestRunDialog.value = true;
|
||||
};
|
||||
|
||||
const handleTestRun = async () => {
|
||||
const s = testRunSchedule.value;
|
||||
if (!s?.id) return;
|
||||
testRunLoading.value = true;
|
||||
testRunResult.value = null;
|
||||
testRunKbSyncAttempted.value = testRunKbSync.value;
|
||||
try {
|
||||
const result = await testAdminScheduleRun(s.id, {
|
||||
fetch_where_conditions: testRunWhere.value,
|
||||
fetch_order_by: testRunOrderBy.value,
|
||||
limit: testRunLimit.value,
|
||||
kb_sync_enabled: testRunKbSync.value,
|
||||
});
|
||||
testRunResult.value = result;
|
||||
await list.loadSchedules();
|
||||
if (s.id) {
|
||||
await runs.viewScheduleRuns(s.id);
|
||||
}
|
||||
} catch (e: any) {
|
||||
msg.error(`${t('admin.schedule.msg.testRunFailed')}: ${e?.message || e}`);
|
||||
} finally {
|
||||
testRunLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
testRunKbSyncAvailable,
|
||||
openTestRunDialog,
|
||||
handleTestRun,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScheduleAdminTestRun = ReturnType<typeof useScheduleAdminTestRun>;
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/composables/schedules.context.ts
|
||||
* 定时任务管理页 provide/inject 上下文类型与注入 key。
|
||||
* 依赖:useSchedulesAdmin。
|
||||
* 逻辑:SchedulesPage provide;子 panel / overlays inject 消费 admin 状态。
|
||||
*/
|
||||
import { inject, type InjectionKey, type Reactive, type UnwrapNestedRefs } from 'vue';
|
||||
import type { useSchedulesAdmin } from './useSchedulesAdmin';
|
||||
|
||||
/** useSchedulesAdmin() 原始返回(含 Ref/ComputedRef) */
|
||||
export type SchedulesAdminContext = ReturnType<typeof useSchedulesAdmin>;
|
||||
|
||||
/** SchedulesPage provide 后经 reactive() 包装、供子组件 inject 的类型 */
|
||||
export type SchedulesAdminContextProvided = Reactive<UnwrapNestedRefs<SchedulesAdminContext>>;
|
||||
|
||||
export const SCHEDULES_ADMIN_KEY: InjectionKey<SchedulesAdminContextProvided> = Symbol('schedulesAdmin');
|
||||
|
||||
/**
|
||||
* 在 SchedulesPage 子树中获取定时任务管理上下文。
|
||||
* 必须在已 provide(SCHEDULES_ADMIN_KEY) 的组件树内调用。
|
||||
* @returns reactive 包装后的 admin 上下文
|
||||
* @throws 未 provide 时抛出 Error
|
||||
*/
|
||||
export function useSchedulesAdminContext(): SchedulesAdminContextProvided {
|
||||
const ctx = inject(SCHEDULES_ADMIN_KEY);
|
||||
if (!ctx) {
|
||||
throw new Error('[schedules] useSchedulesAdminContext() must be used inside SchedulesPage (provide SCHEDULES_ADMIN_KEY)');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/types/schedule-admin.types.ts
|
||||
* 定时任务管理页表单与 Cron 设计器类型及默认工厂。
|
||||
* 依赖:无运行时依赖。
|
||||
* 逻辑:由 useSchedulesAdmin 与 schedule-cron.utils 引用。
|
||||
*/
|
||||
|
||||
/** Cron 设计器模式 */
|
||||
export type ScheduleCronDesignerMode = 'every_minutes' | 'hourly' | 'daily' | 'weekly';
|
||||
|
||||
/** Cron 可视化设计器状态 */
|
||||
export interface ScheduleCronDesigner {
|
||||
mode: ScheduleCronDesignerMode;
|
||||
every_minutes: number;
|
||||
hourly_minute: number;
|
||||
daily_hour: number;
|
||||
daily_minute: number;
|
||||
weekly_day: number;
|
||||
weekly_hour: number;
|
||||
weekly_minute: number;
|
||||
}
|
||||
|
||||
/** 创建/编辑定时任务主表单 */
|
||||
export interface ScheduleCreateForm {
|
||||
name: string;
|
||||
platform_api_path: string;
|
||||
data_source_type: 'database' | 'external_api';
|
||||
dify_agent_id: number | null;
|
||||
owner_user_id: number | null;
|
||||
wait_seconds: number;
|
||||
notify_enabled: boolean;
|
||||
notify_user_ids_json: number[];
|
||||
kb_sync_enabled: boolean;
|
||||
kb_group_id: number | null;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
/** SQL / 外部 API 配置编辑表单 */
|
||||
export interface ScheduleSqlEditForm {
|
||||
base_fetch_sql: string;
|
||||
fetch_where_conditions: string;
|
||||
fetch_order_by: string;
|
||||
detail_sql: string;
|
||||
writeback_sql: string;
|
||||
row_id_key: string;
|
||||
log_prefix: string;
|
||||
alias_order_str: string;
|
||||
detail_alias_order_str: string;
|
||||
header_labels_str: string;
|
||||
ds_db_type: string;
|
||||
ds_host: string;
|
||||
ds_port: string;
|
||||
ds_database: string;
|
||||
ds_username: string;
|
||||
ds_password: string;
|
||||
ds_driver: string;
|
||||
ds_encrypt: string;
|
||||
ds_trust_cert: string;
|
||||
api_url: string;
|
||||
api_method: string;
|
||||
api_headers_str: string;
|
||||
api_body_template: string;
|
||||
dify_system_prompt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 Cron 设计器默认值(每 30 分钟)。
|
||||
* @returns 新的 ScheduleCronDesigner 副本
|
||||
*/
|
||||
export function createDefaultCronDesigner(): ScheduleCronDesigner {
|
||||
return {
|
||||
mode: 'every_minutes',
|
||||
every_minutes: 30,
|
||||
hourly_minute: 0,
|
||||
daily_hour: 9,
|
||||
daily_minute: 0,
|
||||
weekly_day: 1,
|
||||
weekly_hour: 9,
|
||||
weekly_minute: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回创建任务主表单默认值。
|
||||
* @returns 新的 ScheduleCreateForm 副本
|
||||
*/
|
||||
export function createDefaultScheduleCreateForm(): ScheduleCreateForm {
|
||||
return {
|
||||
name: '',
|
||||
platform_api_path: '',
|
||||
data_source_type: 'database',
|
||||
dify_agent_id: null,
|
||||
owner_user_id: null,
|
||||
wait_seconds: 300,
|
||||
notify_enabled: true,
|
||||
notify_user_ids_json: [],
|
||||
kb_sync_enabled: false,
|
||||
kb_group_id: null,
|
||||
enabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 SQL/API 配置表单默认值。
|
||||
* @returns 新的 ScheduleSqlEditForm 副本
|
||||
*/
|
||||
export function createDefaultScheduleSqlEditForm(): ScheduleSqlEditForm {
|
||||
return {
|
||||
base_fetch_sql: '',
|
||||
fetch_where_conditions: '',
|
||||
fetch_order_by: '',
|
||||
detail_sql: '',
|
||||
writeback_sql: '',
|
||||
row_id_key: 'id',
|
||||
log_prefix: '',
|
||||
alias_order_str: '',
|
||||
detail_alias_order_str: '',
|
||||
header_labels_str: '{}',
|
||||
ds_db_type: 'sqlserver',
|
||||
ds_host: '',
|
||||
ds_port: '',
|
||||
ds_database: '',
|
||||
ds_username: '',
|
||||
ds_password: '',
|
||||
ds_driver: '',
|
||||
ds_encrypt: '',
|
||||
ds_trust_cert: '',
|
||||
api_url: '',
|
||||
api_method: 'POST',
|
||||
api_headers_str: '{}',
|
||||
api_body_template: '',
|
||||
dify_system_prompt: '',
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/utils/schedule-cron.utils.ts
|
||||
* Cron 表达式与设计器互转及下次执行时间预览纯函数。
|
||||
* 依赖:schedule-admin.types。
|
||||
* 逻辑:由 useSchedulesAdmin 的 computed 与编辑流程调用。
|
||||
*/
|
||||
import type { ScheduleCronDesigner } from '../types/schedule-admin.types';
|
||||
import { createDefaultCronDesigner } from '../types/schedule-admin.types';
|
||||
|
||||
export { createDefaultCronDesigner } from '../types/schedule-admin.types';
|
||||
|
||||
/**
|
||||
* 根据 Cron 设计器状态生成五段 cron 表达式。
|
||||
* 核心逻辑:按 mode clamp 数值后拼接 `分 时 日 月 周`。
|
||||
* @param cfg - 设计器当前配置
|
||||
* @returns cron 表达式字符串
|
||||
*/
|
||||
export function buildCronExprFromDesigner(cfg: ScheduleCronDesigner): string {
|
||||
if (cfg.mode === 'every_minutes') {
|
||||
const every = Math.max(1, Math.min(59, Number(cfg.every_minutes || 30)));
|
||||
return `*/${every} * * * *`;
|
||||
}
|
||||
if (cfg.mode === 'hourly') {
|
||||
const minute = Math.max(0, Math.min(59, Number(cfg.hourly_minute || 0)));
|
||||
return `${minute} * * * *`;
|
||||
}
|
||||
if (cfg.mode === 'daily') {
|
||||
const minute = Math.max(0, Math.min(59, Number(cfg.daily_minute || 0)));
|
||||
const hour = Math.max(0, Math.min(23, Number(cfg.daily_hour || 0)));
|
||||
return `${minute} ${hour} * * *`;
|
||||
}
|
||||
const minute = Math.max(0, Math.min(59, Number(cfg.weekly_minute || 0)));
|
||||
const hour = Math.max(0, Math.min(23, Number(cfg.weekly_hour || 0)));
|
||||
const day = Number(cfg.weekly_day);
|
||||
return `${minute} ${hour} * * ${Number.isNaN(day) ? 1 : day}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 cron 表达式为设计器状态(不修改入参,返回新对象)。
|
||||
* 核心逻辑:匹配 every_minutes(星斜杠 N)、hourly、daily、weekly 四种已知模式,否则回退默认。
|
||||
* @param expr - 后端存储的 cron 表达式
|
||||
* @returns 新的 ScheduleCronDesigner
|
||||
*/
|
||||
export function parseCronExprToDesigner(expr: string | null | undefined): ScheduleCronDesigner {
|
||||
const text = String(expr || '').trim();
|
||||
const parts = text.split(/\s+/);
|
||||
if (parts.length !== 5) {
|
||||
return createDefaultCronDesigner();
|
||||
}
|
||||
const m = parts[0] ?? '';
|
||||
const h = parts[1] ?? '';
|
||||
const dow = parts[4] ?? '';
|
||||
if (/^\*\/\d+$/.test(m) && h === '*' && dow === '*') {
|
||||
return {
|
||||
...createDefaultCronDesigner(),
|
||||
mode: 'every_minutes',
|
||||
every_minutes: Number(m.replace('*/', '')) || 30,
|
||||
};
|
||||
}
|
||||
if (/^\d+$/.test(m) && h === '*' && dow === '*') {
|
||||
return {
|
||||
...createDefaultCronDesigner(),
|
||||
mode: 'hourly',
|
||||
hourly_minute: Number(m) || 0,
|
||||
};
|
||||
}
|
||||
if (/^\d+$/.test(m) && /^\d+$/.test(h) && dow === '*') {
|
||||
return {
|
||||
...createDefaultCronDesigner(),
|
||||
mode: 'daily',
|
||||
daily_hour: Number(h) || 0,
|
||||
daily_minute: Number(m) || 0,
|
||||
};
|
||||
}
|
||||
if (/^\d+$/.test(m) && /^\d+$/.test(h) && /^\d+$/.test(dow)) {
|
||||
return {
|
||||
...createDefaultCronDesigner(),
|
||||
mode: 'weekly',
|
||||
weekly_hour: Number(h) || 0,
|
||||
weekly_minute: Number(m) || 0,
|
||||
weekly_day: Number(dow),
|
||||
};
|
||||
}
|
||||
return createDefaultCronDesigner();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 cron 表达式估算下一次本地执行时间(仅支持设计器可表达的模式)。
|
||||
* 核心逻辑:解析五段式 cron,按 every_minutes / hourly / daily / weekly 分支推算 Date。
|
||||
* @param expr - cron 表达式
|
||||
* @returns 下次执行时间,无法解析时 null
|
||||
*/
|
||||
export function computeNextRunPreview(expr: string): Date | null {
|
||||
if (!expr) return null;
|
||||
try {
|
||||
const parts = expr.trim().split(/\s+/);
|
||||
if (parts.length !== 5) return null;
|
||||
const now = new Date();
|
||||
const minuteRaw = parts[0]!;
|
||||
const hourRaw = parts[1]!;
|
||||
const dayOfMonth = parts[2]!;
|
||||
const month = parts[3]!;
|
||||
const dayOfWeek = parts[4]!;
|
||||
if (month !== '*') return null;
|
||||
if (dayOfMonth !== '*' && dayOfWeek !== '*') return null;
|
||||
const minute = minuteRaw.startsWith('*/') ? undefined : parseInt(minuteRaw, 10);
|
||||
const hour = hourRaw === '*' ? undefined : parseInt(hourRaw, 10);
|
||||
if (minuteRaw.startsWith('*/')) {
|
||||
const every = parseInt(minuteRaw.replace('*/', ''), 10);
|
||||
const next = new Date(now);
|
||||
next.setSeconds(0, 0);
|
||||
const mod = next.getMinutes() % every;
|
||||
next.setMinutes(next.getMinutes() + (every - mod));
|
||||
if (next <= now) next.setMinutes(next.getMinutes() + every);
|
||||
return next;
|
||||
}
|
||||
if (minute !== undefined && hour === undefined) {
|
||||
const next = new Date(now);
|
||||
next.setMinutes(minute, 0, 0);
|
||||
if (next <= now) next.setHours(next.getHours() + 1);
|
||||
return next;
|
||||
}
|
||||
if (minute !== undefined && hour !== undefined) {
|
||||
const next = new Date(now);
|
||||
next.setHours(hour, minute, 0, 0);
|
||||
if (next <= now) {
|
||||
if (dayOfWeek !== '*') {
|
||||
const dow = parseInt(dayOfWeek, 10);
|
||||
const currentDow = next.getDay();
|
||||
let diff = dow - currentDow;
|
||||
if (diff <= 0) diff += 7;
|
||||
next.setDate(next.getDate() + diff);
|
||||
} else {
|
||||
next.setDate(next.getDate() + 1);
|
||||
}
|
||||
} else if (dayOfWeek !== '*') {
|
||||
const dow = parseInt(dayOfWeek, 10);
|
||||
const target = new Date(next);
|
||||
const currentDow = target.getDay();
|
||||
let diff = dow - currentDow;
|
||||
if (diff < 0) diff += 7;
|
||||
if (diff > 0) target.setDate(target.getDate() + diff);
|
||||
if (target <= now) {
|
||||
target.setDate(target.getDate() + 7);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/utils/schedule-form-payload.utils.ts
|
||||
* 创建/编辑定时任务时 config 与请求 payload 组装。
|
||||
*/
|
||||
import type { ScheduleSqlEditForm } from '../types/schedule-admin.types';
|
||||
|
||||
export function buildScheduleConfigPayload(
|
||||
scheduleSqlEditForm: ScheduleSqlEditForm,
|
||||
hasAgent: boolean,
|
||||
headerLabels: Record<string, string>,
|
||||
apiHeaders: Record<string, string>,
|
||||
) {
|
||||
const aliasOrder = scheduleSqlEditForm.alias_order_str.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
const detailAliasOrder = scheduleSqlEditForm.detail_alias_order_str.split(',').map((s) => s.trim()).filter(Boolean);
|
||||
|
||||
return {
|
||||
base_fetch_sql: scheduleSqlEditForm.base_fetch_sql,
|
||||
fetch_where_conditions: scheduleSqlEditForm.fetch_where_conditions,
|
||||
fetch_order_by: scheduleSqlEditForm.fetch_order_by,
|
||||
detail_sql: scheduleSqlEditForm.detail_sql,
|
||||
writeback_sql: scheduleSqlEditForm.writeback_sql,
|
||||
row_id_key: scheduleSqlEditForm.row_id_key || 'id',
|
||||
log_prefix: scheduleSqlEditForm.log_prefix,
|
||||
alias_order: aliasOrder,
|
||||
detail_alias_order: detailAliasOrder,
|
||||
header_labels: headerLabels,
|
||||
data_source: scheduleSqlEditForm.ds_host.trim() ? {
|
||||
db_type: scheduleSqlEditForm.ds_db_type,
|
||||
host: scheduleSqlEditForm.ds_host,
|
||||
port: scheduleSqlEditForm.ds_port,
|
||||
database: scheduleSqlEditForm.ds_database,
|
||||
username: scheduleSqlEditForm.ds_username,
|
||||
password: scheduleSqlEditForm.ds_password,
|
||||
driver: scheduleSqlEditForm.ds_driver,
|
||||
encrypt: scheduleSqlEditForm.ds_encrypt,
|
||||
trust_cert: scheduleSqlEditForm.ds_trust_cert,
|
||||
} : undefined,
|
||||
external_api: scheduleSqlEditForm.api_url.trim() ? {
|
||||
url: scheduleSqlEditForm.api_url,
|
||||
method: scheduleSqlEditForm.api_method,
|
||||
headers: apiHeaders,
|
||||
body_template: scheduleSqlEditForm.api_body_template,
|
||||
} : undefined,
|
||||
dify_system_prompt: hasAgent ? scheduleSqlEditForm.dify_system_prompt : '',
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* features/admin/modules/schedules/utils/schedule-format.utils.ts
|
||||
* 定时任务 API 日期解析与展示格式化纯函数。
|
||||
* 依赖:无。
|
||||
* 逻辑:由 useSchedulesAdmin 及视图组件通过 admin.formatDateTime 间接使用。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 将 API 返回的 ISO 字符串解析为 Date(无时区后缀则按 UTC 处理)。
|
||||
* @param iso - ISO 8601 或无时区后缀的时间字符串
|
||||
* @returns Date 实例
|
||||
*/
|
||||
export function parseApiUtcDate(iso: string): Date {
|
||||
const normalized = /(?:Z|[+-]\d{2}:\d{2})$/i.test(iso) ? iso : `${iso}Z`;
|
||||
return new Date(normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化为本地 `YYYY-MM-DD HH:mm:ss`;空值或非法日期返回 `-` 或原字符串。
|
||||
* @param iso - 可选 ISO 时间字符串
|
||||
* @returns 展示用日期时间文本
|
||||
*/
|
||||
export function formatDateTime(iso?: string | null): string {
|
||||
if (!iso) return '-';
|
||||
const d = parseApiUtcDate(iso);
|
||||
if (isNaN(d.getTime())) return iso;
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* features/chat/api/toolRunProgress.api.ts
|
||||
* 工具运行进度查询 API(Chat 输入栏进度卡片轮询)。
|
||||
*/
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import type { ToolRunProgressResponse } from '../types/tool-run-progress.types';
|
||||
|
||||
export type { ToolRunProgress, ToolRunProgressResponse } from '../types/tool-run-progress.types';
|
||||
|
||||
export const getToolRunProgress = (url: string) =>
|
||||
requestJson<ToolRunProgressResponse>(url, { headers: getAuthHeaders() });
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import ToolRunProgressCard from './ToolRunProgressCard.vue';
|
||||
import type { ToolRunProgress } from '@/api/toolRunProgress';
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
|
||||
export interface ChatInputAttachmentPolicy {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { AlertCircle, CheckCircle2, Clock3, Download, Loader2 } from 'lucide-vue-next';
|
||||
import type { ToolRunProgress } from '@/api/toolRunProgress';
|
||||
import type { ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
|
||||
const props = defineProps<{
|
||||
run: ToolRunProgress | null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { computed, onBeforeUnmount, ref, type Ref, watch } from 'vue';
|
||||
import { getToolRunProgress, type ToolRunProgress } from '@/api/toolRunProgress';
|
||||
import { getToolRunProgress, type ToolRunProgress } from '../api/toolRunProgress.api';
|
||||
|
||||
export interface ToolRunProgressConfig {
|
||||
type?: string;
|
||||
|
||||
@@ -29,5 +29,7 @@ export {
|
||||
} from './composables/chat.context';
|
||||
export * from './api/chat.api';
|
||||
export * from './api/shipping.api';
|
||||
export * from './api/toolRunProgress.api';
|
||||
export type * from './types/tool-run-progress.types';
|
||||
export type * from './types/chat.types';
|
||||
export type * from './types/shipping.api.types';
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* features/chat/types/tool-run-progress.types.ts
|
||||
* 工具运行进度 SSE/轮询接口的类型定义。
|
||||
*/
|
||||
|
||||
export interface ToolRunProgress {
|
||||
run_id: number;
|
||||
run_no: string;
|
||||
task_id?: number;
|
||||
title: string;
|
||||
status: string;
|
||||
total_count: number;
|
||||
processed_count: number;
|
||||
success_count: number;
|
||||
failed_count: number;
|
||||
skipped_count: number;
|
||||
current_step?: {
|
||||
step?: string;
|
||||
label?: string;
|
||||
row_id?: string | number | null;
|
||||
started_at?: string | null;
|
||||
processed_count?: number;
|
||||
success_count?: number;
|
||||
failed_count?: number;
|
||||
skipped_count?: number;
|
||||
} | null;
|
||||
judgement?: {
|
||||
qualified_count?: number;
|
||||
unqualified_count?: number;
|
||||
manual_count?: number;
|
||||
dify_error_count?: number;
|
||||
invalid_result_count?: number;
|
||||
};
|
||||
progress_percent: number;
|
||||
started_at?: string | null;
|
||||
finished_at?: string | null;
|
||||
duration_ms?: number | null;
|
||||
error_message?: string | null;
|
||||
excel?: {
|
||||
file_name?: string | null;
|
||||
file_size?: number | null;
|
||||
download_url?: string | null;
|
||||
};
|
||||
knowledge_base?: {
|
||||
sync_status?: string | null;
|
||||
error_message?: string | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ToolRunProgressResponse {
|
||||
ok: boolean;
|
||||
run: ToolRunProgress | null;
|
||||
}
|
||||
@@ -0,0 +1,635 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/kb/components/KbWorkspaceOverlays.vue
|
||||
* 知识库作业面弹窗层:记录/Markdown/来源/失败/路径上传等。
|
||||
*/
|
||||
import { Upload, X } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import type { useKbWorkspace } from '../composables/useKbWorkspace';
|
||||
|
||||
defineProps<{
|
||||
kb: ReturnType<typeof useKbWorkspace>;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="kb.showRecordModal"
|
||||
class="dialog-overlay z-[55] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-5xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.recordModal.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.recordModal.viewing', { name: kb.documentDisplayName(kb.selectedDocument, kb.selectedDocumentId) }) }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeDocumentDetail"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isRecordLoading" class="flex min-h-[360px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.recordModal.loading') }}
|
||||
</div>
|
||||
<div v-else class="space-y-6 overflow-y-auto pr-1">
|
||||
<div>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">{{ kb.t('kbWorkspace.recordModal.versionsTitle') }}</h3>
|
||||
<span class="text-xs text-muted">{{ kb.t('kbWorkspace.recordModal.versionsCount', { count: kb.selectedDocumentVersions.length }) }}</span>
|
||||
</div>
|
||||
<div v-if="kb.selectedDocumentVersions.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.recordModal.versionsEmpty') }}
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="version in kb.selectedDocumentVersions"
|
||||
:key="version.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-primary">
|
||||
v{{ version.version_no }} · {{ version.source_file_name }}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(version.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(version.status) }}
|
||||
</span>
|
||||
<span>{{ kb.t('kbWorkspace.recordModal.sizeBytes', { size: version.source_file_size ?? 0 }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(version.created_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">{{ kb.t('kbWorkspace.recordModal.syncTitle') }}</h3>
|
||||
<span class="text-xs text-muted">{{ kb.t('kbWorkspace.recordModal.versionsCount', { count: kb.selectedDocumentSyncRecords.length }) }}</span>
|
||||
</div>
|
||||
<div v-if="kb.selectedDocumentSyncRecords.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.recordModal.syncEmpty') }}
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="record in kb.selectedDocumentSyncRecords"
|
||||
:key="record.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-primary">
|
||||
{{ record.dataset_name || record.dataset_id }} · {{ record.remote_document_name || record.remote_document_id }}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(record.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(record.status) }}
|
||||
</span>
|
||||
<span>{{ kb.t('kbWorkspace.recordModal.versionLabel', { id: record.document_version_id }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(record.updated_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.showMarkdownModal"
|
||||
class="dialog-overlay z-[60] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-5xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h3 class="truncate text-lg font-semibold text-primary">{{ kb.markdownModalTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.markdownVersionLabel || kb.t('kbWorkspace.markdownModal.readingVersion') }}
|
||||
<span class="ml-2 rounded-full bg-surface-soft px-2 py-0.5 text-xs text-muted">
|
||||
{{ kb.markdownKind === 'preview' ? kb.t('kbWorkspace.markdownModal.previewText') : kb.t('kbWorkspace.markdownModal.cleanMarkdown') }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeMarkdownModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="kb.markdownError"
|
||||
class="mb-4 text-sm text-rose-500"
|
||||
>
|
||||
{{ kb.markdownError }}
|
||||
</p>
|
||||
|
||||
<div v-if="kb.isMarkdownLoading" class="flex min-h-[420px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.markdownModal.loading') }}
|
||||
</div>
|
||||
<textarea
|
||||
v-else
|
||||
v-model="kb.markdownContent"
|
||||
spellcheck="false"
|
||||
class="min-h-[420px] w-full flex-1 rounded-2xl border border-default bg-surface-soft px-4 py-3 font-mono text-sm text-primary outline-none transition-colors focus:border-brand-300 focus:bg-surface"
|
||||
:placeholder="kb.t('kbWorkspace.markdownModal.placeholder')"
|
||||
/>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closeMarkdownModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.close') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleSaveMarkdown"
|
||||
:disabled="kb.isMarkdownLoading || kb.isMarkdownSaving || !kb.markdownDocumentId"
|
||||
class="inline-flex items-center justify-center rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.isMarkdownSaving ? kb.t('kbWorkspace.markdownModal.saving') : kb.t('kbWorkspace.markdownModal.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.showSourceInfoModal"
|
||||
class="dialog-overlay z-[58] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-4xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h3 class="truncate text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.sourceInfoModal.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.sourceInfoModal.viewing', { name: kb.documentDisplayName(kb.sourceInfoDocument, kb.sourceInfoDocumentId) }) }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeSourceInfoModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isSourceInfoLoading" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.sourceInfoModal.loading') }}
|
||||
</div>
|
||||
<div v-else-if="kb.sourceInfoVersions.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.sourceInfoModal.empty') }}
|
||||
</div>
|
||||
<div v-else class="space-y-3 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="version in kb.sourceInfoVersions"
|
||||
:key="version.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.openOriginalSourceFile(version)"
|
||||
class="font-semibold text-primary underline-offset-2 transition-colors hover:text-brand-600 hover:underline hover:text-brand-600"
|
||||
>
|
||||
v{{ version.version_no }} · {{ version.source_file_name }}
|
||||
</button>
|
||||
<span
|
||||
v-if="version.is_current"
|
||||
class="inline-flex items-center rounded-full border border-brand-200 bg-brand-50 px-2.5 py-1 text-xs font-semibold text-brand-700 border-brand-200"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.sourceInfoModal.currentVersion') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="kb.openingSourceVersionId === version.id"
|
||||
class="text-xs text-muted"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.sourceInfoModal.opening') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(version.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(version.status) }}
|
||||
</span>
|
||||
<span>{{ kb.t('kbWorkspace.sourceInfoModal.fileName', { name: version.source_file_name }) }}</span>
|
||||
<span>{{ kb.t('kbWorkspace.sourceInfoModal.fileSize', { size: kb.formatFileSize(version.source_file_size) }) }}</span>
|
||||
<span v-if="version.source_file_ext">{{ kb.t('kbWorkspace.sourceInfoModal.fileType', { ext: version.source_file_ext }) }}</span>
|
||||
</div>
|
||||
<div v-if="version.error_message" class="mt-2 text-sm text-rose-500">
|
||||
{{ kb.t('kbWorkspace.common.failureReason', { reason: version.error_message }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(version.created_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closeSourceInfoModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.close') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.showFailureModal"
|
||||
class="dialog-overlay z-[65] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-6xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ kb.failureModalTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.failureModal.summary', { count: kb.failureModalItems.length, pageSize: kb.FAILURE_PAGE_SIZE }) }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeFailureModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.failureModalItems.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.failureModal.empty') }}
|
||||
</div>
|
||||
<div v-else class="space-y-4 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.pagedFailureModalItems"
|
||||
:key="item.key"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<div class="max-w-full truncate text-base font-semibold text-primary">
|
||||
{{ kb.getDocumentDisplayTitle(item.document) }}
|
||||
</div>
|
||||
<span class="inline-flex items-center rounded-full border border-rose-200 bg-rose-50 px-2.5 py-1 text-xs font-semibold text-rose-700 border-rose-200">
|
||||
{{ item.stageLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.failureModal.currentVersion') }}
|
||||
<span v-if="item.document.latest_version">
|
||||
v{{ item.document.latest_version.version_no }} · {{ item.document.latest_version.source_file_name }}
|
||||
</span>
|
||||
<span v-else>{{ kb.t('kbWorkspace.failureModal.noVersion') }}</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-rose-500">
|
||||
{{ kb.t('kbWorkspace.common.failureReason', { reason: item.errorMessage }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 text-right text-sm text-muted">
|
||||
{{ kb.formatDateTime(item.updatedAt) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
@click="kb.handleRetryFailedItem(item, 'submit')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-submit`"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-sky-200 px-3 py-2 text-xs font-medium text-sky-700 transition-colors hover:bg-sky-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-submit` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.failureModal.resubmit') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleRetryFailedItem(item, 'clean')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-clean` || !item.document.latest_version"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-amber-200 px-3 py-2 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-50 disabled:cursor-not-allowed disabled:opacity-60 border-amber-200"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-clean` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.failureModal.reclean') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleRetryFailedItem(item, 'sync')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-sync` || !item.document.latest_version"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-emerald-200 px-3 py-2 text-xs font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60 border-emerald-200"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-sync` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.failureModal.resync') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.failureModalItems.length > kb.FAILURE_PAGE_SIZE"
|
||||
class="mt-5 flex items-center justify-between gap-3 border-t border-default pt-4 "
|
||||
>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.failureModal.pageInfo', { page: kb.failureModalPage, totalPages: kb.failureModalTotalPages }) }}
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@click="kb.failureModalPage = Math.max(1, kb.failureModalPage - 1)"
|
||||
:disabled="kb.failureModalPage === 1"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.prevPage') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.failureModalPage = Math.min(kb.failureModalTotalPages, kb.failureModalPage + 1)"
|
||||
:disabled="kb.failureModalPage === kb.failureModalTotalPages"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.nextPage') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.showPathUploadModal"
|
||||
class="dialog-overlay z-[66] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-4xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.pathUploadModal.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.subtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closePathUploadModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4 overflow-y-auto pr-1">
|
||||
<div class="rounded-2xl border border-default bg-surface-soft p-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-primary">{{ kb.t('kbWorkspace.pathUploadModal.localPickerTitle') }}</div>
|
||||
<div class="mt-1 text-xs text-muted">
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.localPickerHint') }}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.triggerPathUploadSelection"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-brand-200 px-4 py-2.5 text-sm font-medium text-brand-700 transition-colors hover:bg-brand-50 border-brand-200 hover:bg-brand-50"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.pickFolder') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label-field block mb-2">{{ kb.t('kbWorkspace.pathUploadModal.pathListLabel') }}</label>
|
||||
<textarea
|
||||
v-model="kb.pathUploadDraftText"
|
||||
rows="5"
|
||||
class="input-field"
|
||||
:placeholder="kb.t('kbWorkspace.pathUploadModal.pathListPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between gap-3">
|
||||
<div class="text-sm font-medium text-secondary">
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.pendingFiles') }}
|
||||
<span class="ml-2 text-xs text-muted">{{ kb.t('kbWorkspace.recordModal.versionsCount', { count: kb.pathUploadSelectedFiles.length }) }}</span>
|
||||
</div>
|
||||
<div class="text-xs text-muted">
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.selectedRoots', { paths: kb.selectedPathRoots.length ? kb.selectedPathRoots.join('、') : kb.t('kbWorkspace.pathUploadModal.noRoots') }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="kb.pathUploadSelectedFiles.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.pickFolderFirst') }}
|
||||
</div>
|
||||
<div v-else class="max-h-72 space-y-2 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.pathUploadSelectedFiles"
|
||||
:key="item.key"
|
||||
class="flex items-start justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-sm font-medium text-primary">{{ item.file.name }}</div>
|
||||
<div class="mt-1 truncate text-xs text-muted">{{ item.displayPath }}</div>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.removeSelectedPathFile(item.key)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.remove') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closePathUploadModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleConfirmPathUpload"
|
||||
class="inline-flex items-center justify-center gap-2 rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
{{ kb.t('kbWorkspace.pathUploadModal.confirmUpload') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.showPathUploadHistoryModal"
|
||||
class="dialog-overlay z-[67] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-6xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.pathUploadHistoryModal.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">{{ kb.t('kbWorkspace.pathUploadHistoryModal.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closePathUploadHistoryModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.pathUploadHistoryJobs.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
{{ kb.t('kbWorkspace.pathUpload.emptyHistory') }}
|
||||
</div>
|
||||
<div v-else class="grid min-h-0 flex-1 grid-cols-1 gap-4 lg:grid-cols-[320px_minmax(0,1fr)]">
|
||||
<div class="space-y-3 overflow-y-auto pr-1">
|
||||
<button
|
||||
v-for="job in kb.pathUploadHistoryJobs"
|
||||
:key="job.id"
|
||||
@click="kb.selectedPathUploadHistoryJobId = job.id"
|
||||
class="w-full rounded-2xl border px-4 py-4 text-left transition-colors"
|
||||
:class="String(kb.selectedPathUploadHistoryJobId || kb.selectedPathUploadHistoryJob?.id) === String(job.id)
|
||||
? 'border-brand-200 bg-brand-50 border-brand-200 '
|
||||
: 'border-default bg-surface hover:bg-surface-soft hover-surface-soft'"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate text-sm font-semibold text-primary">{{ kb.t('kbWorkspace.pathUpload.batchLabel', { id: job.id }) }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ kb.formatDateTime(job.created_at) }}</div>
|
||||
</div>
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(job.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(job.status) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-2 gap-2 text-xs text-muted">
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.total', { count: kb.getPathUploadJobSummary(job).total }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.success', { count: kb.getPathUploadJobSummary(job).success }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.failed', { count: kb.getPathUploadJobSummary(job).failed }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.pendingProcess', { count: kb.getPathUploadJobSummary(job).pending }) }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.selectedPathUploadHistoryJob" class="min-h-0 rounded-2xl border border-default p-4 ">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-base font-semibold text-primary">{{ kb.t('kbWorkspace.pathUpload.batchLabel', { id: kb.selectedPathUploadHistoryJob.id }) }}</div>
|
||||
<div class="mt-1 text-sm text-muted">
|
||||
{{ kb.t('kbWorkspace.pathUpload.createdAt', { time: kb.formatDateTime(kb.selectedPathUploadHistoryJob.created_at) }) }}
|
||||
<span v-if="kb.selectedPathUploadHistoryJob.finished_at">{{ kb.t('kbWorkspace.pathUpload.finishedAt', { time: kb.formatDateTime(kb.selectedPathUploadHistoryJob.finished_at) }) }}</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-muted">{{ kb.selectedPathUploadHistoryJob.message || kb.t('kbWorkspace.pathUpload.noBatchMessage') }}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(kb.selectedPathUploadHistoryJob.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(kb.selectedPathUploadHistoryJob.status) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="kb.selectedPathUploadHistoryItems.length && !kb.pathUploadRunning"
|
||||
@click="kb.toggleSelectAllPathUploadHistoryItems"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.isAllPathUploadHistoryItemsSelected ? kb.t('kbWorkspace.pathUpload.deselectAll') : kb.t('kbWorkspace.pathUpload.selectAll') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!kb.pathUploadRunning"
|
||||
@click="kb.handleBatchDeletePathUploadItems"
|
||||
:disabled="!kb.selectedPathUploadHistorySelectedItems.length || kb.deletingPathUploadBatch"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.pathUploadBatchDeleteLabel(kb.deletingPathUploadBatch, kb.selectedPathUploadHistorySelectedItems.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.hasRetryablePathUploadFailure(kb.selectedPathUploadHistoryJob) && !kb.pathUploadRunning"
|
||||
@click="kb.handleRetryFailedPathUpload(kb.selectedPathUploadHistoryJob)"
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:all`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:all` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.pathUpload.retryAllFailed') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-2 gap-3 text-sm text-secondary md:grid-cols-4">
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">{{ kb.t('kbWorkspace.pathUpload.total', { count: kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).total }) }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">{{ kb.t('kbWorkspace.pathUpload.success', { count: kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).success }) }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">{{ kb.t('kbWorkspace.pathUpload.failed', { count: kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).failed }) }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">{{ kb.t('kbWorkspace.pathUpload.pendingProcess', { count: kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).pending }) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 max-h-[50vh] space-y-2 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.selectedPathUploadHistoryItems"
|
||||
:key="item.key"
|
||||
class="flex flex-wrap items-start justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<label class="flex items-center pt-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="kb.selectedPathUploadHistoryItemKeys.includes(item.key)"
|
||||
@change="kb.togglePathUploadHistoryItemSelection(item.key)"
|
||||
class="h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
</label>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-sm font-medium text-primary">{{ item.title }}</div>
|
||||
<div class="mt-1 truncate text-xs text-muted">{{ item.displayPath }}</div>
|
||||
<div v-if="item.error" class="mt-1 text-xs text-rose-500">{{ kb.t('kbWorkspace.common.failureReason', { reason: item.error }) }}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getPathUploadItemDisplayState(item).className"
|
||||
>
|
||||
{{ kb.getPathUploadItemDisplayState(item).label }}
|
||||
</span>
|
||||
<button
|
||||
v-if="item.retryable && !kb.pathUploadRunning"
|
||||
@click="kb.handleRetryFailedPathUpload(kb.selectedPathUploadHistoryJob, [item.displayPath])"
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:${item.displayPath}`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-2.5 py-1 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:${item.displayPath}` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.common.retry') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!kb.pathUploadRunning"
|
||||
@click="kb.handleDeletePathUploadItem(kb.selectedPathUploadHistoryJob, item)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-2.5 py-1 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.t('kbWorkspace.common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="kb.showDeleteConfirmDialog"
|
||||
:message="kb.deleteConfirmMessage"
|
||||
@confirm="kb.handleDeleteConfirm"
|
||||
@cancel="kb.closeDeleteConfirmDialog"
|
||||
/>
|
||||
</template>
|
||||
@@ -135,7 +135,7 @@ export function createKbWorkspaceState(options: CreateKbWorkspaceStateOptions =
|
||||
await pendingDeleteAction();
|
||||
} catch (err) {
|
||||
console.error('[deleteConfirm]', err);
|
||||
feedback.value = String(err) || '操作失败';
|
||||
feedback.value = String(err) || t('kbWorkspace.msg.operationFailed');
|
||||
feedbackType.value = 'error';
|
||||
}
|
||||
closeDeleteConfirmDialog();
|
||||
|
||||
@@ -47,6 +47,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
selectedPathUploadHistoryJobId,
|
||||
selectedPathUploadHistoryItemKeys,
|
||||
groups,
|
||||
t,
|
||||
} = state;
|
||||
|
||||
const selectedDocument = computed(() =>
|
||||
@@ -60,7 +61,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
);
|
||||
const markdownModalTitle = computed(() => {
|
||||
const current = documents.value.find((item) => item.id === markdownDocumentId.value);
|
||||
return current ? getDocumentDisplayTitle(current) : 'Markdown 编辑器';
|
||||
return current ? getDocumentDisplayTitle(current, t) : t('kbWorkspace.markdownModal.editorTitle');
|
||||
});
|
||||
const activeGroupJobs = computed(() =>
|
||||
jobs.value.filter((item) => item.group_id === selectedGroupId.value),
|
||||
@@ -68,13 +69,13 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const getLatestJobForDocument = buildGetLatestJobForDocument(() => activeGroupJobs.value);
|
||||
const resolveWorkflowState = (doc: KbDocumentItem) =>
|
||||
getDocumentWorkflowState(doc, getLatestJobForDocument);
|
||||
getDocumentWorkflowState(doc, getLatestJobForDocument, t);
|
||||
const getWorkflowBadgesForDoc = (doc: KbDocumentItem) =>
|
||||
getWorkflowBadges(doc, getLatestJobForDocument);
|
||||
getWorkflowBadges(doc, getLatestJobForDocument, t);
|
||||
const getMarkdownUnavailableMessageForDoc = (
|
||||
doc: KbDocumentItem,
|
||||
fallback?: string | null,
|
||||
) => getMarkdownUnavailableMessage(doc, getLatestJobForDocument, fallback);
|
||||
) => getMarkdownUnavailableMessage(doc, getLatestJobForDocument, t, fallback);
|
||||
|
||||
const groupSummaryItems = computed(() => {
|
||||
const docItems = documents.value;
|
||||
@@ -86,12 +87,12 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const syncFailedCount = workflowStates.filter((item) => item.sync.code === 'failed').length;
|
||||
|
||||
return [
|
||||
{ label: '当前知识库分组', value: groupName, wide: true, clickable: false },
|
||||
{ label: '文档数量', value: String(docItems.length), wide: false, clickable: false },
|
||||
{ label: '待同步数量', value: String(pendingSyncCount), wide: false, clickable: false },
|
||||
{ label: '上传失败数量', value: String(uploadFailedCount), wide: false, clickable: uploadFailedCount > 0, failureType: 'upload' as const },
|
||||
{ label: '清洗失败数量', value: String(cleanFailedCount), wide: false, clickable: cleanFailedCount > 0, failureType: 'clean' as const },
|
||||
{ label: '同步失败数量', value: String(syncFailedCount), wide: false, clickable: syncFailedCount > 0, failureType: 'sync' as const },
|
||||
{ label: t('kbWorkspace.summary.currentGroup'), value: groupName, wide: true, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.documentCount'), value: String(docItems.length), wide: false, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.pendingSync'), value: String(pendingSyncCount), wide: false, clickable: false },
|
||||
{ label: t('kbWorkspace.summary.uploadFailed'), value: String(uploadFailedCount), wide: false, clickable: uploadFailedCount > 0, failureType: 'upload' as const },
|
||||
{ label: t('kbWorkspace.summary.cleanFailed'), value: String(cleanFailedCount), wide: false, clickable: cleanFailedCount > 0, failureType: 'clean' as const },
|
||||
{ label: t('kbWorkspace.summary.syncFailed'), value: String(syncFailedCount), wide: false, clickable: syncFailedCount > 0, failureType: 'sync' as const },
|
||||
];
|
||||
});
|
||||
|
||||
@@ -114,8 +115,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const normalizedKeyword = keyword.trim().toLowerCase();
|
||||
if (!normalizedKeyword) return true;
|
||||
const candidates = [
|
||||
getDocumentDisplayTitle(doc),
|
||||
getDocumentDisplayDescription(doc),
|
||||
getDocumentDisplayTitle(doc, t),
|
||||
getDocumentDisplayDescription(doc, t),
|
||||
doc.title,
|
||||
doc.description,
|
||||
doc.latest_version?.source_file_name,
|
||||
@@ -125,10 +126,10 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const stageFilterTabs = computed(() => {
|
||||
const filters: Array<{ key: 'all' | 'upload' | 'clean' | 'sync'; label: string }> = [
|
||||
{ key: 'all', label: '全部' },
|
||||
{ key: 'upload', label: '上传' },
|
||||
{ key: 'clean', label: '清洗' },
|
||||
{ key: 'sync', label: '同步' },
|
||||
{ key: 'all', label: t('kbWorkspace.filters.all') },
|
||||
{ key: 'upload', label: t('kbWorkspace.filters.upload') },
|
||||
{ key: 'clean', label: t('kbWorkspace.filters.clean') },
|
||||
{ key: 'sync', label: t('kbWorkspace.filters.sync') },
|
||||
];
|
||||
return filters.map((item) => ({
|
||||
...item,
|
||||
@@ -189,8 +190,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-clean`,
|
||||
document: doc,
|
||||
stage: 'clean',
|
||||
stageLabel: '清洗失败',
|
||||
errorMessage: workflow.clean.errorMessage || workflow.primaryError || '清洗失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageCleanFailed'),
|
||||
errorMessage: workflow.clean.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageCleanFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'clean'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -200,8 +201,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-sync`,
|
||||
document: doc,
|
||||
stage: 'sync',
|
||||
stageLabel: '同步失败',
|
||||
errorMessage: workflow.sync.errorMessage || workflow.primaryError || '同步失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageSyncFailed'),
|
||||
errorMessage: workflow.sync.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageSyncFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'sync_dify'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -211,8 +212,8 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
key: `${doc.id}-upload`,
|
||||
document: doc,
|
||||
stage: 'upload',
|
||||
stageLabel: '上传失败',
|
||||
errorMessage: workflow.upload.errorMessage || workflow.primaryError || '上传失败',
|
||||
stageLabel: t('kbWorkspace.failureModal.stageUploadFailed'),
|
||||
errorMessage: workflow.upload.errorMessage || workflow.primaryError || t('kbWorkspace.failureModal.stageUploadFailed'),
|
||||
latestJob: getLatestJobForDocument(doc, 'upload'),
|
||||
updatedAt: doc.updated_at || doc.latest_version?.created_at || null,
|
||||
}];
|
||||
@@ -232,11 +233,11 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
|
||||
const failureModalTitle = computed(() => {
|
||||
const map = {
|
||||
upload: '上传失败数据',
|
||||
clean: '清洗失败数据',
|
||||
sync: '同步失败数据',
|
||||
upload: t('kbWorkspace.failureModal.uploadData'),
|
||||
clean: t('kbWorkspace.failureModal.cleanData'),
|
||||
sync: t('kbWorkspace.failureModal.syncData'),
|
||||
};
|
||||
return failureModalType.value ? map[failureModalType.value] : '失败数据';
|
||||
return failureModalType.value ? map[failureModalType.value] : t('kbWorkspace.failureModal.generic');
|
||||
});
|
||||
|
||||
const documentById = computed(() =>
|
||||
@@ -273,7 +274,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
);
|
||||
|
||||
const selectedPathUploadHistoryItems = computed(() =>
|
||||
getPathUploadJobItems(selectedPathUploadHistoryJob.value),
|
||||
getPathUploadJobItems(selectedPathUploadHistoryJob.value, t),
|
||||
);
|
||||
|
||||
const selectedPathUploadHistorySelectedItems = computed(() => {
|
||||
@@ -290,7 +291,7 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
if (item.status === 'failed') {
|
||||
return {
|
||||
normalized: 'failed',
|
||||
label: '失败',
|
||||
label: t('kbWorkspace.status.failed'),
|
||||
className: getStatusBadgeClass('failed'),
|
||||
};
|
||||
}
|
||||
@@ -299,27 +300,27 @@ export function useKbWorkspaceComputed(state: KbWorkspaceState) {
|
||||
const latestStatus = String(doc?.latest_version?.status || doc?.status || '').toLowerCase();
|
||||
|
||||
if (latestStatus === 'processing') {
|
||||
return { normalized: 'processing', label: '清洗中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'processing', label: t('kbWorkspace.status.cleaning'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
if (['cleaned', 'ready'].includes(latestStatus)) {
|
||||
return { normalized: latestStatus, label: '已清洗', className: getStatusBadgeClass(latestStatus) };
|
||||
return { normalized: latestStatus, label: t('kbWorkspace.status.cleaned'), className: getStatusBadgeClass(latestStatus) };
|
||||
}
|
||||
if (latestStatus === 'syncing') {
|
||||
return { normalized: 'syncing', label: '同步中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'syncing', label: t('kbWorkspace.status.syncing'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
if (latestStatus === 'synced') {
|
||||
return { normalized: 'synced', label: '已同步', className: getStatusBadgeClass('synced') };
|
||||
return { normalized: 'synced', label: t('kbWorkspace.status.synced'), className: getStatusBadgeClass('synced') };
|
||||
}
|
||||
if (latestStatus === 'uploaded') {
|
||||
return { normalized: 'uploaded', label: '待清洗', className: getStatusBadgeClass('uploaded') };
|
||||
return { normalized: 'uploaded', label: t('kbWorkspace.status.pendingClean'), className: getStatusBadgeClass('uploaded') };
|
||||
}
|
||||
if (item.status === 'success' || item.documentId) {
|
||||
return { normalized: 'success', label: '已上传', className: getStatusBadgeClass('success') };
|
||||
return { normalized: 'success', label: t('kbWorkspace.status.uploaded'), className: getStatusBadgeClass('success') };
|
||||
}
|
||||
if (item.status === 'uploading') {
|
||||
return { normalized: 'uploading', label: '上传中', className: getStatusBadgeClass('processing') };
|
||||
return { normalized: 'uploading', label: t('kbWorkspace.status.uploading'), className: getStatusBadgeClass('processing') };
|
||||
}
|
||||
return { normalized: 'queued', label: '待上传', className: getStatusBadgeClass('queued') };
|
||||
return { normalized: 'queued', label: t('kbWorkspace.status.draft'), className: getStatusBadgeClass('queued') };
|
||||
};
|
||||
|
||||
const pathUploadSummary = computed(() => {
|
||||
|
||||
@@ -48,6 +48,8 @@ export function useKbWorkspaceData(
|
||||
selectedPathUploadHistoryJobId,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
kbJobPollingActive,
|
||||
latestPathUploadJob,
|
||||
@@ -63,7 +65,7 @@ export function useKbWorkspaceData(
|
||||
try {
|
||||
const result = await getKbGroupsSafe();
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载知识库分组失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadGroupsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ export function useKbWorkspaceData(
|
||||
}
|
||||
const result = await getKbGroupFilesSafe(groupId);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载文档列表失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadDocumentsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -126,13 +128,13 @@ export function useKbWorkspaceData(
|
||||
const hadActiveKbJobs = kbJobPollingActive.value;
|
||||
const result = await getKbJobsSafe();
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '加载任务列表失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.loadJobsFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
jobs.value = result.data;
|
||||
applyPathUploadJob(latestPathUploadJob.value);
|
||||
if (latestPathUploadJob.value && getPathUploadJobSummary(latestPathUploadJob.value).failed > 0) {
|
||||
if (latestPathUploadJob.value && getPathUploadJobSummary(latestPathUploadJob.value, t).failed > 0) {
|
||||
showPathUploadDetails.value = true;
|
||||
}
|
||||
if (
|
||||
|
||||
@@ -48,6 +48,8 @@ export function useKbWorkspaceDocuments(
|
||||
openDeleteConfirmDialog,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
filteredDocuments,
|
||||
selectedDocuments,
|
||||
@@ -86,10 +88,10 @@ export function useKbWorkspaceDocuments(
|
||||
};
|
||||
|
||||
const handleDeleteDocument = async (doc: KbDocumentItem) => {
|
||||
openDeleteConfirmDialog(`确认删除文档「${getDocumentDisplayTitle(doc)}」吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.deleteDocumentConfirm', { name: getDocumentDisplayTitle(doc, t) }), async () => {
|
||||
const result = await deleteKbDocument(doc.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '删除文档失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.deleteDocumentFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -98,7 +100,7 @@ export function useKbWorkspaceDocuments(
|
||||
selectedDocumentId.value = null;
|
||||
showRecordModal.value = false;
|
||||
}
|
||||
feedback.value = '文档已删除';
|
||||
feedback.value = t('kbWorkspace.msg.documentDeleted');
|
||||
feedbackType.value = 'success';
|
||||
await Promise.all([loadGroups(), loadDocuments(selectedGroupId.value), loadJobs()]);
|
||||
selectedDocumentVersions.value = [];
|
||||
@@ -108,7 +110,7 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchSync = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要批量同步的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToSync');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -123,10 +125,12 @@ export function useKbWorkspaceDocuments(
|
||||
const successCount = results.filter(({ result }) => result.ok).length;
|
||||
const failResults = results.filter(({ result }) => !result.ok);
|
||||
const failCount = failResults.length;
|
||||
const errors = failResults.map(({ doc, result }) => `${getDocumentDisplayTitle(doc)}: ${result.error || '同步失败'}`);
|
||||
const errors = failResults.map(({ doc, result }) =>
|
||||
`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.failureModal.stageSyncFailed')}`,
|
||||
);
|
||||
feedback.value = failCount
|
||||
? `批量同步任务已提交:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量同步任务已提交:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchSyncResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchSyncSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
if (successCount > 0) {
|
||||
startPathUploadPolling();
|
||||
@@ -139,12 +143,12 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchClean = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要清洗的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToClean');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!selectedCleanableDocuments.value.length) {
|
||||
feedback.value = '当前所选文档没有可重新清洗的项';
|
||||
feedback.value = t('kbWorkspace.msg.noDocumentsToClean');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -159,10 +163,12 @@ export function useKbWorkspaceDocuments(
|
||||
const successCount = results.filter(({ result }) => result.ok).length;
|
||||
const failResults = results.filter(({ result }) => !result.ok);
|
||||
const failCount = failResults.length;
|
||||
const errors = failResults.map(({ doc, result }) => `${getDocumentDisplayTitle(doc)}: ${result.error || '提交清洗失败'}`);
|
||||
const errors = failResults.map(({ doc, result }) =>
|
||||
`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.failureModal.stageCleanFailed')}`,
|
||||
);
|
||||
feedback.value = failCount
|
||||
? `批量清洗任务已提交:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量清洗任务已提交:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchCleanResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchCleanSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
if (successCount > 0) {
|
||||
startPathUploadPolling();
|
||||
@@ -175,12 +181,12 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
const handleBatchDelete = async () => {
|
||||
if (!selectedDocuments.value.length) {
|
||||
feedback.value = '请先选择要批量删除的文档';
|
||||
feedback.value = t('kbWorkspace.msg.selectDocumentsToDelete');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
openDeleteConfirmDialog(
|
||||
`确认批量删除已选中的 ${selectedDocuments.value.length} 条文档吗?会同步删除 Dify 对应文档。`,
|
||||
t('kbWorkspace.msg.batchDeleteDocumentsConfirm', { count: selectedDocuments.value.length }),
|
||||
async () => {
|
||||
batchSubmitting.value = true;
|
||||
let successCount = 0;
|
||||
@@ -193,12 +199,12 @@ export function useKbWorkspaceDocuments(
|
||||
successCount += 1;
|
||||
} else {
|
||||
failCount += 1;
|
||||
errors.push(`${getDocumentDisplayTitle(doc)}: ${result.error || '删除失败'}`);
|
||||
errors.push(`${getDocumentDisplayTitle(doc, t)}: ${result.error || t('kbWorkspace.msg.deleteDocumentFailed')}`);
|
||||
}
|
||||
}
|
||||
feedback.value = failCount
|
||||
? `批量删除完成:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量删除完成:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchDeleteResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchDeleteSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
selectedDocumentIds.value = [];
|
||||
await Promise.all([loadGroups(), loadDocuments(selectedGroupId.value), loadJobs()]);
|
||||
@@ -223,28 +229,30 @@ export function useKbWorkspaceDocuments(
|
||||
try {
|
||||
if (action === 'submit') {
|
||||
triggerUploadForDocument(item.document.id);
|
||||
feedback.value = `请重新为「${getDocumentDisplayTitle(item.document)}」选择文件后提交`;
|
||||
feedback.value = t('kbWorkspace.msg.reselectFile', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
return;
|
||||
}
|
||||
if (action === 'clean') {
|
||||
const result = await submitKbDocumentClean(item.document.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '重新清洗失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.recleanFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.message || `已重新提交清洗:${getDocumentDisplayTitle(item.document)}`;
|
||||
feedback.value = result.message || t('kbWorkspace.msg.recleanSubmitted', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
} else {
|
||||
const result = await syncKbDocumentToDify(item.document.id);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error ? `重新同步失败:${result.error}` : '重新同步失败';
|
||||
feedback.value = result.error
|
||||
? t('kbWorkspace.msg.resyncFailed', { detail: result.error })
|
||||
: t('kbWorkspace.failureModal.stageSyncFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.job?.message || `已重新提交同步:${getDocumentDisplayTitle(item.document)}`;
|
||||
feedback.value = result.job?.message || t('kbWorkspace.msg.resyncSubmitted', { name: getDocumentDisplayTitle(item.document, t) });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
}
|
||||
@@ -270,7 +278,7 @@ export function useKbWorkspaceDocuments(
|
||||
}
|
||||
|
||||
isSubmitting.value = true;
|
||||
feedback.value = '开始处理文件...';
|
||||
feedback.value = t('kbWorkspace.msg.processingFile');
|
||||
feedbackType.value = 'success';
|
||||
|
||||
if (activeUploadDocumentId.value) {
|
||||
@@ -278,10 +286,10 @@ export function useKbWorkspaceDocuments(
|
||||
if (!file) return;
|
||||
const result = await uploadKbDocumentVersion(activeUploadDocumentId.value, file);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '文件上传失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.uploadFailed');
|
||||
feedbackType.value = 'error';
|
||||
} else {
|
||||
feedback.value = result.message || `版本文件「${file.name}」上传成功,清洗已排队`;
|
||||
feedback.value = result.message || t('kbWorkspace.msg.versionUploaded', { file: file.name });
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
}
|
||||
@@ -296,7 +304,11 @@ export function useKbWorkspaceDocuments(
|
||||
for (let i = 0; i < fileArray.length; i++) {
|
||||
const file = fileArray[i];
|
||||
if (!file) continue;
|
||||
feedback.value = `正在上传 ${i + 1}/${fileArray.length}: ${file.name}`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadingProgress', {
|
||||
current: i + 1,
|
||||
total: fileArray.length,
|
||||
file: file.name,
|
||||
});
|
||||
|
||||
const createResult = await createKbDocument(selectedGroupId.value, {
|
||||
title: file.name,
|
||||
@@ -305,18 +317,21 @@ export function useKbWorkspaceDocuments(
|
||||
|
||||
if (!createResult.ok || !createResult.document) {
|
||||
failCount++;
|
||||
errors.push(`${file.name}: ${normalizeDuplicateDocumentError(createResult.error || '创建文档失败')}`);
|
||||
const createError = createResult.error
|
||||
? normalizeDuplicateDocumentError(createResult.error, t)
|
||||
: t('kbWorkspace.msg.createDocumentFailed');
|
||||
errors.push(`${file.name}: ${createError}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const uploadResult = await uploadKbDocumentVersion(createResult.document.id, file);
|
||||
if (!uploadResult.ok) {
|
||||
failCount++;
|
||||
const uploadError = uploadResult.error || '上传文档版本失败';
|
||||
const uploadError = uploadResult.error || t('kbWorkspace.msg.uploadVersionFailed');
|
||||
errors.push(`${file.name}: ${uploadError}`);
|
||||
const cleanupResult = await deleteKbDocument(createResult.document.id);
|
||||
if (!cleanupResult.ok) {
|
||||
errors.push(`${file.name}: 上传失败后未能自动清理空文档(${cleanupResult.error || '删除失败'})`);
|
||||
errors.push(`${file.name}: ${t('kbWorkspace.msg.uploadCleanupFailed', { detail: cleanupResult.error || t('kbWorkspace.msg.deleteDocumentFailed') })}`);
|
||||
}
|
||||
} else {
|
||||
successCount++;
|
||||
@@ -324,10 +339,14 @@ export function useKbWorkspaceDocuments(
|
||||
}
|
||||
|
||||
if (failCount > 0) {
|
||||
feedback.value = `上传完成:成功 ${successCount} 个,失败 ${failCount} 个。${errors[0] || ''}`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadSummary', {
|
||||
success: successCount,
|
||||
fail: failCount,
|
||||
detail: errors[0] || '',
|
||||
});
|
||||
feedbackType.value = successCount > 0 ? 'success' : 'error';
|
||||
} else {
|
||||
feedback.value = `成功上传 ${successCount} 个文件,清洗任务已排队`;
|
||||
feedback.value = t('kbWorkspace.msg.uploadAllSuccess', { count: successCount });
|
||||
feedbackType.value = 'success';
|
||||
}
|
||||
if (successCount > 0) {
|
||||
@@ -355,14 +374,16 @@ export function useKbWorkspaceDocuments(
|
||||
syncingDocumentId.value = null;
|
||||
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error ? `同步到 Dify 失败:${result.error}` : '同步到 Dify 失败';
|
||||
feedback.value = result.error
|
||||
? t('kbWorkspace.msg.syncDifyFailed', { detail: result.error })
|
||||
: t('kbWorkspace.msg.syncDifyFailedGeneric');
|
||||
feedbackType.value = 'error';
|
||||
await loadDocuments(selectedGroupId.value, { silent: true });
|
||||
await loadJobs();
|
||||
return;
|
||||
}
|
||||
|
||||
feedback.value = result.job?.message || '同步任务已提交,等待后台处理';
|
||||
feedback.value = result.job?.message || t('kbWorkspace.msg.syncSubmitted');
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
await loadDocuments(selectedGroupId.value, { silent: true });
|
||||
|
||||
@@ -46,6 +46,7 @@ export function useKbWorkspaceModals(
|
||||
selectedGroupId,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
const { getMarkdownUnavailableMessageForDoc } = computed;
|
||||
const { loadDocumentVersions, loadSourceInfoVersions, loadDocuments, loadJobs } = data;
|
||||
|
||||
@@ -78,7 +79,7 @@ export function useKbWorkspaceModals(
|
||||
const result = await getKbDocumentVersionSourceFile(version.id);
|
||||
openingSourceVersionId.value = null;
|
||||
if (!result.ok || !result.blob) {
|
||||
feedback.value = result.error || '读取原始文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.readSourceFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -112,7 +113,7 @@ export function useKbWorkspaceModals(
|
||||
markdownKind.value = payload.kind;
|
||||
markdownVersionLabel.value = payload.version
|
||||
? `v${payload.version.version_no} · ${payload.version.source_file_name}`
|
||||
: '暂无版本';
|
||||
: t('kbWorkspace.msg.noVersion');
|
||||
};
|
||||
|
||||
const openMarkdownEditor = async (doc: KbDocumentItem) => {
|
||||
@@ -127,7 +128,10 @@ export function useKbWorkspaceModals(
|
||||
const result = await getKbDocumentMarkdown(doc.id);
|
||||
isMarkdownLoading.value = false;
|
||||
if (!result.ok || !result.data) {
|
||||
markdownError.value = getMarkdownUnavailableMessageForDoc(doc, result.error || '读取清洗后的 Markdown 失败');
|
||||
markdownError.value = getMarkdownUnavailableMessageForDoc(
|
||||
doc,
|
||||
result.error || t('kbWorkspace.msg.readMarkdownFailed'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
applyMarkdownPayload(result.data);
|
||||
@@ -156,13 +160,13 @@ export function useKbWorkspaceModals(
|
||||
if (!result.ok || !result.data) {
|
||||
const currentDoc = documents.value.find((item) => item.id === markdownDocumentId.value) || null;
|
||||
markdownError.value = currentDoc
|
||||
? getMarkdownUnavailableMessageForDoc(currentDoc, result.error || '保存 Markdown 失败')
|
||||
: (result.error || '保存 Markdown 失败');
|
||||
? getMarkdownUnavailableMessageForDoc(currentDoc, result.error || t('kbWorkspace.msg.saveMarkdownFailed'))
|
||||
: (result.error || t('kbWorkspace.msg.saveMarkdownFailed'));
|
||||
return;
|
||||
}
|
||||
|
||||
applyMarkdownPayload(result.data);
|
||||
feedback.value = '清洗后的 Markdown 已保存';
|
||||
feedback.value = t('kbWorkspace.msg.markdownSaved');
|
||||
feedbackType.value = 'success';
|
||||
await loadDocuments(selectedGroupId.value);
|
||||
await loadJobs();
|
||||
|
||||
@@ -50,6 +50,8 @@ export function useKbWorkspacePathUpload(
|
||||
openDeleteConfirmDialog,
|
||||
} = state;
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const {
|
||||
pathUploadRunning,
|
||||
kbJobPollingActive,
|
||||
@@ -77,7 +79,12 @@ export function useKbWorkspacePathUpload(
|
||||
const updatePathUploadFeedback = () => {
|
||||
const summary = pathUploadSummary.value;
|
||||
if (!pathUploadTask.value.total) return;
|
||||
feedback.value = `路径上传进度:总计 ${summary.total} 条,待上传 ${summary.pending} 条,已上传 ${summary.uploaded} 条,失败 ${summary.failed} 条`;
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadProgress', {
|
||||
total: summary.total,
|
||||
pending: summary.pending,
|
||||
uploaded: summary.uploaded,
|
||||
failed: summary.failed,
|
||||
});
|
||||
feedbackType.value = summary.failed > 0 ? 'error' : 'success';
|
||||
};
|
||||
|
||||
@@ -102,9 +109,9 @@ export function useKbWorkspacePathUpload(
|
||||
const items = Array.isArray(payload.files)
|
||||
? payload.files.map((item: Record<string, unknown>, index: number) => ({
|
||||
key: String(item.relative_path || item.original_name || index),
|
||||
title: String(item.original_name || item.relative_path || `文件${index + 1}`),
|
||||
title: String(item.original_name || item.relative_path || t('kbWorkspace.errors.fileFallback', { index: index + 1 })),
|
||||
displayPath: String(item.relative_path || item.original_name || ''),
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || '本地目录',
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || t('kbWorkspace.errors.localFolder'),
|
||||
status: (['queued', 'uploading', 'success', 'failed'].includes(String(item.status)) ? item.status : 'queued') as PathUploadStatus,
|
||||
error: item.error as string | undefined,
|
||||
documentId: item.document_id as number | undefined,
|
||||
@@ -148,7 +155,7 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const openPathUploadModal = () => {
|
||||
if (pathUploadRunning.value) {
|
||||
feedback.value = '有文件正在上传请稍等再试~';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadBusy');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -224,17 +231,17 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const handleConfirmPathUpload = async () => {
|
||||
if (pathUploadRunning.value) {
|
||||
feedback.value = '有文件正在上传请稍等再试~';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadBusy');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!selectedGroupId.value) {
|
||||
feedback.value = '请先选择知识库分组';
|
||||
feedback.value = t('kbWorkspace.msg.selectGroupFirst');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
if (!pathUploadSelectedFiles.value.length) {
|
||||
feedback.value = '请先选择至少一个本地目录或文件';
|
||||
feedback.value = t('kbWorkspace.msg.selectPathFiles');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -249,13 +256,13 @@ export function useKbWorkspacePathUpload(
|
||||
})),
|
||||
});
|
||||
if (!createResult.ok || !createResult.job) {
|
||||
feedback.value = createResult.error || '创建上传路径任务失败';
|
||||
feedback.value = createResult.error || t('kbWorkspace.msg.createPathJobFailed');
|
||||
feedbackType.value = 'error';
|
||||
isPathUploadStaging.value = false;
|
||||
return;
|
||||
}
|
||||
const createdJob = createResult.job;
|
||||
const existingJobItems = getPathUploadJobItems(createdJob);
|
||||
const existingJobItems = getPathUploadJobItems(createdJob, t);
|
||||
const existingItemMap = new Map(existingJobItems.map((item) => [item.displayPath, item]));
|
||||
const selectedPathSet = new Set(pathUploadSelectedFiles.value.map((item) => item.displayPath));
|
||||
const pendingFiles = pathUploadSelectedFiles.value.filter((item) => {
|
||||
@@ -302,7 +309,9 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const stageResult = await uploadKbPathJobFile(createdJob.id, item.file, item.displayPath);
|
||||
if (!stageResult.ok) {
|
||||
const errorMessage = normalizeDuplicateDocumentError(stageResult.error || '路径文件暂存失败');
|
||||
const errorMessage = stageResult.error
|
||||
? normalizeDuplicateDocumentError(stageResult.error, t)
|
||||
: t('kbWorkspace.msg.pathStageFailed');
|
||||
const failedResult = await markKbPathJobFileFailed(createdJob.id, {
|
||||
relative_path: item.displayPath,
|
||||
original_name: item.file.name,
|
||||
@@ -345,7 +354,7 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
isPathUploadStaging.value = false;
|
||||
pathUploadTask.value.currentFile = '';
|
||||
feedback.value = '路径文件已逐个上传并提交清洗';
|
||||
feedback.value = t('kbWorkspace.msg.pathUploadDone');
|
||||
feedbackType.value = 'success';
|
||||
startPathUploadPolling();
|
||||
resetPathUploadDraft();
|
||||
@@ -354,14 +363,16 @@ export function useKbWorkspacePathUpload(
|
||||
|
||||
const handleDeletePathUploadItem = async (job: KbJob | null, item: PathUploadTaskItem) => {
|
||||
if (!job) return;
|
||||
openDeleteConfirmDialog(`确认删除路径文件「${item.displayPath || item.title}」吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.deletePathFileConfirm', { path: item.displayPath || item.title }), async () => {
|
||||
const result = await deleteKbPathJobFile(job.id, item.displayPath);
|
||||
if (!result.ok) {
|
||||
feedback.value = result.error || '删除路径上传文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.deletePathFileFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
feedback.value = result.document_deleted ? '已删除路径记录,并同步删除对应文档' : '已删除路径记录';
|
||||
feedback.value = result.document_deleted
|
||||
? t('kbWorkspace.msg.pathRecordDeletedWithDoc')
|
||||
: t('kbWorkspace.msg.pathRecordDeleted');
|
||||
feedbackType.value = 'success';
|
||||
if (pathUploadTask.value.items.length <= 1) {
|
||||
showPathUploadDetails.value = false;
|
||||
@@ -374,11 +385,11 @@ export function useKbWorkspacePathUpload(
|
||||
const job = selectedPathUploadHistoryJob.value;
|
||||
const items = selectedPathUploadHistorySelectedItems.value;
|
||||
if (!job || !items.length) {
|
||||
feedback.value = '请先选择要删除的文件';
|
||||
feedback.value = t('kbWorkspace.msg.selectPathFilesToDelete');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
openDeleteConfirmDialog(`确认批量删除已选中的 ${items.length} 条路径文件吗?`, async () => {
|
||||
openDeleteConfirmDialog(t('kbWorkspace.msg.batchDeletePathConfirm', { count: items.length }), async () => {
|
||||
deletingPathUploadBatch.value = true;
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
@@ -391,11 +402,11 @@ export function useKbWorkspacePathUpload(
|
||||
continue;
|
||||
}
|
||||
failCount += 1;
|
||||
errors.push(`${item.displayPath}: ${result.error || '删除失败'}`);
|
||||
errors.push(`${item.displayPath}: ${result.error || t('kbWorkspace.msg.deleteDocumentFailed')}`);
|
||||
}
|
||||
feedback.value = failCount
|
||||
? `批量删除完成:成功 ${successCount} 条,失败 ${failCount} 条。${errors[0] || ''}`
|
||||
: `批量删除完成:共成功 ${successCount} 条`;
|
||||
? t('kbWorkspace.msg.batchDeletePathResult', { success: successCount, fail: failCount, detail: errors[0] || '' })
|
||||
: t('kbWorkspace.msg.batchDeletePathSuccess', { success: successCount });
|
||||
feedbackType.value = failCount ? 'error' : 'success';
|
||||
selectedPathUploadHistoryItemKeys.value = [];
|
||||
await Promise.all([
|
||||
@@ -419,13 +430,15 @@ export function useKbWorkspacePathUpload(
|
||||
const result = await retryFailedKbPathUploadJob(job.id, relativePaths?.length ? { relative_paths: relativePaths } : {});
|
||||
retryingPathUploadKey.value = '';
|
||||
if (!result.ok || !result.job) {
|
||||
feedback.value = result.error || '重试失败文件失败';
|
||||
feedback.value = result.error || t('kbWorkspace.msg.retryPathFailed');
|
||||
feedbackType.value = 'error';
|
||||
return;
|
||||
}
|
||||
applyPathUploadJob(result.job);
|
||||
startPathUploadPolling();
|
||||
feedback.value = relativePaths?.length === 1 ? '已重新提交该失败文件' : '已重新提交失败文件';
|
||||
feedback.value = relativePaths?.length === 1
|
||||
? t('kbWorkspace.msg.retryPathOne')
|
||||
: t('kbWorkspace.msg.retryPathAll');
|
||||
feedbackType.value = 'success';
|
||||
await bridge.refreshWorkflowStatusOnly();
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ import { useKbWorkspaceData } from './kb-workspace/useKbWorkspaceData';
|
||||
import { useKbWorkspaceDocuments } from './kb-workspace/useKbWorkspaceDocuments';
|
||||
import { useKbWorkspaceModals } from './kb-workspace/useKbWorkspaceModals';
|
||||
import { useKbWorkspacePathUpload } from './kb-workspace/useKbWorkspacePathUpload';
|
||||
import type { KbDocumentItem } from '../api/kb.api';
|
||||
|
||||
export interface UseKbWorkspaceOptions {
|
||||
embedded?: boolean;
|
||||
@@ -108,7 +109,7 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
});
|
||||
|
||||
watch(selectedPathUploadHistoryJob, (job) => {
|
||||
const validKeys = new Set(getPathUploadJobItems(job).map((item) => item.key));
|
||||
const validKeys = new Set(getPathUploadJobItems(job, t).map((item) => item.key));
|
||||
selectedPathUploadHistoryItemKeys.value = selectedPathUploadHistoryItemKeys.value.filter((key) => validKeys.has(key));
|
||||
if (!job) {
|
||||
selectedPathUploadHistoryItemKeys.value = [];
|
||||
@@ -128,6 +129,37 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
pathUpload.stopPathUploadPollTimer();
|
||||
});
|
||||
|
||||
const { t } = state;
|
||||
|
||||
const batchActionLabel = (action: 'clean' | 'sync' | 'delete', submitting: boolean, count: number) => {
|
||||
if (submitting) return t('kbWorkspace.common.processing');
|
||||
const keys = {
|
||||
clean: ['batchClean', 'batchCleanCount'],
|
||||
sync: ['batchSync', 'batchSyncCount'],
|
||||
delete: ['batchDelete', 'batchDeleteCount'],
|
||||
} as const;
|
||||
const [base, withCount] = keys[action];
|
||||
return count > 0
|
||||
? t(`kbWorkspace.documents.${withCount}`, { count })
|
||||
: t(`kbWorkspace.documents.${base}`);
|
||||
};
|
||||
|
||||
const pathUploadBatchDeleteLabel = (submitting: boolean, count: number) => {
|
||||
if (submitting) return t('kbWorkspace.pathUpload.deleting');
|
||||
return count > 0
|
||||
? t('kbWorkspace.pathUpload.batchDeleteCount', { count })
|
||||
: t('kbWorkspace.pathUpload.batchDelete');
|
||||
};
|
||||
|
||||
const documentEmptyMessage = (documentsLength: number, hasKeyword: boolean) => {
|
||||
if (documentsLength === 0) return t('kbWorkspace.documents.emptyNoDocs');
|
||||
if (hasKeyword) return t('kbWorkspace.documents.emptyNoSearchMatch');
|
||||
return t('kbWorkspace.documents.emptyNoFilterMatch');
|
||||
};
|
||||
|
||||
const documentDisplayName = (doc: KbDocumentItem | null | undefined, id: number | null) =>
|
||||
doc ? getDocumentDisplayTitle(doc, t) : t('kbWorkspace.documents.documentFallback', { id });
|
||||
|
||||
// reactive 便于模板以 kb.xxx 统一访问,ref/computed 在属性读取时自动解包
|
||||
return reactive({
|
||||
...state,
|
||||
@@ -140,17 +172,22 @@ export function useKbWorkspace(options: UseKbWorkspaceOptions = {}) {
|
||||
getDocumentWorkflowState: computed.resolveWorkflowState,
|
||||
formatDateTime,
|
||||
formatFileSize,
|
||||
getDocumentDisplayTitle,
|
||||
getDocumentDisplayDescription,
|
||||
getStatusLabel,
|
||||
getDocumentDisplayTitle: (doc: KbDocumentItem) => getDocumentDisplayTitle(doc, t),
|
||||
getDocumentDisplayDescription: (doc: KbDocumentItem) => getDocumentDisplayDescription(doc, t),
|
||||
getStatusLabel: (status: string | null | undefined) => getStatusLabel(status, t),
|
||||
getStatusBadgeClass,
|
||||
getPathUploadJobItems,
|
||||
hasRetryablePathUploadFailure,
|
||||
getPathUploadJobSummary,
|
||||
getPathUploadJobItems: (job: Parameters<typeof getPathUploadJobItems>[0]) => getPathUploadJobItems(job, t),
|
||||
hasRetryablePathUploadFailure: (job: Parameters<typeof hasRetryablePathUploadFailure>[0]) =>
|
||||
hasRetryablePathUploadFailure(job, t),
|
||||
getPathUploadJobSummary: (job: Parameters<typeof getPathUploadJobSummary>[0]) => getPathUploadJobSummary(job, t),
|
||||
DOCUMENT_PAGE_SIZE_OPTIONS,
|
||||
FAILURE_PAGE_SIZE,
|
||||
PATH_UPLOAD_BATCH_SIZE,
|
||||
PATH_UPLOAD_BATCH_INTERVAL_MS,
|
||||
PATH_UPLOAD_CONCURRENCY,
|
||||
batchActionLabel,
|
||||
pathUploadBatchDeleteLabel,
|
||||
documentEmptyMessage,
|
||||
documentDisplayName,
|
||||
});
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
* 文档标题、时间、文件大小与状态徽标等纯展示工具。
|
||||
*/
|
||||
import type { KbDocumentItem } from '../api/kb.api';
|
||||
import type { KbTranslateFn } from './kb-i18n.types';
|
||||
|
||||
export const formatDateTime = (value?: string | null) => {
|
||||
if (!value) return '--';
|
||||
@@ -27,40 +28,43 @@ const trimPathText = (value?: string | null) => {
|
||||
return text.split(/[\\/]/).filter(Boolean).pop() || text;
|
||||
};
|
||||
|
||||
export const getDocumentDisplayTitle = (doc: KbDocumentItem) => trimPathText(doc.title) || '未命名文档';
|
||||
const STATUS_I18N_KEYS: Record<string, string> = {
|
||||
draft: 'kbWorkspace.status.draft',
|
||||
uploaded: 'kbWorkspace.status.uploaded',
|
||||
processing: 'kbWorkspace.status.processing',
|
||||
cleaned: 'kbWorkspace.status.cleaned',
|
||||
ready: 'kbWorkspace.status.ready',
|
||||
synced: 'kbWorkspace.status.synced',
|
||||
syncing: 'kbWorkspace.status.syncing',
|
||||
failed: 'kbWorkspace.status.failed',
|
||||
queued: 'kbWorkspace.status.queued',
|
||||
running: 'kbWorkspace.status.running',
|
||||
success: 'kbWorkspace.status.success',
|
||||
cancelled: 'kbWorkspace.status.cancelled',
|
||||
};
|
||||
|
||||
export const getDocumentDisplayDescription = (doc: KbDocumentItem) => {
|
||||
export const getDocumentDisplayTitle = (doc: KbDocumentItem, t: KbTranslateFn) =>
|
||||
trimPathText(doc.title) || t('kbWorkspace.status.unnamedDocument');
|
||||
|
||||
export const getDocumentDisplayDescription = (doc: KbDocumentItem, t: KbTranslateFn) => {
|
||||
const text = trimPathText(doc.description);
|
||||
return text || getDocumentDisplayTitle(doc);
|
||||
return text || getDocumentDisplayTitle(doc, t);
|
||||
};
|
||||
|
||||
/** 将后端重复文档错误归一为前端可展示的简短文案 */
|
||||
export const normalizeDuplicateDocumentError = (message?: string | null) => {
|
||||
export const normalizeDuplicateDocumentError = (message: string | null | undefined, t: KbTranslateFn) => {
|
||||
const text = String(message || '').trim();
|
||||
if (!text) return '知识库接口请求失败';
|
||||
if (!text) return t('kbWorkspace.errors.apiRequestFailed');
|
||||
if (text.includes('当前分组下已存在同名文档') || text.includes('上传失败,文件已存在')) {
|
||||
return '上传失败,文件已存在';
|
||||
return t('kbWorkspace.errors.duplicateFile');
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
export const getStatusLabel = (status?: string | null) => {
|
||||
export const getStatusLabel = (status: string | null | undefined, t: KbTranslateFn) => {
|
||||
const normalized = String(status || '').toLowerCase();
|
||||
const map: Record<string, string> = {
|
||||
draft: '待上传',
|
||||
uploaded: '已上传',
|
||||
processing: '清洗中',
|
||||
cleaned: '已清洗',
|
||||
ready: '已就绪',
|
||||
synced: '已同步',
|
||||
syncing: '同步中',
|
||||
failed: '失败',
|
||||
queued: '排队中',
|
||||
running: '进行中',
|
||||
success: '成功',
|
||||
cancelled: '已取消',
|
||||
};
|
||||
return map[normalized] || status || '未知状态';
|
||||
const key = STATUS_I18N_KEYS[normalized];
|
||||
return key ? t(key) : (status || t('kbWorkspace.status.unknown'));
|
||||
};
|
||||
|
||||
export const getStatusBadgeClass = (status?: string | null) => {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/** 知识库作业面 i18n 翻译函数(vue-i18n `t` 的简化类型) */
|
||||
export type KbTranslateFn = (key: string, params?: Record<string, unknown>) => string;
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import type { KbJob } from '../api/kb.api';
|
||||
import type { PathUploadStatus, PathUploadTaskItem } from '../types/kb-workspace.types';
|
||||
import type { KbTranslateFn } from './kb-i18n.types';
|
||||
|
||||
export const getPathUploadJobProgress = (job: KbJob | null) => {
|
||||
const payload = job?.payload_json || {};
|
||||
@@ -32,22 +33,22 @@ export const getPathUploadJobPriority = (job: KbJob) => {
|
||||
return (hasProgress ? 1000 : 0) + statusScore;
|
||||
};
|
||||
|
||||
export const getPathUploadJobItems = (job: KbJob | null): PathUploadTaskItem[] => {
|
||||
export const getPathUploadJobItems = (job: KbJob | null, t: KbTranslateFn): PathUploadTaskItem[] => {
|
||||
if (!job || job.job_type !== 'path_upload') return [];
|
||||
const payload = job.payload_json || {};
|
||||
const files = Array.isArray(payload.files) ? payload.files : [];
|
||||
const failedCount = files.filter((item: { status?: string }) => String(item?.status || '').toLowerCase() === 'failed').length;
|
||||
return files.map((item: Record<string, unknown>, index: number) => ({
|
||||
key: `${job.id}-${item.relative_path || item.original_name || index}`,
|
||||
title: String(item.original_name || item.relative_path || `文件${index + 1}`),
|
||||
title: String(item.original_name || item.relative_path || t('kbWorkspace.errors.fileFallback', { index: index + 1 })),
|
||||
displayPath: String(item.relative_path || item.original_name || ''),
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || '本地目录',
|
||||
rootLabel: String(item.relative_path || item.original_name || '').split('/')[0] || t('kbWorkspace.errors.localFolder'),
|
||||
status: (['queued', 'uploading', 'success', 'failed'].includes(String(item.status))
|
||||
? item.status
|
||||
: 'queued') as PathUploadStatus,
|
||||
error: (item.error as string | undefined)
|
||||
|| (String(item.status || '').toLowerCase() === 'failed' && failedCount === 1
|
||||
? (job.error_message || job.message || '上传失败')
|
||||
? (job.error_message || job.message || t('kbWorkspace.errors.uploadFailed'))
|
||||
: undefined),
|
||||
documentId: (item.document_id as number | undefined) || undefined,
|
||||
retryable: Boolean(String(item.staged_path || '').trim()) && String(item.status || '').toLowerCase() === 'failed',
|
||||
@@ -56,11 +57,11 @@ export const getPathUploadJobItems = (job: KbJob | null): PathUploadTaskItem[] =
|
||||
}));
|
||||
};
|
||||
|
||||
export const hasRetryablePathUploadFailure = (job: KbJob | null) =>
|
||||
getPathUploadJobItems(job).some((item) => item.retryable);
|
||||
export const hasRetryablePathUploadFailure = (job: KbJob | null, t: KbTranslateFn) =>
|
||||
getPathUploadJobItems(job, t).some((item) => item.retryable);
|
||||
|
||||
export const getPathUploadJobSummary = (job: KbJob | null) => {
|
||||
const items = getPathUploadJobItems(job);
|
||||
export const getPathUploadJobSummary = (job: KbJob | null, t: KbTranslateFn) => {
|
||||
const items = getPathUploadJobItems(job, t);
|
||||
const total = Number(job?.payload_json?.total_files || job?.result_json?.total || items.length || 0);
|
||||
const success = Number(job?.result_json?.success || items.filter((item) => item.status === 'success').length || 0);
|
||||
const failed = Number(job?.result_json?.failed || items.filter((item) => item.status === 'failed').length || 0);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import type { KbDocumentItem, KbJob } from '../api/kb.api';
|
||||
import { IDLE_BADGE_CLASS, type WorkflowStageState } from '../types/kb-workspace.types';
|
||||
import { getStatusBadgeClass } from './kb-display.utils';
|
||||
import type { KbTranslateFn } from './kb-i18n.types';
|
||||
|
||||
export const isUnreadableErrorMessage = (value: string | null | undefined) => {
|
||||
const text = String(value || '').trim();
|
||||
@@ -17,27 +18,24 @@ export const isUnreadableErrorMessage = (value: string | null | undefined) => {
|
||||
export const normalizeWorkflowErrorMessage = (
|
||||
value: string | null | undefined,
|
||||
stage: 'upload' | 'clean' | 'sync',
|
||||
t: KbTranslateFn,
|
||||
) => {
|
||||
const text = String(value || '').trim();
|
||||
if (!text) return null;
|
||||
const upper = text.toUpperCase();
|
||||
if (isUnreadableErrorMessage(text)) {
|
||||
if (stage === 'clean') {
|
||||
return '历史失败任务原因不可读,请重新点击“清洗数据”发起清洗';
|
||||
}
|
||||
if (stage === 'sync') {
|
||||
return '历史同步失败原因不可读,请重新发起同步';
|
||||
}
|
||||
return '历史上传失败原因不可读,请重新上传文件';
|
||||
if (stage === 'clean') return t('kbWorkspace.errors.unreadableClean');
|
||||
if (stage === 'sync') return t('kbWorkspace.errors.unreadableSync');
|
||||
return t('kbWorkspace.errors.unreadableUpload');
|
||||
}
|
||||
if (upper.includes('LEGACY_CLEAN_TASK_RECOVERED_MANUALLY')) {
|
||||
return '历史遗留清洗任务已人工回收,请重新点击“清洗数据”发起清洗';
|
||||
return t('kbWorkspace.errors.legacyCleanRecovered');
|
||||
}
|
||||
if (upper.includes('SOURCE_FILE_NOT_FOUND') || text.includes('源文件不存在')) {
|
||||
return '原始文件不存在,请重新上传后再清洗';
|
||||
return t('kbWorkspace.errors.sourceFileNotFound');
|
||||
}
|
||||
if (upper.includes('CLEAN_TIMEOUT') || text.includes('清洗超时')) {
|
||||
return '文件清洗超时,请稍后重试;若多次失败,请检查源文件是否损坏';
|
||||
return t('kbWorkspace.errors.cleanTimeout');
|
||||
}
|
||||
return text;
|
||||
};
|
||||
@@ -69,6 +67,7 @@ export type GetLatestJobForDocument = ReturnType<typeof buildGetLatestJobForDocu
|
||||
export const getDocumentWorkflowState = (
|
||||
doc: KbDocumentItem,
|
||||
getLatestJobForDocument: GetLatestJobForDocument,
|
||||
t: KbTranslateFn,
|
||||
) => {
|
||||
const latestStatus = String(doc.latest_version?.status || '').toLowerCase();
|
||||
const uploadJob = getLatestJobForDocument(doc, 'upload');
|
||||
@@ -76,72 +75,73 @@ export const getDocumentWorkflowState = (
|
||||
const syncJob = getLatestJobForDocument(doc, 'sync_dify');
|
||||
|
||||
const uploadStage: WorkflowStageState = !doc.latest_version
|
||||
? { code: 'pending', label: '待上传', className: getStatusBadgeClass('draft') }
|
||||
? { code: 'pending', label: t('kbWorkspace.status.draft'), className: getStatusBadgeClass('draft') }
|
||||
: uploadJob?.status === 'failed'
|
||||
? {
|
||||
code: 'failed',
|
||||
label: '失败',
|
||||
label: t('kbWorkspace.status.failed'),
|
||||
className: getStatusBadgeClass('failed'),
|
||||
errorMessage: normalizeWorkflowErrorMessage(uploadJob.error_message || uploadJob.message, 'upload'),
|
||||
errorMessage: normalizeWorkflowErrorMessage(uploadJob.error_message || uploadJob.message, 'upload', t),
|
||||
}
|
||||
: { code: 'success', label: '已完成', className: getStatusBadgeClass('success') };
|
||||
: { code: 'success', label: t('kbWorkspace.status.done'), className: getStatusBadgeClass('success') };
|
||||
|
||||
let cleanStage: WorkflowStageState;
|
||||
if (!doc.latest_version) {
|
||||
cleanStage = { code: 'idle', label: '未开始', className: IDLE_BADGE_CLASS };
|
||||
cleanStage = { code: 'idle', label: t('kbWorkspace.status.idle'), className: IDLE_BADGE_CLASS };
|
||||
} else if (cleanJob?.status === 'failed' || latestStatus === 'failed') {
|
||||
cleanStage = {
|
||||
code: 'failed',
|
||||
label: '失败',
|
||||
label: t('kbWorkspace.status.failed'),
|
||||
className: getStatusBadgeClass('failed'),
|
||||
errorMessage: normalizeWorkflowErrorMessage(
|
||||
cleanJob?.error_message || doc.latest_version?.error_message || cleanJob?.message || null,
|
||||
'clean',
|
||||
t,
|
||||
),
|
||||
};
|
||||
} else if (['cleaned', 'ready', 'syncing', 'synced'].includes(latestStatus)) {
|
||||
cleanStage = { code: 'success', label: '已完成', className: getStatusBadgeClass('success') };
|
||||
cleanStage = { code: 'success', label: t('kbWorkspace.status.done'), className: getStatusBadgeClass('success') };
|
||||
} else if (['running', 'queued'].includes(String(cleanJob?.status || '').toLowerCase()) || latestStatus === 'processing') {
|
||||
cleanStage = {
|
||||
code: 'running',
|
||||
label: latestStatus === 'processing' ? '清洗中' : '待清洗',
|
||||
label: latestStatus === 'processing' ? t('kbWorkspace.status.cleaning') : t('kbWorkspace.status.pendingClean'),
|
||||
className: getStatusBadgeClass(latestStatus === 'processing' ? 'processing' : 'uploaded'),
|
||||
};
|
||||
} else if (latestStatus === 'uploaded') {
|
||||
cleanStage = { code: 'pending', label: '待清洗', className: getStatusBadgeClass('uploaded') };
|
||||
cleanStage = { code: 'pending', label: t('kbWorkspace.status.pendingClean'), className: getStatusBadgeClass('uploaded') };
|
||||
} else {
|
||||
cleanStage = { code: 'idle', label: '未开始', className: IDLE_BADGE_CLASS };
|
||||
cleanStage = { code: 'idle', label: t('kbWorkspace.status.idle'), className: IDLE_BADGE_CLASS };
|
||||
}
|
||||
|
||||
let syncStage: WorkflowStageState;
|
||||
if (!doc.latest_version || cleanStage.code === 'failed') {
|
||||
syncStage = { code: 'idle', label: '未开始', className: IDLE_BADGE_CLASS };
|
||||
syncStage = { code: 'idle', label: t('kbWorkspace.status.idle'), className: IDLE_BADGE_CLASS };
|
||||
} else if (syncJob?.status === 'failed') {
|
||||
syncStage = {
|
||||
code: 'failed',
|
||||
label: '失败',
|
||||
label: t('kbWorkspace.status.failed'),
|
||||
className: getStatusBadgeClass('failed'),
|
||||
errorMessage: normalizeWorkflowErrorMessage(syncJob.error_message || syncJob.message, 'sync'),
|
||||
errorMessage: normalizeWorkflowErrorMessage(syncJob.error_message || syncJob.message, 'sync', t),
|
||||
};
|
||||
} else if (latestStatus === 'synced' || syncJob?.status === 'success') {
|
||||
syncStage = { code: 'success', label: '已完成', className: getStatusBadgeClass('success') };
|
||||
syncStage = { code: 'success', label: t('kbWorkspace.status.done'), className: getStatusBadgeClass('success') };
|
||||
} else if (['running', 'queued'].includes(String(syncJob?.status || '').toLowerCase()) || latestStatus === 'syncing') {
|
||||
syncStage = {
|
||||
code: 'running',
|
||||
label: latestStatus === 'syncing' ? '同步中' : '待同步',
|
||||
label: latestStatus === 'syncing' ? t('kbWorkspace.status.syncing') : t('kbWorkspace.status.pendingSync'),
|
||||
className: getStatusBadgeClass(latestStatus === 'syncing' ? 'processing' : 'uploaded'),
|
||||
};
|
||||
} else if (['cleaned', 'ready'].includes(latestStatus)) {
|
||||
syncStage = { code: 'pending', label: '待同步', className: getStatusBadgeClass('uploaded') };
|
||||
syncStage = { code: 'pending', label: t('kbWorkspace.status.pendingSync'), className: getStatusBadgeClass('uploaded') };
|
||||
} else {
|
||||
syncStage = { code: 'idle', label: '未开始', className: IDLE_BADGE_CLASS };
|
||||
syncStage = { code: 'idle', label: t('kbWorkspace.status.idle'), className: IDLE_BADGE_CLASS };
|
||||
}
|
||||
|
||||
const primaryError =
|
||||
syncStage.errorMessage ||
|
||||
cleanStage.errorMessage ||
|
||||
uploadStage.errorMessage ||
|
||||
normalizeWorkflowErrorMessage(doc.latest_version?.error_message, 'clean') ||
|
||||
normalizeWorkflowErrorMessage(doc.latest_version?.error_message, 'clean', t) ||
|
||||
null;
|
||||
|
||||
return {
|
||||
@@ -155,39 +155,42 @@ export const getDocumentWorkflowState = (
|
||||
export const getWorkflowBadges = (
|
||||
doc: KbDocumentItem,
|
||||
getLatestJobForDocument: GetLatestJobForDocument,
|
||||
t: KbTranslateFn,
|
||||
) => {
|
||||
const workflow = getDocumentWorkflowState(doc, getLatestJobForDocument);
|
||||
const workflow = getDocumentWorkflowState(doc, getLatestJobForDocument, t);
|
||||
return [
|
||||
{ label: '上传', value: workflow.upload.label, className: workflow.upload.className },
|
||||
{ label: '清洗', value: workflow.clean.label, className: workflow.clean.className },
|
||||
{ label: '同步', value: workflow.sync.label, className: workflow.sync.className },
|
||||
{ label: t('kbWorkspace.workflow.upload'), value: workflow.upload.label, className: workflow.upload.className },
|
||||
{ label: t('kbWorkspace.workflow.clean'), value: workflow.clean.label, className: workflow.clean.className },
|
||||
{ label: t('kbWorkspace.workflow.sync'), value: workflow.sync.label, className: workflow.sync.className },
|
||||
];
|
||||
};
|
||||
|
||||
export const getMarkdownUnavailableMessage = (
|
||||
doc: KbDocumentItem,
|
||||
_getLatestJobForDocument: GetLatestJobForDocument,
|
||||
t: KbTranslateFn,
|
||||
fallback?: string | null,
|
||||
) => {
|
||||
const latestStatus = String(doc.latest_version?.status || '').toLowerCase();
|
||||
const normalizedReason = normalizeWorkflowErrorMessage(
|
||||
doc.latest_version?.error_message,
|
||||
'clean',
|
||||
t,
|
||||
);
|
||||
|
||||
if (latestStatus === 'failed') {
|
||||
return normalizedReason
|
||||
? `当前文档清洗失败,尚未生成 Markdown。失败原因:${normalizedReason}`
|
||||
: '当前文档清洗失败,尚未生成 Markdown,请重新清洗后重试';
|
||||
? t('kbWorkspace.msg.markdownFailedWithReason', { reason: normalizedReason })
|
||||
: t('kbWorkspace.msg.markdownFailedRetry');
|
||||
}
|
||||
|
||||
if (latestStatus === 'processing') {
|
||||
return '当前文档正在清洗中,暂未生成 Markdown,请稍后再试';
|
||||
return t('kbWorkspace.msg.markdownProcessing');
|
||||
}
|
||||
|
||||
if (latestStatus === 'uploaded') {
|
||||
return '当前文档待清洗,暂未生成 Markdown,请先发起清洗';
|
||||
return t('kbWorkspace.msg.markdownPendingClean');
|
||||
}
|
||||
|
||||
return fallback || '当前文档尚未生成 Markdown';
|
||||
return fallback || t('kbWorkspace.msg.markdownNotGenerated');
|
||||
};
|
||||
@@ -3,8 +3,8 @@
|
||||
* features/kb/views/KbWorkspaceView.vue
|
||||
* 知识库作业面视图壳:模板与弹窗布局,业务逻辑见 useKbWorkspace。
|
||||
*/
|
||||
import { ArrowLeft, BookOpen, ChevronDown, ChevronUp, FileText, Info, RefreshCw, Search, Trash2, Upload, X } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { ArrowLeft, BookOpen, ChevronDown, ChevronUp, FileText, Info, RefreshCw, Search, Trash2, Upload } from 'lucide-vue-next';
|
||||
import KbWorkspaceOverlays from '../components/KbWorkspaceOverlays.vue';
|
||||
import { useKbWorkspace } from '../composables/useKbWorkspace';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -131,13 +131,12 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
/>
|
||||
<section class="kb-ws-section">
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h2 class="text-lg font-semibold text-primary">分组列表</h2>
|
||||
<span class="text-xs text-muted">接口壳已接入</span>
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.sidebar.groupsTitle') }}</h2>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isLoading" class="py-10 text-center text-sm text-muted">正在加载分组...</div>
|
||||
<div v-if="kb.isLoading" class="py-10 text-center text-sm text-muted">{{ kb.t('kbWorkspace.sidebar.loadingGroups') }}</div>
|
||||
<div v-else-if="kb.groups.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
暂无知识库分组。后续接通 `/api/kb/groups` 后将在这里显示真实数据。
|
||||
{{ kb.t('kbWorkspace.sidebar.emptyGroups') }}
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<button
|
||||
@@ -150,7 +149,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate font-semibold">{{ group.name }}</div>
|
||||
<div class="mt-1 text-sm opacity-80">{{ group.description || '暂无描述' }}</div>
|
||||
<div class="mt-1 text-sm opacity-80">{{ group.description || kb.t('kbWorkspace.sidebar.noDescription') }}</div>
|
||||
</div>
|
||||
<span class="rounded-full bg-surface/70 px-2 py-1 text-xs ">
|
||||
{{ group.document_count ?? 0 }}
|
||||
@@ -165,7 +164,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<div class="mb-4 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 class="text-lg font-semibold text-primary">文档列表</h2>
|
||||
<h2 class="text-lg font-semibold text-primary">{{ kb.t('kbWorkspace.documents.title') }}</h2>
|
||||
<div class="group relative">
|
||||
<button
|
||||
type="button"
|
||||
@@ -174,7 +173,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<Info class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
<div class="pointer-events-none absolute left-0 top-8 z-10 hidden w-80 rounded-2xl border border-default bg-surface px-4 py-3 text-sm text-muted shadow-xl group-hover:block">
|
||||
当前分组下的基础文档条目,上传文件后将自动创建文档并开始清洗流程。
|
||||
{{ kb.t('kbWorkspace.documents.infoTip') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,7 +185,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-brand-200 px-4 py-2.5 text-sm font-medium text-brand-700 transition-colors hover:bg-brand-50 disabled:cursor-not-allowed disabled:opacity-60 border-brand-200 hover:bg-brand-50"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
上传路径
|
||||
{{ kb.t('kbWorkspace.documents.uploadPath') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@@ -195,7 +194,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="btn-primary"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
上传文件
|
||||
{{ kb.t('kbWorkspace.documents.uploadFile') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -207,7 +206,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-amber-200 px-4 py-2.5 text-sm font-medium text-amber-700 transition-colors hover:bg-amber-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchSubmitting ? '处理中...' : `清洗数据${kb.selectedDocuments.length ? `(${kb.selectedDocuments.length})` : ''}` }}
|
||||
{{ kb.batchActionLabel('clean', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin && kb.selectedGroupId"
|
||||
@@ -216,7 +215,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-emerald-200 px-4 py-2.5 text-sm font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60 border-emerald-200"
|
||||
>
|
||||
<RefreshCw class="h-4 w-4" />
|
||||
{{ kb.batchSubmitting ? '处理中...' : `批量同步${kb.selectedDocuments.length ? `(${kb.selectedDocuments.length})` : ''}` }}
|
||||
{{ kb.batchActionLabel('sync', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@@ -225,7 +224,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-rose-200 px-4 py-2.5 text-sm font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
<Trash2 class="h-4 w-4" />
|
||||
{{ kb.batchSubmitting ? '处理中...' : `批量删除${kb.selectedDocuments.length ? `(${kb.selectedDocuments.length})` : ''}` }}
|
||||
{{ kb.batchActionLabel('delete', kb.batchSubmitting, kb.selectedDocuments.length) }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.selectedGroupId"
|
||||
@@ -233,7 +232,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="btn-secondary"
|
||||
>
|
||||
<FileText class="h-4 w-4" />
|
||||
历史批次
|
||||
{{ kb.t('kbWorkspace.documents.historyBatches') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="kb.selectedGroupId" class="flex flex-wrap items-center gap-3">
|
||||
@@ -243,7 +242,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
v-model.trim="kb.documentKeyword"
|
||||
type="text"
|
||||
class="w-full rounded-2xl border border-default bg-surface py-2.5 pl-10 pr-4 text-sm text-primary outline-none transition-colors focus:border-brand-300"
|
||||
placeholder="按文件名称模糊搜索"
|
||||
:placeholder="kb.t('kbWorkspace.documents.searchPlaceholder')"
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
@@ -252,7 +251,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
@click="kb.documentKeyword = ''"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
>
|
||||
清空搜索
|
||||
{{ kb.t('kbWorkspace.documents.clearSearch') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -271,29 +270,29 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
路径上传进度
|
||||
{{ kb.t('kbWorkspace.pathUpload.progressTitle') }}
|
||||
<span
|
||||
class="ml-2 inline-flex items-center rounded-full border px-2.5 py-1 text-xs"
|
||||
:class="kb.pathUploadRunning
|
||||
? 'border-amber-200 bg-amber-50 text-amber-700 border-amber-200'
|
||||
: 'border-emerald-200 bg-emerald-50 text-emerald-700 border-emerald-200 '"
|
||||
>
|
||||
{{ kb.pathUploadRunning ? '上传中' : '已完成' }}
|
||||
{{ kb.pathUploadRunning ? kb.t('kbWorkspace.pathUpload.uploading') : kb.t('kbWorkspace.pathUpload.completed') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-muted">
|
||||
建议每批 {{ kb.pathUploadTask.batchSize }} 条,间隔 {{ kb.PATH_UPLOAD_BATCH_INTERVAL_MS / 1000 }} 秒自动继续。
|
||||
{{ kb.t('kbWorkspace.pathUpload.batchHint', { batchSize: kb.pathUploadTask.batchSize, seconds: kb.PATH_UPLOAD_BATCH_INTERVAL_MS / 1000 }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-2 text-sm text-secondary md:grid-cols-4">
|
||||
<div>总计 {{ kb.pathUploadSummary.total }}</div>
|
||||
<div>待上传 {{ kb.pathUploadSummary.pending }}</div>
|
||||
<div>已上传 {{ kb.pathUploadSummary.uploaded }}</div>
|
||||
<div>失败 {{ kb.pathUploadSummary.failed }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.total', { count: kb.pathUploadSummary.total }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.pending', { count: kb.pathUploadSummary.pending }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.uploaded', { count: kb.pathUploadSummary.uploaded }) }}</div>
|
||||
<div>{{ kb.t('kbWorkspace.pathUpload.failed', { count: kb.pathUploadSummary.failed }) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="kb.pathUploadTask.currentFile" class="mt-3 text-sm text-brand-600 ">
|
||||
当前文件:{{ kb.pathUploadTask.currentFile }}
|
||||
{{ kb.t('kbWorkspace.pathUpload.currentFile', { name: kb.pathUploadTask.currentFile }) }}
|
||||
</div>
|
||||
<div class="mt-4 space-y-2">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
@@ -302,7 +301,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
@click="kb.showPathUploadDetails = !kb.showPathUploadDetails"
|
||||
class="inline-flex items-center gap-2 text-sm font-medium text-secondary transition-colors hover:text-brand-600 hover:text-brand-600"
|
||||
>
|
||||
<span>上传详情</span>
|
||||
<span>{{ kb.t('kbWorkspace.pathUpload.details') }}</span>
|
||||
<ChevronDown v-if="!kb.showPathUploadDetails" class="h-4 w-4" />
|
||||
<ChevronUp v-else class="h-4 w-4" />
|
||||
</button>
|
||||
@@ -311,7 +310,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
@click="kb.openPathUploadHistoryModal(kb.latestPathUploadJob?.id || null)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
查看历史
|
||||
{{ kb.t('kbWorkspace.pathUpload.viewHistory') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.latestPathUploadJob && kb.hasRetryablePathUploadFailure(kb.latestPathUploadJob) && !kb.pathUploadRunning"
|
||||
@@ -319,7 +318,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:all`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-3 py-1.5 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:all` ? '处理中...' : '重试失败文件' }}
|
||||
{{ kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:all` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.pathUpload.retryFailedFiles') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -332,7 +331,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate font-medium text-primary">{{ item.title }}</div>
|
||||
<div class="mt-1 truncate text-xs text-muted">{{ item.displayPath }}</div>
|
||||
<div v-if="item.error" class="mt-1 text-xs text-rose-500">失败原因:{{ item.error }}</div>
|
||||
<div v-if="item.error" class="mt-1 text-xs text-rose-500">{{ kb.t('kbWorkspace.common.failureReason', { reason: item.error }) }}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
@@ -347,14 +346,14 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:${item.displayPath}`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-2.5 py-1 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:${item.displayPath}` ? '处理中...' : '重试' }}
|
||||
{{ kb.retryingPathUploadKey === `${kb.latestPathUploadJob.id}:${item.displayPath}` ? kb.t('kbWorkspace.common.processing') : kb.t('kbWorkspace.common.retry') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.latestPathUploadJob && !kb.pathUploadRunning"
|
||||
@click="kb.handleDeletePathUploadItem(kb.latestPathUploadJob, item)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-2.5 py-1 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
删除
|
||||
{{ kb.t('kbWorkspace.common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -370,7 +369,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
@click="kb.toggleSelectAllFiltered"
|
||||
class="inline-flex items-center gap-2 rounded-full border border-default bg-surface px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.isAllFilteredSelected ? '取消全选' : '全选当前筛选' }}
|
||||
{{ kb.isAllFilteredSelected ? kb.t('kbWorkspace.pathUpload.deselectAllFiltered') : kb.t('kbWorkspace.pathUpload.selectAllFiltered') }}
|
||||
</button>
|
||||
<button
|
||||
v-for="tab in kb.stageFilterTabs"
|
||||
@@ -387,28 +386,28 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm text-muted">
|
||||
<label class="inline-flex items-center gap-2">
|
||||
<span>每页</span>
|
||||
<span>{{ kb.t('kbWorkspace.common.perPage') }}</span>
|
||||
<select
|
||||
v-model.number="kb.documentListPageSize"
|
||||
class="rounded-xl border border-default bg-surface px-3 py-1.5 text-sm text-secondary outline-none transition-colors focus:border-brand-300"
|
||||
>
|
||||
<option v-for="size in kb.DOCUMENT_PAGE_SIZE_OPTIONS" :key="size" :value="size">{{ size }}</option>
|
||||
</select>
|
||||
<span>条</span>
|
||||
<span>{{ kb.t('kbWorkspace.common.countUnit') }}</span>
|
||||
</label>
|
||||
<span>已选 {{ kb.selectedDocuments.length }} 条 · 共 {{ kb.filteredDocuments.length }} 条</span>
|
||||
<span v-if="kb.filteredDocuments.length > 0">当前显示 {{ kb.pagedDocumentRange.start }}-{{ kb.pagedDocumentRange.end }} 条</span>
|
||||
<span>{{ kb.t('kbWorkspace.documents.selectedCount', { selected: kb.selectedDocuments.length, total: kb.filteredDocuments.length }) }}</span>
|
||||
<span v-if="kb.filteredDocuments.length > 0">{{ kb.t('kbWorkspace.documents.showingRange', { start: kb.pagedDocumentRange.start, end: kb.pagedDocumentRange.end }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!kb.selectedGroupId" class="rounded-2xl border border-dashed border-default px-4 py-12 text-center text-sm text-muted ">
|
||||
请选择一个知识库分组。
|
||||
{{ kb.t('kbWorkspace.documents.selectGroup') }}
|
||||
</div>
|
||||
<div v-else-if="kb.isDocumentsLoading" class="rounded-2xl border border-dashed border-default px-4 py-12 text-center text-sm text-muted ">
|
||||
正在加载文档...
|
||||
{{ kb.t('kbWorkspace.documents.loadingDocuments') }}
|
||||
</div>
|
||||
<div v-else-if="kb.filteredDocuments.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-12 text-center text-sm text-muted ">
|
||||
{{ kb.documents.length === 0 ? '当前分组暂无文档,可直接在上方创建第一条文档记录。' : (kb.documentKeyword ? '当前搜索和筛选条件下暂无匹配文档。' : '当前筛选条件下暂无匹配文档。') }}
|
||||
{{ kb.documentEmptyMessage(kb.documents.length, !!kb.documentKeyword) }}
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
@@ -444,9 +443,9 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
{{ kb.getDocumentDisplayDescription(doc) }}
|
||||
</button>
|
||||
<div class="mt-2 text-xs text-muted">
|
||||
<span>版本数:{{ doc.version_count ?? 0 }}</span>
|
||||
<span>{{ kb.t('kbWorkspace.documents.versionCount', { count: doc.version_count ?? 0 }) }}</span>
|
||||
<span v-if="doc.latest_version">
|
||||
<span> · 当前版本:v{{ doc.latest_version.version_no }} · </span>
|
||||
<span>{{ kb.t('kbWorkspace.documents.currentVersion', { version: doc.latest_version.version_no }) }}</span>
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.openSourceInfo(doc)"
|
||||
@@ -464,14 +463,14 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-violet-200 px-3 py-2 text-xs font-medium text-violet-700 transition-colors hover:bg-violet-50"
|
||||
>
|
||||
<FileText class="h-3.5 w-3.5" />
|
||||
查看记录
|
||||
{{ kb.t('kbWorkspace.documents.viewRecord') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.triggerUploadForDocument(doc.id)"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-brand-200 px-3 py-2 text-xs font-medium text-brand-700 transition-colors hover:bg-brand-50 border-brand-200 hover:bg-brand-50"
|
||||
>
|
||||
<Upload class="h-3.5 w-3.5" />
|
||||
上传版本
|
||||
{{ kb.t('kbWorkspace.documents.uploadVersion') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@@ -480,27 +479,27 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-emerald-200 px-3 py-2 text-xs font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60 border-emerald-200"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
{{ kb.syncingDocumentId === doc.id ? '同步中...' : '同步 Dify' }}
|
||||
{{ kb.syncingDocumentId === doc.id ? kb.t('kbWorkspace.documents.syncingDify') : kb.t('kbWorkspace.documents.syncDify') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleDeleteDocument(doc)"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
<Trash2 class="h-3.5 w-3.5" />
|
||||
删除
|
||||
{{ kb.t('kbWorkspace.common.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex items-end justify-between gap-3 border-kb.t border-default pt-3 ">
|
||||
<div class="mt-4 flex items-end justify-between gap-3 border-t border-default pt-3 ">
|
||||
<div class="space-y-1">
|
||||
<div class="text-xs text-muted">
|
||||
更新时间:{{ kb.formatDateTime(doc.updated_at) }}
|
||||
{{ kb.t('kbWorkspace.documents.updatedAt', { time: kb.formatDateTime(doc.updated_at) }) }}
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.getDocumentWorkflowState(doc).primaryError"
|
||||
class="max-w-xl text-xs text-rose-500"
|
||||
>
|
||||
失败原因:{{ kb.getDocumentWorkflowState(doc).primaryError }}
|
||||
{{ kb.t('kbWorkspace.common.failureReason', { reason: kb.getDocumentWorkflowState(doc).primaryError }) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||||
@@ -520,7 +519,7 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
class="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<div class="text-sm text-muted">
|
||||
第 {{ kb.documentListPage }} / {{ kb.filteredDocumentTotalPages }} 页 · 共 {{ kb.filteredDocuments.length }} 条
|
||||
{{ kb.t('kbWorkspace.documents.pageInfo', { page: kb.documentListPage, totalPages: kb.filteredDocumentTotalPages, total: kb.filteredDocuments.length }) }}
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@@ -528,14 +527,14 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
:disabled="kb.documentListPage === 1"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
上一页
|
||||
{{ kb.t('kbWorkspace.common.prevPage') }}
|
||||
</button>
|
||||
<button
|
||||
@click="kb.documentListPage = Math.min(kb.filteredDocumentTotalPages, kb.documentListPage + 1)"
|
||||
:disabled="kb.documentListPage === kb.filteredDocumentTotalPages"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
下一页
|
||||
{{ kb.t('kbWorkspace.common.nextPage') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -546,621 +545,8 @@ const kb = useKbWorkspace({ embedded: props.embedded });
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showRecordModal"
|
||||
class="dialog-overlay z-[55] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-5xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">文档记录</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
当前查看:{{ kb.selectedDocument ? kb.getDocumentDisplayTitle(kb.selectedDocument) : `文档 #${kb.selectedDocumentId}` }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeDocumentDetail"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isRecordLoading" class="flex min-h-[360px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
正在加载文档记录...
|
||||
</div>
|
||||
<div v-else class="space-y-6 overflow-y-auto pr-1">
|
||||
<div>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">版本记录</h3>
|
||||
<span class="text-xs text-muted">{{ kb.selectedDocumentVersions.length }} 条</span>
|
||||
</div>
|
||||
<div v-if="kb.selectedDocumentVersions.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
暂无版本记录,上传版本后会显示在这里。
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="version in kb.selectedDocumentVersions"
|
||||
:key="version.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-primary">
|
||||
v{{ version.version_no }} · {{ version.source_file_name }}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(version.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(version.status) }}
|
||||
</span>
|
||||
<span>大小:{{ version.source_file_size ?? 0 }} bytes</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(version.created_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="mb-3 flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold text-primary">Dify 同步记录</h3>
|
||||
<span class="text-xs text-muted">{{ kb.selectedDocumentSyncRecords.length }} 条</span>
|
||||
</div>
|
||||
<div v-if="kb.selectedDocumentSyncRecords.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
暂无 Dify 同步记录,手动点击“同步 Dify”后会显示在这里。
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="record in kb.selectedDocumentSyncRecords"
|
||||
:key="record.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="font-semibold text-primary">
|
||||
{{ record.dataset_name || record.dataset_id }} · {{ record.remote_document_name || record.remote_document_id }}
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(record.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(record.status) }}
|
||||
</span>
|
||||
<span>版本:{{ record.document_version_id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(record.updated_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showMarkdownModal"
|
||||
class="dialog-overlay z-[60] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-5xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h3 class="truncate text-lg font-semibold text-primary">{{ kb.markdownModalTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
{{ kb.markdownVersionLabel || '正在读取当前版本...' }}
|
||||
<span class="ml-2 rounded-full bg-surface-soft px-2 py-0.5 text-xs text-muted">
|
||||
{{ kb.markdownKind === 'preview' ? '预览文本' : '清洗 Markdown' }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeMarkdownModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="kb.markdownError"
|
||||
class="mb-4 text-sm text-rose-500"
|
||||
>
|
||||
{{ kb.markdownError }}
|
||||
</p>
|
||||
|
||||
<div v-if="kb.isMarkdownLoading" class="flex min-h-[420px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
正在加载清洗后的 Markdown...
|
||||
</div>
|
||||
<textarea
|
||||
v-else
|
||||
v-model="kb.markdownContent"
|
||||
spellcheck="false"
|
||||
class="min-h-[420px] w-full flex-1 rounded-2xl border border-default bg-surface-soft px-4 py-3 font-mono text-sm text-primary outline-none transition-colors focus:border-brand-300 focus:bg-surface"
|
||||
placeholder="当前文档尚未生成 Markdown,可在此粘贴或编辑内容。"
|
||||
/>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closeMarkdownModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleSaveMarkdown"
|
||||
:disabled="kb.isMarkdownLoading || kb.isMarkdownSaving || !kb.markdownDocumentId"
|
||||
class="inline-flex items-center justify-center rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.isMarkdownSaving ? '保存中...' : '保存 Markdown' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showSourceInfoModal"
|
||||
class="dialog-overlay z-[58] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-4xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div class="min-w-0">
|
||||
<h3 class="truncate text-lg font-semibold text-primary">源文件信息</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
当前查看:{{ kb.sourceInfoDocument ? kb.getDocumentDisplayTitle(kb.sourceInfoDocument) : `文档 #${kb.sourceInfoDocumentId}` }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeSourceInfoModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.isSourceInfoLoading" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
正在加载源文件信息...
|
||||
</div>
|
||||
<div v-else-if="kb.sourceInfoVersions.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
暂无源文件信息,上传版本后会显示在这里。
|
||||
</div>
|
||||
<div v-else class="space-y-3 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="version in kb.sourceInfoVersions"
|
||||
:key="version.id"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.openOriginalSourceFile(version)"
|
||||
class="font-semibold text-primary underline-offset-2 transition-colors hover:text-brand-600 hover:underline hover:text-brand-600"
|
||||
>
|
||||
v{{ version.version_no }} · {{ version.source_file_name }}
|
||||
</button>
|
||||
<span
|
||||
v-if="version.is_current"
|
||||
class="inline-flex items-center rounded-full border border-brand-200 bg-brand-50 px-2.5 py-1 text-xs font-semibold text-brand-700 border-brand-200"
|
||||
>
|
||||
当前版本
|
||||
</span>
|
||||
<span
|
||||
v-if="kb.openingSourceVersionId === version.id"
|
||||
class="text-xs text-muted"
|
||||
>
|
||||
正在打开...
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(version.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(version.status) }}
|
||||
</span>
|
||||
<span>文件名:{{ version.source_file_name }}</span>
|
||||
<span>大小:{{ kb.formatFileSize(version.source_file_size) }}</span>
|
||||
<span v-if="version.source_file_ext">类型:{{ version.source_file_ext }}</span>
|
||||
</div>
|
||||
<div v-if="version.error_message" class="mt-2 text-sm text-rose-500">
|
||||
失败原因:{{ version.error_message }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-sm text-muted">
|
||||
{{ kb.formatDateTime(version.created_at) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closeSourceInfoModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showFailureModal"
|
||||
class="dialog-overlay z-[65] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-6xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">{{ kb.failureModalTitle }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
当前分组共 {{ kb.failureModalItems.length }} 条失败记录,每页 {{ kb.FAILURE_PAGE_SIZE }} 条。
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closeFailureModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.failureModalItems.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
当前没有失败数据。
|
||||
</div>
|
||||
<div v-else class="space-y-4 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.pagedFailureModalItems"
|
||||
:key="item.key"
|
||||
class="rounded-2xl border border-default px-4 py-4 "
|
||||
>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<div class="max-w-full truncate text-base font-semibold text-primary">
|
||||
{{ kb.getDocumentDisplayTitle(item.document) }}
|
||||
</div>
|
||||
<span class="inline-flex items-center rounded-full border border-rose-200 bg-rose-50 px-2.5 py-1 text-xs font-semibold text-rose-700 border-rose-200">
|
||||
{{ item.stageLabel }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-muted">
|
||||
当前版本:
|
||||
<span v-if="item.document.latest_version">
|
||||
v{{ item.document.latest_version.version_no }} · {{ item.document.latest_version.source_file_name }}
|
||||
</span>
|
||||
<span v-else>暂无版本</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-rose-500">
|
||||
失败原因:{{ item.errorMessage }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 text-right text-sm text-muted">
|
||||
{{ kb.formatDateTime(item.updatedAt) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
@click="kb.handleRetryFailedItem(item, 'submit')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-submit`"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-sky-200 px-3 py-2 text-xs font-medium text-sky-700 transition-colors hover:bg-sky-50 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-submit` ? '处理中...' : '重新提交' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleRetryFailedItem(item, 'clean')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-clean` || !item.document.latest_version"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-amber-200 px-3 py-2 text-xs font-medium text-amber-700 transition-colors hover:bg-amber-50 disabled:cursor-not-allowed disabled:opacity-60 border-amber-200"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-clean` ? '处理中...' : '重新清洗' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.isKbAdmin"
|
||||
@click="kb.handleRetryFailedItem(item, 'sync')"
|
||||
:disabled="kb.retryingFailureKey === `${item.key}-sync` || !item.document.latest_version"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-emerald-200 px-3 py-2 text-xs font-medium text-emerald-700 transition-colors hover:bg-emerald-50 disabled:cursor-not-allowed disabled:opacity-60 border-emerald-200"
|
||||
>
|
||||
{{ kb.retryingFailureKey === `${item.key}-sync` ? '处理中...' : '重新同步' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="kb.failureModalItems.length > kb.FAILURE_PAGE_SIZE"
|
||||
class="mt-5 flex items-center justify-between gap-3 border-kb.t border-default pt-4 "
|
||||
>
|
||||
<div class="text-sm text-muted">
|
||||
第 {{ kb.failureModalPage }} / {{ kb.failureModalTotalPages }} 页
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@click="kb.failureModalPage = Math.max(1, kb.failureModalPage - 1)"
|
||||
:disabled="kb.failureModalPage === 1"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
上一页
|
||||
</button>
|
||||
<button
|
||||
@click="kb.failureModalPage = Math.min(kb.failureModalTotalPages, kb.failureModalPage + 1)"
|
||||
:disabled="kb.failureModalPage === kb.failureModalTotalPages"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60 hover-surface-soft"
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showPathUploadModal"
|
||||
class="dialog-overlay z-[66] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-4xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">上传路径</h3>
|
||||
<p class="mt-1 text-sm text-muted">
|
||||
选择本地目录后,系统会按批次将该路径下文件导入当前分组并自动进入清洗流程。
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closePathUploadModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4 overflow-y-auto pr-1">
|
||||
<div class="rounded-2xl border border-default bg-surface-soft p-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-sm font-medium text-primary">本地路径选择</div>
|
||||
<div class="mt-1 text-xs text-muted">
|
||||
支持多次选择目录追加文件;当前浏览器安全限制下,手动粘贴任意本机路径不能直接读取文件内容。
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.triggerPathUploadSelection"
|
||||
class="inline-flex items-center gap-2 rounded-2xl border border-brand-200 px-4 py-2.5 text-sm font-medium text-brand-700 transition-colors hover:bg-brand-50 border-brand-200 hover:bg-brand-50"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
选择本地目录
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label-field block mb-2">路径清单</label>
|
||||
<textarea
|
||||
v-model="kb.pathUploadDraftText"
|
||||
rows="5"
|
||||
class="input-field"
|
||||
placeholder="目录选择后会自动填充路径清单;如需记录多路径,可在此粘贴备注。"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between gap-3">
|
||||
<div class="text-sm font-medium text-secondary">
|
||||
待上传文件
|
||||
<span class="ml-2 text-xs text-muted">{{ kb.pathUploadSelectedFiles.length }} 条</span>
|
||||
</div>
|
||||
<div class="text-xs text-muted">
|
||||
已选根路径:{{ kb.selectedPathRoots.length ? kb.selectedPathRoots.join('、') : '暂无' }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="kb.pathUploadSelectedFiles.length === 0" class="rounded-2xl border border-dashed border-default px-4 py-8 text-center text-sm text-muted ">
|
||||
请选择本地目录后再确认上传。
|
||||
</div>
|
||||
<div v-else class="max-h-72 space-y-2 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.pathUploadSelectedFiles"
|
||||
:key="item.key"
|
||||
class="flex items-start justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-sm font-medium text-primary">{{ item.file.name }}</div>
|
||||
<div class="mt-1 truncate text-xs text-muted">{{ item.displayPath }}</div>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.removeSelectedPathFile(item.key)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-1.5 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
移除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 flex justify-end gap-3">
|
||||
<button
|
||||
type="button"
|
||||
@click="kb.closePathUploadModal"
|
||||
class="inline-flex items-center justify-center rounded-xl border border-default px-4 py-2 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
@click="kb.handleConfirmPathUpload"
|
||||
class="inline-flex items-center justify-center gap-2 rounded-xl bg-brand-600px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-brand-700"
|
||||
>
|
||||
<Upload class="h-4 w-4" />
|
||||
确认上传
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="kb.showPathUploadHistoryModal"
|
||||
class="dialog-overlay z-[67] items-center"
|
||||
>
|
||||
<div class="dialog-panel max-w-6xl max-h-[90vh] p-6">
|
||||
<div class="mb-4 flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold text-primary">上传路径历史批次</h3>
|
||||
<p class="mt-1 text-sm text-muted">查看每次路径上传的批次结果、失败文件与重试入口。</p>
|
||||
</div>
|
||||
<button
|
||||
@click="kb.closePathUploadHistoryModal"
|
||||
class="rounded-full p-1 text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.pathUploadHistoryJobs.length === 0" class="flex min-h-[320px] items-center justify-center rounded-2xl border border-dashed border-default text-sm text-muted ">
|
||||
当前暂无上传路径历史批次。
|
||||
</div>
|
||||
<div v-else class="grid min-h-0 flex-1 grid-cols-1 gap-4 lg:grid-cols-[320px_minmax(0,1fr)]">
|
||||
<div class="space-y-3 overflow-y-auto pr-1">
|
||||
<button
|
||||
v-for="job in kb.pathUploadHistoryJobs"
|
||||
:key="job.id"
|
||||
@click="kb.selectedPathUploadHistoryJobId = job.id"
|
||||
class="w-full rounded-2xl border px-4 py-4 text-left transition-colors"
|
||||
:class="String(kb.selectedPathUploadHistoryJobId || kb.selectedPathUploadHistoryJob?.id) === String(job.id)
|
||||
? 'border-brand-200 bg-brand-50 border-brand-200 '
|
||||
: 'border-default bg-surface hover:bg-surface-soft hover-surface-soft'"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-3">
|
||||
<div class="min-w-0">
|
||||
<div class="truncate text-sm font-semibold text-primary">批次 #{{ job.id }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ kb.formatDateTime(job.created_at) }}</div>
|
||||
</div>
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(job.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(job.status) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-3 grid grid-cols-2 gap-2 text-xs text-muted">
|
||||
<div>总计 {{ kb.getPathUploadJobSummary(job).total }}</div>
|
||||
<div>成功 {{ kb.getPathUploadJobSummary(job).success }}</div>
|
||||
<div>失败 {{ kb.getPathUploadJobSummary(job).failed }}</div>
|
||||
<div>待处理 {{ kb.getPathUploadJobSummary(job).pending }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="kb.selectedPathUploadHistoryJob" class="min-h-0 rounded-2xl border border-default p-4 ">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-base font-semibold text-primary">批次 #{{ kb.selectedPathUploadHistoryJob.id }}</div>
|
||||
<div class="mt-1 text-sm text-muted">
|
||||
创建时间:{{ kb.formatDateTime(kb.selectedPathUploadHistoryJob.created_at) }}
|
||||
<span v-if="kb.selectedPathUploadHistoryJob.finished_at"> · 完成时间:{{ kb.formatDateTime(kb.selectedPathUploadHistoryJob.finished_at) }}</span>
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-muted">{{ kb.selectedPathUploadHistoryJob.message || '暂无批次说明' }}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getStatusBadgeClass(kb.selectedPathUploadHistoryJob.status)"
|
||||
>
|
||||
{{ kb.getStatusLabel(kb.selectedPathUploadHistoryJob.status) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="kb.selectedPathUploadHistoryItems.length && !kb.pathUploadRunning"
|
||||
@click="kb.toggleSelectAllPathUploadHistoryItems"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
{{ kb.isAllPathUploadHistoryItemsSelected ? '取消全选' : '全选' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!kb.pathUploadRunning"
|
||||
@click="kb.handleBatchDeletePathUploadItems"
|
||||
:disabled="!kb.selectedPathUploadHistorySelectedItems.length || kb.deletingPathUploadBatch"
|
||||
class="inline-flex items-center rounded-xl border border-default px-3 py-2 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
|
||||
>
|
||||
{{ kb.deletingPathUploadBatch ? '删除中...' : `批量删除${kb.selectedPathUploadHistorySelectedItems.length ? ` (${kb.selectedPathUploadHistorySelectedItems.length})` : ''}` }}
|
||||
</button>
|
||||
<button
|
||||
v-if="kb.hasRetryablePathUploadFailure(kb.selectedPathUploadHistoryJob) && !kb.pathUploadRunning"
|
||||
@click="kb.handleRetryFailedPathUpload(kb.selectedPathUploadHistoryJob)"
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:all`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-3 py-2 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:all` ? '处理中...' : '重试全部失败文件' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid grid-cols-2 gap-3 text-sm text-secondary md:grid-cols-4">
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">总计 {{ kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).total }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">成功 {{ kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).success }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">失败 {{ kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).failed }}</div>
|
||||
<div class="rounded-xl bg-surface-soft px-3 py-2 ">待处理 {{ kb.getPathUploadJobSummary(kb.selectedPathUploadHistoryJob).pending }}</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 max-h-[50vh] space-y-2 overflow-y-auto pr-1">
|
||||
<div
|
||||
v-for="item in kb.selectedPathUploadHistoryItems"
|
||||
:key="item.key"
|
||||
class="flex flex-wrap items-start justify-between gap-3 rounded-2xl border border-default px-4 py-3 "
|
||||
>
|
||||
<label class="flex items-center pt-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="kb.selectedPathUploadHistoryItemKeys.includes(item.key)"
|
||||
@change="kb.togglePathUploadHistoryItemSelection(item.key)"
|
||||
class="h-4 w-4 rounded border-default text-brand-600 focus:ring-brand-500"
|
||||
/>
|
||||
</label>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="truncate text-sm font-medium text-primary">{{ item.title }}</div>
|
||||
<div class="mt-1 truncate text-xs text-muted">{{ item.displayPath }}</div>
|
||||
<div v-if="item.error" class="mt-1 text-xs text-rose-500">失败原因:{{ item.error }}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span
|
||||
class="inline-flex items-center rounded-full border px-2.5 py-1 text-xs font-semibold"
|
||||
:class="kb.getPathUploadItemDisplayState(item).className"
|
||||
>
|
||||
{{ kb.getPathUploadItemDisplayState(item).label }}
|
||||
</span>
|
||||
<button
|
||||
v-if="item.retryable && !kb.pathUploadRunning"
|
||||
@click="kb.handleRetryFailedPathUpload(kb.selectedPathUploadHistoryJob, [item.displayPath])"
|
||||
:disabled="kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:${item.displayPath}`"
|
||||
class="inline-flex items-center rounded-xl border border-rose-200 px-2.5 py-1 text-xs font-medium text-rose-600 transition-colors hover:bg-rose-50 disabled:cursor-not-allowed disabled:opacity-60 border-rose-200 hover:bg-rose-50"
|
||||
>
|
||||
{{ kb.retryingPathUploadKey === `${kb.selectedPathUploadHistoryJob.id}:${item.displayPath}` ? '处理中...' : '重试' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!kb.pathUploadRunning"
|
||||
@click="kb.handleDeletePathUploadItem(kb.selectedPathUploadHistoryJob, item)"
|
||||
class="inline-flex items-center rounded-xl border border-default px-2.5 py-1 text-xs font-medium text-muted transition-colors hover:bg-surface-soft hover-surface-soft"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="kb.showDeleteConfirmDialog"
|
||||
:message="kb.deleteConfirmMessage"
|
||||
@confirm="kb.handleDeleteConfirm"
|
||||
@cancel="kb.closeDeleteConfirmDialog"
|
||||
/>
|
||||
<KbWorkspaceOverlays :kb="kb" />
|
||||
</template>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* features/workspace/pages/ShippingNoticePage.vue
|
||||
* 货代发货通知嵌入页,复用 ShippingNoticeView 的 embedded 模式。
|
||||
*/
|
||||
import ShippingNoticeView from '@/views/ShippingNoticeView.vue';
|
||||
import ShippingNoticeView from '../views/ShippingNoticeView.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/workspace/views/ShippingNoticeView.vue
|
||||
* 货代发货任务只读工作台:列表筛选、详情、跳转 Chat 继续处理。
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ArrowLeft, Download, ExternalLink, RefreshCw } from 'lucide-vue-next';
|
||||
import {
|
||||
getWorkspaceShippingTask,
|
||||
listWorkspaceShippingTasks,
|
||||
SHIPPING_NOTICE_AGENT_NAME,
|
||||
workspaceShippingExportUrl,
|
||||
type ShippingTaskDetail,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
const props = defineProps<{
|
||||
embedded?: boolean;
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const tasks = ref<ShippingTaskSummary[]>([]);
|
||||
const selectedTaskNo = ref<string | null>(null);
|
||||
const detail = ref<ShippingTaskDetail | null>(null);
|
||||
const statusFilter = ref('all');
|
||||
const chatAgentId = ref<number | null>(null);
|
||||
|
||||
const statusOptions = computed(() => [
|
||||
{ value: 'all', label: t('workspace.shippingNotice.status.all') },
|
||||
{ value: 'created', label: t('workspace.shippingNotice.status.created') },
|
||||
{ value: 'waiting_inventory', label: t('workspace.shippingNotice.status.waitingInventory') },
|
||||
{ value: 'inventory_ready', label: t('workspace.shippingNotice.status.inventoryReady') },
|
||||
{ value: 'matched', label: t('workspace.shippingNotice.status.matched') },
|
||||
{ value: 'waiting_upload', label: t('workspace.shippingNotice.status.waitingUpload') },
|
||||
{ value: 'uploaded', label: t('workspace.shippingNotice.status.uploaded') },
|
||||
{ value: 'upload_failed', label: t('workspace.shippingNotice.status.uploadFailed') },
|
||||
]);
|
||||
|
||||
const statusBadge = (status: string) => {
|
||||
const map: Record<string, { cls: string; label: string }> = {
|
||||
created: { cls: 'bg-slate-100 text-secondary', label: t('workspace.shippingNotice.status.created') },
|
||||
waiting_inventory: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingInventory') },
|
||||
inventory_ready: { cls: 'bg-blue-100 text-blue-700', label: t('workspace.shippingNotice.status.inventoryReady') },
|
||||
matched: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.matched') },
|
||||
waiting_upload: { cls: 'bg-amber-100 text-amber-700', label: t('workspace.shippingNotice.status.waitingUpload') },
|
||||
uploaded: { cls: 'bg-emerald-100 text-emerald-700', label: t('workspace.shippingNotice.status.uploaded') },
|
||||
upload_failed: { cls: 'bg-rose-100 text-rose-700', label: t('workspace.shippingNotice.status.uploadFailed') },
|
||||
};
|
||||
return map[status] || { cls: 'bg-slate-100 text-secondary', label: status };
|
||||
};
|
||||
|
||||
const loadCases = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
tasks.value = await listWorkspaceShippingTasks({
|
||||
process_status: statusFilter.value === 'all' ? undefined : statusFilter.value,
|
||||
limit: 100,
|
||||
});
|
||||
} catch {
|
||||
tasks.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const loadDetail = async (taskNo: string) => {
|
||||
detailLoading.value = true;
|
||||
try {
|
||||
detail.value = await getWorkspaceShippingTask(taskNo);
|
||||
} catch {
|
||||
detail.value = null;
|
||||
} finally {
|
||||
detailLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resolveChatAgent = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/agents', { headers: getAuthHeaders() });
|
||||
if (!res.ok) return;
|
||||
const agents = (await res.json()) as Array<{ id: number; name: string }>;
|
||||
const found = agents.find((a) => a.name === SHIPPING_NOTICE_AGENT_NAME);
|
||||
if (found) chatAgentId.value = found.id;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
};
|
||||
|
||||
const openInChat = (taskNo: string, conversationId?: string | null) => {
|
||||
if (!chatAgentId.value) return;
|
||||
const query: Record<string, string> = { task_id: taskNo };
|
||||
const cid = String(conversationId || '').trim();
|
||||
if (/^[0-9a-f]{32}$/i.test(cid)) query.conversation_id = cid;
|
||||
router.push({ path: `/chat/${chatAgentId.value}`, query });
|
||||
};
|
||||
|
||||
const downloadExport = async (taskNo: string) => {
|
||||
const url = workspaceShippingExportUrl(taskNo);
|
||||
const res = await fetch(url, { headers: getAuthHeaders() });
|
||||
if (!res.ok) return;
|
||||
const blob = await res.blob();
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = detail.value?.export_file_name || `${taskNo}.xlsx`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
};
|
||||
|
||||
watch(selectedTaskNo, (val) => {
|
||||
if (val) loadDetail(val);
|
||||
else detail.value = null;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadCases(), resolveChatAgent()]);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-5 animate-fade-in-up">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
v-if="!embedded"
|
||||
type="button"
|
||||
class="inline-flex h-9 w-9 items-center justify-center rounded-xl border border-default text-secondary hover:bg-surface-soft"
|
||||
@click="router.push('/workspace')"
|
||||
>
|
||||
<ArrowLeft class="h-4 w-4" />
|
||||
</button>
|
||||
<div>
|
||||
<h2 class="text-2xl font-bold text-primary">{{ $t('workspace.shippingNotice.title') }}</h2>
|
||||
<p class="text-sm text-muted">{{ $t('workspace.shippingNotice.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1.5 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="loadCases"
|
||||
>
|
||||
<RefreshCw class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-end gap-3 rounded-2xl border border-default/80 bg-surface/70 px-4 py-3 shadow-sm">
|
||||
<div>
|
||||
<label class="mb-1 block text-xs font-medium text-muted">{{ $t('workspace.shippingNotice.filters.status') }}</label>
|
||||
<select v-model="statusFilter" class="rounded-xl border border-default bg-surface px-3 py-2 text-sm">
|
||||
<option v-for="opt in statusOptions" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700"
|
||||
@click="loadCases"
|
||||
>
|
||||
{{ $t('workspace.shippingNotice.search') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-5 lg:grid-cols-5">
|
||||
<div class="lg:col-span-2 space-y-2">
|
||||
<div v-if="loading" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.loading') }}
|
||||
</div>
|
||||
<div v-else-if="tasks.length === 0" class="rounded-2xl border border-dashed border-default py-10 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.empty') }}
|
||||
</div>
|
||||
<button
|
||||
v-for="item in tasks"
|
||||
:key="item.task_no"
|
||||
type="button"
|
||||
class="w-full rounded-2xl border px-4 py-3 text-left transition-colors"
|
||||
:class="selectedTaskNo === item.task_no ? 'border-brand-400 bg-brand-50/60' : 'border-default hover:bg-surface-soft/70'"
|
||||
@click="selectedTaskNo = item.task_no"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="font-mono text-sm font-semibold text-primary">{{ item.task_no }}</span>
|
||||
<span class="rounded-full px-2 py-0.5 text-xs font-medium" :class="statusBadge(item.process_status).cls">
|
||||
{{ statusBadge(item.process_status).label }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1 truncate text-sm text-secondary">{{ item.customer_name || '—' }}</div>
|
||||
<div class="mt-1 text-xs text-muted">{{ item.created_at || '' }}</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="lg:col-span-3 rounded-2xl border border-default bg-surface/50 p-5">
|
||||
<div v-if="!selectedTaskNo" class="py-16 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.selectCase') }}
|
||||
</div>
|
||||
<div v-else-if="detailLoading" class="py-16 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.loading') }}
|
||||
</div>
|
||||
<div v-else-if="!detail" class="py-16 text-center text-sm text-muted">
|
||||
{{ $t('workspace.shippingNotice.loadFailed') }}
|
||||
</div>
|
||||
<div v-else class="space-y-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="font-mono text-lg font-bold text-primary">{{ detail.task_no }}</div>
|
||||
<div class="text-sm text-muted">{{ detail.customer_name }} · {{ detail.customer_code || '—' }}</div>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
v-if="chatAgentId"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-brand-300 bg-brand-50 px-3 py-1.5 text-sm font-medium text-brand-700 hover:bg-brand-100"
|
||||
@click="openInChat(detail.task_no, detail.conversation_id)"
|
||||
>
|
||||
<ExternalLink class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.openChat') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="detail.export_file_name"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-default px-3 py-1.5 text-sm font-medium text-secondary hover:bg-surface-soft"
|
||||
@click="downloadExport(detail.task_no)"
|
||||
>
|
||||
<Download class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.shippingNotice.download') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<dl class="grid gap-3 sm:grid-cols-2 text-sm">
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.status') }}</dt><dd>{{ detail.process_status }}</dd></div>
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.match') }}</dt><dd>{{ detail.match_status || '—' }}</dd></div>
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.shipTo') }}</dt><dd>{{ detail.ship_to || '—' }}</dd></div>
|
||||
<div><dt class="text-muted">{{ $t('workspace.shippingNotice.fields.freightRef') }}</dt><dd>{{ detail.freight_ref_no || '—' }}</dd></div>
|
||||
</dl>
|
||||
|
||||
<div v-if="detail.error_message" class="rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-sm text-rose-700">
|
||||
{{ detail.error_message }}
|
||||
</div>
|
||||
|
||||
<div v-if="detail.lines?.length">
|
||||
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.lines') }}</h3>
|
||||
<div class="overflow-x-auto rounded-xl border border-default">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead class="bg-surface-soft text-left text-xs text-muted">
|
||||
<tr>
|
||||
<th class="px-3 py-2">{{ $t('workspace.shippingNotice.columns.sku') }}</th>
|
||||
<th class="px-3 py-2">{{ $t('workspace.shippingNotice.qty') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(line, idx) in detail.lines" :key="idx" class="border-t border-default/60">
|
||||
<td class="px-3 py-2 font-mono">{{ line.sku || line.part_no || '—' }}</td>
|
||||
<td class="px-3 py-2">{{ line.qty ?? line.quantity ?? '—' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="detail.events?.length">
|
||||
<h3 class="mb-2 text-sm font-semibold text-secondary">{{ $t('workspace.shippingNotice.events') }}</h3>
|
||||
<ul class="max-h-48 space-y-1 overflow-y-auto text-xs text-muted">
|
||||
<li v-for="(ev, idx) in [...detail.events].reverse()" :key="idx">
|
||||
<span class="font-medium text-secondary">{{ ev.event_type }}</span>
|
||||
<span class="ml-2">{{ ev.created_at }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user