mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:09:19 +08:00
feat(前端): 增加按钮级权限控制
This commit is contained in:
@@ -15,6 +15,11 @@ import {
|
||||
deletePositionApi,
|
||||
getPositionPageApi,
|
||||
} from '#/api/org/position';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import {
|
||||
syncVxeGridColumns,
|
||||
useActionColumnVisible,
|
||||
} from '#/composables/use-vxe-action-column';
|
||||
|
||||
import PositionModal from './components/PositionModal.vue';
|
||||
|
||||
@@ -47,9 +52,14 @@ const departmentOptions = ref([
|
||||
{ label: '市场部', value: 4 },
|
||||
]);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
const positionActionCodes = [
|
||||
'org:position:create',
|
||||
'org:position:update',
|
||||
'org:position:delete',
|
||||
];
|
||||
const showActionColumn = useActionColumnVisible(positionActionCodes);
|
||||
|
||||
const positionTableBaseColumns: VxeGridProps<any>['columns'] = [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
@@ -87,13 +97,25 @@ const gridOptions: VxeGridProps<any> = {
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const positionActionColumn: NonNullable<VxeGridProps<any>['columns']>[number] =
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
};
|
||||
|
||||
const positionTableColumns = computed(() =>
|
||||
showActionColumn.value
|
||||
? [...(positionTableBaseColumns ?? []), positionActionColumn]
|
||||
: (positionTableBaseColumns ?? []),
|
||||
);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: positionTableColumns.value,
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
@@ -231,6 +253,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
showSearchForm: true,
|
||||
tableTitle: '职位管理',
|
||||
});
|
||||
syncVxeGridColumns(gridApi, positionTableColumns);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -246,10 +269,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加职位
|
||||
</Button>
|
||||
<PermissionGate code="org:position:create">
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加职位
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
@@ -272,15 +297,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<template v-if="showActionColumn" #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个职位吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
<PermissionGate code="org:position:update">
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="org:position:delete">
|
||||
<Popconfirm
|
||||
title="确定要删除这个职位吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
@@ -27,6 +27,8 @@ import {
|
||||
batchUpdatePositionMenusApi,
|
||||
getPositionMenuIdsApi,
|
||||
} from '#/api/org/position/menu';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
defineOptions({
|
||||
name: 'PositionMenuManagePage',
|
||||
@@ -34,6 +36,9 @@ defineOptions({
|
||||
|
||||
const BriefcaseIcon = createIconifyIcon('lucide:briefcase');
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
const canAssignMenu = computed(() => hasPermission('org:position:menu:assign'));
|
||||
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
@@ -306,23 +311,25 @@ onMounted(() => {
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button :disabled="!currentPosition" @click="handleSelectNone">
|
||||
取消全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition"
|
||||
@click="handleSelectAll"
|
||||
>
|
||||
一键全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition || !stats.changed"
|
||||
@click="savePositionPermissions"
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
<PermissionGate code="org:position:menu:assign">
|
||||
<Button :disabled="!currentPosition" @click="handleSelectNone">
|
||||
取消全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition"
|
||||
@click="handleSelectAll"
|
||||
>
|
||||
一键全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition || !stats.changed"
|
||||
@click="savePositionPermissions"
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
@@ -511,7 +518,7 @@ onMounted(() => {
|
||||
v-model:checked-keys="checkedKeys"
|
||||
v-model:expanded-keys="expandedKeys"
|
||||
:tree-data="menuTreeData"
|
||||
checkable
|
||||
:checkable="canAssignMenu"
|
||||
block-node
|
||||
:selectable="false"
|
||||
@check="handleTreeCheckChange"
|
||||
|
||||
@@ -27,11 +27,18 @@ import {
|
||||
getPositionAssignablePermissionTreeApi,
|
||||
getPositionPermissionIdsApi,
|
||||
} from '#/api/org/position/permission';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import { usePermission } from '#/composables/use-permission';
|
||||
|
||||
defineOptions({ name: 'PositionPermissionManagePage' });
|
||||
|
||||
const BriefcaseIcon = createIconifyIcon('lucide:briefcase');
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
const canAssignPermission = computed(() =>
|
||||
hasPermission('org:position:permission:assign'),
|
||||
);
|
||||
|
||||
type PermissionTreeNode = {
|
||||
key: number;
|
||||
title: string;
|
||||
@@ -260,17 +267,19 @@ onMounted(() => {
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button :disabled="!currentPosition" @click="selectNone">取消全选</Button>
|
||||
<Button type="primary" :disabled="!currentPosition" @click="selectAll">
|
||||
一键全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition || !stats.changed"
|
||||
@click="handleSave"
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
<PermissionGate code="org:position:permission:assign">
|
||||
<Button :disabled="!currentPosition" @click="selectNone">取消全选</Button>
|
||||
<Button type="primary" :disabled="!currentPosition" @click="selectAll">
|
||||
一键全选
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="!currentPosition || !stats.changed"
|
||||
@click="handleSave"
|
||||
>
|
||||
保存配置
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
@@ -450,7 +459,7 @@ onMounted(() => {
|
||||
v-model:checked-keys="selectedPermissionIds"
|
||||
v-model:expanded-keys="expandedKeys"
|
||||
:tree-data="permissionTreeData"
|
||||
checkable
|
||||
:checkable="canAssignPermission"
|
||||
block-node
|
||||
:selectable="false"
|
||||
@check="handleTreeCheckChange"
|
||||
|
||||
Reference in New Issue
Block a user