config.data.ts 3.21 KB
import { PlayProtocol } from '../manage/config.data';
import type { StreamingMediaModel } from '/@/api/camera/model/cameraModel';
import { findDictItemByCode } from '/@/api/system/dict';
import { DictEnum } from '/@/enums/dictEnum';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();

export interface DrawerParams {
  createFlag: boolean;
  record?: StreamingMediaModel;
}

export const streamingMediaTypeMapping = {
  0: t('dict.streaming_media_type.hikvisionIscPlatform'),
  1: t('dict.streaming_media_type.fluoritePlatform'),
};

export const streamingMediaSSLMapping = {
  0: 'http',
  1: 'https',
};

export const formatSecret = (string: string) => {
  if (string.length < 6) {
    return string;
  } else {
    const reg = /(^\S{2}).*(\S{4}$)/;
    const prefix = string.match(reg)?.at(1);
    const suffix = string.match(reg)?.at(2);
    return `${prefix}${''.padStart(string.length - 6, '*')}${suffix}`;
  }
};

export const columnSchema: BasicColumn[] = [
  {
    title: t('video.stream.platformAddressText'),
    dataIndex: 'host',
    width: 80,
  },
  {
    title: t('video.stream.userKeyText'),
    dataIndex: 'appKey',
    width: 80,
    format(text) {
      return formatSecret(text);
    },
  },
  {
    title: t('video.stream.userSecretText'),
    dataIndex: 'appSecret',
    width: 80,
    format(text) {
      return formatSecret(text);
    },
  },
  {
    title: t('video.stream.platformTypeText'),
    dataIndex: 'type',
    width: 80,
    slots: { customRender: 'type' },
  },
  {
    title: t('video.stream.deploymentEnvironmentText'),
    dataIndex: 'ssl',
    width: 80,
    slots: { customRender: 'ssl' },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'host',
    label: t('video.stream.platformAddressText'),
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formDetailSchema: FormSchema[] = [
  {
    label: t('video.stream.platformTypeText'),
    field: 'type',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: async (params) => {
        const values = await findDictItemByCode(params);
        return values.map((item) => ({ label: item.itemText, value: Number(item.itemValue) }));
      },
      params: {
        dictCode: DictEnum.STREAMING_MEDIA_TYPE,
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    label: t('video.stream.deploymentEnvironmentText'),
    field: 'ssl',
    component: 'RadioGroup',
    ifShow: false,
    required: true,
    defaultValue: PlayProtocol.HTTPS,
  },
  {
    label: t('video.stream.platformAddressText'),
    field: 'host',
    component: 'Input',
    helpMessage: t('video.stream.platformAddressHelpText'),
    required: true,
    componentProps: {
      maxLength: 36,
    },
  },
  {
    label: t('video.stream.userKeyText'),
    field: 'appKey',
    component: 'InputPassword',
    required: true,
    componentProps: {
      maxLength: 36,
    },
  },
  {
    label: t('video.stream.userSecretText'),
    field: 'appSecret',
    component: 'InputPassword',
    required: true,
    rules: [{ required: true, min: 20, message: t('video.stream.userSecretRuleText') }],
    componentProps: {
      maxLength: 36,
    },
  },
];