用户反馈: 操作列只显示一个文字按钮+⋯ 不方便, 期望按按钮数量智能显示 - 过滤 when 后 ≤3 个: 全部显示文字按钮, 不显示 ⋯ - 过滤 when 后 ≥4 个: 前 2 个常驻文字按钮 + ⋯ (收纳剩余) - 默认 visibleCount=2 (可配置) TableActions API 调整 (W17.6 → W17.6.1): - 原来: :primary=[A] + :more=[B,C,D] (人为主次划分) - 现在: :actions=[A,B,C,D] (按数组顺序自动前 2 显 + ⋯) 16 文件改动 (1 组件 + 15 view 调用方式): - 15 view 合并 :primary/:more → :actions - 3 按钮页 (10 个): 现在全部显示文字按钮无 ⋯, 体验更直接 - 4/5 按钮页 (5 个): 前 2 显 + ⋯, 比之前详情+⋯更直观
205 lines
7.9 KiB
Vue
205 lines
7.9 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* F006 定时任务 - W4.16
|
|
*
|
|
* W11 A8: 套 PageHeader/SearchBar 标准化模板
|
|
*
|
|
* 后端: GET /sys/schedule/page
|
|
* 字段: id/beanName/methodName/params/cron/expression/status/remark/createDate
|
|
*/
|
|
import { onMounted, ref, reactive } from 'vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import { httpGet, httpPost, httpPut, httpDelete } from '@/utils/request'
|
|
import DataTable from '@/components/DataTable/DataTable.vue'
|
|
import PageHeader from '@/components/PageHeader/PageHeader.vue'
|
|
import SearchBar from '@/components/SearchBar/SearchBar.vue'
|
|
import TableActions from '@/components/TableActions/TableActions.vue'
|
|
|
|
interface Schedule {
|
|
id: string
|
|
beanName: string
|
|
methodName: string
|
|
params: string | null
|
|
cron: string
|
|
expression: string | null
|
|
status: 0 | 1
|
|
remark: string | null
|
|
createDate: string | number
|
|
raw: any
|
|
}
|
|
|
|
const STATUS_MAP: Record<number, { label: string; type: string }> = {
|
|
1: { label: '正常', type: 'success' },
|
|
0: { label: '暂停', type: 'info' }
|
|
}
|
|
|
|
const list = ref<Schedule[]>([])
|
|
const total = ref(0)
|
|
const loading = ref(false)
|
|
const error = ref<string | null>(null)
|
|
const page = ref(1)
|
|
const limit = ref(10)
|
|
const filters = reactive({ beanName: '' })
|
|
|
|
function fmtDate(ts?: string | number | null) {
|
|
if (!ts) return '--'
|
|
const n = typeof ts === 'string' ? Date.parse(ts) : ts
|
|
if (!n || isNaN(n)) return String(ts)
|
|
const d = new Date(n)
|
|
if (isNaN(d.getTime())) return String(ts)
|
|
const pad = (x: number) => String(x).padStart(2, '0')
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
}
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
error.value = null
|
|
try {
|
|
const data = await httpGet<{ total: number | string; list: any[] }>('/sys/schedule/page', {
|
|
page: page.value,
|
|
limit: limit.value,
|
|
...(filters.beanName ? { beanName: filters.beanName } : {})
|
|
})
|
|
list.value = (data.list || []).map((it: any) => ({
|
|
id: String(it.id),
|
|
beanName: it.beanName || '--',
|
|
methodName: it.methodName || '--',
|
|
params: it.params,
|
|
cron: it.cron || '--',
|
|
expression: it.expression,
|
|
status: (it.status ?? 1) as 0 | 1,
|
|
remark: it.remark,
|
|
createDate: it.createDate,
|
|
raw: it
|
|
}))
|
|
total.value = Number(data.total) || 0
|
|
} catch (e: any) {
|
|
error.value = e?.msg || e?.message || '后端接口异常'
|
|
list.value = []
|
|
total.value = 0
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function onSearch() { page.value = 1; load() }
|
|
function onReset() { filters.beanName = ''; page.value = 1; load() }
|
|
function onPageChange(p: number) { page.value = p; load() }
|
|
function onLimitChange(l: number) { limit.value = l; page.value = 1; load() }
|
|
|
|
async function runHandle(row: Schedule) {
|
|
try {
|
|
await ElMessageBox.confirm(`确认立即执行 ${row.beanName}.${row.methodName}?`, '执行确认', { type: 'info', confirmButtonText: '执行' })
|
|
} catch { return }
|
|
try {
|
|
await httpPost(`/sys/schedule/run/${row.id}`)
|
|
ElMessage.success('执行成功')
|
|
} catch (e: any) {
|
|
ElMessage.error(e?.msg || e?.message || '执行失败')
|
|
}
|
|
}
|
|
|
|
async function pauseHandle(row: Schedule) {
|
|
try {
|
|
await httpPost(`/sys/schedule/pause/${row.id}`)
|
|
ElMessage.success('暂停成功')
|
|
load()
|
|
} catch (e: any) { ElMessage.error(e?.msg || e?.message || '暂停失败') }
|
|
}
|
|
|
|
async function resumeHandle(row: Schedule) {
|
|
try {
|
|
await httpPost(`/sys/schedule/resume/${row.id}`)
|
|
ElMessage.success('恢复成功')
|
|
load()
|
|
} catch (e: any) { ElMessage.error(e?.msg || e?.message || '恢复失败') }
|
|
}
|
|
|
|
async function deleteHandle(row: Schedule) {
|
|
try { await ElMessageBox.confirm(`确认删除定时任务 ${row.beanName} 吗?`, '删除确认', { type: 'warning' }) } catch { return }
|
|
try { await httpDelete(`/sys/schedule/${row.id}`); ElMessage.success('删除成功'); load() }
|
|
catch (e: any) { ElMessage.error(e?.msg || e?.message || '删除失败') }
|
|
}
|
|
|
|
onMounted(load)
|
|
</script>
|
|
|
|
<template>
|
|
<div class="rr-sys-schedule">
|
|
<PageHeader title="定时任务" :sub="`共 ${total} 个任务`">
|
|
<el-button @click="onReset" class="rr-btn-secondary">重置</el-button>
|
|
</PageHeader>
|
|
|
|
<SearchBar
|
|
v-model:filters="filters"
|
|
:fields='[
|
|
{ key: "beanName", label: "Bean 名", type: "text", placeholder: "Bean 名" }
|
|
]'
|
|
@search="onSearch"
|
|
@reset="onReset"
|
|
/>
|
|
|
|
<div class="rr-list-card">
|
|
<DataTable
|
|
:columns="[
|
|
{ prop: 'beanName', label: 'Bean 名', minWidth: 200, slot: 'beanName' },
|
|
{ prop: 'methodName', label: '方法名', width: 180 },
|
|
{ prop: 'params', label: '参数', minWidth: 200 },
|
|
{ prop: 'cron', label: 'Cron 表达式', minWidth: 160, slot: 'cron' },
|
|
{ prop: 'remark', label: '备注', minWidth: 200 },
|
|
{ prop: 'status', label: '状态', width: 100, slot: 'status' },
|
|
{ prop: 'createDate', label: '创建时间', width: 170, slot: 'createDate' },
|
|
{ label: '操作', width: 140, slot: 'action' }
|
|
]"
|
|
:data="list"
|
|
:loading="loading"
|
|
:total="total"
|
|
:page="page"
|
|
:limit="limit"
|
|
:show-pagination="true" :page-sizes="[10, 20, 50, 100]"
|
|
:error="error"
|
|
empty-text="暂无定时任务"
|
|
borderless
|
|
row-key="id"
|
|
@page-change="onPageChange"
|
|
@limit-change="onLimitChange"
|
|
>
|
|
<template #beanName="{ row }"><code class="rr-mono">{{ row.beanName }}</code></template>
|
|
<template #cron="{ row }"><code class="rr-mono-sm">{{ row.cron }}</code></template>
|
|
<template #status="{ row }">
|
|
<el-tag :type="STATUS_MAP[row.status].type as any" size="small" effect="light">{{ STATUS_MAP[row.status].label }}</el-tag>
|
|
</template>
|
|
<template #createDate="{ row }"><span class="rr-time">{{ fmtDate(row.createDate) }}</span></template>
|
|
<template #action="{ row }">
|
|
<TableActions
|
|
:row="row"
|
|
:actions="[
|
|
{ label: '执行', type: 'primary', onClick: runHandle },
|
|
{ label: '暂停', type: 'warning', when: (r: any) => r.status === 1, onClick: pauseHandle },
|
|
{ label: '恢复', type: 'primary', when: (r: any) => r.status !== 1, onClick: resumeHandle },
|
|
{ label: '删除', type: 'danger', onClick: deleteHandle }
|
|
]"
|
|
/>
|
|
</template>
|
|
</DataTable>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.rr-sys-schedule { padding: 16px; }
|
|
.rr-list-card { background: var(--surface); border-radius: 12px; padding: 4px; }
|
|
.rr-time { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--ink-2); }
|
|
.rr-muted { color: var(--ink-3); font-size: 12px; }
|
|
.rr-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
|
|
.rr-page-titles { display: flex; flex-direction: column; gap: 2px; }
|
|
.rr-page-title { margin: 0; font-size: 18px; font-weight: 600; color: var(--el-text-color-primary); }
|
|
.rr-page-sub { margin: 0; font-size: 12px; color: var(--el-text-color-secondary); }
|
|
.rr-page-actions { display: flex; gap: 8px; }
|
|
.rr-filters-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; padding: 12px 16px; background: var(--el-fill-color-light); border-radius: 8px; }
|
|
.rr-bean-input { width: 240px; }
|
|
.rr-list-card { background: var(--el-bg-color); border-radius: 12px; padding: 4px; }
|
|
.rr-time { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--el-text-color-regular); }
|
|
.rr-mono { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; padding: 2px 6px; background: var(--el-fill-color-light); border-radius: 4px; color: var(--el-color-primary); }
|
|
.rr-mono-sm { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 11px; color: var(--el-text-color-regular); }
|
|
</style> |