Files
iot-device-management-frontend/apps/web-antd/src/views/system/notify/template/index.vue

212 lines
5.6 KiB
Vue
Raw Normal View History

2025-04-04 14:13:30 +08:00
<script lang="ts" setup>
2025-05-19 17:58:06 +08:00
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
2025-04-04 14:13:30 +08:00
import type { SystemNotifyTemplateApi } from '#/api/system/notify/template';
import { ref } from 'vue';
2025-06-10 16:32:29 +08:00
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
2025-05-19 17:58:06 +08:00
import { message } from 'ant-design-vue';
2025-04-04 14:13:30 +08:00
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
2025-04-22 22:10:33 +08:00
import {
deleteNotifyTemplate,
deleteNotifyTemplateList,
2025-04-22 22:10:33 +08:00
exportNotifyTemplate,
getNotifyTemplatePage,
} from '#/api/system/notify/template';
2025-04-22 11:25:11 +08:00
import { $t } from '#/locales';
2025-04-04 14:13:30 +08:00
import { useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
import SendForm from './modules/send-form.vue';
2025-04-04 14:13:30 +08:00
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: Form,
destroyOnClose: true,
});
const [SendModal, sendModalApi] = useVbenModal({
connectedComponent: SendForm,
destroyOnClose: true,
});
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 导出表格 */
2025-05-20 11:23:02 +08:00
async function handleExport() {
2025-04-04 14:13:30 +08:00
const data = await exportNotifyTemplate(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '站内信模板.xls', source: data });
2025-04-04 14:13:30 +08:00
}
/** 创建站内信模板 */
2025-05-20 11:23:02 +08:00
function handleCreate() {
2025-04-04 14:13:30 +08:00
formModalApi.setData(null).open();
}
/** 编辑站内信模板 */
2025-05-20 11:23:02 +08:00
function handleEdit(row: SystemNotifyTemplateApi.NotifyTemplate) {
2025-04-04 14:13:30 +08:00
formModalApi.setData(row).open();
}
/** 发送测试站内信 */
2025-05-20 11:23:02 +08:00
function handleSend(row: SystemNotifyTemplateApi.NotifyTemplate) {
2025-04-04 14:13:30 +08:00
sendModalApi.setData(row).open();
}
/** 删除站内信模板 */
2025-05-20 11:23:02 +08:00
async function handleDelete(row: SystemNotifyTemplateApi.NotifyTemplate) {
const hideLoading = message.loading({
2025-04-04 14:13:30 +08:00
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
2025-04-04 14:13:30 +08:00
});
2025-05-20 11:23:02 +08:00
try {
await deleteNotifyTemplate(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemNotifyTemplateApi.NotifyTemplate[];
}) {
checkedIds.value = records.map((item) => item.id as number);
}
/** 批量删除站内信模板 */
async function handleDeleteBatch() {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteNotifyTemplateList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
2025-05-20 11:23:02 +08:00
onRefresh();
} finally {
hideLoading();
}
2025-04-04 14:13:30 +08:00
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
2025-05-19 17:58:06 +08:00
columns: useGridColumns(),
2025-04-04 14:13:30 +08:00
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getNotifyTemplatePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
2025-04-04 14:13:30 +08:00
},
toolbarConfig: {
2025-07-19 17:15:39 +08:00
refresh: true,
2025-04-04 14:13:30 +08:00
search: true,
},
2025-04-22 22:10:33 +08:00
} as VxeTableGridOptions<SystemNotifyTemplateApi.NotifyTemplate>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
2025-04-04 14:13:30 +08:00
});
</script>
2025-04-04 14:13:30 +08:00
<template>
<Page auto-content-height>
<template #doc>
<DocAlert title="短信配置" url="https://doc.iocoder.cn/sms/" />
</template>
2025-04-05 17:09:16 +08:00
2025-04-04 14:13:30 +08:00
<FormModal @success="onRefresh" />
<SendModal />
<Grid table-title="站内信模板列表">
<template #toolbar-tools>
2025-05-19 17:58:06 +08:00
<TableAction
:actions="[
{
2025-05-28 20:05:46 +08:00
label: $t('ui.actionTitle.create', ['站内信模板']),
2025-05-19 17:58:06 +08:00
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['system:notify-template:create'],
2025-05-20 11:23:02 +08:00
onClick: handleCreate,
2025-05-19 17:58:06 +08:00
},
{
label: $t('ui.actionTitle.export'),
type: 'primary',
icon: ACTION_ICON.DOWNLOAD,
auth: ['system:notify-template:export'],
2025-05-20 11:23:02 +08:00
onClick: handleExport,
2025-05-19 17:58:06 +08:00
},
{
label: '批量删除',
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:notify-template:delete'],
onClick: handleDeleteBatch,
},
2025-05-19 17:58:06 +08:00
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['system:notify-template:update'],
2025-05-20 11:23:02 +08:00
onClick: handleEdit.bind(null, row),
2025-05-19 17:58:06 +08:00
},
{
label: '测试',
type: 'link',
icon: ACTION_ICON.ADD,
auth: ['system:notify-template:send-notify'],
2025-05-20 11:23:02 +08:00
onClick: handleSend.bind(null, row),
2025-05-19 17:58:06 +08:00
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['system:notify-template:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
2025-05-20 11:23:02 +08:00
confirm: handleDelete.bind(null, row),
2025-05-19 17:58:06 +08:00
},
},
]"
/>
2025-04-04 14:13:30 +08:00
</template>
</Grid>
</Page>
</template>