diff --git a/ecom-dmb-frontend/apps/web-antd/src/bootstrap.ts b/ecom-dmb-frontend/apps/web-antd/src/bootstrap.ts
index ec721125..c68c5498 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/bootstrap.ts
+++ b/ecom-dmb-frontend/apps/web-antd/src/bootstrap.ts
@@ -9,6 +9,7 @@ import '@vben/styles/antd';
import { useTitle } from '@vueuse/core';
+import { registerPermissionDirective } from '#/directives/permission';
import { $t, setupI18n } from '#/locales';
import { initComponentAdapter } from './adapter/component';
@@ -46,8 +47,9 @@ async function bootstrap(namespace: string) {
// 配置 pinia-tore
await initStores(app, { namespace });
- // 安装权限指令
+ // 安装权限指令(业务页请用 v-permission / PermissionGate,与后端 API 码一致)
registerAccessDirective(app);
+ registerPermissionDirective(app);
// 初始化 tippy
const { initTippy } = await import('@vben/common-ui/es/tippy');
diff --git a/ecom-dmb-frontend/apps/web-antd/src/components/SwitchCompanyModal.vue b/ecom-dmb-frontend/apps/web-antd/src/components/SwitchCompanyModal.vue
index 70449b30..cc0b67ea 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/components/SwitchCompanyModal.vue
+++ b/ecom-dmb-frontend/apps/web-antd/src/components/SwitchCompanyModal.vue
@@ -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);
diff --git a/ecom-dmb-frontend/apps/web-antd/src/components/permission/PermissionGate.vue b/ecom-dmb-frontend/apps/web-antd/src/components/permission/PermissionGate.vue
new file mode 100644
index 00000000..22e0613d
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/components/permission/PermissionGate.vue
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ecom-dmb-frontend/apps/web-antd/src/components/permission/index.ts b/ecom-dmb-frontend/apps/web-antd/src/components/permission/index.ts
new file mode 100644
index 00000000..da3d49f0
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/components/permission/index.ts
@@ -0,0 +1 @@
+export { default as PermissionGate } from './PermissionGate.vue';
diff --git a/ecom-dmb-frontend/apps/web-antd/src/composables/use-permission.ts b/ecom-dmb-frontend/apps/web-antd/src/composables/use-permission.ts
new file mode 100644
index 00000000..2e0b3ea4
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/composables/use-permission.ts
@@ -0,0 +1,42 @@
+import type { PermissionMatchMode } from '#/utils/permission-match';
+
+import { computed } from 'vue';
+
+import { useAccessStore } from '@vben/stores';
+
+import { matchPermissions } from '#/utils/permission-match';
+
+/**
+ * 按钮级权限:用户码来自 GET /auth/codes(accessStore.accessCodes);
+ * 组件/指令传入的 code 为当前操作对应的后端 @RequirePermission 值。
+ */
+export function usePermission() {
+ const accessStore = useAccessStore();
+
+ const accessCodes = computed(() => accessStore.accessCodes ?? []);
+
+ function hasPermission(
+ code: string | string[],
+ mode: PermissionMatchMode = 'any',
+ ): boolean {
+ if (accessStore.isSuper) {
+ return true;
+ }
+ return matchPermissions(accessCodes.value, code, mode);
+ }
+
+ function hasSomePermission(codes: string[]): boolean {
+ return hasPermission(codes, 'any');
+ }
+
+ function hasEveryPermission(codes: string[]): boolean {
+ return hasPermission(codes, 'all');
+ }
+
+ return {
+ accessCodes,
+ hasEveryPermission,
+ hasPermission,
+ hasSomePermission,
+ };
+}
diff --git a/ecom-dmb-frontend/apps/web-antd/src/composables/use-vxe-action-column.ts b/ecom-dmb-frontend/apps/web-antd/src/composables/use-vxe-action-column.ts
new file mode 100644
index 00000000..7d70834a
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/composables/use-vxe-action-column.ts
@@ -0,0 +1,29 @@
+import type { ComputedRef } from 'vue';
+
+import { computed, watch } from 'vue';
+
+import { usePermission } from '#/composables/use-permission';
+
+/** 是否拥有操作列内任一按钮权限 */
+export function useActionColumnVisible(actionCodes: string[]) {
+ const { hasPermission } = usePermission();
+ return computed(() => hasPermission(actionCodes, 'any'));
+}
+
+interface GridColumnsApi {
+ setGridOptions: (options: Record) => void;
+}
+
+/** 权限变化时同步 VXE 列配置(无操作权限时去掉整列) */
+export function syncVxeGridColumns(
+ gridApi: GridColumnsApi,
+ columns: ComputedRef,
+) {
+ watch(
+ columns,
+ (cols) => {
+ gridApi.setGridOptions({ columns: cols });
+ },
+ { immediate: true },
+ );
+}
diff --git a/ecom-dmb-frontend/apps/web-antd/src/directives/permission.ts b/ecom-dmb-frontend/apps/web-antd/src/directives/permission.ts
new file mode 100644
index 00000000..ece98742
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/directives/permission.ts
@@ -0,0 +1,37 @@
+import type { App, Directive, DirectiveBinding } from 'vue';
+
+import { useAccessStore } from '@vben/stores';
+
+import { matchPermissions } from '#/utils/permission-match';
+
+function resolveAllowed(value: string | string[] | undefined): boolean {
+ if (!value) {
+ return true;
+ }
+ const accessStore = useAccessStore();
+ if (accessStore.isSuper) {
+ return true;
+ }
+ const codes = accessStore.accessCodes ?? [];
+ const required = Array.isArray(value) ? value : [value];
+ return matchPermissions(codes, required, 'any');
+}
+
+function applyPermission(
+ el: Element,
+ binding: DirectiveBinding,
+) {
+ if (resolveAllowed(binding.value)) {
+ return;
+ }
+ el.remove();
+}
+
+/** 无权限时移除 DOM,用法:v-permission="'sys:menu:create'" */
+export function registerPermissionDirective(app: App) {
+ const directive: Directive = {
+ mounted: applyPermission,
+ updated: applyPermission,
+ };
+ app.directive('permission', directive);
+}
diff --git a/ecom-dmb-frontend/apps/web-antd/src/router/guard.ts b/ecom-dmb-frontend/apps/web-antd/src/router/guard.ts
index e9a3c57b..bde896dd 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/router/guard.ts
+++ b/ecom-dmb-frontend/apps/web-antd/src/router/guard.ts
@@ -91,10 +91,12 @@ function setupAccessGuard(router: Router) {
}
// 生成路由表
- // 当前登录用户拥有的角色标识列表
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
const userRoles = userInfo.roles ?? [];
+ // 权限码(刷新页面时与菜单一并重拉,避免仅用 localStorage 旧数据)
+ await authStore.fetchAccessCodes();
+
// 系统配置(刷新页面后补拉)
try {
const { useAppConfigStore } = await import('#/store/app-config');
diff --git a/ecom-dmb-frontend/apps/web-antd/src/store/auth.ts b/ecom-dmb-frontend/apps/web-antd/src/store/auth.ts
index 951d2a8b..c391fed5 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/store/auth.ts
+++ b/ecom-dmb-frontend/apps/web-antd/src/store/auth.ts
@@ -73,14 +73,8 @@ export const useAuthStore = defineStore('auth', () => {
console.warn('获取系统配置失败:', error);
}
- // 获取用户权限码(可选,如果接口不存在则跳过)
- try {
- const accessCodes = await getAccessCodesApi();
- accessStore.setAccessCodes(accessCodes);
- } catch (error) {
- console.warn('获取用户权限码失败,使用默认权限:', error);
- accessStore.setAccessCodes([]);
- }
+ // 用户权限码
+ await fetchAccessCodes();
if (accessStore.loginExpired) {
accessStore.setLoginExpired(false);
@@ -154,14 +148,8 @@ export const useAuthStore = defineStore('auth', () => {
console.warn('获取系统配置失败:', error);
}
- // 获取用户权限码(可选,如果接口不存在则跳过)
- try {
- const accessCodes = await getAccessCodesApi();
- accessStore.setAccessCodes(accessCodes);
- } catch (error) {
- console.warn('获取用户权限码失败,使用默认权限:', error);
- accessStore.setAccessCodes([]);
- }
+ // 用户权限码
+ await fetchAccessCodes();
if (accessStore.loginExpired) {
accessStore.setLoginExpired(false);
@@ -227,6 +215,19 @@ export const useAuthStore = defineStore('auth', () => {
return userInfo;
}
+ /** 拉取并写入当前用户 API 权限码(GET /auth/codes) */
+ async function fetchAccessCodes() {
+ try {
+ const accessCodes = await getAccessCodesApi();
+ accessStore.setAccessCodes(accessCodes);
+ return accessCodes;
+ } catch (error) {
+ console.warn('获取用户权限码失败:', error);
+ accessStore.setAccessCodes([]);
+ return [];
+ }
+ }
+
function $reset() {
loginLoading.value = false;
}
@@ -235,6 +236,7 @@ export const useAuthStore = defineStore('auth', () => {
$reset,
authLogin,
authRegister,
+ fetchAccessCodes,
fetchUserInfo,
loginLoading,
logout,
diff --git a/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.test.ts b/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.test.ts
new file mode 100644
index 00000000..4d1920fe
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ codeCoversRequired,
+ matchPermission,
+ matchPermissions,
+} from './permission-match';
+
+describe('permission-match', () => {
+ it('通配符放行', () => {
+ expect(matchPermission(['*'], 'sys:menu:create')).toBe(true);
+ expect(matchPermission(['company:*'], 'org:company:read')).toBe(true);
+ });
+
+ it('精确匹配与父码前缀', () => {
+ const codes = ['sys:menu', 'sys:user:read'];
+ expect(matchPermission(codes, 'sys:menu:read')).toBe(true);
+ expect(matchPermission(codes, 'sys:menu:create')).toBe(true);
+ expect(matchPermission(codes, 'sys:user:read')).toBe(true);
+ expect(matchPermission(codes, 'sys:user:update')).toBe(false);
+ });
+
+ it('codeCoversRequired 边界', () => {
+ expect(codeCoversRequired('sys', 'sys:menu')).toBe(true);
+ expect(codeCoversRequired('sys:menu', 'sys:menu')).toBe(true);
+ expect(codeCoversRequired('sys:menu', 'sys:menux')).toBe(false);
+ });
+
+ it('多码 any/all', () => {
+ const codes = ['sys:a:read'];
+ expect(
+ matchPermissions(codes, ['sys:a:read', 'sys:b:read'], 'any'),
+ ).toBe(true);
+ expect(
+ matchPermissions(codes, ['sys:a:read', 'sys:b:read'], 'all'),
+ ).toBe(false);
+ });
+});
diff --git a/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.ts b/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.ts
new file mode 100644
index 00000000..70165e65
--- /dev/null
+++ b/ecom-dmb-frontend/apps/web-antd/src/utils/permission-match.ts
@@ -0,0 +1,53 @@
+/** 与 GET /auth/codes 返回的全局通配一致 */
+export const PERMISSION_WILDCARD_ALL = '*';
+export const PERMISSION_WILDCARD_COMPANY = 'company:*';
+
+export type PermissionMatchMode = 'all' | 'any';
+
+/** 用户持有的权限码是否覆盖所需码(精确或父码前缀,对齐后端岗位/公司继承语义) */
+export function codeCoversRequired(userCode: string, required: string): boolean {
+ if (userCode === required) {
+ return true;
+ }
+ return required.startsWith(`${userCode}:`);
+}
+
+export function isWildcardAll(userCodes: readonly string[]): boolean {
+ return userCodes.includes(PERMISSION_WILDCARD_ALL);
+}
+
+export function isWildcardCompany(userCodes: readonly string[]): boolean {
+ return userCodes.includes(PERMISSION_WILDCARD_COMPANY);
+}
+
+/** 单个 API 权限码是否满足 */
+export function matchPermission(
+ userCodes: readonly string[],
+ required: string,
+): boolean {
+ if (!required) {
+ return false;
+ }
+ if (isWildcardAll(userCodes) || isWildcardCompany(userCodes)) {
+ return true;
+ }
+ return userCodes.some((code) => codeCoversRequired(code, required));
+}
+
+/** 多码匹配:any=任一,all=全部 */
+export function matchPermissions(
+ userCodes: readonly string[],
+ required: string | string[],
+ mode: PermissionMatchMode = 'any',
+): boolean {
+ const list = (Array.isArray(required) ? required : [required]).filter(
+ Boolean,
+ );
+ if (list.length === 0) {
+ return false;
+ }
+ if (mode === 'all') {
+ return list.every((code) => matchPermission(userCodes, code));
+ }
+ return list.some((code) => matchPermission(userCodes, code));
+}
diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/sys/menu/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/sys/menu/index.vue
index 1ce23b87..174ed0f5 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/views/sys/menu/index.vue
+++ b/ecom-dmb-frontend/apps/web-antd/src/views/sys/menu/index.vue
@@ -2,7 +2,7 @@
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { MenuDTO, MenuVO } from '#/api/sys/menu/types';
-import { ref } from 'vue';
+import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon, IconifyIcon } from '@vben/icons';
@@ -15,10 +15,17 @@ import {
deleteMenuApi,
getAllMenusApi,
} from '#/api/sys/menu';
+import type { VxeRowContextMenuItem } from '#/components/vxe-row-context-menu/types';
import {
useVxeRowContextMenu,
VxeRowContextMenu,
} from '#/components/vxe-row-context-menu';
+import { PermissionGate } from '#/components/permission';
+import { usePermission } from '#/composables/use-permission';
+import {
+ syncVxeGridColumns,
+ useActionColumnVisible,
+} from '#/composables/use-vxe-action-column';
import MenuFormModal from './components/MenuFormModal.vue';
@@ -31,6 +38,15 @@ const PlusCircleIcon = createIconifyIcon('lucide:plus-circle');
const ExpandIcon = createIconifyIcon('lucide:chevrons-down');
const CollapseIcon = createIconifyIcon('lucide:chevrons-up');
+const { hasPermission } = usePermission();
+
+const menuActionCodes = [
+ 'sys:menu:create',
+ 'sys:menu:update',
+ 'sys:menu:delete',
+];
+const showActionColumn = useActionColumnVisible(menuActionCodes);
+
// 响应式数据
const loading = ref(false);
const menuFormModalRef = ref();
@@ -50,82 +66,90 @@ function sameMenuParent(a: unknown, b: unknown) {
return normalizeMenuParentId(a) === normalizeMenuParentId(b);
}
+const menuTableBaseColumns: VxeGridProps['columns'] = [
+ {
+ type: 'seq' as const,
+ minWidth: 60,
+ title: '序号',
+ },
+ {
+ field: 'name',
+ title: '菜单名称',
+ minWidth: 200,
+ showOverflow: 'tooltip' as const,
+ treeNode: true,
+ dragSort: true,
+ },
+ {
+ field: 'routeName',
+ title: '路由名称',
+ minWidth: 140,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ field: 'title',
+ title: '菜单标题',
+ minWidth: 150,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ field: 'icon',
+ title: '图标',
+ width: 72,
+ align: 'center' as const,
+ slots: { default: 'icon' },
+ },
+ {
+ field: 'path',
+ title: '路由路径',
+ minWidth: 200,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ field: 'component',
+ title: '页面组件',
+ minWidth: 180,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ title: '权限列表',
+ minWidth: 200,
+ slots: { default: 'permissions' },
+ },
+ {
+ title: '类型',
+ minWidth: 100,
+ slots: { default: 'menuType' },
+ },
+ {
+ title: '状态',
+ minWidth: 100,
+ slots: { default: 'menuStatus' },
+ },
+ {
+ field: 'createTime',
+ title: '创建时间',
+ minWidth: 160,
+ },
+];
+
+const menuActionColumn: NonNullable['columns']>[number] = {
+ title: '操作',
+ minWidth: 280,
+ fixed: 'right' as const,
+ showOverflow: false,
+ slots: { default: 'action' },
+};
+
+const menuTableColumns = computed(() =>
+ showActionColumn.value
+ ? [...(menuTableBaseColumns ?? []), menuActionColumn]
+ : (menuTableBaseColumns ?? []),
+);
+
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps = {
- columns: [
- {
- type: 'seq' as const,
- minWidth: 60,
- title: '序号',
- },
- {
- field: 'name',
- title: '菜单名称',
- minWidth: 200,
- showOverflow: 'tooltip' as const,
- treeNode: true, // 启用树节点显示
- dragSort: true, // 启用拖拽排序
- // 移除自定义插槽,让拖拽控件正常显示
- },
- {
- field: 'routeName',
- title: '路由名称',
- minWidth: 140,
- showOverflow: 'tooltip' as const,
- },
- {
- field: 'title',
- title: '菜单标题',
- minWidth: 150,
- showOverflow: 'tooltip' as const,
- },
- {
- field: 'icon',
- title: '图标',
- width: 72,
- align: 'center' as const,
- slots: { default: 'icon' },
- },
- {
- field: 'path',
- title: '路由路径',
- minWidth: 200,
- showOverflow: 'tooltip' as const,
- },
- {
- field: 'component',
- title: '页面组件',
- minWidth: 180,
- showOverflow: 'tooltip' as const,
- },
- {
- title: '权限列表',
- minWidth: 200,
- slots: { default: 'permissions' },
- },
- {
- title: '类型',
- minWidth: 100,
- slots: { default: 'menuType' },
- },
- {
- title: '状态',
- minWidth: 100,
- slots: { default: 'menuStatus' },
- },
- {
- field: 'createTime',
- title: '创建时间',
- minWidth: 160,
- },
- {
- title: '操作',
- minWidth: 280,
- fixed: 'right' as const,
- showOverflow: false,
- slots: { default: 'action' },
- },
- ],
+ columns: menuTableColumns.value,
height: 'auto',
border: true,
stripe: true,
@@ -274,24 +298,32 @@ const {
row: ctxMenuRow,
items: ctxMenuItems,
onCellMenu,
-} = useVxeRowContextMenu((_row) => [
- {
- key: 'addChild',
- label: '新增',
- icon: PlusCircleIcon,
- },
- {
- key: 'edit',
- label: '编辑',
- icon: EditIcon,
- },
- {
- key: 'delete',
- label: '删除',
- icon: TrashIcon,
- danger: true,
- },
-]);
+} = useVxeRowContextMenu(() => {
+ const items: VxeRowContextMenuItem[] = [];
+ if (hasPermission('sys:menu:create')) {
+ items.push({
+ key: 'addChild',
+ label: '新增',
+ icon: PlusCircleIcon,
+ });
+ }
+ if (hasPermission('sys:menu:update')) {
+ items.push({
+ key: 'edit',
+ label: '编辑',
+ icon: EditIcon,
+ });
+ }
+ if (hasPermission('sys:menu:delete')) {
+ items.push({
+ key: 'delete',
+ label: '删除',
+ icon: TrashIcon,
+ danger: true,
+ });
+ }
+ return items;
+});
function handleCtxMenuSelect(key: string) {
const row = ctxMenuRow.value;
@@ -429,6 +461,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
cellMenu: onCellMenu,
} as any,
});
+
+syncVxeGridColumns(gridApi, menuTableColumns);
@@ -438,10 +472,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
-
+
+
+
-
+
-
-
-
-
+
+
+
+
+ 编辑
+
+
+
+
+
+
+ 删除
+
+
+
diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/sys/permission/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/sys/permission/index.vue
index c9f14bc3..24368254 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/views/sys/permission/index.vue
+++ b/ecom-dmb-frontend/apps/web-antd/src/views/sys/permission/index.vue
@@ -2,7 +2,7 @@
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PermissionVO } from '#/api/sys/permission';
-import { nextTick, ref } from 'vue';
+import { computed, nextTick, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
@@ -15,10 +15,17 @@ import {
deletePermissionApi,
getSystemPermissionTreeApi,
} from '#/api/sys/permission';
+import type { VxeRowContextMenuItem } from '#/components/vxe-row-context-menu/types';
import {
useVxeRowContextMenu,
VxeRowContextMenu,
} from '#/components/vxe-row-context-menu';
+import { PermissionGate } from '#/components/permission';
+import { usePermission } from '#/composables/use-permission';
+import {
+ syncVxeGridColumns,
+ useActionColumnVisible,
+} from '#/composables/use-vxe-action-column';
import PermissionFormModal from './components/PermissionFormModal.vue';
@@ -31,6 +38,15 @@ const TrashIcon = createIconifyIcon('lucide:trash-2');
const UnfoldIcon = createIconifyIcon('lucide:unfold-vertical');
const FoldIcon = createIconifyIcon('lucide:fold-vertical');
+const { hasPermission } = usePermission();
+
+const permissionActionCodes = [
+ 'sys:permission:create',
+ 'sys:permission:update',
+ 'sys:permission:delete',
+];
+const showActionColumn = useActionColumnVisible(permissionActionCodes);
+
const loading = ref(false);
const permissionFormModalRef = ref();
@@ -47,62 +63,72 @@ function flattenTree(
return result;
}
+const permissionTableBaseColumns: VxeGridProps['columns'] = [
+ {
+ type: 'seq' as const,
+ minWidth: 60,
+ title: '序号',
+ },
+ {
+ field: 'name',
+ title: '权限名称',
+ minWidth: 200,
+ showOverflow: 'tooltip' as const,
+ treeNode: true,
+ dragSort: true,
+ },
+ {
+ field: 'code',
+ title: '权限码',
+ minWidth: 200,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ field: 'type',
+ title: '权限类型',
+ minWidth: 120,
+ slots: { default: 'type' },
+ },
+ {
+ field: 'sortOrder',
+ title: '排序',
+ minWidth: 80,
+ },
+ {
+ field: 'status',
+ title: '状态',
+ minWidth: 80,
+ slots: { default: 'status' },
+ },
+ {
+ field: 'remark',
+ title: '备注',
+ minWidth: 200,
+ showOverflow: 'tooltip' as const,
+ },
+ {
+ field: 'createTime',
+ title: '创建时间',
+ minWidth: 160,
+ },
+];
+
+const permissionActionColumn: NonNullable['columns']>[number] =
+ {
+ title: '操作',
+ minWidth: 260,
+ fixed: 'right' as const,
+ slots: { default: 'action' },
+ };
+
+const permissionTableColumns = computed(() =>
+ showActionColumn.value
+ ? [...(permissionTableBaseColumns ?? []), permissionActionColumn]
+ : (permissionTableBaseColumns ?? []),
+);
+
const gridOptions: VxeGridProps = {
- columns: [
- {
- type: 'seq' as const,
- minWidth: 60,
- title: '序号',
- },
- {
- field: 'name',
- title: '权限名称',
- minWidth: 200,
- showOverflow: 'tooltip' as const,
- treeNode: true,
- dragSort: true,
- },
- {
- field: 'code',
- title: '权限码',
- minWidth: 200,
- showOverflow: 'tooltip' as const,
- },
- {
- field: 'type',
- title: '权限类型',
- minWidth: 120,
- slots: { default: 'type' },
- },
- {
- field: 'sortOrder',
- title: '排序',
- minWidth: 80,
- },
- {
- field: 'status',
- title: '状态',
- minWidth: 80,
- slots: { default: 'status' },
- },
- {
- field: 'remark',
- title: '备注',
- minWidth: 200,
- showOverflow: 'tooltip' as const,
- },
- {
- field: 'createTime',
- title: '创建时间',
- minWidth: 160,
- },
- {
- title: '操作',
- minWidth: 260,
- fixed: 'right' as const,
- slots: { default: 'action' },
- },
- ],
+ columns: permissionTableColumns.value,
height: 'auto',
border: true,
stripe: true,
@@ -308,24 +334,32 @@ const {
row: ctxMenuRow,
items: ctxMenuItems,
onCellMenu,
-} = useVxeRowContextMenu(() => [
- {
- key: 'addChild',
- label: '增加下级',
- icon: PlusCircleIcon,
- },
- {
- key: 'edit',
- label: '编辑',
- icon: EditIcon,
- },
- {
- key: 'delete',
- label: '删除',
- icon: TrashIcon,
- danger: true,
- },
-]);
+} = useVxeRowContextMenu(() => {
+ const items: VxeRowContextMenuItem[] = [];
+ if (hasPermission('sys:permission:create')) {
+ items.push({
+ key: 'addChild',
+ label: '增加下级',
+ icon: PlusCircleIcon,
+ });
+ }
+ if (hasPermission('sys:permission:update')) {
+ items.push({
+ key: 'edit',
+ label: '编辑',
+ icon: EditIcon,
+ });
+ }
+ if (hasPermission('sys:permission:delete')) {
+ items.push({
+ key: 'delete',
+ label: '删除',
+ icon: TrashIcon,
+ danger: true,
+ });
+ }
+ return items;
+});
function handleCtxMenuSelect(key: string) {
const row = ctxMenuRow.value;
@@ -355,6 +389,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
} as any,
});
+syncVxeGridColumns(gridApi, permissionTableColumns);
+
async function handleModalSuccess(payload?: { parentId?: null | number }) {
const extra =
payload?.parentId != null ? [payload.parentId] : ([] as number[]);
@@ -387,10 +423,12 @@ const getTypeColor = (type: string) => {
-
-
- 添加权限
-
+
+
+
+ 添加权限
+
+
全部展开
@@ -414,25 +452,31 @@ const getTypeColor = (type: string) => {
-
+
-
-
- 增加下级
-
-
-
- 编辑
-
-
-
-
- 删除
+
+
+
+ 增加下级
-
+
+
+
+
+ 编辑
+
+
+
+
+
+
+ 删除
+
+
+