feat(常量): 添加超级管理员ID和启用状态常量

在核心常量文件中添加 SUPERADMIN_USER_ID 和 EnableStatus 常量
在用户管理页面中使用新常量替代硬编码值
This commit is contained in:
dap 2026-01-15 09:54:42 +08:00
parent 35c96b3a9e
commit b84eabf1c9
2 changed files with 19 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { computed, ref } from 'vue';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui'; import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
import { EnableStatus, SUPERADMIN_USER_ID } from '@vben/constants';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { preferences } from '@vben/preferences'; import { preferences } from '@vben/preferences';
@ -204,7 +205,7 @@ async function handleChangeStatus(checked: boolean, row: User) {
console.log(checked); console.log(checked);
await userStatusChange({ await userStatusChange({
userId: row.userId, userId: row.userId,
status: checked ? '0' : '1', status: checked ? EnableStatus.Enable : EnableStatus.Disable,
}); });
} }
</script> </script>
@ -258,16 +259,17 @@ async function handleChangeStatus(checked: boolean, row: User) {
<template #status="{ row }"> <template #status="{ row }">
<!-- value只能接收boolean值 --> <!-- value只能接收boolean值 -->
<ApiSwitch <ApiSwitch
:value="row.status === '0'" :value="row.status === EnableStatus.Enable"
:api="(checked) => handleChangeStatus(checked, row)" :api="(checked) => handleChangeStatus(checked, row)"
:disabled=" :disabled="
row.userId === 1 || !hasAccessByCodes(['system:user:edit']) row.userId === SUPERADMIN_USER_ID ||
!hasAccessByCodes(['system:user:edit'])
" "
@reload="() => tableApi.query()" @reload="() => tableApi.query()"
/> />
</template> </template>
<template #action="{ row }"> <template #action="{ row }">
<template v-if="row.userId !== 1"> <template v-if="row.userId !== SUPERADMIN_USER_ID">
<Space> <Space>
<ghost-button <ghost-button
v-access:code="['system:user:edit']" v-access:code="['system:user:edit']"

View File

@ -36,3 +36,16 @@ export const BUSINESS_SUCCESS_CODE = 200;
* () * ()
*/ */
export const UNAUTHORIZED_CODE = 401; export const UNAUTHORIZED_CODE = 401;
/**
* ID
*/
export const SUPERADMIN_USER_ID = 1;
/**
* -S系统开关的状态
*/
export const EnableStatus = {
Enable: '0',
Disable: '1',
};