config.ts 2.33 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { PackageField, PackageType } from './packageDetail.config';
import { dateUtil } from '/@/utils/dateUtil';
import { DEFAULT_DATE_FORMAT } from '/@/views/visual/board/detail/config/util';
import { useI18n } from '/@/hooks/web/useI18n';

export interface ModalPassRecord {
  isUpdate: boolean;
  record?: Recordable;
}

export enum OtaPermissionKey {
  CREATE = 'api:operation:ota:post',
  UPDATE = 'api:operation:ota:update',
  DELETE = 'api:operation:ota:delete',
  DOWNLOAD = 'api:operation:ota:download',
  DETAIL = 'api:operation:ota:detail',
}

const { t } = useI18n();

export const columns: BasicColumn[] = [
  {
    title: t('monitor.ota.createTime'),
    dataIndex: PackageField.CREATE_TIME,
    format(text) {
      return dateUtil(text).format(DEFAULT_DATE_FORMAT);
    },
    width: 140,
  },
  {
    title: t('monitor.ota.title'),
    dataIndex: PackageField.TITLE,
    width: 120,
  },
  {
    title: t('monitor.ota.version'),
    dataIndex: PackageField.VERSION,
    width: 120,
  },
  {
    title: t('monitor.ota.versionLabel'),
    dataIndex: PackageField.VERSION_TAG,
    width: 120,
  },
  {
    title: t('monitor.ota.packageType'),
    dataIndex: PackageField.PACKAGE_TYPE,
    format: (text) => {
      return text === PackageType.FIRMWARE ? t('monitor.ota.firm') : t('monitor.ota.soft');
    },
    width: 120,
  },
  {
    title: t('monitor.ota.direct'),
    dataIndex: PackageField.URL,
    width: 120,
  },
  {
    title: t('monitor.ota.fileName'),
    dataIndex: PackageField.FILE_NAME,
    width: 120,
  },
  {
    title: t('monitor.ota.fileSize'),
    dataIndex: PackageField.FILE_SIZE,
    format(text, record) {
      return record[PackageField.FILE_SIZE]
        ? `${Math.ceil(((text as unknown as number) / 1024) * 100) / 100}kb`
        : '';
    },
    width: 120,
  },
  {
    title: t('monitor.ota.checksum'),
    dataIndex: PackageField.CHECK_SUM,
    slots: { customRender: PackageField.CHECK_SUM },
    width: 120,
  },
  {
    title: t('common.actionText'),
    dataIndex: 'action',
    flag: 'ACTION',
    fixed: 'right',
    width: 200,
    slots: {
      customRender: 'action',
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: PackageField.TITLE,
    label: t('monitor.ota.title'),
    component: 'Input',
    colProps: { span: 8 },
  },
];