reactor:【infra 基础设施】config 进一步统一代码风格

pull/210/head
YunaiV 2025-09-09 12:20:48 +08:00
parent 8d10030185
commit 96158f22b9
4 changed files with 73 additions and 81 deletions

View File

@ -126,26 +126,32 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'id', field: 'id',
title: '参数主键', title: '参数主键',
minWidth: 100,
}, },
{ {
field: 'category', field: 'category',
title: '参数分类', title: '参数分类',
minWidth: 120,
}, },
{ {
field: 'name', field: 'name',
title: '参数名称', title: '参数名称',
minWidth: 200,
}, },
{ {
field: 'key', field: 'key',
title: '参数键名', title: '参数键名',
minWidth: 200,
}, },
{ {
field: 'value', field: 'value',
title: '参数键值', title: '参数键值',
minWidth: 150,
}, },
{ {
field: 'visible', field: 'visible',
title: '是否可见', title: '是否可见',
minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING }, props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
@ -154,6 +160,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'type', field: 'type',
title: '系统内置', title: '系统内置',
minWidth: 100,
cellRender: { cellRender: {
name: 'CellDict', name: 'CellDict',
props: { type: DICT_TYPE.INFRA_CONFIG_TYPE }, props: { type: DICT_TYPE.INFRA_CONFIG_TYPE },
@ -162,10 +169,12 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{ {
field: 'remark', field: 'remark',
title: '备注', title: '备注',
minWidth: 150,
}, },
{ {
field: 'createTime', field: 'createTime',
title: '创建时间', title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {

View File

@ -4,7 +4,7 @@ import type { InfraConfigApi } from '#/api/infra/config';
import { ref } from 'vue'; import { ref } from 'vue';
import { Page, useVbenModal } from '@vben/common-ui'; import { confirm, Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@ -52,14 +52,10 @@ async function handleDelete(row: InfraConfigApi.Config) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]), content: $t('ui.actionMessage.deleting', [row.name]),
duration: 0, duration: 0,
key: 'action_key_msg',
}); });
try { try {
await deleteConfig(row.id as number); await deleteConfig(row.id as number);
message.success({ message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh(); onRefresh();
} finally { } finally {
hideLoading(); hideLoading();
@ -68,10 +64,10 @@ async function handleDelete(row: InfraConfigApi.Config) {
/** 批量删除参数 */ /** 批量删除参数 */
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 deleteConfigList(checkedIds.value); await deleteConfigList(checkedIds.value);
@ -135,7 +131,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<TableAction <TableAction
:actions="[ :actions="[
{ {
label: $t('ui.actionTitle.create', ['参数列表']), label: $t('ui.actionTitle.create', ['参数']),
type: 'primary', type: 'primary',
icon: ACTION_ICON.ADD, icon: ACTION_ICON.ADD,
auth: ['infra:config:create'], auth: ['infra:config:create'],
@ -149,11 +145,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
onClick: handleExport, onClick: handleExport,
}, },
{ {
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,
disabled: isEmpty(checkedIds),
auth: ['infra:config:delete'], auth: ['infra:config:delete'],
onClick: handleDeleteBatch, onClick: handleDeleteBatch,
}, },
@ -167,7 +163,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
label: $t('common.edit'), label: $t('common.edit'),
type: 'link', type: 'link',
icon: ACTION_ICON.EDIT, icon: ACTION_ICON.EDIT,
auth: ['system:post:update'], auth: ['infra:config:update'],
onClick: handleEdit.bind(null, row), onClick: handleEdit.bind(null, row),
}, },
{ {
@ -175,7 +171,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'link', type: 'link',
danger: true, danger: true,
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
auth: ['system:post:delete'], auth: ['infra:config:delete'],
popConfirm: { popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]), title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row), confirm: handleDelete.bind(null, row),

View File

@ -1,16 +1,11 @@
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 { InfraConfigApi } from '#/api/infra/config';
import { useAccess } from '@vben/access';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess();
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
@ -125,9 +120,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns<T = InfraConfigApi.Config>( export function useGridColumns(): VxeTableGridOptions['columns'] {
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [ return [
{ type: 'checkbox', width: 40 }, { type: 'checkbox', width: 40 },
{ {
@ -185,29 +178,10 @@ export function useGridColumns<T = InfraConfigApi.Config>(
formatter: 'formatDateTime', formatter: 'formatDateTime',
}, },
{ {
field: 'operation',
title: '操作', title: '操作',
minWidth: 130, width: 160,
align: 'center',
fixed: 'right', fixed: 'right',
cellRender: { slots: { default: 'actions' },
attrs: {
nameField: 'name',
nameTitle: '参数',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'edit',
show: hasAccessByCodes(['infra:config:update']),
},
{
code: 'delete',
show: hasAccessByCodes(['infra:config:delete']),
},
],
},
}, },
]; ];
} }

View File

@ -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 { InfraConfigApi } from '#/api/infra/config'; import type { InfraConfigApi } from '#/api/infra/config';
import { ref } from 'vue'; import { ref } from 'vue';
@ -30,47 +27,54 @@ const [FormModal, formModalApi] = useVbenModal({
}); });
/** 刷新表格 */ /** 刷新表格 */
function onRefresh() { function handleRefresh() {
gridApi.query(); gridApi.query();
} }
/** 导出表格 */ /** 导出表格 */
async function onExport() { async function handleExport() {
const data = await exportConfig(await gridApi.formApi.getValues()); const data = await exportConfig(await gridApi.formApi.getValues());
downloadFileFromBlobPart({ fileName: '参数配置.xls', source: data }); downloadFileFromBlobPart({ fileName: '参数配置.xls', source: data });
} }
/** 创建参数 */ /** 创建参数 */
function onCreate() { function handleCreate() {
formModalApi.setData(null).open(); formModalApi.setData(null).open();
} }
/** 编辑参数 */ /** 编辑参数 */
function onEdit(row: InfraConfigApi.Config) { function handleEdit(row: InfraConfigApi.Config) {
formModalApi.setData(row).open(); formModalApi.setData(row).open();
} }
/** 删除参数 */ /** 删除参数 */
async function onDelete(row: InfraConfigApi.Config) { async function handleDelete(row: InfraConfigApi.Config) {
const loadingInstance = ElLoading.service({ const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.name]), text: $t('ui.actionMessage.deleting', [row.name]),
}); });
try { try {
await deleteConfig(row.id as number); await deleteConfig(row.id as number);
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name])); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
onRefresh(); handleRefresh();
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
} }
/** 批量删除参数 */ /** 批量删除参数 */
async function onDeleteBatch() { async function handleDeleteBatch() {
await confirm('确定要批量删除该参数吗?'); await confirm($t('ui.actionMessage.deleteBatchConfirm'));
await deleteConfigList(checkedIds.value); const loadingInstance = ElLoading.service({
checkedIds.value = []; text: $t('ui.actionMessage.deletingBatch'),
ElMessage.success($t('ui.actionMessage.deleteSuccess')); });
onRefresh(); try {
await deleteConfigList(checkedIds.value);
checkedIds.value = [];
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
loadingInstance.close();
}
} }
const checkedIds = ref<number[]>([]); const checkedIds = ref<number[]>([]);
@ -82,29 +86,12 @@ function handleRowCheckboxChange({
checkedIds.value = records.map((item) => item.id!); checkedIds.value = records.map((item) => item.id!);
} }
/** 表格操作按钮的回调函数 */
function onActionClick({
code,
row,
}: OnActionClickParams<InfraConfigApi.Config>) {
switch (code) {
case 'delete': {
onDelete(row);
break;
}
case 'edit': {
onEdit(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: {
@ -120,6 +107,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,
@ -135,7 +123,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="onRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title=""> <Grid table-title="">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
@ -145,14 +133,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
type: 'primary', type: 'primary',
icon: ACTION_ICON.ADD, icon: ACTION_ICON.ADD,
auth: ['infra:config:create'], auth: ['infra:config:create'],
onClick: onCreate, onClick: handleCreate,
}, },
{ {
label: $t('ui.actionTitle.export'), label: $t('ui.actionTitle.export'),
type: 'primary', type: 'primary',
icon: ACTION_ICON.DOWNLOAD, icon: ACTION_ICON.DOWNLOAD,
auth: ['infra:config:export'], auth: ['infra:config:export'],
onClick: onExport, onClick: handleExport,
}, },
{ {
label: $t('ui.actionTitle.deleteBatch'), label: $t('ui.actionTitle.deleteBatch'),
@ -160,7 +148,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
icon: ACTION_ICON.DELETE, icon: ACTION_ICON.DELETE,
disabled: isEmpty(checkedIds), disabled: isEmpty(checkedIds),
auth: ['infra:config:delete'], auth: ['infra:config:delete'],
onClick: onDeleteBatch, onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: $t('common.edit'),
type: 'primary',
link: true,
icon: ACTION_ICON.EDIT,
auth: ['infra:config:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'danger',
link: true,
icon: ACTION_ICON.DELETE,
auth: ['infra:config:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
}, },
]" ]"
/> />