cmc-web/webs/cop-web/src/views/history/config.ts

117 lines
3.4 KiB
TypeScript

/*
* @Author: Haijun Zhang
* @Date: 2022-11-03 15:30:02
* @LastEditTime: 2023-06-27 14:05:52
* @LastEditors: Haijun Zhang
* @Description:
* @FilePath: \csc-webd:\workspace\product\cmc-web\webs\cop-web\src\views\history\config.ts
*/
import { taskExeOptions as exeOpt } from '@cmp/cmp-common/commonData'
import { getTenant } from '@cmp/cmp-api/system/tenant'
import { filterCosData } from 'utils/filter'
const objToArr = (obj: any) => {
const arr = []
for (const a in obj) {
arr.push({
id: a,
name: obj[a],
})
}
return arr
}
export const taskExeOptions = exeOpt
export const columns = filterCosData([
{ type: 'selection' },
{ label: '任务名称', prop: 'name', scopedSlots: { customRender: 'name' } },
{ label: '实例ID', prop: 'uuid' },
{ label: '启动人', prop: 'operator' },
{ label: '任务状态', prop: 'status', scopedSlots: { customRender: 'status' } },
{ label: '开始时间', prop: 'gmtStart', minWidth: '110px' },
{ label: '结束时间', prop: 'gmtFinish', minWidth: '110px' },
{ label: '启动方式', prop: 'executeMode', scopedSlots: { customRender: 'executeMode' } },
{ label: '耗时(s)', prop: 'cost' },
{ label: '执行方式', prop: 'executeType' },
{ label: '所属租户', prop: 'tenantName' },
{ label: '所属平台', prop: 'platform' },
{ label: '创建时间', prop: 'gmtCreate' },
{ label: '操作', disabled: true, width: '200px', scopedSlots: { customRender: 'operate' } },
])
export const executeModeOptions = {
WEB: '页面执行',
API: 'API调用',
CRON: '定时执行',
}
export function getInitTime(type: 'day' | 'month' = 'day') {
const date = new Date()
const today = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
const currentYear = date.getFullYear()
const currentMonth = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
const nowDate = new Date(`${currentYear}-${currentMonth}-${today}`)
const nextDate = new Date(nowDate.valueOf() + 60 * 60 * 24 * 1000)
var Y = nextDate.getFullYear()
var M = nextDate.getMonth() + 1 < 10 ? '0' + (nextDate.getMonth() + 1) : nextDate.getMonth() + 1
var D = nextDate.getDate() < 10 ? '0' + nextDate.getDate() : nextDate.getDate()
// 当天时间
const dayTime = [`${currentYear}-${currentMonth}-${today}` + ' 00:00:00', `${Y}-${M}-${D}` + ' 00:00:00']
// 本月时间
const monthTime = [`${Y}-${currentMonth}-01` + ' 00:00:00', `${Y}-${M}-${D}` + ' 00:00:00']
if (type === 'month') return monthTime
return dayTime
}
export const searchConfigs = filterCosData([
{
label: '任务名称',
value: 'name',
type: 'Input',
},
{
label: '任务状态',
value: 'status',
type: 'Select',
data: objToArr(taskExeOptions),
},
{
label: '执行',
value: 'gmtCreate',
type: 'DateRange',
initValue: getInitTime('month'),
},
{
label: '启动任务',
value: 'executeMode',
type: 'Select',
data: objToArr(executeModeOptions),
},
{
label: '目标机器',
value: 'host',
type: 'Input',
sign: 'EQ',
},
{
label: '实例id',
value: 'uuid',
type: 'Input',
},
{
label: '所属平台',
value: 'platform',
type: 'Input',
},
{
label: '所属租户',
value: 'tenantId',
type: 'Select',
data: [],
service: {
api: getTenant,
params: { simple: true },
attr: 'data.rows',
},
},
])