<!--
 * @Author: renxin renxin0828@163.com
 * @Date: 2023-03-27 09:56:14
 * @LastEditors: renxin renxin0828@163.com
 * @LastEditTime: 2023-03-27 10:04:21
 * @FilePath: \thingskit-front\src\views\system\log\backup\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <BasicTable :clickToRowSelect="false" @register="registerTable">
      <template #toolbar> </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '详情',
              auth: 'api:yt:log:get',
              icon: 'clarity:note-edit-line',
              onClick: handleViewDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <ExceptionDrawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useDrawer } from '/@/components/Drawer';
  import ExceptionDrawer from './ExceptionDrawer.vue';
  import { getBackupPage } from '/@/api/log/logManager';
  import { searchFormSchema, columns } from './config.data';
  import { useModal } from '/@/components/Modal';

  export default defineComponent({
    components: {
      BasicTable,
      TableAction,
      ExceptionDrawer,
    },
    setup() {
      const [registerModal] = useModal();
      const [registerTable, { reload }] = useTable({
        title: '备份日志列表',
        api: getBackupPage,
        columns,
        showIndexColumn: false,
        clickToRowSelect: false,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
          fieldMapToTime: [['queryTime', ['startTime', 'endTime'], 'x']],
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        rowKey: 'id',
        actionColumn: {
          width: 200,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      // 弹框
      const [registerDrawer, { openDrawer }] = useDrawer();

      // 刷新
      const handleSuccess = () => {
        reload();
      };

      const handleViewDetail = (record) => {
        openDrawer(true, {
          isUpdate: true,
          record,
        });
      };
      return {
        handleSuccess,
        registerTable,
        registerDrawer,
        handleViewDetail,
        registerModal,
      };
    },
  });
</script>
