<template>
  <div class="table-box">
    <ProTable ref="proTable" :columns="columns" row-key="infoId" :request-api="listLogininforApi" :init-param="initParam">
    </ProTable>
    <FormDialog ref="formDialogRef" />
    <ImportExcel ref="dialogRef" />
  </div>
</template>

<script setup lang="tsx" name="Logininfor">
import { ref, reactive } from 'vue'
import ProTable from '@/components/ProTable/index.vue'
import ImportExcel from '@/components/ImportExcel/index.vue'
import FormDialog from '@/components/DialogOld/form.vue'
import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
import { listLogininforApi } from '@/api/modules/monitor/logininfor'
import { getDictsApi } from '@/api/modules/system/dictData'

// ProTable 实例
const proTable = ref<ProTableInstance>()

// 如果表格需要初始化请求参数，直接定义传给 ProTable (之后每次请求都会自动带上该参数，此参数更改之后也会一直带上，改变此参数会自动刷新表格数据)
const initParam = reactive({ type: 1 })

// 批量添加系统访问记录
const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)

const formDialogRef = ref<InstanceType<typeof FormDialog> | null>(null)

// 表格配置项
const columns = reactive<ColumnProps<any>[]>([
  { prop: 'infoId', label: '访问ID' },
  {
    prop: 'userName',
    label: '用户账号',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'ipaddr',
    label: '登录IP地址',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'loginLocation',
    label: '登录地点',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'browser',
    label: '浏览器类型',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'os',
    label: '操作系统',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'status',
    label: '登录状态',
    tag: true,
    enum: () => getDictsApi('sys_common_status'),
    fieldNames: {
      label: 'dictLabel',
      value: 'dictValue'
    },
    search: {
      el: 'input'
    }
  },
  {
    prop: 'msg',
    label: '提示消息',
    search: {
      el: 'input'
    }
  },
  {
    prop: 'loginTime',
    label: '访问时间',
    search: {
      el: 'date-picker',
      props: { type: 'datetimerange', valueFormat: 'YYYY-MM-DD HH:mm:ss' }
    }
  }
])
</script>
