<template>
  <el-dialog
      v-model="props.visible"
      title="登录日志详情"
      width="700"
      :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}}s
    </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>
  <el-descriptions class="margin-top" :column="1" border>
    <el-descriptions-item label="调用方法"label-class-name="des-width">
      {{formData.method}}
    </el-descriptions-item>
  </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
    <el-descriptions-item label="请求参数"label-class-name="des-width">
      {{formData.param}}
    </el-descriptions-item>
  </el-descriptions>
    <el-descriptions class="margin-top" :column="1" border>
    <el-descriptions-item label="返回结果" label-class-name="des-width">
      {{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>

