import { BasicColumn, FormSchema } from '/@/components/Table';
import moment from 'moment';
import { findDictItemByCode } from '/@/api/system/dict';
import { format } from '../util';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';

//格式化资源类型和操作类型
let formatText;
let actionTypeText;
async function formatTextFunc () {
  formatText = await findDictItemByCode({ dictCode: 'operate_log' });
  actionTypeText = await findDictItemByCode({ dictCode: 'exception_log' });
}
formatTextFunc();
// 表格数据
export const columns: BasicColumn[] = [


  {
    title: '备份数据库',
    dataIndex: 'actionData.database',
    width: 180,
  },
  {
    title: '备份目录',
    dataIndex: 'actionData.path',
    width: 180,
  },
  {
    title: '备份文件名',
    dataIndex: 'actionData.file',
    width: 180,
  },
  {
    title: '备份时间',
    dataIndex: 'createdTime',
    width: 180,
    format: (_, record) => {
      return format(record.createdTime, 'yyyy-MM-dd HH:mm:ss');
    },
  },



  // {
  //   title: '操作类型',
  //   dataIndex: 'actionType',
  //   width: 180,
  //   format: (_, record) => {
  //     const text = actionTypeText.find((f) => {
  //       if (f.itemValue == record.actionType) {
  //         return f.itemText;
  //       }
  //     });
  //     return text?.itemText;
  //   },
  // },
  // {
  //   title: '操作状态',
  //   dataIndex: 'actionStatus',
  //   width: 180,
  //   customRender: ({ record }) => {
  //     const status = record.actionStatus;
  //     const enable = status === 'SUCCESS' ? '成功' : '失败';
  //     const color = enable === '成功' ? 'green' : 'red';
  //     const text = enable === '成功' ? '成功' : '失败';
  //     return h(Tag, { color }, () => text);
  //   },
  // },
  // {
  //   title: '操作时间',
  //   dataIndex: 'createdTime',
  //   width: 180,
  //   format: (_, record) => {
  //     return format(record.createdTime, 'yyyy-MM-dd HH:mm:ss');
  //   },
  // },
];

// 分页查询
export const searchFormSchema: FormSchema[] = [
  {
    field: 'queryTime',
    label: '查询时间',
    component: 'RangePicker',
    componentProps: {
      showTime: {
        defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
      },
    },
    colProps: { span: 6 },
  },
];

// 详情配置
export const formSchema: FormSchema[] = [
  {
    field: 'actionData_database',
    label: '备份数据库',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'actionData_path',
    label: '备份目录',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'actionData_file',
    label: '备份文件名',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },

  {
    field: 'createdTime',
    label: '备份时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },

];
