feat(rohs-check): 新增 RoHS 检核工具 API 及相关功能

This commit is contained in:
hugo committed 2026-06-10 15:17:09 +08:00
1 parent 8a541211b7
commit 24551e9a9a
39 files changed
+3128 -189

No files matched your search

+23 -1
View File
@@ -13,6 +13,8 @@ export interface ScheduleTask {
dify_agent_id?: number | null;
platform_api_path?: string | null;
data_source_type?: string;
kb_sync_enabled?: boolean;
kb_group_id?: number | null;
notify_user_ids_json: number[];
notify_enabled: boolean;
enabled: boolean;
@@ -45,6 +47,12 @@ export interface ScheduleRun {
error_message?: string | null;
excel_file_name?: string | null;
excel_file_size?: number | null;
kb_sync_status?: string | null;
kb_group_id?: number | null;
kb_document_id?: number | null;
kb_document_version_id?: number | null;
kb_sync_job_id?: number | null;
kb_sync_error?: string | null;
wecom_notified: boolean;
wecom_notified_at?: string | null;
wecom_notify_error?: string | null;
@@ -77,6 +85,9 @@ async function getJson<T>(url: string): Promise<T> {
export const listAdminSchedules = () =>
getJson<ScheduleTask[]>('/api/admin/schedules');
export const getAdminSchedule = (taskId: number) =>
getJson<ScheduleTask>(`/api/admin/schedules/${taskId}`);
export const exportAdminScheduleUrl = (taskId: number) => `/api/admin/schedules/${taskId}/export`;
export const importAdminSchedules = async (payload: any) => {
@@ -127,9 +138,20 @@ export interface TestScheduleRunResult {
step_logs: StepLog[];
dify_agent_id: number | null;
dify_execution_snapshot?: DifyExecutionSnapshot | null;
kb_sync_status?: string | null;
kb_sync_error?: string | null;
kb_document_id?: number | null;
}
export const testAdminScheduleRun = (taskId: number, payload: { fetch_where_conditions?: string; fetch_order_by?: string; limit?: number }) =>
export const testAdminScheduleRun = (
taskId: number,
payload: {
fetch_where_conditions?: string;
fetch_order_by?: string;
limit?: number;
kb_sync_enabled?: boolean;
},
) =>
requestJson<TestScheduleRunResult>(`/api/admin/schedule-config/${taskId}/test-run`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
@@ -15,17 +15,20 @@ const admin = useSchedulesAdmin();
onMounted(() => { void admin.loadAll(); });
const {
agents, users, schedules, selectedScheduleRuns, scheduleLoading, scheduleRunsLoading,
agents, users, kbGroups, schedules, selectedScheduleRuns, scheduleLoading, scheduleRunsLoading,
selectedScheduleId, scheduleRunStatusFilter, scheduleRunStartedAfter, scheduleRunStartedBefore,
scheduleRunColumnDefs, scheduleViewMode, showScheduleCreateModal, scheduleCreateSaving,
scheduleEditingId, scheduleCreateForm, scheduleConfigCollapsed, scheduleCronDesigner,
weeklyDayOptions, scheduleCronPreview, scheduleNextRunPreview, selectedSchedule,
scheduleRunStatusOptions, getScheduleRunStatusBadge, formatDateTime, expandedScheduleRunId,
expandedScheduleRun, stepLabelMap, stepStatusMap, showTestRunDialog, testRunSchedule,
testRunWhere, testRunOrderBy, testRunBaseFetchSql, testRunLimit, testRunLoading, testRunResult,
testRunWhere, testRunOrderBy, testRunBaseFetchSql, testRunLimit, testRunKbSync, testRunKbSyncAvailable,
testRunKbSyncAttempted, testRunLoading, testRunResult,
filteredScheduleRuns, selectedScheduleRunMetrics, selectedScheduleLatestRunAt,
scheduleEnabledCount, scheduleDisabledCount, scheduleRunningCount, scheduleSqlEditForm,
scheduleTestLoading, scheduleTestResult, scheduleNotifyDropdownOpen,
scheduleTestLoading, scheduleTestResult, scheduleNotifyDropdownOpen, scheduleNotifyUserQuery,
filteredNotifyUsers, scheduleCloseNotifyDropdown, scheduleOwnerDropdownOpen, scheduleOwnerQuery,
filteredOwnerUsers, selectScheduleOwner, handleScheduleOwnerInput, scheduleCloseOwnerDropdown,
showDeleteConfirmDialog, deleteConfirmTitle, deleteConfirmMessage,
loadSchedules, startScheduleColResize, openScheduleCreateModal, openScheduleEditModal,
openScheduleRunSubmenu, backToScheduleOverview, viewScheduleRuns, resetScheduleRunFilters,
@@ -416,7 +419,7 @@ const {
<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"
v-if="(r.step_logs && r.step_logs.length > 0) || r.dify_execution_snapshot || r.kb_sync_status"
@click="expandedScheduleRunId = 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"
>
@@ -435,6 +438,23 @@ const {
>
<td colspan="10" class="px-4 py-3 bg-surface-soft/60">
<div class="space-y-3">
<div
v-if="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>
{{ expandedScheduleRun.kb_sync_status }}
</div>
<div v-if="expandedScheduleRun.kb_document_id" class="mt-1">
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.document') }}:</span>
{{ expandedScheduleRun.kb_document_id }}
</div>
<div v-if="expandedScheduleRun.kb_sync_error" class="mt-1 text-rose-600">
{{ expandedScheduleRun.kb_sync_error }}
</div>
</div>
<div
v-if="expandedScheduleRun.dify_execution_snapshot"
class="rounded-xl border border-indigo-200 bg-indigo-50/50 p-3"
@@ -544,6 +564,20 @@ const {
<input type="number" v-model.number="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="testRunKbSync"
type="checkbox"
class="h-4 w-4 rounded border-default text-emerald-600 focus:ring-emerald-300"
:disabled="!testRunKbSyncAvailable"
/>
{{ $t('admin.schedule.testRun.writeToKb') }}
</label>
<p class="mt-1 text-xs text-muted">
{{ 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"
@@ -636,6 +670,30 @@ const {
<summary class="cursor-pointer text-xs font-semibold text-rose-600 hover:text-rose-800">{{ $t('admin.schedule.testRun.errors', { count: 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">{{ testRunResult.errors.join('\n') }}</pre>
</details>
<div
v-if="testRunKbSyncAttempted"
class="rounded-xl border px-4 py-3 text-xs text-secondary"
:class="testRunResult.kb_sync_status === 'success' ? 'border-emerald-200 bg-emerald-50/40' : testRunResult.kb_sync_status === 'failed' ? 'border-rose-200 bg-rose-50/40' : 'border-amber-200 bg-amber-50/40'"
>
<div class="font-bold" :class="testRunResult.kb_sync_status === 'success' ? 'text-emerald-800' : testRunResult.kb_sync_status === 'failed' ? 'text-rose-800' : 'text-amber-800'">
{{ $t('admin.schedule.kbSync.title') }}
</div>
<div v-if="testRunResult.kb_sync_status" class="mt-1">
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.status') }}:</span>
{{ testRunResult.kb_sync_status }}
</div>
<div v-else class="mt-1 text-amber-700">
{{ $t('admin.schedule.testRun.kbSyncNoStatus') }}
</div>
<div v-if="testRunResult.kb_document_id" class="mt-1">
<span class="font-semibold text-muted">{{ $t('admin.schedule.kbSync.document') }}:</span>
{{ testRunResult.kb_document_id }}
</div>
<div v-if="testRunResult.kb_sync_error" class="mt-1 text-rose-600">
{{ testRunResult.kb_sync_error }}
</div>
</div>
</div>
</div>
</div>
@@ -661,12 +719,33 @@ const {
<div>
<label class="mb-2 block text-sm font-medium text-secondary">{{ $t('admin.schedule.form.owner') }}</label>
<div class="relative">
<select v-model="scheduleCreateForm.owner_user_id" class="input-field appearance-none pr-10 !text-sm !leading-5" :disabled="users.length === 0">
<option :value="null">{{ users.length === 0 ? $t('admin.schedule.form.noUsers') : $t('admin.schedule.form.selectOwner') }}</option>
<option v-for="u in users" :key="u.id" :value="u.id">{{ u.real_name || u.username }}{{ u.employee_id ? '(' + u.employee_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>
<input
v-model="scheduleOwnerQuery"
type="text"
class="input-field !text-sm !leading-5"
:placeholder="users.length === 0 ? $t('admin.schedule.form.noUsers') : $t('admin.schedule.form.selectOwner')"
:disabled="users.length === 0"
@focus="scheduleOwnerDropdownOpen = true"
@input="handleScheduleOwnerInput"
@blur="scheduleCloseOwnerDropdown"
/>
<div
v-if="scheduleOwnerDropdownOpen && users.length > 0"
class="admin-dropdown max-h-60 w-full overflow-y-auto"
>
<button
v-for="u in 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="scheduleCreateForm.owner_user_id === u.id ? 'bg-blue-50/50' : ''"
@mousedown.prevent="selectScheduleOwner(u.id)"
>
<span class="text-secondary">{{ u.real_name || u.username }}{{ u.employee_id ? '(' + u.employee_id + ')' : '' }}</span>
</button>
<div v-if="filteredOwnerUsers.length === 0" class="px-3 py-2 text-sm text-muted">
{{ $t('admin.wecom.noData') }}
</div>
</div>
</div>
</div>
@@ -927,6 +1006,21 @@ const {
</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="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="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="scheduleCreateForm.kb_group_id" class="input-field !text-sm !leading-5" :disabled="kbGroups.length === 0">
<option :value="null">{{ kbGroups.length === 0 ? $t('admin.schedule.form.noKbGroups') : $t('admin.schedule.form.selectKbGroup') }}</option>
<option v-for="group in kbGroups" :key="group.id" :value="group.id">{{ group.name }}</option>
</select>
</div>
</div>
<div v-if="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">Dify System Prompt</label>
@@ -1045,44 +1139,53 @@ const {
</label>
<div v-if="scheduleCreateForm.notify_enabled" class="relative flex-1">
<div
class="min-h-[38px] cursor-pointer 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"
@click="scheduleNotifyDropdownOpen = !scheduleNotifyDropdownOpen"
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"
>
<template v-if="scheduleCreateForm.notify_user_ids_json.length > 0">
<span
v-for="uid in 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"
>
{{ getUserName(uid) }}
<button
class="ml-0.5 text-blue-400 hover:text-blue-600"
@click.stop="removeNotifyUser(uid)"
>✕</button>
</span>
</template>
<span v-else class="text-muted">{{ $t('admin.schedule.form.selectNotifyUsers') }}</span>
<span
v-for="uid in 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"
>
{{ getUserName(uid) }}
<button
type="button"
class="ml-0.5 text-blue-400 hover:text-blue-600"
@click.stop="removeNotifyUser(uid)"
>✕</button>
</span>
<input
v-model="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="scheduleNotifyDropdownOpen = true"
@input="scheduleNotifyDropdownOpen = true"
@blur="scheduleCloseNotifyDropdown"
/>
</div>
<div
v-if="scheduleNotifyDropdownOpen"
class="admin-dropdown w-full"
class="admin-dropdown max-h-60 w-full overflow-y-auto"
>
<div
v-for="u in users"
<button
v-for="u in filteredNotifyUsers"
:key="u.id"
class="flex cursor-pointer items-center gap-2 px-3 py-2 text-sm transition hover:bg-surface-soft"
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="scheduleCreateForm.notify_user_ids_json.includes(u.id) ? 'bg-blue-50/50' : ''"
@click="toggleNotifyUser(u.id)"
@mousedown.prevent="toggleNotifyUser(u.id)"
>
<input
type="checkbox"
class="h-3.5 w-3.5 rounded text-blue-600"
class="pointer-events-none h-3.5 w-3.5 rounded text-blue-600"
:checked="scheduleCreateForm.notify_user_ids_json.includes(u.id)"
@click.stop
@change.stop="toggleNotifyUser(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="filteredNotifyUsers.length === 0" class="px-3 py-2 text-sm text-muted">
{{ $t('admin.wecom.noData') }}
</div>
</div>
</div>
+66 -2
View File
@@ -1203,6 +1203,11 @@ const messages = {
nextRun: 'Next run',
notifyEnabled: 'Enable notifications',
selectNotifyUsers: 'Select notification recipients...',
kbSyncEnabled: 'Sync result Excel to knowledge base',
kbSyncHint: 'After successful or partially successful runs, the generated Excel will be added to the selected knowledge base group.',
kbGroup: 'Knowledge base group',
selectKbGroup: 'Select knowledge base group...',
noKbGroups: 'No knowledge base groups available',
enableOnCreate: 'Enable after creation',
cancel: 'Cancel',
saving: 'Saving...',
@@ -1227,7 +1232,11 @@ const messages = {
errors: 'Errors ({count})',
queryResult: 'Query result',
resultSummary: '{total} total, showing {showing}',
viewGeneratedSql: 'View generated SQL'
viewGeneratedSql: 'View generated SQL',
writeToKb: 'Write to knowledge base',
writeToKbHint: 'After a successful or partially successful test run, sync the Excel result to the schedule knowledge base group.',
noKbGroupHint: 'Enable knowledge base sync and select a group in schedule settings first.',
kbSyncNoStatus: 'Knowledge base sync was requested but no status was returned. Check backend logs or schedule KB settings.'
},
status: {
all: 'All',
@@ -1253,6 +1262,11 @@ const messages = {
callInternalApi: 'Call internal API',
preDify: 'Dify pre-processing'
},
kbSync: {
title: 'Knowledge base sync',
status: 'Status',
document: 'Document ID'
},
deleteDialogTitle: 'Delete Schedule',
deleteConfirmMessage: 'Confirm deleting schedule \"{name}\"?',
msg: {
@@ -2771,6 +2785,11 @@ const messages = {
nextRun: '下次执行',
notifyEnabled: '启用通知',
selectNotifyUsers: '选择通知人员...',
kbSyncEnabled: '同步结果 Excel 至知识库',
kbSyncHint: '排程成功或部分成功后,会把生成的 Excel 加入所选知识库分组。',
kbGroup: '知识库分组',
selectKbGroup: '选择知识库分组...',
noKbGroups: '暂无可用知识库分组',
enableOnCreate: '创建后启用',
cancel: '取消',
saving: '保存中...',
@@ -2795,7 +2814,11 @@ const messages = {
errors: '错误信息 ({count})',
queryResult: '查询结果',
resultSummary: '共 {total} 条,展示 {showing} 条',
viewGeneratedSql: '查看生成 SQL'
viewGeneratedSql: '查看生成 SQL',
writeToKb: '写入知识库',
writeToKbHint: '测试成功或部分成功后,将 Excel 结果同步至排程已配置的知识库分组。',
noKbGroupHint: '请先在排程编辑中启用知识库同步并选择分组。',
kbSyncNoStatus: '已请求写入知识库,但未返回同步状态,请检查排程知识库配置或后端日志。'
},
status: {
all: '全部状态',
@@ -2821,6 +2844,11 @@ const messages = {
callInternalApi: '调用内部API',
preDify: 'Dify前处理'
},
kbSync: {
title: '知识库同步',
status: '状态',
document: '文档 ID'
},
deleteDialogTitle: '删除排程',
deleteConfirmMessage: '确认删除排程「{name}」?',
msg: {
@@ -4186,6 +4214,13 @@ const messages = {
// Common Messages
schedule: {
form: {
kbSyncEnabled: '同步結果 Excel 至知識庫',
kbSyncHint: '排程成功或部分成功後,會把生成的 Excel 加入所選知識庫分組。',
kbGroup: '知識庫分組',
selectKbGroup: '選擇知識庫分組...',
noKbGroups: '暫無可用知識庫分組'
},
status: {
all: '全部狀態',
success: '成功',
@@ -4210,6 +4245,17 @@ const messages = {
callInternalApi: '調用內部API',
preDify: 'Dify前處理'
},
kbSync: {
title: '知識庫同步',
status: '狀態',
document: '文件 ID'
},
testRun: {
writeToKb: '寫入知識庫',
writeToKbHint: '測試成功或部分成功後,將 Excel 結果同步至排程已配置的知識庫分組。',
noKbGroupHint: '請先在排程編輯中啟用知識庫同步並選擇分組。',
kbSyncNoStatus: '已請求寫入知識庫,但未返回同步狀態,請檢查排程知識庫配置或後端日誌。'
},
deleteDialogTitle: '刪除排程',
deleteConfirmMessage: '確認刪除排程「{name}」?',
msg: {
@@ -5465,6 +5511,13 @@ const messages = {
// Common Messages
schedule: {
form: {
kbSyncEnabled: 'ซิงค์ Excel ผลลัพธ์ไปยังคลังความรู้',
kbSyncHint: 'เมื่อรันสำเร็จหรือสำเร็จบางส่วน ระบบจะเพิ่ม Excel ที่สร้างขึ้นไปยังกลุ่มคลังความรู้ที่เลือก',
kbGroup: 'กลุ่มคลังความรู้',
selectKbGroup: 'เลือกกลุ่มคลังความรู้...',
noKbGroups: 'ไม่มีกลุ่มคลังความรู้ที่ใช้งานได้'
},
status: {
all: 'ทุกสถานะ',
success: 'สำเร็จ',
@@ -5489,6 +5542,17 @@ const messages = {
callInternalApi: 'เรียกใช้ API ภายใน',
preDify: 'ประมวลผลก่อน Dify'
},
kbSync: {
title: 'การซิงค์คลังความรู้',
status: 'สถานะ',
document: 'รหัสเอกสาร'
},
testRun: {
writeToKb: 'เขียนไปยังคลังความรู้',
writeToKbHint: 'หลังทดสอบสำเร็จหรือสำเร็จบางส่วน จะซิงค์ Excel ไปยังกลุ่มคลังความรู้ของตารางเวลา',
noKbGroupHint: 'โปรดเปิดใช้การซิงค์คลังความรู้และเลือกกลุ่มในการแก้ไขตารางเวลาก่อน',
kbSyncNoStatus: 'มีการขอเขียนคลังความรู้แล้ว แต่ไม่ได้รับสถานะซิงค์ โปรดตรวจการตั้งค่าคลังความรู้หรือบันทึก backend'
},
deleteDialogTitle: 'ลบตารางเวลา',
deleteConfirmMessage: 'ยืนยันการลบตารางเวลา \"{name}\"?',
msg: {