<template>
  <vab-dialog v-model="dialogFormVisible" append-to-body :title="title" width="800px" @close="close">
    <el-form ref="formRef" label-width="100px" :model="form">
      <el-row>
        <el-col :span="12">
          <el-form-item label="操作模块：">{{ form.title }} / {{ typeFormat(form) }}</el-form-item>
          <el-form-item label="登录信息：">{{ form.operName }} / {{ form.operIp }} / {{ form.operLocation }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="请求地址：">{{ form.operUrl }}</el-form-item>
          <el-form-item label="请求方式：">{{ form.requestMethod }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="操作方法：">{{ form.method }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="请求参数：">{{ form.operParam }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="返回参数：">{{ form.jsonResult }}</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="操作状态：">
            <div v-if="form.status === 0">正常</div>
            <div v-else-if="form.status === 1">失败</div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="消耗时间：">{{ form.costTime }}毫秒</el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="操作时间：">{{ parseTime(form.operTime) }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item v-if="form.status === 1" label="异常信息：">{{ form.errorMsg }}</el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="close">关 闭</el-button>
    </template>
  </vab-dialog>
</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'

defineOptions({
  name: 'OperatorDetail',
})

const { proxy } = getCurrentInstance() as any
const { sys_oper_type } = proxy.useDict('sys_oper_type')

const formRef = ref<FormInstance>()
const form = ref<any>({})
const title = ref<string>('操作日志详细')
const dialogFormVisible = ref<boolean>(false)

/** 操作日志类型字典翻译 */
function typeFormat(row: any) {
  return proxy.selectDictLabel(sys_oper_type.value, row.businessType)
}

const show = (row?: any) => {
  form.value = Object.assign({}, row)
  dialogFormVisible.value = true
}

const close = () => {
  dialogFormVisible.value = false
}

defineExpose({
  show,
})
</script>

<style lang="scss" scoped>
:deep() {
  .el-select {
    width: 100%;
  }

  .el-form-item__content {
    word-break: break-all;
  }
}
</style>
