1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 14:08:06 +08:00

fix: 修改计划任务报告样式 (#1142)

This commit is contained in:
ssongliu 2023-05-25 15:12:16 +08:00 committed by GitHub
parent c76c24e102
commit 48e3ef3e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 78 deletions

View File

@ -87,7 +87,7 @@ func ExecCronjobWithTimeOut(cmdStr string, timeout time.Duration) (string, error
if len(errMsg) != 0 { if len(errMsg) != 0 {
errMsg = fmt.Sprintf("%s \n\n; stdout:\n %s", errMsg, stdout.String()) errMsg = fmt.Sprintf("%s \n\n; stdout:\n %s", errMsg, stdout.String())
} else { } else {
errMsg = fmt.Sprintf("stdout\n: %s", stdout.String()) errMsg = fmt.Sprintf("stdout:\n %s", stdout.String())
} }
} }
return errMsg, err return errMsg, err

View File

@ -84,7 +84,7 @@
<el-col :span="8"> <el-col :span="8">
<el-date-picker <el-date-picker
style="width: calc(100% - 20px)" style="width: calc(100% - 20px)"
@change="search(true)" @change="search()"
v-model="timeRangeLoad" v-model="timeRangeLoad"
type="datetimerange" type="datetimerange"
:range-separator="$t('commons.search.timeRange')" :range-separator="$t('commons.search.timeRange')"
@ -94,7 +94,7 @@
></el-date-picker> ></el-date-picker>
</el-col> </el-col>
<el-col :span="16"> <el-col :span="16">
<el-select @change="search(true)" v-model="searchInfo.status"> <el-select @change="search()" v-model="searchInfo.status">
<template #prefix>{{ $t('commons.table.status') }}</template> <template #prefix>{{ $t('commons.table.status') }}</template>
<el-option :label="$t('commons.table.all')" value="" /> <el-option :label="$t('commons.table.all')" value="" />
<el-option :label="$t('commons.status.success')" value="Success" /> <el-option :label="$t('commons.status.success')" value="Success" />
@ -105,29 +105,39 @@
</el-row> </el-row>
</template> </template>
<template #main> <template #main>
<el-row :gutter="20" v-if="hasRecords"> <el-row :gutter="20" v-show="hasRecords">
<el-col :span="8"> <el-col :span="8">
<el-card> <div>
<ul v-infinite-scroll="nextPage" class="infinite-list" style="overflow: auto"> <ul class="infinite-list" style="overflow: auto">
<li <li
v-for="(item, index) in records" v-for="(item, index) in records"
:key="index" :key="index"
@click="forDetail(item, index)" @click="forDetail(item)"
class="infinite-list-item" class="infinite-list-item"
> >
<el-icon v-if="item.status === 'Success'"><Select /></el-icon> <el-icon v-if="item.status === 'Success'"><Select /></el-icon>
<el-icon v-if="item.status === 'Waiting'"><Loading /></el-icon> <el-icon v-if="item.status === 'Waiting'"><Loading /></el-icon>
<el-icon v-if="item.status === 'Failed'"><CloseBold /></el-icon> <el-icon v-if="item.status === 'Failed'"><CloseBold /></el-icon>
<span v-if="index === currentRecordIndex" style="color: red"> <span v-if="item.id === currentRecord.id" style="color: red">
{{ dateFormat(0, 0, item.startTime) }} {{ dateFormat(0, 0, item.startTime) }}
</span> </span>
<span v-else>{{ dateFormat(0, 0, item.startTime) }}</span> <span v-else>{{ dateFormat(0, 0, item.startTime) }}</span>
</li> </li>
</ul> </ul>
<div style="margin-top: 10px; margin-bottom: 5px; font-size: 12px; float: right"> <div style="margin-top: 10px; font-size: 12px; float: right">
<span>{{ $t('commons.table.total', [searchInfo.recordTotal]) }}</span> <el-pagination
:page-size="searchInfo.pageSize"
:current-page="searchInfo.page"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
:pager-count="5"
:page-sizes="[6, 8, 10, 12, 14]"
small
layout="total, sizes, prev, pager, next"
:total="searchInfo.recordTotal"
/>
</div>
</div> </div>
</el-card>
</el-col> </el-col>
<el-col :span="16"> <el-col :span="16">
<el-form label-position="top" :v-key="refresh"> <el-form label-position="top" :v-key="refresh">
@ -272,7 +282,7 @@
</el-form> </el-form>
</el-col> </el-col>
</el-row> </el-row>
<div class="app-warn" v-if="!hasRecords"> <div class="app-warn" v-show="!hasRecords">
<div> <div>
<span>{{ $t('cronjob.noRecord') }}</span> <span>{{ $t('cronjob.noRecord') }}</span>
<div> <div>
@ -342,21 +352,29 @@ const dialogData = ref();
const records = ref<Array<Cronjob.Record>>([]); const records = ref<Array<Cronjob.Record>>([]);
const currentRecord = ref<Cronjob.Record>(); const currentRecord = ref<Cronjob.Record>();
const currentRecordDetail = ref<string>(''); const currentRecordDetail = ref<string>('');
const currentRecordIndex = ref();
const deleteVisiable = ref(); const deleteVisiable = ref();
const delLoading = ref(); const delLoading = ref();
const cleanData = ref(); const cleanData = ref();
const acceptParams = async (params: DialogProps): Promise<void> => { const acceptParams = async (params: DialogProps): Promise<void> => {
dialogData.value = params;
recordShow.value = true; recordShow.value = true;
search(true); dialogData.value = params;
search();
timer = setInterval(() => { timer = setInterval(() => {
onRefresh(); search();
}, 1000 * 5); }, 1000 * 5);
}; };
const handleSizeChange = (val: number) => {
searchInfo.pageSize = val;
search();
};
const handleCurrentChange = (val: number) => {
searchInfo.page = val;
search();
};
const shortcuts = [ const shortcuts = [
{ {
text: i18n.global.t('monitor.today'), text: i18n.global.t('monitor.today'),
@ -418,7 +436,7 @@ const timeRangeLoad = ref<[Date, Date]>([
]); ]);
const searchInfo = reactive({ const searchInfo = reactive({
page: 1, page: 1,
pageSize: 12, pageSize: 8,
recordTotal: 0, recordTotal: 0,
cronjobID: 0, cronjobID: 0,
startTime: new Date(), startTime: new Date(),
@ -432,7 +450,7 @@ const onHandle = async (row: Cronjob.CronjobInfo) => {
.then(() => { .then(() => {
loading.value = false; loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
onRefresh(); search();
}) })
.catch(() => { .catch(() => {
loading.value = false; loading.value = false;
@ -451,12 +469,7 @@ const onChangeStatus = async (id: number, status: string) => {
}); });
}; };
const search = async (isInit: boolean) => { const search = async () => {
if (isInit) {
searchInfo.page = 1;
searchInfo.pageSize = 12;
records.value = [];
}
if (timeRangeLoad.value && timeRangeLoad.value.length === 2) { if (timeRangeLoad.value && timeRangeLoad.value.length === 2) {
searchInfo.startTime = timeRangeLoad.value[0]; searchInfo.startTime = timeRangeLoad.value[0];
searchInfo.endTime = timeRangeLoad.value[1]; searchInfo.endTime = timeRangeLoad.value[1];
@ -473,52 +486,24 @@ const search = async (isInit: boolean) => {
status: searchInfo.status, status: searchInfo.status,
}; };
const res = await searchRecords(params); const res = await searchRecords(params);
if (searchInfo.page === 1 && !res.data.items) {
hasRecords.value = false;
return;
}
if (!res.data.items) {
return;
}
for (const item of res.data.items) {
records.value.push(item);
}
hasRecords.value = true;
currentRecord.value = records.value[0];
currentRecordIndex.value = 0;
loadRecord(currentRecord.value);
searchInfo.recordTotal = res.data.total;
};
const onRefresh = async () => {
records.value = [];
searchInfo.pageSize = searchInfo.pageSize * searchInfo.page;
searchInfo.page = 1;
if (timeRangeLoad.value && timeRangeLoad.value.length === 2) {
searchInfo.startTime = timeRangeLoad.value[0];
searchInfo.endTime = timeRangeLoad.value[1];
} else {
searchInfo.startTime = new Date(new Date().setHours(0, 0, 0, 0));
searchInfo.endTime = new Date();
}
let params = {
page: searchInfo.page,
pageSize: searchInfo.pageSize,
cronjobID: dialogData.value.rowData!.id,
startTime: searchInfo.startTime,
endTime: searchInfo.endTime,
status: searchInfo.status,
};
const res = await searchRecords(params);
if (res.data.items) {
records.value = res.data.items; records.value = res.data.items;
hasRecords.value = true; searchInfo.recordTotal = res.data.total;
hasRecords.value = searchInfo.recordTotal !== 0;
if (!hasRecords.value) {
return;
}
if (!currentRecord.value) {
currentRecord.value = records.value[0]; currentRecord.value = records.value[0];
loadRecord(currentRecord.value);
} else { } else {
records.value = []; for (const item of records.value) {
hasRecords.value = false; if (item.id === currentRecord.value.id) {
refresh.value = !refresh.value; currentRecord.value = item;
break;
}
}
}
if (currentRecord.value?.records) {
loadRecord(currentRecord.value);
} }
}; };
@ -554,16 +539,8 @@ const onDownload = async (record: any, backupID: number) => {
}); });
}; };
const nextPage = async () => { const forDetail = async (row: Cronjob.Record) => {
if (searchInfo.pageSize >= searchInfo.recordTotal) {
return;
}
searchInfo.page = searchInfo.page + 1;
search(false);
};
const forDetail = async (row: Cronjob.Record, index: number) => {
currentRecord.value = row; currentRecord.value = row;
currentRecordIndex.value = index;
loadRecord(row); loadRecord(row);
}; };
const loadRecord = async (row: Cronjob.Record) => { const loadRecord = async (row: Cronjob.Record) => {
@ -578,7 +555,7 @@ const loadRecord = async (row: Cronjob.Record) => {
}; };
const onClean = async () => { const onClean = async () => {
if (dialogData.value.rowData.type === 'shell' || dialogData.value.rowData.type === 'curl') { if (!isBackup()) {
ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), { ElMessageBox.confirm(i18n.global.t('commons.msg.clean'), i18n.global.t('commons.msg.deleteTitle'), {
confirmButtonText: i18n.global.t('commons.button.confirm'), confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'), cancelButtonText: i18n.global.t('commons.button.cancel'),
@ -588,7 +565,7 @@ const onClean = async () => {
.then(() => { .then(() => {
delLoading.value = false; delLoading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
search(true); search();
}) })
.catch(() => { .catch(() => {
delLoading.value = false; delLoading.value = false;
@ -606,7 +583,7 @@ const cleanRecord = async () => {
delLoading.value = false; delLoading.value = false;
deleteVisiable.value = false; deleteVisiable.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
search(true); search();
}) })
.catch(() => { .catch(() => {
delLoading.value = false; delLoading.value = false;