1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-21 17:29:17 +08:00

298 lines
11 KiB
Vue
Raw Normal View History

<template>
<div>
<RouterButton
:buttons="[
{
label: i18n.global.t('cronjob.cronTask'),
path: '/cronjobs',
},
]"
/>
2023-02-07 10:29:55 +08:00
<LayoutContent v-loading="loading" v-if="!isRecordShow" :title="$t('cronjob.cronTask')">
<template #toolbar>
2023-02-07 18:48:32 +08:00
<el-row>
2023-02-10 15:55:56 +08:00
<el-col :span="16">
2023-02-07 18:48:32 +08:00
<el-button type="primary" @click="onOpenDialog('create')">
{{ $t('commons.button.create') }}{{ $t('cronjob.cronTask') }}
</el-button>
<el-button type="primary" plain :disabled="selects.length === 0" @click="onBatchDelete(null)">
{{ $t('commons.button.delete') }}
</el-button>
</el-col>
2023-02-10 15:55:56 +08:00
<el-col :span="8">
<TableSetting @search="search()" />
2023-02-07 18:48:32 +08:00
<div class="search-button">
<el-input
v-model="searchName"
clearable
@clear="search()"
suffix-icon="Search"
@keyup.enter="search()"
@blur="search()"
:placeholder="$t('commons.button.search')"
></el-input>
</div>
</el-col>
</el-row>
</template>
<template #main>
2023-01-30 09:39:37 +08:00
<ComplexTable
:pagination-config="paginationConfig"
v-model:selects="selects"
@search="search"
:data="data"
>
<el-table-column type="selection" fix />
2023-02-07 18:48:32 +08:00
<el-table-column :label="$t('cronjob.taskName')" :min-width="120" prop="name">
<template #default="{ row }">
<el-link @click="loadDetail(row)" type="primary">{{ row.name }}</el-link>
</template>
</el-table-column>
2023-02-07 18:48:32 +08:00
<el-table-column :label="$t('commons.table.status')" :min-width="80" prop="status">
2023-01-30 09:39:37 +08:00
<template #default="{ row }">
<el-button
v-if="row.status === 'Enable'"
@click="onChangeStatus(row.id, 'disable')"
link
type="success"
>
{{ $t('commons.status.enabled') }}
</el-button>
<el-button v-else link type="danger" @click="onChangeStatus(row.id, 'enable')">
{{ $t('commons.status.disabled') }}
</el-button>
</template>
</el-table-column>
2023-02-07 18:48:32 +08:00
<el-table-column :label="$t('cronjob.cronSpec')" :min-width="120">
2023-01-30 09:39:37 +08:00
<template #default="{ row }">
<span v-if="row.specType.indexOf('N') === -1 || row.specType === 'perWeek'">
{{ $t('cronjob.' + row.specType) }}
</span>
<span v-else>{{ $t('cronjob.per') }}</span>
<span v-if="row.specType === 'perMonth'">
{{ row.day }}{{ $t('cronjob.day') }} {{ loadZero(row.hour) }} :
{{ loadZero(row.minute) }}
</span>
<span v-if="row.specType === 'perWeek'">
{{ loadWeek(row.week) }} {{ loadZero(row.hour) }} : {{ loadZero(row.minute) }}
</span>
<span v-if="row.specType === 'perDay'">
&#32;{{ loadZero(row.hour) }} : {{ loadZero(row.minute) }}
</span>
<span v-if="row.specType === 'perNDay'">
{{ row.day }} {{ $t('cronjob.day1') }}, {{ loadZero(row.hour) }} :
{{ loadZero(row.minute) }}
</span>
<span v-if="row.specType === 'perNHour'">
{{ row.hour }}{{ $t('cronjob.hour') }}, {{ loadZero(row.minute) }}
</span>
<span v-if="row.specType === 'perHour'">{{ loadZero(row.minute) }}</span>
<span v-if="row.specType === 'perNMinute'">{{ row.minute }}{{ $t('cronjob.minute') }}</span>
{{ $t('cronjob.handle') }}
</template>
</el-table-column>
2023-02-07 18:48:32 +08:00
<el-table-column :label="$t('cronjob.retainCopies')" :min-width="90" prop="retainCopies">
2023-02-07 10:29:55 +08:00
<template #default="{ row }">
{{ loadCopies(row) }}
</template>
</el-table-column>
2023-02-07 18:48:32 +08:00
<el-table-column :label="$t('cronjob.lastRecrodTime')" :min-width="120" prop="lastRecrodTime">
2023-01-30 09:39:37 +08:00
<template #default="{ row }">
{{ row.lastRecrodTime }}
</template>
</el-table-column>
2023-02-07 18:48:32 +08:00
<el-table-column :min-width="80" :label="$t('cronjob.target')" prop="targetDir">
2023-01-30 09:39:37 +08:00
<template #default="{ row }">
{{ loadBackupName(row.targetDir) }}
</template>
</el-table-column>
<fu-table-operations
width="200px"
:buttons="buttons"
:ellipsis="10"
:label="$t('commons.table.operate')"
fix
/>
</ComplexTable>
</template>
</LayoutContent>
2022-09-22 14:19:49 +08:00
<OperatrDialog @search="search" ref="dialogRef" />
2023-02-07 18:48:32 +08:00
<Records @search="search()" ref="dialogRecordRef" />
</div>
</template>
<script lang="ts" setup>
import ComplexTable from '@/components/complex-table/index.vue';
2023-02-10 15:55:56 +08:00
import TableSetting from '@/components/table-setting/index.vue';
2022-09-22 14:19:49 +08:00
import OperatrDialog from '@/views/cronjob/operate/index.vue';
2023-02-07 10:29:55 +08:00
import Records from '@/views/cronjob/record/index.vue';
2023-01-30 09:39:37 +08:00
import LayoutContent from '@/layout/layout-content.vue';
2022-09-29 11:13:05 +08:00
import { loadZero } from '@/utils/util';
import { onMounted, reactive, ref } from 'vue';
import RouterButton from '@/components/router-button/index.vue';
2022-09-29 11:13:05 +08:00
import { deleteCronjob, getCronjobPage, handleOnce, updateStatus } from '@/api/modules/cronjob';
import { loadBackupName } from '@/views/setting/helper';
import i18n from '@/lang';
2022-09-22 14:19:49 +08:00
import { Cronjob } from '@/api/interface/cronjob';
import { useDeleteData } from '@/hooks/use-delete-data';
import { ElMessage, ElMessageBox } from 'element-plus';
const loading = ref();
const selects = ref<any>([]);
2023-02-07 10:29:55 +08:00
const isRecordShow = ref();
const data = ref();
const paginationConfig = reactive({
currentPage: 1,
pageSize: 10,
total: 0,
});
2023-02-07 18:48:32 +08:00
const searchName = ref();
2022-09-29 11:13:05 +08:00
const weekOptions = [
{ label: i18n.global.t('cronjob.monday'), value: 1 },
{ label: i18n.global.t('cronjob.tuesday'), value: 2 },
{ label: i18n.global.t('cronjob.wednesday'), value: 3 },
{ label: i18n.global.t('cronjob.thursday'), value: 4 },
{ label: i18n.global.t('cronjob.friday'), value: 5 },
{ label: i18n.global.t('cronjob.saturday'), value: 6 },
{ label: i18n.global.t('cronjob.sunday'), value: 7 },
];
const search = async () => {
let params = {
2023-02-07 18:48:32 +08:00
info: searchName.value,
page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize,
};
loading.value = true;
await getCronjobPage(params)
.then((res) => {
loading.value = false;
data.value = res.data.items || [];
for (const item of data.value) {
if (item.targetDir !== '-') {
item.targetDir = loadBackupName(item.targetDir);
}
}
paginationConfig.total = res.data.total;
})
.catch(() => {
loading.value = false;
});
};
2023-02-07 10:29:55 +08:00
const dialogRecordRef = ref();
2023-02-07 10:29:55 +08:00
const dialogRef = ref();
2022-09-22 14:19:49 +08:00
const onOpenDialog = async (
title: string,
rowData: Partial<Cronjob.CronjobInfo> = {
specType: 'perMonth',
week: 1,
day: 3,
hour: 1,
minute: 30,
keepLocal: true,
retainCopies: 7,
2022-09-22 14:19:49 +08:00
},
) => {
let params = {
title,
rowData: { ...rowData },
};
dialogRef.value!.acceptParams(params);
};
2022-09-22 14:19:49 +08:00
const onBatchDelete = async (row: Cronjob.CronjobInfo | null) => {
let ids: Array<number> = [];
if (row) {
ids.push(row.id);
} else {
selects.value.forEach((item: Cronjob.CronjobInfo) => {
ids.push(item.id);
});
}
2022-12-02 10:59:07 +08:00
await useDeleteData(deleteCronjob, { ids: ids }, 'commons.msg.delete');
2022-09-22 14:19:49 +08:00
search();
};
const onChangeStatus = async (id: number, status: string) => {
ElMessageBox.confirm(i18n.global.t('cronjob.' + status + 'Msg'), i18n.global.t('cronjob.changeStatus'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
}).then(async () => {
let itemStatus = status === 'enable' ? 'Enable' : 'Disable';
await updateStatus({ id: id, status: itemStatus });
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
search();
});
};
2022-09-29 11:13:05 +08:00
const onHandle = async (row: Cronjob.CronjobInfo) => {
2023-02-07 10:29:55 +08:00
loading.value = true;
await handleOnce(row.id)
.then(() => {
loading.value = false;
ElMessage.success(i18n.global.t('commons.msg.operationSuccess'));
search();
})
.catch(() => {
loading.value = false;
});
};
const loadCopies = (item) => {
if (item.type === 'shell' || item.type === 'curl') {
return '-';
} else {
return item.retainCopies + '';
}
2022-09-29 11:13:05 +08:00
};
2022-09-22 14:19:49 +08:00
const loadDetail = (row: any) => {
isRecordShow.value = true;
let params = {
rowData: { ...row },
};
dialogRecordRef.value!.acceptParams(params);
};
const buttons = [
2022-09-29 11:13:05 +08:00
{
label: i18n.global.t('commons.button.handle'),
icon: 'Pointer',
click: (row: Cronjob.CronjobInfo) => {
onHandle(row);
},
},
{
label: i18n.global.t('commons.button.edit'),
icon: 'Edit',
2022-09-22 14:19:49 +08:00
click: (row: Cronjob.CronjobInfo) => {
onOpenDialog('edit', row);
},
},
{
label: i18n.global.t('commons.button.delete'),
icon: 'Delete',
2022-09-22 14:19:49 +08:00
click: (row: Cronjob.CronjobInfo) => {
onBatchDelete(row);
2022-09-22 14:19:49 +08:00
},
},
];
2022-09-29 11:13:05 +08:00
function loadWeek(i: number) {
for (const week of weekOptions) {
if (week.value === i) {
return week.label;
}
}
return '';
}
onMounted(() => {
search();
});
</script>