<template>
  <a-modal v-model:visible="props.visible" title="操作日志详情" width="800px" @cancel="dialogClose">
    <a-descriptions class="margin-top" :column="2" bordered :labelStyle="{ width: '120px' }">
      <a-descriptions-item label="日志标题">
        {{ formData.title }}
      </a-descriptions-item>
      <a-descriptions-item label="操作用户">
        {{ formData.createUser }}
      </a-descriptions-item>
      <a-descriptions-item label="IP地址">
        {{ formData.ip }}
      </a-descriptions-item>
      <a-descriptions-item label="操作系统">
        {{ formData.os }}
      </a-descriptions-item>
      <a-descriptions-item label="操作浏览器">
        {{ formData.browser }}
      </a-descriptions-item>
      <a-descriptions-item label="请求耗时"> {{ formData.consumeTime }}s </a-descriptions-item>
      <a-descriptions-item label="请求方式">
        {{ formData.requestMethod }}
      </a-descriptions-item>
      <a-descriptions-item label="请求状态">
        <a-tag :color="formData.status ? 'danger' : 'success'">{{
          formData.status ? '异常' : '正常'
        }}</a-tag>
      </a-descriptions-item>
      <a-descriptions-item label="调用方法" :span="3">
        {{ formData.method }}
      </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>
    <template #footer>
      <span class="dialog-footer">
        <a-button @click="dialogClose">取消</a-button>
      </span>
    </template>
  </a-modal>
</template>
<script lang="ts" setup>
  import { getOperLogDetail } from '@/api/system/operLog';
  import { onMounted, ref } from 'vue';

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

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

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

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

  /**
   * 钩子函数
   */
  onMounted(() => {
    if (props.operlogId) {
      setFormData();
    }
  });
</script>
