<template>
  <div class='table-box'>
    <ProTable
      ref='proTable'
      :columns='columns'
      :data='logData'
      @selection-change='handleSelectionChange'
      type='selection'
    >
      <!-- 表格 header 按钮 -->
      <template #tableHeader>
        <el-button type='primary' :icon='DataAnalysis' >分析</el-button>
        <el-button type='primary' :icon='Upload'>导出csv</el-button>
      </template>
    </ProTable>
  </div>

</template>
<script setup lang='tsx' name='useProTable'>
// 根据实际路径调整
import TimeControl from '@/components/TimeControl/index.vue'
import { type Log } from '@/api/log/interface'
import ProTable from '@/components/ProTable/index.vue'
import { Upload ,DataAnalysis} from '@element-plus/icons-vue'
import logDataList from '@/api/log/logData'
import type { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
import { reactive,ref } from 'vue'
let multipleSelection = ref<string[]>([])
const logData = logDataList
// 定义包含和排除的单位
const includedUnits = ['日', '周', '月', '自定义']; // 可以根据需要包含的单位
const excludedUnits = ['季度','年']; // 要排除的单位
const defaultUnits = '日'; // 默认的单位
// ProTable 实例
const proTable = ref<ProTableInstance>()
// 表格配置项
const columns = reactive<ColumnProps<Log.LogList>[]>([
  { type: 'selection', fixed: 'left', width: 70 },
  {
    prop: 'id',
    label: '序号',
    width: 70,
  },
  {
    prop: 'user',
    label: '操作用户',
    search: { el: 'select', props: { filterable: true } },
    width: 150,
  },
  {
    prop: 'record_Time',
    label: '记录时间',
    width: 200,
    search: {
      span: 2,
      render: ({ searchParam }) => {
        return (
          <div class='flx-flex-start'>
            <TimeControl 
            include={includedUnits} 
            exclude={excludedUnits} 
            default={defaultUnits} 
            />
          </div>
        )
      },
    },
  },
  {
    prop: 'content',
    label: '内容',
  
  },
  {
    prop: 'type',
    label: '日志类型',
    width: 200,
    search: { el: 'select', props: { filterable: true } },
  },
  {
    prop: 'level',
    label: '日志等级',
    width: 200,
    search: { el: 'select', props: { filterable: true } },
  },
  
])

//选中
// 处理选择变化
const handleSelectionChange = (selection: Log.LogList[]) => {
  multipleSelection.value = selection.map(row => row.id) // 更新选中的行
 
}



</script>

<style scoped>

</style>
