<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>
    <UserDrawer @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 UserDrawer from './UserDrawer.vue';
  import { getUserPage } from '/@/api/log/logManager';
  import { searchFormSchema, columns } from './config.data';
  import { useModal } from '/@/components/Modal';

  export default defineComponent({
    components: {
      BasicTable,
      TableAction,
      UserDrawer,
    },
    setup() {
      const [registerModal] = useModal();
      const [registerTable, { reload }] = useTable({
        title: '登录登出日志列表',
        api: getUserPage,
        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>
