- 33 个 ListView.vue 加 :borderless=true + :page-sizes=[10,20,50,100]
覆盖: order/inquiry/finance/operateguide/sys/Dept|Menu|File|Notice|
Params|User|Role|Post|DictType|DictData|Product|Schedule|RoleGroup
user/Enterprise|enterpriselevel|enterprisescore|enterpriserating
supplier/promoter|couponscope|historylog|logistics|ordercomment|Activity
other/goodunit|label|textconfig
api/feedback|help|lunbo
openapi/AuditLog|CompanyAccount
- OrderListView: columns 抽到 script setup (computed) + :borderless +
:page-sizes + sub 动态显示选中数
- router/index.ts: /product/shop → redirect /supplier/good
(删 src/modules/product/shop/ShopListView.vue 旧占位, 后端 404 无意义)
- 沿用 W17 设计规范 v2 (PageHeader+SearchBar+DataTable+ListTabs)
199 lines
7.8 KiB
Vue
199 lines
7.8 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'
|
|
|
|
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: 280, 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 }">
|
|
<el-button text type="primary" size="small" @click="runHandle(row)">执行</el-button>
|
|
<el-button v-if="row.status === 1" text type="warning" size="small" @click="pauseHandle(row)">暂停</el-button>
|
|
<el-button v-else text type="primary" size="small" @click="resumeHandle(row)">恢复</el-button>
|
|
<el-button text type="primary" size="small" @click="deleteHandle(row)">删除</el-button>
|
|
</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> |