<template>
  <div class="p-4">
    <BasicTable @register="registerTable" :dataSource="dataSource">
      <template #tableTitle>
        <div slot="message">
          共追踪到 {{ dataSource.length }} 条近期HTTP请求记录
          <a-divider type="vertical" />
          <a @click="loadDate">立即刷新</a>
        </div>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" name="monitor-trace" setup>
  import { onMounted, ref } from 'vue';
  import { BasicTable, useTable } from '@jdlinker/ui';
  import { getActuatorList } from './trace.api';
  import { columns } from './trace.data';
  import { useMessage } from '@jdlinker/func';

  const dataSource = ref([]);
  const { createMessage } = useMessage();

  const [registerTable, { reload }] = useTable({
    columns,
    showIndexColumn: false,
    bordered: true,
    rowKey: 'id'
  });

  function loadDate() {
    getActuatorList().then((res) => {
      let filterData = [];
      for (let d of res.traces) {
        if (d.request.method !== 'OPTIONS' && d.request.uri.indexOf('httptrace') === -1) {
          filterData.push(d);
        }
      }
      dataSource.value = filterData;
    });
  }

  onMounted(() => {
    loadDate();
  });
</script>
