修复插件定时任务星期与时间格式显示问题
变更项:1) async_job 触发文案把每周数字改为中文星期(周一到周日),消除星期显示歧义。2) async_job 时间序列化改为 yyyy-MM-dd HH:mm:ss,去掉 ISO 格式中的 T。3) 插件定时任务页面统一使用 formatDateTime 渲染下次执行、上次执行与日志触发时间,前端兜底去除 T。4) 补充中文注释说明显示层与调度层格式化意图。
This commit is contained in:
@@ -27,8 +27,16 @@
|
||||
<el-tag :type="scope.row.enabled ? 'success' : 'info'">{% raw %}{{ scope.row.enabled ? '是' : '否' }}{% endraw %}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="next_run_at" label="下次执行" min-width="165"></el-table-column>
|
||||
<el-table-column prop="last_run_at" label="上次执行" min-width="165"></el-table-column>
|
||||
<el-table-column label="下次执行" min-width="165">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ formatDateTime(scope.row.next_run_at) }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="上次执行" min-width="165">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ formatDateTime(scope.row.last_run_at) }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="最近结果" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-tag :type="statusTag(scope.row.last_status)">{% raw %}{{ scope.row.last_status || 'never' }}{% endraw %}</el-tag>
|
||||
@@ -129,7 +137,11 @@
|
||||
|
||||
<el-dialog title="调度日志" :visible.sync="logsDialogVisible" width="860px">
|
||||
<el-table :data="logs" style="width:100%">
|
||||
<el-table-column prop="triggered_at" label="触发时间" width="180"></el-table-column>
|
||||
<el-table-column label="触发时间" width="180">
|
||||
<template slot-scope="scope">
|
||||
{% raw %}{{ formatDateTime(scope.row.triggered_at) }}{% endraw %}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="status" label="状态" width="100"></el-table-column>
|
||||
<el-table-column prop="summary" label="摘要" min-width="220"></el-table-column>
|
||||
<el-table-column label="详情">
|
||||
@@ -185,6 +197,26 @@ new Vue({
|
||||
if (status === 'running') return 'warning'
|
||||
return 'info'
|
||||
},
|
||||
formatDateTime(value) {
|
||||
// 统一清洗时间展示:去掉 ISO 'T',并兼容字符串与日期对象。
|
||||
if (!value) return ''
|
||||
if (typeof value === 'string') {
|
||||
return value.replace('T', ' ').slice(0, 19)
|
||||
}
|
||||
try {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) return String(value)
|
||||
const yyyy = date.getFullYear()
|
||||
const mm = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const dd = String(date.getDate()).padStart(2, '0')
|
||||
const hh = String(date.getHours()).padStart(2, '0')
|
||||
const mi = String(date.getMinutes()).padStart(2, '0')
|
||||
const ss = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${yyyy}-${mm}-${dd} ${hh}:${mi}:${ss}`
|
||||
} catch (e) {
|
||||
return String(value)
|
||||
}
|
||||
},
|
||||
async loadSchedules() {
|
||||
this.loading = true
|
||||
try {
|
||||
|
||||
@@ -48,7 +48,22 @@ class AsyncJob:
|
||||
|
||||
@staticmethod
|
||||
def _safe_iso(dt: Optional[datetime]) -> Optional[str]:
|
||||
return dt.isoformat(timespec="seconds") if dt else None
|
||||
# 后台展示统一使用空格分隔时间,避免前端看到 ISO 格式中的 'T'。
|
||||
return dt.strftime("%Y-%m-%d %H:%M:%S") if dt else None
|
||||
|
||||
@staticmethod
|
||||
def _weekday_to_label(weekday: int) -> str:
|
||||
"""把 0-6(周一到周日)转换为中文星期标签。"""
|
||||
mapping = {
|
||||
0: "周一",
|
||||
1: "周二",
|
||||
2: "周三",
|
||||
3: "周四",
|
||||
4: "周五",
|
||||
5: "周六",
|
||||
6: "周日",
|
||||
}
|
||||
return mapping.get(int(weekday), f"周{weekday}")
|
||||
|
||||
@staticmethod
|
||||
def _normalize_time_str(time_str: str) -> str:
|
||||
@@ -94,9 +109,11 @@ class AsyncJob:
|
||||
if trigger_type == "at_times":
|
||||
return "每天 " + ", ".join(trigger_config.get("time_list", []))
|
||||
if trigger_type == "every_weekday_time":
|
||||
return f"每周{trigger_config['weekday']} {trigger_config['time_str']}"
|
||||
# 触发文案显示中文星期,避免出现“周5显示成4”的数字歧义。
|
||||
return f"每{self._weekday_to_label(trigger_config['weekday'])} {trigger_config['time_str']}"
|
||||
if trigger_type == "every_week_time":
|
||||
return f"每周{trigger_config['weekday']} {trigger_config['time_str']}"
|
||||
# 与 every_weekday_time 保持一致,统一中文星期展示。
|
||||
return f"每{self._weekday_to_label(trigger_config['weekday'])} {trigger_config['time_str']}"
|
||||
if trigger_type == "every_month_last_day_time":
|
||||
return f"每月最后一天 {trigger_config['time_str']}"
|
||||
return trigger_type
|
||||
|
||||
Reference in New Issue
Block a user