<template>
  <el-dialog
    v-model="props.visible"
    title="登录日志详情"
    width="750"
    :close-on-click-modal="false"
    :before-close="dialogClose"
  >
    <el-descriptions class="margin-top" :column="2" border>
      <el-descriptions-item label="操作用户" label-class-name="des-width">
        {{ formData.createUser }}
      </el-descriptions-item>
      <el-descriptions-item label="IP地址" label-class-name="des-width">
        {{ formData.ip }}
      </el-descriptions-item>
      <el-descriptions-item label="操作系统">
        {{ formData.os }}
      </el-descriptions-item>
      <el-descriptions-item label="浏览器">
        {{ formData.browser }}
      </el-descriptions-item>
      <el-descriptions-item label="请求耗时"> {{ formData.consumeTime }}ms </el-descriptions-item>
      <el-descriptions-item label="请求地区">
        {{ formData.location }}
      </el-descriptions-item>
      <el-descriptions-item label="请求方式">
        {{ formData.requestMethod }}
      </el-descriptions-item>
      <el-descriptions-item label="请求状态">
        <el-tag :type="formData.status ? 'danger' : 'success'">{{
          formData.status ? '异常' : '正常'
        }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="调用方法" :span="3">
        {{ formData.method }}
      </el-descriptions-item>
      <el-descriptions-item label="请求参数" :span="3">
        {{ formData.param }}
      </el-descriptions-item>
      <el-descriptions-item label="返回结果" :span="3">
        {{ formData.result }}
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogClose">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
  import { getLoginLogDetail } from '@/api/system/loginLog';
  import { onMounted, ref } from 'vue';

  const emit = defineEmits(['success', 'update:visible']);
  const formData = ref({});

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

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

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

  /**
   * 钩子函数
   */
  onMounted(() => {
    // 组件挂载后执行的代码
    if (props.loginlogId) {
      setFormData();
    }
  });
</script>
<style lang="scss" scoped>
  :deep(.des-width) {
    width: 120px;
  }
  :deep(.el-descriptions__body .el-descriptions__table .el-descriptions__cell) {
    word-break: break-all;
  }
</style>
