<template>
  <basicModal @register="modalRegister" ref="modalRef" class="basicModal basicFormModal">
    <template #default>
      <n-descriptions
        class="margin-top"
        :column="2"
        bordered
        :labelStyle="{ width: '120px' }"
        label-placement="left"
      >
        <n-descriptions-item label="日志标题">
          {{ formData.title }}
        </n-descriptions-item>
        <n-descriptions-item label="操作用户">
          {{ formData.createUser }}
        </n-descriptions-item>
        <n-descriptions-item label="IP地址">
          {{ formData.ip }}
        </n-descriptions-item>
        <n-descriptions-item label="操作系统">
          {{ formData.os }}
        </n-descriptions-item>
        <n-descriptions-item label="操作浏览器">
          {{ formData.browser }}
        </n-descriptions-item>
        <n-descriptions-item label="请求耗时"> {{ formData.consumeTime }}s </n-descriptions-item>
        <n-descriptions-item label="请求方式">
          {{ formData.requestMethod }}
        </n-descriptions-item>
        <n-descriptions-item label="请求状态">
          <n-tag :type="formData.status ? 'danger' : 'success'">{{
            formData.status ? '异常' : '正常'
          }}</n-tag>
        </n-descriptions-item>
        <n-descriptions-item label="调用方法" :span="3">
          {{ formData.method }}
        </n-descriptions-item>
        <n-descriptions-item label="请求参数" :span="3">
          {{ formData.param }}
        </n-descriptions-item>
        <n-descriptions-item label="返回结果" :span="3">
          {{ formData.result }}
        </n-descriptions-item>
      </n-descriptions>
    </template>
    <template #action>
      <n-button @click="handleClose">取消</n-button>
    </template>
  </basicModal>
</template>
<script lang="ts" setup>
  import { getOperLogDetail } from '@/api/system/operLog';
  import { onMounted, ref } from 'vue';
  import { useModal } from '@/components/Modal';

  /**
   * 定义参数变量
   */
  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});
  const [modalRegister, { openModal, setSubLoading }] = useModal({
    title: '操作日志详情',
    subBtuText: '确定',
    width: 800,
  });

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

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

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

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

  /**
   * 定义函数
   */
  defineExpose({
    openModal,
  });
</script>
<style lang="less" scoped>
  :deep(.ant-descriptions__body .ant-descriptions__table .ant-descriptions__cell) {
    word-break: break-all;
  }
</style>
