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())}`;
|
||||
}
|
||||
Reference in new issue
Block a user