feat(客户端管理): 优化客户端管理界面功能

- 添加默认客户端ID常量
- 重构密钥输入组件使用SpaceCompact布局
- 替换TableSwitch为ApiSwitch并优化状态切换逻辑
This commit is contained in:
dap 2026-01-16 09:36:49 +08:00
parent 29e0d0437e
commit e5bbaf5f9a
3 changed files with 34 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import type { Client } from '#/api/system/client/model';
import { useAccess } from '@vben/access';
import { Page, useVbenDrawer } from '@vben/common-ui';
import { DEFAULT_CLIENT_ID, EnableStatus } from '@vben/constants';
import { Modal, Popconfirm, Space } from 'antdv-next';
@ -16,7 +17,7 @@ import {
clientList,
clientRemove,
} from '#/api/system/client';
import { TableSwitch } from '#/components/table';
import { ApiSwitch } from '#/components/global';
import { commonDownloadExcel } from '#/utils/file/download';
import clientDrawer from './client-drawer.vue';
@ -108,6 +109,12 @@ function handleDownloadExcel() {
}
const { hasAccessByCodes } = useAccess();
async function handleChangeStatus(checked: boolean, row: Client) {
await clientChangeStatus({
clientId: row.id,
status: checked ? EnableStatus.Enable : EnableStatus.Disable,
});
}
</script>
<template>
@ -142,10 +149,13 @@ const { hasAccessByCodes } = useAccess();
<template #status="{ row }">
<!-- pc不允许禁用 禁用了直接登录不了 应该设置disabled -->
<!-- 登录提示: 认证权限类型已禁用 -->
<TableSwitch
v-model:value="row.status"
:api="() => clientChangeStatus(row)"
:disabled="row.id === 1 || !hasAccessByCodes(['system:client:edit'])"
<ApiSwitch
:value="row.status === EnableStatus.Enable"
:api="(checked) => handleChangeStatus(checked, row)"
:disabled="
row.id === DEFAULT_CLIENT_ID ||
!hasAccessByCodes(['system:client:edit'])
"
@reload="tableApi.query()"
/>
</template>

View File

@ -2,7 +2,7 @@
import { IconifyIcon } from '@vben/icons';
import { buildUUID } from '@vben/utils';
import { Input } from 'antdv-next';
import { Input, SpaceCompact } from 'antdv-next';
defineOptions({ name: 'SecretInput' });
@ -27,16 +27,19 @@ defineExpose({ refreshSecret });
</script>
<template>
<Input v-model:value="value" :disabled="disabled" :placeholder="placeholder">
<template v-if="!disabled" #addonAfter>
<a-button type="primary" @click="refreshSecret">
<div class="flex items-center gap-[4px]">
<IconifyIcon icon="charm:refresh" />
<span>随机生成</span>
</div>
</a-button>
</template>
</Input>
<SpaceCompact>
<Input
v-model:value="value"
:disabled="disabled"
:placeholder="placeholder"
/>
<a-button v-if="!disabled" type="primary" @click="refreshSecret">
<div class="flex items-center gap-[4px]">
<IconifyIcon icon="charm:refresh" />
<span>随机生成</span>
</div>
</a-button>
</SpaceCompact>
</template>
<style lang="scss" scoped>

View File

@ -52,6 +52,11 @@ export const SUPERADMIN_ROLE_KEY = 'superadmin';
*/
export const ADMIN_ROLE_KEY = 'admin';
/**
* ID
*/
export const DEFAULT_CLIENT_ID = 1;
/**
* -S系统开关的状态
*/