config.data.ts 3.8 KB
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';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();

// 表格数据
export const columns: BasicColumn[] = [
  {
    title: t('log.user.table.tenantName'),
    dataIndex: 'tenantName',
    width: 120,
  },
  {
    title: t('log.user.table.customerName'),
    dataIndex: 'customerName',
    width: 120,
  },
  {
    title: t('log.user.table.operators'),
    dataIndex: 'userName',
    width: 180,
  },
  {
    title: t('log.user.table.operationType'),
    dataIndex: 'actionType',
    width: 180,
    format: (_, record) => {
      return record.actionType == 'LOGIN' ? t('dict.user_log.login') : t('dict.user_log.logout');
    },
  },
  {
    title: t('log.user.table.operationStatus'),
    dataIndex: 'actionStatus',
    width: 180,
    customRender: ({ record }) => {
      const status = record.actionStatus;
      const enable = status === 'SUCCESS';
      const color = enable ? 'green' : 'red';
      const text = enable ? t('common.successText') : t('common.failText');
      return h(Tag, { color }, () => text);
    },
  },
  {
    title: t('log.user.table.operationTime'),
    dataIndex: 'createdTime',
    width: 180,
    format: (_, record) => {
      return format(record.createdTime, 'yyyy-MM-dd HH:mm:ss');
    },
  },
];

// 分页查询
export const searchFormSchema: FormSchema[] = [
  {
    field: 'actionType',
    label: t('log.user.search.entityType'),
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'user_log',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
    colProps: { span: 6 },
  },
  {
    field: 'queryTime',
    label: t('log.user.search.time'),
    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: 'createdTime',
    label: t('log.user.search.time'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'tenantName',
    label: t('log.user.table.tenantName'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'customerName',
    label: t('log.user.table.customerName'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'entityType',
    label: t('log.user.table.entityType'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'entityName',
    label: t('log.user.table.entityName'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'userName',
    label: t('log.user.table.operators'),
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'actionType',
    label: t('log.user.table.operationType'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'actionStatus',
    label: t('log.user.table.operationStatus'),
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'actionData',
    label: t('log.user.operationalData'),
    component: 'InputTextArea',
    componentProps: {
      disabled: true,
      autosize: true,
      allowClear: false,
    },
  },
  {
    field: 'actionFailureDetails',
    label: t('log.user.failureInformation'),
    component: 'InputTextArea',
    componentProps: {
      disabled: true,
      autosize: true,
      allowClear: false,
    },
  },
];