<template>
  <a-modal v-model:visible="props.visible" title="文件日志详情" width="800px" @cancel="dialogClose">
    <a-descriptions class="margin-top" :column="2" bordered :labelStyle="{ width: '125px' }">
      <a-descriptions-item label="文件名称:"
        ><a :href="formData.filePath" target="_blank">{{
          formData.originalName
        }}</a></a-descriptions-item
      >
      <a-descriptions-item label="文件类型:">{{ formData.fileType }}</a-descriptions-item>
      <a-descriptions-item label="文件大小:">{{ formData.fileSize }}B</a-descriptions-item>
      <a-descriptions-item label="请求耗时:">{{ formData.consumeTime }}s</a-descriptions-item>
      <a-descriptions-item label="业务类型:">{{
        formData.bizType ? (formData.bizType == 1 ? '订单' : '其他') : ''
      }}</a-descriptions-item>
      <a-descriptions-item label="业务ID:">{{ formData.bizId }}</a-descriptions-item>
      <a-descriptions-item label="业务内容" :span="3">
        {{ formData.bizContent }}
      </a-descriptions-item>
      <a-descriptions-item label="请求状态" :span="3">
        {{ formData.status ? '失败' : '成功' }}
      </a-descriptions-item>
      <a-descriptions-item label="请求参数" :span="3">
        {{ formData.param }}
      </a-descriptions-item>
      <a-descriptions-item label="返回结果" :span="3">
        {{ formData.result }}
      </a-descriptions-item>
      <a-descriptions-item label="错误描述" :span="3">
        {{ formData.error }}
      </a-descriptions-item>
    </a-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <a-button @click="dialogClose">取消</a-button>
      </span>
    </template>
  </a-modal>
</template>
<script lang="ts" setup>
  import { getFileLogDetail } from '@/api/logger/fileLog';
  import { onMounted, ref } from 'vue';

  /**
   * 定义参数变量
   */
  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});

  /**
   * 定义接收的参数
   */
  const props = defineProps({
    visible: {
      type: Boolean,
      required: true,
      default: false,
    },
    fileId: {
      type: Number,
      required: true,
      default: 0,
    },
  });

  /**
   * 关闭窗体
   */
  const dialogClose = () => {
    emit('update:visible', false);
  };

  /**
   * 设置表单数据
   */
  const setFormData = async () => {
    const data = await getFileLogDetail(props.fileId);
    formData.value = data;
  };

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.fileId) {
      setFormData();
    }
  });
</script>
<style lang="less" scoped>
  :deep(.ant-descriptions__body .ant-descriptions__table .ant-descriptions__cell) {
    word-break: break-all;
  }
</style>
