jcloud平台站点任务列表页显示为中文
This commit is contained in:
parent
8f18a47a1c
commit
11c77c7177
@ -41,7 +41,7 @@
|
|||||||
<div class="text-base text-gray-600" v-else-if="column.type == 'Timestamp'">
|
<div class="text-base text-gray-600" v-else-if="column.type == 'Timestamp'">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<Tooltip :text="$format.date(value)">
|
<Tooltip :text="$format.date(value)">
|
||||||
{{ value ? $dayjs(value).fromNow() : '' }}
|
{{ value ? (column.format ? formattedValue : $dayjs(value).fromNow()) : '' }}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -7,6 +7,46 @@ import { isMobile } from '../../utils/device';
|
|||||||
import { duration } from '../../utils/format';
|
import { duration } from '../../utils/format';
|
||||||
import ObjectList from '../ObjectList.vue';
|
import ObjectList from '../ObjectList.vue';
|
||||||
|
|
||||||
|
// 英文 job_type 到中文的映射
|
||||||
|
const jobTypeI18nMap = {
|
||||||
|
'Update Site Status': '更新站点状态',
|
||||||
|
'Update Site Configuration': '更新站点配置',
|
||||||
|
'Install App on Site': '安装应用到站点',
|
||||||
|
'Uninstall App from Site': '从站点卸载应用',
|
||||||
|
'Backup Site': '备份站点',
|
||||||
|
'Restore Site': '恢复站点',
|
||||||
|
'Create Server': '创建服务器',
|
||||||
|
'Update In Place': '原地升级',
|
||||||
|
// 可按需补充更多
|
||||||
|
};
|
||||||
|
function jobTypeI18n(type) {
|
||||||
|
return jobTypeI18nMap[type] || type;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 状态映射
|
||||||
|
const statusI18nMap = {
|
||||||
|
'Pending': '待处理',
|
||||||
|
'Running': '运行中',
|
||||||
|
'Success': '成功',
|
||||||
|
'Failure': '失败',
|
||||||
|
};
|
||||||
|
function statusI18n(status) {
|
||||||
|
return statusI18nMap[status] || status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 中文时间格式化
|
||||||
|
function formatTimeZh(time) {
|
||||||
|
if (!time) return '';
|
||||||
|
const date = typeof time === 'string' ? new Date(time) : time;
|
||||||
|
const now = new Date();
|
||||||
|
const diff = (now.getTime() - date.getTime()) / 1000;
|
||||||
|
if (diff < 60) return '刚刚';
|
||||||
|
if (diff < 3600) return Math.floor(diff / 60) + '分钟前';
|
||||||
|
if (diff < 86400) return Math.floor(diff / 3600) + '小时前';
|
||||||
|
if (diff < 2592000) return Math.floor(diff / 86400) + '天前';
|
||||||
|
return date.toLocaleDateString('zh-CN');
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'SiteJobs',
|
name: 'SiteJobs',
|
||||||
props: ['name'],
|
props: ['name'],
|
||||||
@ -61,22 +101,15 @@ export default {
|
|||||||
{
|
{
|
||||||
label: '任务类型',
|
label: '任务类型',
|
||||||
fieldname: 'job_type',
|
fieldname: 'job_type',
|
||||||
class: 'font-medium'
|
class: 'font-medium',
|
||||||
|
format: jobTypeI18n
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '状态',
|
label: '状态',
|
||||||
fieldname: 'status',
|
fieldname: 'status',
|
||||||
type: 'Badge',
|
type: 'Badge',
|
||||||
width: 0.5,
|
width: 0.5,
|
||||||
format(value) {
|
format: statusI18n
|
||||||
const statusMap = {
|
|
||||||
'Pending': '待处理',
|
|
||||||
'Running': '运行中',
|
|
||||||
'Success': '成功',
|
|
||||||
'Failure': '失败'
|
|
||||||
};
|
|
||||||
return statusMap[value] || value;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '站点',
|
label: '站点',
|
||||||
@ -102,7 +135,8 @@ export default {
|
|||||||
fieldname: 'creation',
|
fieldname: 'creation',
|
||||||
type: 'Timestamp',
|
type: 'Timestamp',
|
||||||
width: 0.5,
|
width: 0.5,
|
||||||
align: 'right'
|
align: 'right',
|
||||||
|
format: formatTimeZh
|
||||||
}
|
}
|
||||||
].filter(c => (c.condition ? c.condition() : true))
|
].filter(c => (c.condition ? c.condition() : true))
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,34 @@ import { ColumnField, Tab } from './types';
|
|||||||
|
|
||||||
type JobDocTypes = 'Site' | 'Bench' | 'Server' | 'Release Group';
|
type JobDocTypes = 'Site' | 'Bench' | 'Server' | 'Release Group';
|
||||||
|
|
||||||
|
// 英文 job_type 到中文的映射
|
||||||
|
const jobTypeI18nMap: Record<string, string> = {
|
||||||
|
'Update Site Status': '更新站点状态',
|
||||||
|
'Update Site Configuration': '更新站点配置',
|
||||||
|
'Install App on Site': '安装应用到站点',
|
||||||
|
'Uninstall App from Site': '从站点卸载应用',
|
||||||
|
'Backup Site': '备份站点',
|
||||||
|
'Restore Site': '恢复站点',
|
||||||
|
'Create Server': '创建服务器',
|
||||||
|
'Update In Place': '原地升级',
|
||||||
|
// 可按需补充更多
|
||||||
|
};
|
||||||
|
|
||||||
|
function jobTypeI18n(type: string) {
|
||||||
|
return jobTypeI18nMap[type] || type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusI18nMap: Record<string, string> = {
|
||||||
|
'Pending': '待处理',
|
||||||
|
'Running': '运行中',
|
||||||
|
'Success': '成功',
|
||||||
|
'Failure': '失败',
|
||||||
|
};
|
||||||
|
|
||||||
|
function statusI18n(status: string) {
|
||||||
|
return statusI18nMap[status] || status;
|
||||||
|
}
|
||||||
|
|
||||||
export function getJobsTab(pagetype: JobDocTypes) {
|
export function getJobsTab(pagetype: JobDocTypes) {
|
||||||
const jobRoute = getJobRoute(pagetype);
|
const jobRoute = getJobRoute(pagetype);
|
||||||
|
|
||||||
@ -85,13 +113,15 @@ function getJobTabColumns(pagetype: JobDocTypes) {
|
|||||||
{
|
{
|
||||||
label: '任务类型',
|
label: '任务类型',
|
||||||
fieldname: 'job_type',
|
fieldname: 'job_type',
|
||||||
class: 'font-medium'
|
class: 'font-medium',
|
||||||
|
format: jobTypeI18n
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '状态',
|
label: '状态',
|
||||||
fieldname: 'status',
|
fieldname: 'status',
|
||||||
type: 'Badge',
|
type: 'Badge',
|
||||||
width: 0.5
|
width: 0.5,
|
||||||
|
format: statusI18n
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '站点',
|
label: '站点',
|
||||||
@ -116,10 +146,24 @@ function getJobTabColumns(pagetype: JobDocTypes) {
|
|||||||
fieldname: 'creation',
|
fieldname: 'creation',
|
||||||
type: 'Timestamp',
|
type: 'Timestamp',
|
||||||
width: 0.75,
|
width: 0.75,
|
||||||
align: 'right'
|
align: 'right',
|
||||||
|
format: (value) => formatTimeZh(value)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
if (pagetype !== 'Site') return columns;
|
if (pagetype !== 'Site') return columns;
|
||||||
return columns.filter(c => c.fieldname !== 'site');
|
return columns.filter(c => c.fieldname !== 'site');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 中文时间格式化函数
|
||||||
|
function formatTimeZh(time: string | Date) {
|
||||||
|
if (!time) return '';
|
||||||
|
const date = typeof time === 'string' ? new Date(time) : time;
|
||||||
|
const now = new Date();
|
||||||
|
const diff = (now.getTime() - date.getTime()) / 1000;
|
||||||
|
if (diff < 60) return '刚刚';
|
||||||
|
if (diff < 3600) return Math.floor(diff / 60) + '分钟前';
|
||||||
|
if (diff < 86400) return Math.floor(diff / 3600) + '小时前';
|
||||||
|
if (diff < 2592000) return Math.floor(diff / 86400) + '天前';
|
||||||
|
return date.toLocaleDateString('zh-CN');
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user