feat: 新增 ele 站内信管理模块
parent
9bffbb1fcc
commit
78aa64aed3
|
@ -0,0 +1,171 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemNotifyMessageApi } from '#/api/system/notify/message';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
|
||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '用户编号',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入用户编号',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'userType',
|
||||
label: '用户类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
|
||||
placeholder: '请选择用户类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'templateCode',
|
||||
label: '模板编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入模板编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'templateType',
|
||||
label: '模版类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(
|
||||
DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE,
|
||||
'number',
|
||||
),
|
||||
allowClear: true,
|
||||
placeholder: '请选择模版类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemNotifyMessageApi.NotifyMessage>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'userType',
|
||||
title: '用户类型',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.USER_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'userId',
|
||||
title: '用户编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'templateCode',
|
||||
title: '模板编码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'templateNickname',
|
||||
title: '发送人名称',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'templateContent',
|
||||
title: '模版内容',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'templateParams',
|
||||
title: '模版参数',
|
||||
minWidth: 180,
|
||||
formatter: ({ cellValue }) => {
|
||||
try {
|
||||
return JSON.stringify(cellValue);
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'templateType',
|
||||
title: '模版类型',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'readStatus',
|
||||
title: '是否已读',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'readTime',
|
||||
title: '阅读时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
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: hasAccessByCodes(['system:notify-message:query']),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<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 { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getNotifyMessagePage } 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();
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemNotifyMessageApi.NotifyMessage>) {
|
||||
switch (code) {
|
||||
case 'detail': {
|
||||
onDetail(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 getNotifyMessagePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: 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="站内信列表" />
|
||||
</Page>
|
||||
</template>
|
|
@ -0,0 +1,87 @@
|
|||
<script lang="ts" setup>
|
||||
import type { SystemNotifyMessageApi } from '#/api/system/notify/message';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { formatDateTime } from '@vben/utils';
|
||||
|
||||
import { ElDescriptions, ElDescriptionsItem } from 'element-plus';
|
||||
|
||||
import { DictTag } from '#/components/dict-tag';
|
||||
import { DICT_TYPE } from '#/utils';
|
||||
|
||||
const formData = ref<SystemNotifyMessageApi.NotifyMessage>();
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<SystemNotifyMessageApi.NotifyMessage>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = data;
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
title="站内信详情"
|
||||
class="w-1/2"
|
||||
:show-cancel-button="false"
|
||||
:show-confirm-button="false"
|
||||
>
|
||||
<ElDescriptions border :column="1" size="default" class="mx-4">
|
||||
<ElDescriptionsItem label="编号">{{ formData?.id }}</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="用户类型">
|
||||
<DictTag :type="DICT_TYPE.USER_TYPE" :value="formData?.userType" />
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="用户编号">
|
||||
{{ formData?.userId }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="模版编号">
|
||||
{{ formData?.templateId }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="模板编码">
|
||||
{{ formData?.templateCode }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="发送人名称">
|
||||
{{ formData?.templateNickname }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="模版内容">
|
||||
{{ formData?.templateContent }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="模版参数">
|
||||
{{ formData?.templateParams }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="模版类型">
|
||||
<DictTag
|
||||
:type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE"
|
||||
:value="formData?.templateType"
|
||||
/>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="是否已读">
|
||||
<DictTag
|
||||
:type="DICT_TYPE.INFRA_BOOLEAN_STRING"
|
||||
:value="formData?.readStatus"
|
||||
/>
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="阅读时间">
|
||||
{{ formatDateTime(formData?.readTime || '') }}
|
||||
</ElDescriptionsItem>
|
||||
<ElDescriptionsItem label="创建时间">
|
||||
{{ formatDateTime(formData?.createTime || '') }}
|
||||
</ElDescriptionsItem>
|
||||
</ElDescriptions>
|
||||
</Modal>
|
||||
</template>
|
|
@ -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: '消息内容',
|
||||
},
|
||||
];
|
||||
}
|
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,321 @@
|
|||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemNotifyTemplateApi } from '#/api/system/notify/template';
|
||||
|
||||
import { useAccess } from '@vben/access';
|
||||
|
||||
import { z } from '#/adapter/form';
|
||||
import { getSimpleUserList } from '#/api/system/user';
|
||||
import {
|
||||
CommonStatusEnum,
|
||||
DICT_TYPE,
|
||||
getDictOptions,
|
||||
getRangePickerDefaultProps,
|
||||
UserTypeEnum,
|
||||
} from '#/utils';
|
||||
|
||||
const { hasAccessByCodes } = useAccess();
|
||||
|
||||
/** 新增/修改的表单 */
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'id',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '模板名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入模板名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '模板编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入模板编码',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'nickname',
|
||||
label: '发送人名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入发送人名称',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'content',
|
||||
label: '模板内容',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入模板内容',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '模板类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(
|
||||
DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE,
|
||||
'number',
|
||||
),
|
||||
placeholder: '请选择模板类型',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
},
|
||||
rules: z.number().default(CommonStatusEnum.ENABLE),
|
||||
},
|
||||
{
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的搜索表单 */
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'name',
|
||||
label: '模板名称',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入模板名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'code',
|
||||
label: '模板编码',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入模板编码',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
|
||||
allowClear: true,
|
||||
placeholder: '请选择状态',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'type',
|
||||
label: '模板类型',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: getDictOptions(
|
||||
DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE,
|
||||
'number',
|
||||
),
|
||||
allowClear: true,
|
||||
placeholder: '请选择模板类型',
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
...getRangePickerDefaultProps(),
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 发送站内信表单 */
|
||||
export function useSendNotifyFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
fieldName: 'content',
|
||||
label: '模板内容',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'templateCode',
|
||||
label: '模板编码',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldName: 'userType',
|
||||
label: '用户类型',
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
|
||||
},
|
||||
rules: z.number().default(UserTypeEnum.MEMBER),
|
||||
},
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '接收人ID',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入用户编号',
|
||||
},
|
||||
dependencies: {
|
||||
show(values) {
|
||||
return values.userType === UserTypeEnum.MEMBER;
|
||||
},
|
||||
triggerFields: ['userType'],
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'userId',
|
||||
label: '接收人',
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getSimpleUserList,
|
||||
labelField: 'nickname',
|
||||
valueField: 'id',
|
||||
placeholder: '请选择接收人',
|
||||
},
|
||||
dependencies: {
|
||||
show(values) {
|
||||
return values.userType === UserTypeEnum.ADMIN;
|
||||
},
|
||||
triggerFields: ['userType'],
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'templateParams',
|
||||
label: '模板参数',
|
||||
component: 'Input',
|
||||
dependencies: {
|
||||
triggerFields: [''],
|
||||
show: () => false,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemNotifyTemplateApi.NotifyTemplate>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{
|
||||
field: 'id',
|
||||
title: '编号',
|
||||
minWidth: 100,
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '模板名称',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
title: '模板编码',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'nickname',
|
||||
title: '发送人名称',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'content',
|
||||
title: '模板内容',
|
||||
minWidth: 200,
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
title: '模板类型',
|
||||
minWidth: 120,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '状态',
|
||||
minWidth: 100,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 180,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
attrs: {
|
||||
nameField: 'name',
|
||||
nameTitle: '站内信模板',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
{
|
||||
code: 'edit',
|
||||
show: hasAccessByCodes(['system:notify-template:update']),
|
||||
},
|
||||
{
|
||||
code: 'send',
|
||||
text: '测试',
|
||||
show: hasAccessByCodes(['system:notify-template:send-notify']),
|
||||
},
|
||||
{
|
||||
code: 'delete',
|
||||
show: hasAccessByCodes(['system:notify-template:delete']),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
<script lang="ts" setup>
|
||||
import type {
|
||||
OnActionClickParams,
|
||||
VxeTableGridOptions,
|
||||
} from '#/adapter/vxe-table';
|
||||
import type { SystemNotifyTemplateApi } from '#/api/system/notify/template';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Download, Plus } from '@vben/icons';
|
||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
||||
|
||||
import { ElButton, ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteNotifyTemplate,
|
||||
exportNotifyTemplate,
|
||||
getNotifyTemplatePage,
|
||||
} from '#/api/system/notify/template';
|
||||
import { DocAlert } from '#/components/doc-alert';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
import SendForm from './modules/send-form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
const [SendModal, sendModalApi] = useVbenModal({
|
||||
connectedComponent: SendForm,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
/** 刷新表格 */
|
||||
function onRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
/** 导出表格 */
|
||||
async function onExport() {
|
||||
const data = await exportNotifyTemplate(await gridApi.formApi.getValues());
|
||||
downloadFileFromBlobPart({ fileName: '站内信模板.xls', source: data });
|
||||
}
|
||||
|
||||
/** 创建站内信模板 */
|
||||
function onCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
/** 编辑站内信模板 */
|
||||
function onEdit(row: SystemNotifyTemplateApi.NotifyTemplate) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 发送测试站内信 */
|
||||
function onSend(row: SystemNotifyTemplateApi.NotifyTemplate) {
|
||||
sendModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 删除站内信模板 */
|
||||
async function onDelete(row: SystemNotifyTemplateApi.NotifyTemplate) {
|
||||
const loadingInstance = ElMessage({
|
||||
message: $t('ui.actionMessage.deleting', [row.name]),
|
||||
type: 'info',
|
||||
duration: 0,
|
||||
});
|
||||
try {
|
||||
await deleteNotifyTemplate(row.id as number);
|
||||
loadingInstance.close();
|
||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||
onRefresh();
|
||||
} finally {
|
||||
loadingInstance.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** 表格操作按钮的回调函数 */
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemNotifyTemplateApi.NotifyTemplate>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'send': {
|
||||
onSend(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 getNotifyTemplatePage({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: 'id',
|
||||
},
|
||||
toolbarConfig: {
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<SystemNotifyTemplateApi.NotifyTemplate>,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<template #doc>
|
||||
<DocAlert title="站内信" url="https://doc.iocoder.cn/notify/" />
|
||||
</template>
|
||||
|
||||
<FormModal @success="onRefresh" />
|
||||
<SendModal />
|
||||
<Grid table-title="站内信模板列表">
|
||||
<template #toolbar-tools>
|
||||
<ElButton
|
||||
type="primary"
|
||||
@click="onCreate"
|
||||
v-access:code="['system:notify-template:create']"
|
||||
>
|
||||
<Plus class="size-5" />
|
||||
{{ $t('ui.actionTitle.create', ['站内信模板']) }}
|
||||
</ElButton>
|
||||
<ElButton
|
||||
type="primary"
|
||||
class="ml-2"
|
||||
@click="onExport"
|
||||
v-access:code="['system:notify-template:export']"
|
||||
>
|
||||
<Download class="size-5" />
|
||||
{{ $t('ui.actionTitle.export') }}
|
||||
</ElButton>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
|
@ -0,0 +1,89 @@
|
|||
<script lang="ts" setup>
|
||||
import type { SystemNotifyTemplateApi } from '#/api/system/notify/template';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createNotifyTemplate,
|
||||
getNotifyTemplate,
|
||||
updateNotifyTemplate,
|
||||
} from '#/api/system/notify/template';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<SystemNotifyTemplateApi.NotifyTemplate>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['站内信模板'])
|
||||
: $t('ui.actionTitle.create', ['站内信模板']);
|
||||
});
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data =
|
||||
(await formApi.getValues()) as SystemNotifyTemplateApi.NotifyTemplate;
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateNotifyTemplate(data)
|
||||
: createNotifyTemplate(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<SystemNotifyTemplateApi.NotifyTemplate>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
try {
|
||||
formData.value = await getNotifyTemplate(data.id as number);
|
||||
// 设置到 values
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="getTitle">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
|
@ -0,0 +1,112 @@
|
|||
<script lang="ts" setup>
|
||||
import type { SystemNotifyTemplateApi } from '#/api/system/notify/template';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { sendNotify } from '#/api/system/notify/template';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useSendNotifyFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<SystemNotifyTemplateApi.NotifyTemplate>();
|
||||
|
||||
const [Form, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
formItemClass: 'col-span-2',
|
||||
labelWidth: 80,
|
||||
},
|
||||
layout: 'horizontal',
|
||||
showDefaultActions: false,
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
modalApi.lock();
|
||||
// 构建发送请求
|
||||
const values = await formApi.getValues();
|
||||
const paramsObj: Record<string, string> = {};
|
||||
if (formData.value?.params) {
|
||||
formData.value.params.forEach((param) => {
|
||||
paramsObj[param] = values[`param_${param}`];
|
||||
});
|
||||
}
|
||||
const data: SystemNotifyTemplateApi.NotifySendReqVO = {
|
||||
userId: values.userId,
|
||||
userType: values.userType,
|
||||
templateCode: formData.value?.code || '',
|
||||
templateParams: paramsObj,
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
try {
|
||||
await sendNotify(data);
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||
} catch (error) {
|
||||
console.error('发送站内信失败', error);
|
||||
} finally {
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
formData.value = undefined;
|
||||
return;
|
||||
}
|
||||
// 获取数据
|
||||
const data = modalApi.getData<SystemNotifyTemplateApi.NotifyTemplate>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
formData.value = data;
|
||||
// 更新 form schema
|
||||
const schema = buildFormSchema();
|
||||
formApi.setState({ schema });
|
||||
// 设置到 values
|
||||
await formApi.setValues({
|
||||
content: data.content,
|
||||
templateCode: data.code,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
/** 动态构建表单 schema */
|
||||
const buildFormSchema = () => {
|
||||
const schema = useSendNotifyFormSchema();
|
||||
if (formData.value?.params) {
|
||||
formData.value.params.forEach((param: string) => {
|
||||
schema.push({
|
||||
fieldName: `param_${param}`,
|
||||
label: `参数 ${param}`,
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
componentProps: {
|
||||
placeholder: `请输入参数 ${param}`,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
return schema;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="测试发送站内信">
|
||||
<Form class="mx-4" />
|
||||
</Modal>
|
||||
</template>
|
Loading…
Reference in New Issue