gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
src/views/im/manager/message/data.ts
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,254 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { markRaw } from 'vue';
import { DICT_TYPE } from '#/packages/constants/src';
import { getDictOptions } from '#/packages/effects/hooks/src';
import { getRangePickerDefaultProps } from '#/utils';
import { GroupSelect } from '#/views/im/manager/group/components';
import { UserSelect } from '#/views/system/user/components';
/** ç§èŠæ¶ˆæ¯æœç´¢è¡¨å• */
export function usePrivateGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'senderId',
      label: '发送人',
      component: markRaw(UserSelect),
      componentProps: {
        placeholder: '请选择发送人',
      },
    },
    {
      fieldName: 'receiverId',
      label: '接收人',
      component: markRaw(UserSelect),
      componentProps: {
        placeholder: '请选择接收人',
      },
    },
    {
      fieldName: 'type',
      label: '内容类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.IM_CONTENT_TYPE, 'number'),
        placeholder: '请选择内容类型',
      },
    },
    {
      fieldName: 'content',
      label: '消息内容',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入消息内容',
      },
    },
    {
      fieldName: 'sendTime',
      label: '发送时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}
/** ç§èŠæ¶ˆæ¯å­—段 */
export function usePrivateGridColumns(showReadColumns: boolean): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: '编号',
      width: 100,
    },
    {
      title: '发送人',
      minWidth: 160,
      slots: { default: 'sender' },
    },
    {
      title: '接收人',
      minWidth: 160,
      slots: { default: 'receiver' },
    },
    {
      field: 'type',
      title: '类型',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.IM_CONTENT_TYPE },
      },
    },
    {
      title: '内容预览',
      minWidth: 260,
      align: 'left',
      slots: { default: 'content' },
    },
    ...(showReadColumns
      ? [
          {
            field: 'status',
            title: '状态',
            width: 100,
            cellRender: {
              name: 'CellDict',
              props: { type: DICT_TYPE.IM_MESSAGE_STATUS },
            },
          },
          {
            field: 'receiptStatus',
            title: '回执',
            width: 110,
            cellRender: {
              name: 'CellDict',
              // å›žæ‰§çŠ¶æ€ï¼ˆç§èŠ / ç¾¤èŠå…±ç”¨ im_message_receipt_status),与源端「回执」列对齐
              props: { type: DICT_TYPE.IM_MESSAGE_RECEIPT_STATUS },
            },
          },
        ]
      : []),
    {
      field: 'sendTime',
      title: '发送时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 100,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
/** ç¾¤èŠæ¶ˆæ¯æœç´¢è¡¨å• */
export function useGroupGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'groupId',
      label: '群',
      component: markRaw(GroupSelect),
    },
    {
      fieldName: 'senderId',
      label: '发送人',
      component: markRaw(UserSelect),
      componentProps: {
        placeholder: '请选择发送人',
      },
    },
    {
      fieldName: 'type',
      label: '内容类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.IM_CONTENT_TYPE, 'number'),
        placeholder: '请选择内容类型',
      },
    },
    {
      fieldName: 'content',
      label: '消息内容',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入消息内容',
      },
    },
    {
      fieldName: 'sendTime',
      label: '发送时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}
/** ç¾¤èŠæ¶ˆæ¯å­—段 */
export function useGroupGridColumns(showReadColumns: boolean): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: '编号',
      width: 100,
    },
    {
      title: '群',
      minWidth: 160,
      slots: { default: 'group' },
    },
    {
      title: '发送人',
      minWidth: 160,
      slots: { default: 'sender' },
    },
    {
      field: 'type',
      title: '类型',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.IM_CONTENT_TYPE },
      },
    },
    {
      title: '@用户',
      minWidth: 180,
      slots: { default: 'atUsers' },
    },
    {
      title: '内容预览',
      minWidth: 260,
      align: 'left',
      slots: { default: 'content' },
    },
    ...(showReadColumns
      ? [
          {
            field: 'status',
            title: '状态',
            width: 100,
            cellRender: {
              name: 'CellDict',
              props: { type: DICT_TYPE.IM_MESSAGE_STATUS },
            },
          },
          {
            field: 'receiptStatus',
            title: '回执',
            width: 110,
            cellRender: {
              name: 'CellDict',
              props: { type: DICT_TYPE.IM_MESSAGE_RECEIPT_STATUS },
            },
          },
        ]
      : []),
    {
      field: 'sendTime',
      title: '发送时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 100,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}