reactor:【system 系统管理】notice 在 ele 和 antd 的代码一致性
parent
cf8745d844
commit
a153a86142
|
@ -92,14 +92,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '公告编号',
|
title: '公告编号',
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'title',
|
field: 'title',
|
||||||
title: '公告标题',
|
title: '公告标题',
|
||||||
|
minWidth: 200,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'type',
|
field: 'type',
|
||||||
title: '公告类型',
|
title: '公告类型',
|
||||||
|
minWidth: 100,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellDict',
|
name: 'CellDict',
|
||||||
props: { type: DICT_TYPE.SYSTEM_NOTICE_TYPE },
|
props: { type: DICT_TYPE.SYSTEM_NOTICE_TYPE },
|
||||||
|
@ -108,6 +111,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
{
|
{
|
||||||
field: 'status',
|
field: 'status',
|
||||||
title: '公告状态',
|
title: '公告状态',
|
||||||
|
minWidth: 100,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellDict',
|
name: 'CellDict',
|
||||||
props: { type: DICT_TYPE.COMMON_STATUS },
|
props: { type: DICT_TYPE.COMMON_STATUS },
|
||||||
|
@ -116,6 +120,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
{
|
{
|
||||||
field: 'createTime',
|
field: 'createTime',
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
|
minWidth: 180,
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { SystemNoticeApi } from '#/api/system/notice';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
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 { isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
@ -45,14 +45,11 @@ function handleEdit(row: SystemNoticeApi.Notice) {
|
||||||
async function handleDelete(row: SystemNoticeApi.Notice) {
|
async function handleDelete(row: SystemNoticeApi.Notice) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.title]),
|
content: $t('ui.actionMessage.deleting', [row.title]),
|
||||||
key: 'action_key_msg',
|
duration: 0,
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteNotice(row.id as number);
|
await deleteNotice(row.id as number);
|
||||||
message.success({
|
message.success($t('ui.actionMessage.deleteSuccess', [row.title]));
|
||||||
content: $t('ui.actionMessage.deleteSuccess', [row.title]),
|
|
||||||
key: 'action_key_msg',
|
|
||||||
});
|
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
@ -61,10 +58,10 @@ async function handleDelete(row: SystemNoticeApi.Notice) {
|
||||||
|
|
||||||
/** 批量删除公告 */
|
/** 批量删除公告 */
|
||||||
async function handleDeleteBatch() {
|
async function handleDeleteBatch() {
|
||||||
|
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting'),
|
content: $t('ui.actionMessage.deletingBatch'),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
key: 'action_process_msg',
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteNoticeList(checkedIds.value);
|
await deleteNoticeList(checkedIds.value);
|
||||||
|
@ -82,21 +79,17 @@ function handleRowCheckboxChange({
|
||||||
}: {
|
}: {
|
||||||
records: SystemNoticeApi.Notice[];
|
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) {
|
async function handlePush(row: SystemNoticeApi.Notice) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: '正在推送中',
|
content: '正在推送中...',
|
||||||
key: 'action_process_msg',
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await pushNotice(row.id as number);
|
await pushNotice(row.id as number);
|
||||||
message.success({
|
message.success($t('ui.actionMessage.operationSuccess'));
|
||||||
content: $t('ui.actionMessage.operationSuccess'),
|
|
||||||
key: 'action_key_msg',
|
|
||||||
});
|
|
||||||
} finally {
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
|
@ -152,12 +145,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
onClick: handleCreate,
|
onClick: handleCreate,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '批量删除',
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
danger: true,
|
danger: true,
|
||||||
disabled: isEmpty(checkedIds),
|
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
auth: ['system:notice:delete'],
|
auth: ['system:notice:delete'],
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
onClick: handleDeleteBatch,
|
onClick: handleDeleteBatch,
|
||||||
},
|
},
|
||||||
]"
|
]"
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
import type { VbenFormSchema } from '#/adapter/form';
|
import type { VbenFormSchema } from '#/adapter/form';
|
||||||
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { SystemNoticeApi } from '#/api/system/notice';
|
|
||||||
|
|
||||||
import { useAccess } from '@vben/access';
|
|
||||||
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
|
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
const { hasAccessByCodes } = useAccess();
|
|
||||||
|
|
||||||
/** 新增/修改的表单 */
|
/** 新增/修改的表单 */
|
||||||
export function useFormSchema(): VbenFormSchema[] {
|
export function useFormSchema(): VbenFormSchema[] {
|
||||||
return [
|
return [
|
||||||
|
@ -91,14 +86,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 列表的字段 */
|
/** 列表的字段 */
|
||||||
export function useGridColumns<T = SystemNoticeApi.Notice>(
|
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||||
onActionClick: OnActionClickFn<T>,
|
|
||||||
): VxeTableGridOptions['columns'] {
|
|
||||||
return [
|
return [
|
||||||
{
|
{ type: 'checkbox', width: 40 },
|
||||||
type: 'checkbox',
|
|
||||||
width: 40,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '公告编号',
|
title: '公告编号',
|
||||||
|
@ -134,34 +124,10 @@ export function useGridColumns<T = SystemNoticeApi.Notice>(
|
||||||
formatter: 'formatDateTime',
|
formatter: 'formatDateTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'operation',
|
|
||||||
title: '操作',
|
title: '操作',
|
||||||
minWidth: 180,
|
width: 220,
|
||||||
align: 'center',
|
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
cellRender: {
|
slots: { default: 'actions' },
|
||||||
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']),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type {
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
OnActionClickParams,
|
|
||||||
VxeTableGridOptions,
|
|
||||||
} from '#/adapter/vxe-table';
|
|
||||||
import type { SystemNoticeApi } from '#/api/system/notice';
|
import type { SystemNoticeApi } from '#/api/system/notice';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
@ -35,21 +32,19 @@ function onRefresh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 创建公告 */
|
/** 创建公告 */
|
||||||
// TODO @霖:【规范讨论】方法名,要不要都换成 handleXXX 开头,和 ep 保持一致;
|
function handleCreate() {
|
||||||
function onCreate() {
|
|
||||||
formModalApi.setData(null).open();
|
formModalApi.setData(null).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑公告 */
|
/** 编辑公告 */
|
||||||
function onEdit(row: SystemNoticeApi.Notice) {
|
function handleEdit(row: SystemNoticeApi.Notice) {
|
||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除公告 */
|
/** 删除公告 */
|
||||||
async function onDelete(row: SystemNoticeApi.Notice) {
|
async function handleDelete(row: SystemNoticeApi.Notice) {
|
||||||
const loadingInstance = ElLoading.service({
|
const loadingInstance = ElLoading.service({
|
||||||
text: $t('ui.actionMessage.deleting', [row.title]),
|
text: $t('ui.actionMessage.deleting', [row.title]),
|
||||||
fullscreen: true,
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await deleteNotice(row.id as number);
|
await deleteNotice(row.id as number);
|
||||||
|
@ -61,12 +56,19 @@ async function onDelete(row: SystemNoticeApi.Notice) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 批量删除公告 */
|
/** 批量删除公告 */
|
||||||
async function onDeleteBatch() {
|
async function handleDeleteBatch() {
|
||||||
await confirm('确定要批量删除该公告吗?');
|
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
|
||||||
await deleteNoticeList(checkedIds.value);
|
const loadingInstance = ElLoading.service({
|
||||||
checkedIds.value = [];
|
text: $t('ui.actionMessage.deletingBatch'),
|
||||||
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
});
|
||||||
onRefresh();
|
try {
|
||||||
|
await deleteNoticeList(checkedIds.value);
|
||||||
|
checkedIds.value = [];
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkedIds = ref<number[]>([]);
|
const checkedIds = ref<number[]>([]);
|
||||||
|
@ -79,48 +81,24 @@ function handleRowCheckboxChange({
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 推送公告 */
|
/** 推送公告 */
|
||||||
async function onPush(row: SystemNoticeApi.Notice) {
|
async function handlePush(row: SystemNoticeApi.Notice) {
|
||||||
const loadingInstance = ElMessage({
|
const loadingInstance = ElLoading.service({
|
||||||
message: $t('ui.actionMessage.processing', ['推送']),
|
text: '正在推送中...',
|
||||||
type: 'info',
|
|
||||||
duration: 0,
|
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
await pushNotice(row.id as number);
|
await pushNotice(row.id as number);
|
||||||
loadingInstance.close();
|
|
||||||
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
ElMessage.success($t('ui.actionMessage.operationSuccess'));
|
||||||
} finally {
|
} finally {
|
||||||
loadingInstance.close();
|
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({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
schema: useGridFormSchema(),
|
schema: useGridFormSchema(),
|
||||||
},
|
},
|
||||||
gridOptions: {
|
gridOptions: {
|
||||||
columns: useGridColumns(onActionClick),
|
columns: useGridColumns(),
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
keepSource: true,
|
keepSource: true,
|
||||||
proxyConfig: {
|
proxyConfig: {
|
||||||
|
@ -136,6 +114,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
},
|
},
|
||||||
rowConfig: {
|
rowConfig: {
|
||||||
keyField: 'id',
|
keyField: 'id',
|
||||||
|
isHover: true,
|
||||||
},
|
},
|
||||||
toolbarConfig: {
|
toolbarConfig: {
|
||||||
refresh: true,
|
refresh: true,
|
||||||
|
@ -161,20 +140,52 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
icon: ACTION_ICON.ADD,
|
icon: ACTION_ICON.ADD,
|
||||||
auth: ['system:notice:create'],
|
auth: ['system:notice:create'],
|
||||||
onClick: onCreate,
|
onClick: handleCreate,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: $t('ui.actionTitle.deleteBatch'),
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
type: 'danger',
|
type: 'danger',
|
||||||
icon: ACTION_ICON.DELETE,
|
icon: ACTION_ICON.DELETE,
|
||||||
disabled: isEmpty(checkedIds),
|
|
||||||
auth: ['system:notice:delete'],
|
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>
|
</template>
|
||||||
<!-- TODO @霖:【规范讨论】要不要类似 antd 一样,改成 TableAction;可见 /apps/web-ele/src/views/system/notice/index.vue 的 167 到 195 -->
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
},
|
},
|
||||||
"actionMessage": {
|
"actionMessage": {
|
||||||
"deleteConfirm": "Are you sure to delete {0}?",
|
"deleteConfirm": "Are you sure to delete {0}?",
|
||||||
|
"deleteBatchConfirm": "Are you sure to delete selected items?",
|
||||||
"deleting": "Deleting {0} ...",
|
"deleting": "Deleting {0} ...",
|
||||||
|
"deletingBatch": "Deleting selected ...",
|
||||||
"deleteSuccess": "{0} deleted successfully",
|
"deleteSuccess": "{0} deleted successfully",
|
||||||
"deleteFailed": "{0} deleted failed",
|
"deleteFailed": "{0} deleted failed",
|
||||||
"operationSuccess": "Operation succeeded",
|
"operationSuccess": "Operation succeeded",
|
||||||
|
|
|
@ -24,7 +24,9 @@
|
||||||
},
|
},
|
||||||
"actionMessage": {
|
"actionMessage": {
|
||||||
"deleteConfirm": "确定删除 {0} 吗?",
|
"deleteConfirm": "确定删除 {0} 吗?",
|
||||||
|
"deleteBatchConfirm": "确定删除所选项吗?",
|
||||||
"deleting": "正在删除 {0} ...",
|
"deleting": "正在删除 {0} ...",
|
||||||
|
"deletingBatch": "正在删除所选项 ...",
|
||||||
"deleteSuccess": "{0} 删除成功",
|
"deleteSuccess": "{0} 删除成功",
|
||||||
"deleteFailed": "{0} 删除失败",
|
"deleteFailed": "{0} 删除失败",
|
||||||
"operationSuccess": "操作成功",
|
"operationSuccess": "操作成功",
|
||||||
|
|
Loading…
Reference in New Issue