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

This commit is contained in:
YunaiV
2025-09-06 19:38:48 +08:00
parent 4bdd5552dd
commit c9e782fefe
6 changed files with 154 additions and 102 deletions

View File

@@ -55,3 +55,10 @@ export function updateOAuth2Client(data: SystemOAuth2ClientApi.OAuth2Client) {
export function deleteOAuth2Client(id: number) {
return requestClient.delete(`/system/oauth2-client/delete?id=${id}`);
}
/** 批量删除 OAuth2.0 客户端 */
export function deleteOAuth2ClientList(ids: number[]) {
return requestClient.delete(
`/system/oauth2-client/delete-list?ids=${ids.join(',')}`,
);
}

View File

@@ -109,6 +109,7 @@ export function useFormSchema(): VbenFormSchema[] {
componentProps: {
placeholder: '请输入授权范围',
mode: 'tags',
allowClear: true,
},
},
{
@@ -179,6 +180,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
component: 'Input',
componentProps: {
placeholder: '请输入应用名',
allowClear: true,
},
},
{
@@ -197,21 +199,26 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{ type: 'checkbox', width: 40 },
{
field: 'clientId',
title: '客户端编号',
minWidth: 120,
},
{
field: 'secret',
title: '客户端密钥',
minWidth: 120,
},
{
field: 'name',
title: '应用名',
minWidth: 120,
},
{
field: 'logo',
title: '应用图标',
minWidth: 100,
cellRender: {
name: 'CellImage',
},
@@ -219,6 +226,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'status',
title: '状态',
minWidth: 80,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.COMMON_STATUS },
@@ -227,20 +235,24 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
{
field: 'accessTokenValiditySeconds',
title: '访问令牌的有效期',
minWidth: 150,
formatter: ({ cellValue }) => `${cellValue}`,
},
{
field: 'refreshTokenValiditySeconds',
title: '刷新令牌的有效期',
minWidth: 150,
formatter: ({ cellValue }) => `${cellValue}`,
},
{
field: 'authorizedGrantTypes',
title: '授权类型',
minWidth: 100,
},
{
field: 'createTime',
title: '创建时间',
minWidth: 180,
formatter: 'formatDateTime',
},
{

View File

@@ -2,13 +2,17 @@
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { SystemOAuth2ClientApi } from '#/api/system/oauth2/client';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { ref } from 'vue';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { isEmpty } from '@vben/utils';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteOAuth2Client,
deleteOAuth2ClientList,
getOAuth2ClientPage,
} from '#/api/system/oauth2/client';
import { $t } from '#/locales';
@@ -22,7 +26,7 @@ const [FormModal, formModalApi] = useVbenModal({
});
/** 刷新表格 */
function onRefresh() {
function handleRefresh() {
gridApi.query();
}
@@ -40,20 +44,43 @@ function handleEdit(row: SystemOAuth2ClientApi.OAuth2Client) {
async function handleDelete(row: SystemOAuth2ClientApi.OAuth2Client) {
const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.name]),
key: 'action_key_msg',
duration: 0,
});
try {
await deleteOAuth2Client(row.id as number);
message.success({
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
key: 'action_key_msg',
});
onRefresh();
message.success($t('ui.actionMessage.deleteSuccess', [row.name]));
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 deleteOAuth2ClientList(checkedIds.value);
checkedIds.value = [];
message.success($t('ui.actionMessage.deleteSuccess'));
handleRefresh();
} finally {
hideLoading();
}
}
const checkedIds = ref<number[]>([]);
function handleRowCheckboxChange({
records,
}: {
records: SystemOAuth2ClientApi.OAuth2Client[];
}) {
checkedIds.value = records.map((item) => item.id!);
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
@@ -75,12 +102,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: true,
search: true,
},
} as VxeTableGridOptions<SystemOAuth2ClientApi.OAuth2Client>,
gridEvents: {
checkboxAll: handleRowCheckboxChange,
checkboxChange: handleRowCheckboxChange,
},
});
</script>
@@ -93,7 +125,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
/>
</template>
<FormModal @success="onRefresh" />
<FormModal @success="handleRefresh" />
<Grid table-title="OAuth2 客户端列表">
<template #toolbar-tools>
<TableAction
@@ -105,6 +137,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
auth: ['system:oauth2-client:create'],
onClick: handleCreate,
},
{
label: $t('ui.actionTitle.deleteBatch'),
type: 'primary',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['system:oauth2-client:delete'],
disabled: isEmpty(checkedIds),
onClick: handleDeleteBatch,
},
]"
/>
</template>