<!--
@ 作者: han2015
@ 时间: 2025-10-23 15:39:13
@ 备注: upload log组件
-->
<script lang="ts" setup>

import {logUploadError} from "@/api/doc/type"

const props = withDefaults(defineProps<{
  content:string,
}>(),{})

const moduleDrawer =ref(true)
const logState=ref(false)

const onClosePopup=(done: (cancel?: boolean) => void) => {
  if (logState.value) {
      moduleDrawer.value=false
      return
  }
  
  ElMessageBox.confirm("请确保错误日志安全保存！", "提示", {
    confirmButtonText: "确定",
    type: "warning",
  }).then(()=>{
    handleUploadErrors(props.content)
  })
}


async function handleUploadErrors(result:string){
  await logUploadError({content:result},'/hxpan/api/matter/uploadlog').then(data=>{
    logState.value=true;
    ElMessage({
      message: '保存成功！',
      type: 'success',
      plain: true,
    })
  }).catch(err=>{
    //重传
    ElMessage({
      message: '日志保存失败，开始重传！',
      type: 'error',
      plain: true,
    })
    setTimeout(()=>handleUploadErrors(props.content),2000) 
  })
}

//渲染完页面再执行
onMounted(() => {
    handleUploadErrors(props.content)
});
</script>

<template>
  <el-drawer
    :model-value="moduleDrawer"
    title="上传错误记录:"
    direction="rtl"
    size="30%"
    :close-on-click-modal="false"
    destroy-on-close
    :close-on-press-escape="false"	
    :before-close="onClosePopup"
    :style="{padding:'17px',backgroundColor:'#f3f3f3'}">
     <div v-html="content"></div>
  </el-drawer>
</template>

<style lang="scss" scoped>
.app_container {
  padding: 10px 30px 0px 30px;
  height: 100%;
  width: 100%;
}
</style>
