reactor:【system 系统管理】oauth2/token 进一步统一代码风格

This commit is contained in:
YunaiV
2025-09-06 19:47:13 +08:00
parent c9e782fefe
commit 1d11ebad3a
4 changed files with 148 additions and 61 deletions

View File

@@ -13,6 +13,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Input',
componentProps: {
placeholder: '请输入用户编号',
allowClear: true,
},
},
{
@@ -22,6 +23,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
componentProps: {
options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
placeholder: '请选择用户类型',
allowClear: true,
},
},
{
@@ -30,6 +32,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Input',
componentProps: {
placeholder: '请输入客户端编号',
allowClear: true,
},
},
];
@@ -42,18 +45,22 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'accessToken',
title: '访问令牌',
minWidth: 300,
},
{
field: 'refreshToken',
title: '刷新令牌',
minWidth: 300,
},
{
field: 'userId',
title: '用户编号',
minWidth: 100,
},
{
field: 'userType',
title: '用户类型',
minWidth: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.USER_TYPE },
@@ -62,15 +69,18 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'clientId',
title: '客户端编号',
minWidth: 120,
},
{
field: 'expiresTime',
title: '过期时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@@ -2,7 +2,10 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemOAuth2TokenApi } from '#/api/system/oauth2/token';
import { DocAlert, Page } from '@vben/common-ui';
import { ref } from 'vue';
import { confirm, DocAlert, Page } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
@@ -16,7 +19,7 @@ import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -24,20 +27,43 @@ function onRefresh() {
async function handleDelete(row: SystemOAuth2TokenApi.OAuth2Token) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', ['令牌']),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteOAuth2Token(row.accessToken);
message.success({
content: $t('ui.actionMessage.deleteSuccess', ['令牌']),
key: 'action_key_msg',
});
onRefresh();
message.success($t('ui.actionMessage.deleteSuccess', ['令牌']));
handleRefresh();
} finally {
hideLoading();
}
}
/** 批量删除 OAuth2 令牌 */
async function handleDeleteBatch() {
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
const hideLoading = message.loading({
content: $t('ui.actionMessage.deletingBatch'),
duration: 0,
});
try {
await deleteOAuth2Token(checkedIds.value.join(','));
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<string[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemOAuth2TokenApi.OAuth2Token[];
}) {
checkedIds.value = records.map((item) => item.accessToken);
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -58,13 +84,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
},
rowConfig: {
keyField: 'id',
keyField: 'accessToken',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<SystemOAuth2TokenApi.OAuth2Token>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@@ -78,17 +109,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
</template>
<Grid table-title="令牌列表">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['system:oauth2-token:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '强退',
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['system:oauth2-token:delete'],
popConfirm: {
title: `确定要强退令牌吗?`,
title: $t('ui.actionMessage.deleteConfirm', ['令牌']),
confirm: handleDelete.bind(null, row),
},
},