<template>
  <div>
    <BasicTable @register="failYingxiangRegisterTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'fileName'">
          <span class="content-full">{{ record.fileName }}</span>
        </template>
        <template v-if="column.key === 'filePath'">
          <span class="content-full">{{ record.filePath }}</span>
        </template>
        <template v-if="column.key === 'action'">
          <span class="content-full">
            <a-button type="link" @click="copyToClipboard(record.fileName)">复制文件名</a-button>
            <a-button type="link" @click="copyToClipboard(record.filePath)">复制路径</a-button>
          </span>
        </template>
      </template>
    </BasicTable>
  </div>
</template>
<script lang="ts" setup>
  import { defineProps } from 'vue';
  import { BasicTable, useTable } from '@/components/Table';
  import { useMessage } from '@/hooks/web/useMessage';
  import { failColumns } from './util';

  const { createMessage } = useMessage();

  const props = defineProps(['failYingxiangData']);

  // 更新失败的影像
  const [failYingxiangRegisterTable, { reload, getSelectRows }] = useTable({
    columns: failColumns,
    dataSource: props.failYingxiangData,
    showIndexColumn: true,
    canResize: true,
    useSearchForm: false,
    showTableSetting: false,
    bordered: true,
    immediate: false,
  });

  // 复制到剪贴板
  const copyToClipboard = async (value) => {
    try {
      await navigator.clipboard.writeText(value);
      createMessage.success('复制成功');
    } catch (err) {
      createMessage.error('复制失败');
    }
  };
</script>
<style lang="less">
  .content-full {
    white-space: pre-wrap;
    word-break: break-all;
    overflow-wrap: break-word;
    max-width: 100%;
    display: block;
  }
</style>
