<!--
 * @Author: renxin renxin0828@163.com
 * @Date: 2023-03-27 09:56:14
 * @LastEditors: renxin renxin0828@163.com
 * @LastEditTime: 2023-03-28 15:18:44
 * @FilePath: \thingskit-front\src\views\system\log\backup\ExceptionDrawer.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <BasicDrawer v-bind="$attrs" @register="registerDrawer" title="备份日志详情" width="40%">
    <BasicForm @register="registerForm" />
  </BasicDrawer>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicForm, useForm } from '/@/components/Form';
  import { formSchema } from './config.data';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { getLogManageDetail } from '/@/api/log/logManager';
  import moment from 'moment';

  export default defineComponent({
    name: 'ContactDrawer',
    components: { BasicDrawer, BasicForm },
    emits: ['success', 'register'],
    setup(_) {
      const [registerForm, { setFieldsValue, resetFields }] = useForm({
        labelWidth: 120,
        schemas: formSchema,
        showActionButtonGroup: false,
      });

      const [registerDrawer, { setDrawerProps }] = useDrawerInner(async (data) => {
        await resetFields();
        setDrawerProps({ confirmLoading: false });
        const res = await getLogManageDetail(data.record.id);
        const actionData = JSON.stringify(res.actionData);

        console.log('res', res);

        const createdTime = moment(data.record.createdTime).format('YYYY-MM-DD HH:mm:ss');
        const actionData_database = res.actionData.database;
        const actionData_path = res.actionData.path;
        const actionData_file = res.actionData.file;
        await setFieldsValue(res || data.record);
        await setFieldsValue({ actionData });
        await setFieldsValue({ createdTime });
        await setFieldsValue({ actionData_database });
        await setFieldsValue({ actionData_path });
        await setFieldsValue({ actionData_file });
      });
      return {
        registerDrawer,
        registerForm,
      };
    },
  });
</script>
