config.d.ts 4.29 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { Tinymce } from '/@/components/Tinymce/index';
import { h, ref } from 'vue';
import { findDictItemByCode } from '/@/api/system/dict';
import { getOrganizationList } from '/@/api/system/system';
import { copyTransFun } from '/@/utils/fnUtils';
import { Tag } from 'ant-design-vue';

export const selectWhere = ref(null);
export const isDeptId = ref(null);
export const columns: BasicColumn[] = [
  {
    title: '类型',
    dataIndex: 'type',
    width: 200,
    format: (_text: string, record: Recordable) => {
      return record.type === 'NOTICE'
        ? '公告'
        : record.type === 'MEETING'
        ? '会议'
        : record.type === 'OTHER'
        ? '其他'
        : '';
    },
  },
  {
    title: '标题',
    dataIndex: 'title',
    width: 200,
  },
  {
    title: '内容',
    dataIndex: 'content',
    width: 120,
    format: (text: string, record: Recordable) => {
      return !record.content ? '' : record.content.slice(3, record.content.length - 4);
    },
  },
  {
    title: '发送者',
    dataIndex: 'senderName',
    width: 200,
    format: (text: string, record: Recordable) => {
      return record.senderName ? record.senderName : '无';
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 200,
    customRender: ({ record }) => {
      const status = record.status;
      const enable = status === '已发布' ? '已发布' : status === '草稿' ? '草稿' : '其他';
      const color = enable === '已发布' ? 'green' : enable === '草稿' ? 'yellow' : 'red';
      const text = enable === '已发布' ? '已发布' : enable === '草稿' ? '草稿' : '其他';
      return h(Tag, { color: color }, () => text);
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'type',
    label: '类型',
    colProps: { span: 24 },
    required: true,
    component: 'RadioGroup',
    componentProps: {
      options: [
        {
          label: '公告',
          value: 'NOTICE',
        },
        {
          label: '会议',
          value: 'MEETING',
        },
        {
          label: '其他',
          value: 'OTHER',
        },
      ],
    },
  },
  {
    field: 'title',
    label: '标题',
    required: true,
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入标题',
    },
  },
  {
    field: 'content',
    component: 'Input',
    colProps: { span: 24 },
    label: '内容',
    defaultValue: '',
    rules: [{ required: true }],
    render: ({ model, field }) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
  {
    field: 'organizationId',
    label: '所属组织',
    colProps: { span: 12 },
    component: 'ApiTreeSelect',
    componentProps: {
      api: async () => {
        const data = await getOrganizationList();
        copyTransFun(data as any as any[]);
        return data;
      },
      onChange: (v) => {
        isDeptId.value = v;
      },
    },
  },
  {
    field: 'receiverType',
    required: true,
    label: '接收者',
    colProps: { span: 24 },
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'receiver_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
      onChange: (v) => {
        switch (v) {
          case '0':
            selectWhere.value = v;
            break;
          case '1':
            selectWhere.value = v;
            break;
          case '2':
            selectWhere.value = v;
            break;
          case '3':
            selectWhere.value = v;
            break;
          default:
            selectWhere.value = v;
        }
      },
    },
  },
  {
    field: '',
    component: 'Input',
    label: '',
    colProps: {
      span: 12,
    },
    slot: 'add',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'type',
    label: '',
    colProps: { span: 8 },
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '公告',
          value: 'NOTICE',
        },
        {
          label: '会议',
          value: 'MEETING',
        },
        {
          label: '其他',
          value: 'OTHER',
        },
      ],
    },
  },
];