mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 17:09:19 +08:00
feat(前端): 增加按钮级权限控制
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { MenuVO } from '#/api/sys/menu/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
getCompanyMenuIdsApi,
|
||||
} from '#/api/company/menu';
|
||||
import { getAllMenusApi } from '#/api/sys/menu';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
interface Props {
|
||||
company?: any;
|
||||
@@ -29,6 +31,9 @@ defineOptions({
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
const canAssignMenu = computed(() => hasPermission('org:company:menu:assign'));
|
||||
|
||||
// 系统菜单列表数据
|
||||
const systemMenuList = ref<MenuVO.MenuInfo[]>([]);
|
||||
|
||||
@@ -78,6 +83,14 @@ const [MainDrawer, mainDrawerApi] = useVbenDrawer({
|
||||
},
|
||||
});
|
||||
|
||||
watch(
|
||||
canAssignMenu,
|
||||
(allowed: boolean) => {
|
||||
mainDrawerApi.setState({ showConfirmButton: allowed });
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 将菜单列表转换为树形结构
|
||||
const menuTreeData = computed(() => {
|
||||
const menuMap = new Map<number, any>();
|
||||
@@ -408,8 +421,10 @@ defineExpose({
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
<Button type="primary" @click="handleSelectAll"> 一键全选 </Button>
|
||||
<Button @click="handleSelectNone"> 取消全选 </Button>
|
||||
<PermissionGate code="org:company:menu:assign">
|
||||
<Button type="primary" @click="handleSelectAll"> 一键全选 </Button>
|
||||
<Button @click="handleSelectNone"> 取消全选 </Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -421,7 +436,7 @@ defineExpose({
|
||||
v-model:checked-keys="checkedKeys"
|
||||
v-model:expanded-keys="expandedKeys"
|
||||
:tree-data="menuTreeData"
|
||||
checkable
|
||||
:checkable="canAssignMenu"
|
||||
class="menu-tree"
|
||||
@check="handleTreeCheckChange"
|
||||
>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
getCompanyPermissionIdsApi,
|
||||
} from '#/api/company/permission/apis';
|
||||
import { getAllPermissionsApi } from '#/api/sys/permission';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
interface Props {
|
||||
company?: any;
|
||||
@@ -33,6 +35,11 @@ defineOptions({
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
const canAssignPermission = computed(() =>
|
||||
hasPermission('org:company:permission:assign'),
|
||||
);
|
||||
|
||||
// 所有权限列表
|
||||
const allPermissions = ref<any[]>([]);
|
||||
|
||||
@@ -70,6 +77,14 @@ const [MainDrawer, mainDrawerApi] = useVbenDrawer({
|
||||
},
|
||||
});
|
||||
|
||||
watch(
|
||||
canAssignPermission,
|
||||
(allowed) => {
|
||||
mainDrawerApi.setState({ showConfirmButton: allowed });
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 按类型分组权限
|
||||
const groupedPermissions = computed(() => {
|
||||
const groups: Record<string, any[]> = {};
|
||||
@@ -210,8 +225,10 @@ defineExpose({
|
||||
</div>
|
||||
</div>
|
||||
<div class="stats-right">
|
||||
<Button @click="selectNone">取消全选</Button>
|
||||
<Button type="primary" @click="selectAll">一键全选</Button>
|
||||
<PermissionGate code="org:company:permission:assign">
|
||||
<Button @click="selectNone">取消全选</Button>
|
||||
<Button type="primary" @click="selectAll">一键全选</Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -237,6 +254,7 @@ defineExpose({
|
||||
>
|
||||
<Checkbox
|
||||
:checked="selectedPermissionIds.includes(perm.id)"
|
||||
:disabled="!canAssignPermission"
|
||||
@change="
|
||||
(e: any) => togglePermission(perm.id, e.target.checked)
|
||||
"
|
||||
|
||||
Reference in New Issue
Block a user