config.ts 3.65 KB
import { h } from 'vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { Tinymce } from '/@/components/Tinymce/index';
import { getOrganizationList } from '/@/api/system/system';
import { copyTransFun } from '/@/utils/fnUtils';
import { Tag } from 'ant-design-vue';
import { useComponentRegister } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';
import { NotifyTypeEnum, ReadStatusColorEnum, ReadStatusEnum } from '/@/enums/messageEnum';
import { notifyTypeOptions } from '../myNotices/config';

export enum IsOrgEnum {
  IS_ORG_ENUM = 1,
}
export const isOrg = (type: number) => {
  return type === IsOrgEnum.IS_ORG_ENUM;
};

const { t } = useI18n();
useComponentRegister('Tinymce' as 'Input', Tinymce);

export const columns: BasicColumn[] = [
  {
    title: t('system.notify.notifyTypeText'),
    dataIndex: 'type',
    width: 200,
    format: (text: string) => {
      return text && t(`enum.notifyType.${text}`);
    },
  },
  {
    title: t('system.notify.titleText'),
    dataIndex: 'title',
    width: 200,
  },
  {
    title: t('system.notify.dispatcherText'),
    dataIndex: 'senderName',
    width: 200,
    format: (text: string) => {
      return text ? text : '无';
    },
  },
  {
    title: t('system.notify.readStatusText'),
    dataIndex: 'status',
    width: 200,
    customRender: ({ text }) => {
      return h(Tag, { color: ReadStatusColorEnum[ReadStatusEnum[text]] }, () =>
        t(`enum.readStatus.${ReadStatusEnum[text]}`)
      );
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'type',
    label: t('system.notify.notifyTypeText'),
    colProps: { span: 24 },
    required: true,
    component: 'RadioGroup',
    defaultValue: 'NOTICE',
    componentProps: {
      options: notifyTypeOptions,
    },
  },
  {
    field: 'title',
    label: t('system.notify.titleText'),
    required: true,
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      maxLength: 36,
    },
  },
  {
    field: 'content',
    label: t('system.notify.notifyContentText'),
    component: 'Tinymce' as 'Input',
    colProps: { span: 24 },
    required: true,
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'receiverType',
    label: t('system.notify.receiverText'),
    required: true,
    colProps: { span: 13 },
    component: 'Select',
    componentProps: {
      options: [
        { label: t('system.notify.allText'), value: 0 },
        { label: t('system.notify.organizationText'), value: 1 },
      ],
    },
  },
  {
    field: 'organizationId',
    label: t('business.affiliatedOrganizationText'),
    colProps: { span: 13 },
    component: 'ApiTreeSelect',
    required: true,
    componentProps: {
      multiple: true,
      api: async () => {
        const data = await getOrganizationList();
        copyTransFun(data as any as any[]);
        return data;
      },
    },
    ifShow: ({ values }) => isOrg(Reflect.get(values, 'receiverType')),
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'type',
    label: t('system.notify.notifyTypeText'),
    colProps: { span: 6 },
    component: 'Select',
    componentProps: {
      options: Object.keys(NotifyTypeEnum).map((key) => ({
        label: t(`enum.notifyType.${key}`),
        value: NotifyTypeEnum[key],
      })),
    },
  },
];
export const detailColumns: BasicColumn[] = [
  {
    title: t('system.notify.receiverText'),
    dataIndex: 'receiverName',
    width: 200,
  },
  {
    title: t('system.notify.readStatusText'),
    dataIndex: 'readStatus',
    width: 200,
    slots: { customRender: 'readStatus' },
  },
  {
    title: t('system.notify.readTimeText'),
    dataIndex: 'readDate',
    width: 200,
  },
];