feat: 新增 ele 站内信管理模块

This commit is contained in:
puhui999
2025-05-12 00:44:03 +08:00
parent 9bffbb1fcc
commit 78aa64aed3
10 changed files with 1398 additions and 0 deletions

View File

@@ -0,0 +1,157 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemNotifyMessageApi } from '#/api/system/notify/message';
import type { DescriptionItemSchema } from '#/components/description';
import { h } from 'vue';
import { formatDateTime } from '@vben/utils';
import { DictTag } from '#/components/dict-tag';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'readStatus',
label: '是否已读',
component: 'Select',
componentProps: {
options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
allowClear: true,
placeholder: '请选择是否已读',
},
},
{
fieldName: 'createTime',
label: '发送时间',
component: 'RangePicker',
componentProps: {
allowClear: true,
...getRangePickerDefaultProps(),
},
},
];
}
/** 列表的字段 */
export function useGridColumns<T = SystemNotifyMessageApi.NotifyMessage>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [
{
title: '',
width: 40,
type: 'checkbox',
},
{
field: 'templateNickname',
title: '发送人',
minWidth: 180,
},
{
field: 'createTime',
title: '发送时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'templateType',
title: '类型',
minWidth: 120,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE },
},
},
{
field: 'templateContent',
title: '消息内容',
minWidth: 300,
},
{
field: 'readStatus',
title: '是否已读',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
},
},
{
field: 'readTime',
title: '阅读时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
minWidth: 180,
align: 'center',
fixed: 'right',
cellRender: {
attrs: {
nameField: 'id',
nameTitle: '站内信',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'detail',
text: '查看',
show: (row: any) => row.readStatus,
},
{
code: 'read',
text: '已读',
show: (row: any) => !row.readStatus,
},
],
},
},
];
}
export function useDetailSchema(): DescriptionItemSchema[] {
return [
{
field: 'templateNickname',
label: '发送人',
},
{
field: 'createTime',
label: '发送时间',
content: (data) => formatDateTime(data?.createTime) as string,
},
{
field: 'templateType',
label: '消息类型',
content: (data) =>
h(DictTag, {
type: DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE,
value: data?.templateType,
}),
},
{
field: 'readStatus',
label: '是否已读',
content: (data) =>
h(DictTag, {
type: DICT_TYPE.INFRA_BOOLEAN_STRING,
value: data?.readStatus,
}),
},
{
field: 'readTime',
label: '阅读时间',
content: (data) => formatDateTime(data?.readTime) as string,
},
{
field: 'templateContent',
label: '消息内容',
},
];
}

View File

@@ -0,0 +1,167 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { SystemNotifyMessageApi } from '#/api/system/notify/message';
import { Page, useVbenModal } from '@vben/common-ui';
import { MdiCheckboxMarkedCircleOutline } from '@vben/icons';
import { ElButton, ElMessage } from 'element-plus';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
getMyNotifyMessagePage,
updateAllNotifyMessageRead,
updateNotifyMessageRead,
} from '#/api/system/notify/message';
import { DocAlert } from '#/components/doc-alert';
import { useGridColumns, useGridFormSchema } from './data';
import Detail from './modules/detail.vue';
const [DetailModal, detailModalApi] = useVbenModal({
connectedComponent: Detail,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 查看站内信详情 */
function onDetail(row: SystemNotifyMessageApi.NotifyMessage) {
detailModalApi.setData(row).open();
}
/** 标记一条站内信已读 */
async function onRead(row: SystemNotifyMessageApi.NotifyMessage) {
const loadingInstance = ElMessage({
message: '正在标记已读...',
type: 'info',
duration: 0,
});
// 执行标记已读操作
await updateNotifyMessageRead([row.id]);
// 提示成功
loadingInstance.close();
ElMessage.success('标记已读成功');
onRefresh();
// 打开详情
onDetail(row);
}
/** 标记选中的站内信为已读 */
async function onMarkRead() {
const rows = gridApi.grid.getCheckboxRecords();
if (!rows || rows.length === 0) {
ElMessage.warning('请选择需要标记的站内信');
return;
}
const ids = rows.map((row: SystemNotifyMessageApi.NotifyMessage) => row.id);
const loadingInstance = ElMessage({
message: '正在标记已读...',
type: 'info',
duration: 0,
});
// 执行标记已读操作
await updateNotifyMessageRead(ids);
// 提示成功
loadingInstance.close();
ElMessage.success('标记已读成功');
await gridApi.grid.setAllCheckboxRow(false);
onRefresh();
}
/** 标记所有站内信为已读 */
async function onMarkAllRead() {
const loadingInstance = ElMessage({
message: '正在标记全部已读...',
type: 'info',
duration: 0,
});
// 执行标记已读操作
await updateAllNotifyMessageRead();
// 提示成功
loadingInstance.close();
ElMessage.success('全部标记已读成功');
await gridApi.grid.setAllCheckboxRow(false);
onRefresh();
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemNotifyMessageApi.NotifyMessage>) {
switch (code) {
case 'detail': {
onDetail(row);
break;
}
case 'read': {
onRead(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getMyNotifyMessagePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
checkboxConfig: {
checkMethod: (params: { row: SystemNotifyMessageApi.NotifyMessage }) =>
!params.row.readStatus,
highlight: true,
},
} as VxeTableGridOptions<SystemNotifyMessageApi.NotifyMessage>,
});
</script>
<template>
<Page auto-content-height>
<template #doc>
<DocAlert title="站内信配置" url="https://doc.iocoder.cn/notify/" />
</template>
<DetailModal @success="onRefresh" />
<Grid table-title="我的站内信">
<template #toolbar-tools>
<ElButton type="primary" @click="onMarkRead">
<MdiCheckboxMarkedCircleOutline />
标记已读
</ElButton>
<ElButton type="primary" class="ml-2" @click="onMarkAllRead">
<MdiCheckboxMarkedCircleOutline />
全部已读
</ElButton>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,49 @@
<script lang="ts" setup>
import type { SystemNotifyMessageApi } from '#/api/system/notify/message';
import { useVbenModal } from '@vben/common-ui';
// TODO puhui999: 下次提交
// import { useDescription } from '#/components/description';
// import { useDetailSchema } from '../data';
//
// const [Description, descApi] = useDescription({
// componentProps: {
// bordered: true,
// column: 1,
// size: 'middle',
// class: 'mx-4',
// },
// schema: useDetailSchema(),
// });
const [Modal, modalApi] = useVbenModal({
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
return;
}
// 加载数据
const data = modalApi.getData<SystemNotifyMessageApi.NotifyMessage>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
// descApi.setState({ data });
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal
title="消息详情"
:show-cancel-button="false"
:show-confirm-button="false"
>
<!-- <Description />-->
</Modal>
</template>