mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:09:20 +08:00
feat(前端): 增加按钮级权限控制
This commit is contained in:
@@ -17,6 +17,11 @@ import {
|
||||
} from '#/api/company';
|
||||
import CompanyMenuDrawer from '#/components/CompanyMenuDrawer.vue';
|
||||
import CompanyPermissionDrawer from '#/components/CompanyPermissionDrawer.vue';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
import CompanyLogoAvatar from '#/views/company/components/CompanyLogoAvatar.vue';
|
||||
|
||||
import CompanyFormModal from './components/CompanyFormModal.vue';
|
||||
@@ -46,9 +51,16 @@ const statusOptions = [
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
const companyActionCodes = [
|
||||
'org:company:create',
|
||||
'org:company:update',
|
||||
'org:company:delete',
|
||||
'org:company:menu:assign',
|
||||
'org:company:permission:assign',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(companyActionCodes);
|
||||
|
||||
const companyTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
@@ -108,13 +120,24 @@ const gridOptions: VxeGridProps<any> = {
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const companyActionColumn: NonNullable<VxeGridProps<any>['columns']>[number] = {
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const companyTableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(companyTableBaseColumns ?? []), companyActionColumn]
|
||||
: (companyTableBaseColumns ?? []),
|
||||
);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: companyTableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
@@ -320,6 +343,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
tableTitle: '公司管理',
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
syncVxeGridColumns(gridApi, companyTableColumns);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -335,10 +359,12 @@ gridReloadRef.value = () => gridApi.reload();
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加公司
|
||||
</Button>
|
||||
<PermissionGate code="org:company:create">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加公司
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
@@ -372,26 +398,34 @@ gridReloadRef.value = () => gridApi.reload();
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<template v-if="showActionColumn" #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" type="primary" @click="handleMenuManage(row)">
|
||||
菜单
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
ghost
|
||||
@click="handlePermissionManage(row)"
|
||||
>
|
||||
权限
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个公司吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
<PermissionGate code="org:company:update">
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:company:menu:assign">
|
||||
<Button size="small" type="primary" @click="handleMenuManage(row)">
|
||||
菜单
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:company:permission:assign">
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
ghost
|
||||
@click="handlePermissionManage(row)"
|
||||
>
|
||||
权限
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:company:delete">
|
||||
<Popconfirm
|
||||
title="确定要删除这个公司吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user