mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 12:29:19 +08:00
feat: 按钮级权限复用 /auth/codes,新增 PermissionGate/v-permission 与操作列无权限整列隐藏
This commit is contained in:
@@ -9,7 +9,7 @@ import { useAccessStore, useUserStore } from '@vben/stores';
|
||||
|
||||
import { message, Radio, Spin } from 'ant-design-vue';
|
||||
|
||||
import { getAccessCodesApi, switchCompanyApi } from '#/api/core/auth';
|
||||
import { switchCompanyApi } from '#/api/core/auth';
|
||||
import { getAvailableCompaniesApi } from '#/api/sys/user';
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
@@ -78,13 +78,7 @@ async function handleSwitchCompany() {
|
||||
result.refreshTokenExpiresAt,
|
||||
);
|
||||
|
||||
try {
|
||||
const accessCodes = await getAccessCodesApi();
|
||||
accessStore.setAccessCodes(accessCodes);
|
||||
} catch (error) {
|
||||
console.warn('获取用户权限码失败:', error);
|
||||
accessStore.setAccessCodes([]);
|
||||
}
|
||||
await authStore.fetchAccessCodes();
|
||||
|
||||
await authStore.fetchUserInfo();
|
||||
accessStore.setIsAccessChecked(false);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PermissionMatchMode } from '#/utils/permission-match';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
defineOptions({ name: 'PermissionGate' });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 本操作所需权限码(与接口 @RequirePermission 相同;与用户 accessCodes 比对) */
|
||||
code: string | string[];
|
||||
/** disable 时无权限提示 */
|
||||
disabledTip?: string;
|
||||
match?: PermissionMatchMode;
|
||||
/** hide:无权限不渲染;disable:保留占位并阻断点击 */
|
||||
mode?: 'disable' | 'hide';
|
||||
}>(),
|
||||
{
|
||||
disabledTip: '无操作权限',
|
||||
match: 'any',
|
||||
mode: 'hide',
|
||||
},
|
||||
);
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
|
||||
const allowed = computed(() => hasPermission(props.code, props.match));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-if="allowed">
|
||||
<slot />
|
||||
</template>
|
||||
<template v-else-if="mode === 'disable'">
|
||||
<Tooltip :title="disabledTip">
|
||||
<span
|
||||
class="inline-flex cursor-not-allowed opacity-50 [&_*]:pointer-events-none"
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
</Tooltip>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as PermissionGate } from './PermissionGate.vue';
|
||||
Reference in New Issue
Block a user