<template>
	<div class="page">
		<BaseTable ref="baseTable" :action="action" :columns="columns" :operation="operation" :search="search">
			<template v-slot:operation>
				<a-button type="primary" v-if="checkPermission('备份')" @click="useManageMethod.handleUpdate(undefined)">备份</a-button>
			</template>
		</BaseTable>
		<a-drawer
			:closable="true"
			:maskClosable="false"
			:title="update.title"
			:visible="update.visible"
			destroyOnClose
			placement="right"
			:width="update.width"
			@close="update.visible = false"
		>
			<Add @cancel="update.visible = false" @refresh="useManageMethod.refresh()" />
		</a-drawer>
	</div>
</template>

<script lang="ts" setup>
import { defineAsyncComponent, ref } from 'vue'
import BaseTable from '../../../components/table'
import { BaseUtil } from '../../../utils/base-util'
import columns from './columns'
import search from './search'
import requestMethod from '../../../api/system-log/backup-file'
import { OperationProps } from '../../../components/table/table-helper'
import { manageMethod } from '../../../components/form/method'
import { LogBackupFile } from '../../../entity/system-log/log-backup-file'
import { checkPermission } from '../../../utils/permission-util'

const Add = defineAsyncComponent(() => import('./Add.vue'))

// 列表查询信息的api
const action = requestMethod.page

const useManageMethod = manageMethod<LogBackupFile>()

// 修改面板参数
const update = useManageMethod.update

// 获取当前的数据表
const baseTable = ref<InstanceType<typeof BaseTable>>(null)

// 列表操作信息
const operation = ref<OperationProps<LogBackupFile>[]>([
	{
		title: '下载',
		permission: true,
		action: (vo: LogBackupFile) => {
			BaseUtil.downBackupFile(vo.backupPath, vo.backupName)
		}
	}
])
</script>

<style lang="scss" scoped>
.page {
	height: 100%;
	display: flex;
	flex-direction: column;
}
</style>
