Merge branch 'dev' of https://gitee.com/justop/hxops into dev
This commit is contained in:
commit
c0cb55dce6
9 files changed
+268
-17
No files matched your search
@@ -22,6 +22,7 @@ import { useGlobalMessageDialog } from '../composables/useGlobalMessageDialog';
|
||||
import { buildWecomAuditMeta, formatWecomAuditReason } from '../utils/wecom';
|
||||
import { getAuthHeaders } from '../utils/auth';
|
||||
import { listAdminSchedules, createAdminSchedule, updateAdminSchedule, deleteAdminSchedule, toggleAdminSchedule, runAdminSchedule, listAdminScheduleRuns, getAdminScheduleTaskConfig, testAdminScheduleSql, testAdminScheduleRun, type ScheduleTask, type ScheduleRun, type TestScheduleRunResult } from '../api/schedule';
|
||||
import { exportAdminScheduleUrl, importAdminSchedules } from '../api/schedule';
|
||||
import {
|
||||
ArrowLeft,
|
||||
// Save,
|
||||
@@ -38,6 +39,7 @@ import {
|
||||
MessageSquare,
|
||||
Globe,
|
||||
Download,
|
||||
ArrowUpFromLine,
|
||||
UserCog,
|
||||
Building,
|
||||
MessageCircleQuestion,
|
||||
@@ -708,6 +710,8 @@ const openScheduleCreateModal = async () => {
|
||||
const openScheduleEditModal = async (task: ScheduleTask) => {
|
||||
await Promise.all([loadAgents(), loadUsers()]);
|
||||
scheduleConfigCollapsed.value = true;
|
||||
scheduleNotifyFilterText.value = '';
|
||||
scheduleNotifyDropdownOpen.value = false;
|
||||
scheduleEditingId.value = task.id;
|
||||
scheduleCreateForm.value = {
|
||||
name: task.name || '',
|
||||
@@ -720,6 +724,31 @@ const openScheduleEditModal = async (task: ScheduleTask) => {
|
||||
enabled: !!task.enabled,
|
||||
data_source_type: (task.data_source_type || 'database') as 'database' | 'external_api',
|
||||
};
|
||||
scheduleSqlEditForm.value = {
|
||||
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: '',
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await getAdminScheduleTaskConfig(task.id);
|
||||
@@ -906,6 +935,7 @@ const selectedScheduleLatestRunAt = computed(
|
||||
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 scheduleImportInputRef = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const loadSchedules = async () => {
|
||||
scheduleLoading.value = true;
|
||||
@@ -930,6 +960,38 @@ const loadSchedules = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const exportSchedule = async (taskId: number) => {
|
||||
const res = await fetch(exportAdminScheduleUrl(taskId), { headers: getAuthHeaders() });
|
||||
if (!res.ok) {
|
||||
showMessageDialog('error', '导出失败');
|
||||
return;
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `schedule_${taskId}_${new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-')}.json`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const importSchedulesFromFile = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement;
|
||||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const text = await file.text();
|
||||
const payload = JSON.parse(text);
|
||||
const result = await importAdminSchedules(payload);
|
||||
showMessageDialog('success', `导入完成:${result.imported} 条,跳过 ${result.skipped} 条`);
|
||||
await loadSchedules();
|
||||
} catch (e: any) {
|
||||
showMessageDialog('error', e?.message || '导入失败');
|
||||
} finally {
|
||||
input.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleSqlEditForm = ref({
|
||||
base_fetch_sql: '',
|
||||
fetch_where_conditions: '',
|
||||
@@ -980,6 +1042,24 @@ const handleTestScheduleSql = async () => {
|
||||
};
|
||||
|
||||
const scheduleNotifyDropdownOpen = ref(false);
|
||||
const scheduleNotifyFilterText = ref('');
|
||||
|
||||
const filteredScheduleNotifyUsers = computed(() => {
|
||||
const keyword = scheduleNotifyFilterText.value.trim().toLowerCase();
|
||||
if (!keyword) return users.value;
|
||||
return users.value.filter((u) => {
|
||||
const fields = [
|
||||
u.real_name,
|
||||
u.username,
|
||||
u.employee_id,
|
||||
u.email,
|
||||
u.phone_number,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.map(v => String(v).toLowerCase());
|
||||
return fields.some(v => v.includes(keyword));
|
||||
});
|
||||
});
|
||||
|
||||
const getUserName = (uid: number) => {
|
||||
const u = users.value.find(x => x.id === uid);
|
||||
@@ -4241,7 +4321,7 @@ const handlePermissionImport = async (event: Event) => {
|
||||
|
||||
<template v-if="scheduleViewMode === 'overview'">
|
||||
<div class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<div class="mb-5 grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="mb-5 grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-4">
|
||||
<div class="rounded-2xl bg-slate-50 px-4 py-3">
|
||||
<div class="text-xl font-bold text-slate-900">{{ schedules.length }}</div>
|
||||
<div class="text-sm text-slate-500">排程总数</div>
|
||||
@@ -4272,6 +4352,13 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<Settings2 class="h-4 w-4" />
|
||||
</div>
|
||||
<div class="font-semibold text-slate-900">新增排程</div>
|
||||
<button
|
||||
class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-xl border border-violet-200 text-violet-700 transition hover:bg-violet-50"
|
||||
title="汇入"
|
||||
@click="scheduleImportInputRef?.click()"
|
||||
>
|
||||
<ArrowUpFromLine class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="text-sm text-slate-500">
|
||||
点击按钮后弹窗录入排程字段。
|
||||
@@ -4284,6 +4371,13 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<Plus class="h-4 w-4" />
|
||||
新增排程
|
||||
</button>
|
||||
<input
|
||||
ref="scheduleImportInputRef"
|
||||
type="file"
|
||||
accept=".json,application/json"
|
||||
class="hidden"
|
||||
@change="importSchedulesFromFile"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4295,7 +4389,16 @@ const handlePermissionImport = async (event: Event) => {
|
||||
<button class="w-full text-left" @click="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-slate-900">{{ s.name }}</div>
|
||||
<div class="flex min-w-0 items-center gap-2">
|
||||
<div class="truncate text-base font-semibold text-slate-900">{{ s.name }}</div>
|
||||
<button
|
||||
class="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-xl border border-emerald-200 text-emerald-700 transition hover:bg-emerald-50"
|
||||
title="汇出"
|
||||
@click.stop="exportSchedule(s.id)"
|
||||
>
|
||||
<Download class="h-4 w-4" />
|
||||
</button>
|
||||
</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-slate-200 text-slate-600'">
|
||||
{{ s.enabled ? '启用' : '停用' }}
|
||||
@@ -4303,12 +4406,6 @@ const handlePermissionImport = async (event: Event) => {
|
||||
</div>
|
||||
<div class="mt-2 text-sm text-slate-500">编号:{{ s.schedule_no }}</div>
|
||||
<div class="mt-1 text-sm text-slate-500">Cron:{{ s.cron_expr }}</div>
|
||||
<div
|
||||
v-if="s.schedule_type === 'platform_app' && s.platform_api_path"
|
||||
class="mt-1 text-sm text-slate-500"
|
||||
>
|
||||
配置:{{ s.platform_api_path }}
|
||||
</div>
|
||||
<div class="mt-1 text-sm text-slate-500">所有者:{{ s.owner_username || s.owner_user_id }}</div>
|
||||
</div>
|
||||
</button>
|
||||
@@ -6046,8 +6143,17 @@ const handlePermissionImport = async (event: Event) => {
|
||||
v-if="scheduleNotifyDropdownOpen"
|
||||
class="absolute z-50 mt-1 max-h-52 w-full overflow-auto rounded-xl border border-slate-200 bg-white shadow-lg"
|
||||
>
|
||||
<div class="sticky top-0 z-10 border-b border-slate-100 bg-white p-2">
|
||||
<input
|
||||
v-model.trim="scheduleNotifyFilterText"
|
||||
type="text"
|
||||
class="input-field !h-8 !rounded-lg !px-2.5 !py-1 !text-xs"
|
||||
placeholder="输入姓名 / 工号 / 用户名筛选"
|
||||
@click.stop
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-for="u in users"
|
||||
v-for="u in filteredScheduleNotifyUsers"
|
||||
:key="u.id"
|
||||
class="flex cursor-pointer items-center gap-2 px-3 py-2 text-sm transition hover:bg-slate-50"
|
||||
:class="scheduleCreateForm.notify_user_ids_json.includes(u.id) ? 'bg-blue-50/50' : ''"
|
||||
@@ -6063,6 +6169,9 @@ const handlePermissionImport = async (event: Event) => {
|
||||
/>
|
||||
<span class="text-slate-700">{{ u.real_name || u.username }}{{ u.employee_id ? '(' + u.employee_id + ')' : '' }}</span>
|
||||
</div>
|
||||
<div v-if="filteredScheduleNotifyUsers.length === 0" class="px-3 py-3 text-xs text-slate-400">
|
||||
未找到匹配人员
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user