[Core] [UI] [Refactor] Add schedule history

This commit is contained in:
qianmoQ 2024-03-14 19:13:35 +08:00
parent c034688316
commit d0503bf831
8 changed files with 196 additions and 6 deletions

View File

@ -59,4 +59,4 @@ jobs:
java-version: '11' java-version: '11'
distribution: 'temurin' distribution: 'temurin'
- run: chmod 755 ./mvnw - run: chmod 755 ./mvnw
- run: ./mvnw -T 1C clean install package -Dfindbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true -q - run: ./mvnw -T 1C clean install package -Dfindbugs.skip -Dgpg.skip -Dcheckstyle.skip -DskipTests=true

View File

@ -34,4 +34,7 @@ export default {
expression: 'Expression', expression: 'Expression',
active: 'Active Status', active: 'Active Status',
type: 'Type', type: 'Type',
elapsed: 'Elapsed Time',
state: 'State',
result: 'Result',
} }

View File

@ -33,5 +33,8 @@ export default {
successfully: '成功', successfully: '成功',
expression: '表达式', expression: '表达式',
active: '激活状态', active: '激活状态',
type: '类型' type: '类型',
elapsed: '执行时间',
state: '状态',
result: '结果'
} }

View File

@ -1,5 +1,31 @@
export class PaginationModel { export class PaginationModel
{
pageSize: number = 10 pageSize: number = 10
currentPage: number = 0 currentPage: number = 0
total: number = 0 total: number = 0
} }
export interface PaginationResponseModel
{
size: number
total: number
page: number
}
export class PaginationRequest
{
/**
* Creates a PaginationModel from a PaginationResponseModel.
*
* @param {PaginationResponseModel} data - the pagination response data
* @return {PaginationModel} the created pagination model
*/
public static of(data: PaginationResponseModel): PaginationModel
{
return {
pageSize: data.size,
total: data.total,
currentPage: data.page
}
}
}

View File

@ -1,4 +1,7 @@
import { BaseService } from '@/services/base' import { BaseService } from '@/services/base'
import { FilterModel } from '@/model/filter'
import { ResponseModel } from '@/model/response'
import { HttpUtils } from '@/utils/http'
const DEFAULT_PATH = '/api/v1/schedule' const DEFAULT_PATH = '/api/v1/schedule'
@ -9,6 +12,18 @@ class ScheduleService
{ {
super(DEFAULT_PATH) super(DEFAULT_PATH)
} }
/**
* Get the schedule history.
*
* @param {FilterModel} filter - the filter for the schedule history
* @param {number} id - the ID of the schedule
* @return {Promise<ResponseModel>} the response model promise
*/
getScheduleHistory(filter: FilterModel, id: number): Promise<ResponseModel>
{
return new HttpUtils().post(`${DEFAULT_PATH}/${id}/history`, filter)
}
} }
export default new ScheduleService() export default new ScheduleService()

View File

@ -0,0 +1,107 @@
<template>
<Dialog :open="isVisible" persistent @update:open="handlerCancel">
<DialogContent class="min-w-[60%]">
<DialogHeader class="border-b">
<DialogTitle class="pb-3.5">{{ $t('schedule.common.history') }}</DialogTitle>
<DialogDescription></DialogDescription>
</DialogHeader>
<CardContent class="grid gap-4 mt-5">
<TableCommon :loading="loading" :columns="headers" :data="data" :pagination="pagination" @changePage="handlerChangePage"></TableCommon>
</CardContent>
</DialogContent>
</Dialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { ScheduleModel } from '@/model/schedule'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { CardContent } from '@/components/ui/card'
import TableCommon from '@/views/components/table/TableCommon.vue'
import { FilterModel } from '@/model/filter'
import { PaginationModel, PaginationRequest } from '@/model/pagination'
import { useI18n } from 'vue-i18n'
import { createHistoryHeaders } from '@/views/pages/system/schedule/ScheduleUtils'
import ScheduleService from '@/services/schedule'
import { cn } from '@/lib/utils'
export default defineComponent({
name: 'ScheduleHistory',
components: {
TableCommon,
CardContent,
DialogDescription, DialogTitle, DialogHeader, DialogContent, Dialog
},
props: {
isVisible: {
type: Boolean,
default: () => false
},
info: {
type: Object as () => ScheduleModel | null,
default: null
}
},
computed: {
visible: {
get(): boolean
{
return this.isVisible
},
set(value: boolean)
{
this.$emit('close', value)
}
}
},
setup()
{
const filter: FilterModel = new FilterModel()
const headers = createHistoryHeaders(useI18n())
return {
filter,
headers
}
},
data()
{
return {
loading: false,
data: [],
pagination: {} as PaginationModel
}
},
created()
{
this.handlerInitialize()
},
methods: {
cn,
handlerInitialize()
{
this.loading = true
ScheduleService.getScheduleHistory(this.filter, this.info?.id as number)
.then((response) => {
if (response.status) {
this.data = response.data.content
this.pagination = PaginationRequest.of(response.data)
}
})
.finally(() => {
this.loading = false
})
},
handlerChangePage(value: PaginationModel)
{
this.filter.page = value.currentPage
this.filter.size = value.pageSize
this.handlerInitialize()
},
handlerCancel()
{
this.visible = false
}
}
})
</script>

View File

@ -29,6 +29,7 @@
</TableCommon> </TableCommon>
</CardContent> </CardContent>
</Card> </Card>
<ScheduleHistory v-if="dataHistoryVisible" :is-visible="dataHistoryVisible" :info="dataInfo" @close="handlerChangeInfo(false, null)"></ScheduleHistory>
</div> </div>
</template> </template>
@ -45,10 +46,13 @@ import { useI18n } from 'vue-i18n'
import { PaginationModel } from '@/model/pagination' import { PaginationModel } from '@/model/pagination'
import ScheduleService from '@/services/schedule' import ScheduleService from '@/services/schedule'
import { Switch } from '@/components/ui/switch'; import { Switch } from '@/components/ui/switch';
import ScheduleHistory from '@/views/pages/system/schedule/ScheduleHistory.vue'
import { ScheduleModel } from '@/model/schedule'
export default defineComponent({ export default defineComponent({
name: 'ScheduleHome', name: 'ScheduleHome',
components: { components: {
ScheduleHistory,
ArrowBigUp, History, Pencil, ArrowBigUp, History, Pencil,
Button, Switch, Button, Switch,
Card, CardHeader, CardTitle, CardContent, Card, CardHeader, CardTitle, CardContent,
@ -69,8 +73,10 @@ export default defineComponent({
{ {
return { return {
loading: false, loading: false,
dataHistoryVisible: false,
data: [], data: [],
pagination: {} as PaginationModel pagination: {} as PaginationModel,
dataInfo: null as ScheduleModel | null
} }
}, },
created() created()
@ -99,6 +105,11 @@ export default defineComponent({
this.filter.page = value.currentPage this.filter.page = value.currentPage
this.filter.size = value.pageSize this.filter.size = value.pageSize
this.handlerInitialize() this.handlerInitialize()
},
handlerChangeInfo(isOpen: boolean, dataInfo: any)
{
this.dataHistoryVisible = isOpen
this.dataInfo = dataInfo
} }
} }
}) })

View File

@ -1,3 +1,9 @@
/**
* Creates headers for a table using the given internationalization object.
*
* @param {any} i18n - the internationalization object used for translating header labels
* @return {Array} an array of header objects
*/
const createHeaders = (i18n: any) => { const createHeaders = (i18n: any) => {
return [ return [
{key: 'id', hidden: true, header: i18n.t('common.id'), width: 80}, {key: 'id', hidden: true, header: i18n.t('common.id'), width: 80},
@ -13,6 +19,25 @@ const createHeaders = (i18n: any) => {
] ]
} }
export { /**
createHeaders * Creates history headers with internationalization support.
*
* @param {any} i18n - the internationalization object
* @return {Array} an array of history headers
*/
const createHistoryHeaders = (i18n: any) => {
return [
{key: 'id', hidden: true, header: i18n.t('common.id'), width: 80},
{key: 'name', hidden: true, header: i18n.t('common.name'), width: 100},
{key: 'createTime', hidden: true, header: i18n.t('common.createTime')},
{key: 'updateTime', hidden: true, header: i18n.t('common.updateTime')},
{key: 'elapsed', hidden: true, header: i18n.t('common.elapsed')},
{key: 'state', hidden: true, header: i18n.t('common.state')},
{key: 'result', hidden: true, header: i18n.t('common.result')}
]
}
export {
createHeaders,
createHistoryHeaders
} }