reactor:【system 系统管理】notice 在 ele 和 antd 的代码一致性

pull/209/head^2^2
YunaiV 2025-09-04 21:31:24 +08:00
parent cf8745d844
commit a153a86142
6 changed files with 82 additions and 103 deletions

View File

@ -92,14 +92,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'id',
title: '公告编号',
minWidth: 100,
},
{
field: 'title',
title: '公告标题',
minWidth: 200,
},
{
field: 'type',
title: '公告类型',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.SYSTEM_NOTICE_TYPE },
@ -108,6 +111,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'status',
title: '公告状态',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@ -116,6 +120,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@ -4,7 +4,7 @@ import type { SystemNoticeApi } from '#/api/system/notice';
import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui';
import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
@ -45,14 +45,11 @@ function handleEdit(row: SystemNoticeApi.Notice) {
async function handleDelete(row: SystemNoticeApi.Notice) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.title]),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteNotice(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.title]),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.deleteSuccess', [row.title]));
onRefresh();
} finally {
hideLoading();
@ -61,10 +58,10 @@ async function handleDelete(row: SystemNoticeApi.Notice) {
/** 批量删除公告 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'),
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
key: 'action_process_msg',
});
try {
await deleteNoticeList(checkedIds.value);
@ -82,21 +79,17 @@ function handleRowCheckboxChange({
}: {
records: SystemNoticeApi.Notice[];
}) {
checkedIds.value = records.map((item) => item.id as number);
checkedIds.value = records.map((item) => item.id!);
}
/** 推送公告 */
async function handlePush(row: SystemNoticeApi.Notice) {
const hideLoading = message.loading({
content: '正在推送中',
key: 'action_process_msg',
content: '正在推送中...',
});
try {
await pushNotice(row.id as number);
message.success({
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_key_msg',
});
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
hideLoading();
}
@ -152,12 +145,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleCreate,
},
{
label: '批量删除',
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
disabled: isEmpty(checkedIds),
icon: ACTION_ICON.DELETE,
auth: ['system:notice:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"

View File

@ -1,14 +1,9 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemNoticeApi } from '#/api/system/notice';
import { useAccess } from '@vben/access';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { z } from '#/adapter/form';
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
return [
@ -91,14 +86,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
}
/** 列表的字段 */
export function useGridColumns<T = SystemNoticeApi.Notice>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
type: 'checkbox',
width: 40,
},
{ type: 'checkbox', width: 40 },
{
field: 'id',
title: '公告编号',
@ -134,34 +124,10 @@ export function useGridColumns<T = SystemNoticeApi.Notice>(
formatter: 'formatDateTime',
},
{
field: 'operation',
title: '操作',
minWidth: 180,
align: 'center',
width: 220,
fixed: 'right',
cellRender: {
attrs: {
nameField: 'title',
nameTitle: '公告',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['system:notice:update']),
},
{
code: 'push',
text: '推送',
show: hasAccessByCodes(['system:notice:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['system:notice:delete']),
},
],
},
slots: { default: 'actions' },
},
];
}

View File

@ -1,8 +1,5 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemNoticeApi } from '#/api/system/notice';
import { ref } from 'vue';
@ -35,21 +32,19 @@ function onRefresh() {
}
/** 创建公告 */
// TODO @ handleXXX ep
function onCreate() {
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑公告 */
function onEdit(row: SystemNoticeApi.Notice) {
function handleEdit(row: SystemNoticeApi.Notice) {
formModalApi.setData(row).open();
}
/** 删除公告 */
async function onDelete(row: SystemNoticeApi.Notice) {
async function handleDelete(row: SystemNoticeApi.Notice) {
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.title]),
fullscreen: true,
});
try {
await deleteNotice(row.id as number);
@ -61,12 +56,19 @@ async function onDelete(row: SystemNoticeApi.Notice) {
}
/** 批量删除公告 */
async function onDeleteBatch() {
await confirm('确定要批量删除该公告吗?');
await deleteNoticeList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deletingBatch'),
});
try {
await deleteNoticeList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
onRefresh();
} finally {
loadingInstance.close();
}
}
const checkedIds = ref<number[]>([]);
@ -79,48 +81,24 @@ function handleRowCheckboxChange({
}
/** 推送公告 */
async function onPush(row: SystemNoticeApi.Notice) {
const loadingInstance = ElMessage({
message: $t('ui.actionMessage.processing', ['推送']),
type: 'info',
duration: 0,
async function handlePush(row: SystemNoticeApi.Notice) {
const loadingInstance = ElLoading.service({
text: '正在推送中...',
});
try {
await pushNotice(row.id as number);
loadingInstance.close();
ElMessage.success($t('ui.actionMessage.operationSuccess'));
} finally {
loadingInstance.close();
}
}
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<SystemNoticeApi.Notice>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(row);
break;
}
case 'push': {
onPush(row);
break;
}
}
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(onActionClick),
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
@ -136,6 +114,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
@ -161,20 +140,52 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['system:notice:create'],
onClick: onCreate,
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'danger',
icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds),
auth: ['system:notice:delete'],
onClick: onDeleteBatch,
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['system:notice:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '推送',
type: 'primary',
link: true,
icon: ACTION_ICON.ADD,
auth: ['system:notice:update'],
onClick: handlePush.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['system:notice:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.title]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
<!-- TODO @规范讨论要不要类似 antd 一样改成 TableAction可见 /apps/web-ele/src/views/system/notice/index.vue 167 195 -->
</Grid>
</Page>
</template>

View File

@ -24,7 +24,9 @@
},
"actionMessage": {
"deleteConfirm": "Are you sure to delete {0}?",
"deleteBatchConfirm": "Are you sure to delete selected items?",
"deleting": "Deleting {0} ...",
"deletingBatch": "Deleting selected ...",
"deleteSuccess": "{0} deleted successfully",
"deleteFailed": "{0} deleted failed",
"operationSuccess": "Operation succeeded",

View File

@ -24,7 +24,9 @@
},
"actionMessage": {
"deleteConfirm": "确定删除 {0} 吗?",
"deleteBatchConfirm": "确定删除所选项吗?",
"deleting": "正在删除 {0} ...",
"deletingBatch": "正在删除所选项 ...",
"deleteSuccess": "{0} 删除成功",
"deleteFailed": "{0} 删除失败",
"operationSuccess": "操作成功",