mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:49:20 +08:00
feat(前端): 增加按钮级权限控制
This commit is contained in:
@@ -15,6 +15,11 @@ import {
|
||||
admin_deleteAccountApi,
|
||||
admin_getAccountPageApi,
|
||||
} from '#/api/company/account';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
|
||||
import AccountFormModal from './components/AccountFormModal.vue';
|
||||
|
||||
@@ -51,6 +56,13 @@ const statusOptions = [
|
||||
{ label: '停用', value: 0 },
|
||||
];
|
||||
|
||||
const accountActionCodes = [
|
||||
'org:account:create',
|
||||
'org:account:update',
|
||||
'org:account:delete',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(accountActionCodes);
|
||||
|
||||
// 搜索表单配置
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
@@ -108,9 +120,7 @@ const formOptions = computed(() => ({
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
const accountTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
@@ -163,13 +173,24 @@ const gridOptions: VxeGridProps<any> = {
|
||||
title: '创建时间',
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const accountActionColumn: NonNullable<VxeGridProps<any>['columns']>[number] = {
|
||||
title: '操作',
|
||||
width: 120,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const accountTableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(accountTableBaseColumns ?? []), accountActionColumn]
|
||||
: (accountTableBaseColumns ?? []),
|
||||
);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: accountTableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
@@ -246,6 +267,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
tableTitle: '账户管理',
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
syncVxeGridColumns(gridApi, accountTableColumns);
|
||||
|
||||
// 计算属性
|
||||
const hasSelected = computed(() => {
|
||||
@@ -352,13 +374,17 @@ function handleModalSuccess() {
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加账户
|
||||
</Button>
|
||||
<Button v-if="hasSelected" danger @click="handleBatchDelete">
|
||||
批量删除
|
||||
</Button>
|
||||
<PermissionGate code="org:account:create">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加账户
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:account:delete">
|
||||
<Button v-if="hasSelected" danger @click="handleBatchDelete">
|
||||
批量删除
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
@@ -377,15 +403,19 @@ function handleModalSuccess() {
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }">
|
||||
<template v-if="showActionColumn" #action="{ row }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个账户吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
<PermissionGate code="org:account:update">
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:account:delete">
|
||||
<Popconfirm
|
||||
title="确定要删除这个账户吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user