fix: 管理员用户页按权限隐藏跨俱乐部操作

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-06 18:23:29 +08:00
parent 9b11749903
commit 1a5c8aab88

View File

@@ -53,7 +53,7 @@
<el-table-column prop="phone" label="账号" width="140" />
<el-table-column prop="yonghuid" label="用户ID" width="100" />
<el-table-column prop="nicheng" label="昵称" width="150" />
<el-table-column label="俱乐部任职" min-width="200">
<el-table-column v-if="canManageClubAssignments" label="俱乐部任职" min-width="200">
<template #default="{ row }">
<el-tag
v-for="a in row.assignments || []"
@@ -70,14 +70,14 @@
<el-table-column label="角色" min-width="200">
<template #default="{ row }">
<el-tag
v-for="role in (row.roles || [])"
v-for="role in visibleRolesForRow(row)"
:key="`${role.club_id || ''}-${role.role_code}`"
size="small"
style="margin-right: 6px;"
>
{{ roleClubLabel(role) }}
</el-tag>
<span v-if="!(row.roles || []).length">无角色</span>
<span v-if="!visibleRolesForRow(row).length">无角色</span>
</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="100">
@@ -161,23 +161,14 @@
</el-form>
</div>
<!-- 俱乐部任职 -->
<div class="club-section">
<!-- 俱乐部任职仅集团高层可见 -->
<div v-if="canManageClubAssignments" class="club-section">
<div class="section-title">
<span>俱乐部任职顶栏切换范围</span>
<el-button v-if="canManageClubAssignments" type="primary" size="small" @click="openAddClubDialog">
<span>俱乐部任职</span>
<el-button type="primary" size="small" @click="openAddClubDialog">
<el-icon><Plus /></el-icon> 添加俱乐部
</el-button>
</div>
<el-alert
v-if="!canManageClubAssignments"
type="warning"
:closable="false"
show-icon
title="分配/移除俱乐部仅集团高层可操作"
description="俱乐部负责人000001只能在本俱乐部内绑定功能角色不能跨俱乐部分配任职。"
class="scope-hint"
/>
<div class="club-assign-list">
<div
v-for="a in currentUserAssignments"
@@ -187,37 +178,37 @@
<el-tag :type="a.is_primary ? 'success' : 'info'" size="small">
{{ a.club_label }}{{ a.is_primary ? '(主任职)' : '' }}
</el-tag>
<span class="assign-role-label">任职{{ a.role_name }}</span>
<el-button
v-if="canManageClubAssignments"
type="danger"
link
size="small"
@click="removeClubAssignment(a)"
>移除</el-button>
<span class="assign-role-label">{{ a.role_name }}</span>
<el-button type="danger" link size="small" @click="removeClubAssignment(a)">移除</el-button>
</div>
<div v-if="currentUserAssignments.length === 0" class="empty-role">
暂未分配俱乐部需集团高层添加后用户顶栏才可切换
<div v-if="currentUserAssignments.length === 0" class="empty-role inline-empty">
暂未分配俱乐部
</div>
</div>
</div>
<!-- 各俱乐部功能角色 -->
<div class="role-section">
<!-- 功能角色仅展示/操作有权管理的俱乐部 -->
<div v-if="visibleClubRoleBlocks.length" class="role-section">
<div class="section-title">
<span>各俱乐部功能角色</span>
<span>功能角色</span>
</div>
<div
v-for="block in clubRoleBlocks"
v-for="block in visibleClubRoleBlocks"
:key="block.club_id || '__global__'"
class="club-role-block"
>
<div class="club-block-header">
<div>
<strong class="club-block-title">{{ block.club_label }}</strong>
<span class="club-block-meta">已绑 {{ block.roles.length }} · 可选 {{ block.catalogRoles.length }} </span>
<span class="club-block-meta">已绑 {{ block.roles.length }} </span>
</div>
<el-button type="primary" size="small" link @click="openAddRoleForClub(block.club_id)">
<el-button
v-if="canManageRolesForClub(block.club_id)"
type="primary"
size="small"
link
@click="openAddRoleForClub(block.club_id)"
>
+ 添加角色
</el-button>
</div>
@@ -228,19 +219,20 @@
class="role-tag"
>
{{ role.role_name || role.role_code }}
<el-icon class="remove-icon" @click="removeUserRole(role)">
<el-icon
v-if="canManageRolesForClub(block.club_id)"
class="remove-icon"
@click="removeUserRole(role)"
>
<Close />
</el-icon>
</div>
</div>
<div v-else class="empty-role inline-empty">该俱乐部暂无功能角色</div>
<div v-if="block.catalogRoles.length" class="catalog-hint">
选角色{{ block.catalogRoles.map(r => r.role_name).join('、') }}
<div v-else class="empty-role inline-empty">暂无功能角色</div>
<div v-if="block.catalogRoles.length && canManageRolesForClub(block.club_id)" class="catalog-hint">
分配{{ block.catalogRoles.map(r => r.role_name).join('、') }}
</div>
</div>
<div v-if="!clubRoleBlocks.length" class="empty-role">
请由集团高层先分配俱乐部任职再点击各俱乐部添加角色绑定菜单权限
</div>
</div>
</div>
@@ -407,9 +399,22 @@ const roleClubLabel = (role) => {
return `[${cname}] ${role.role_name || role.role_code || ''}`
}
const canManageRolesForClub = (clubId) => {
const cid = clubId || ''
if (canManageClubAssignments.value) return true
return manageableClubIds.value.includes(cid)
}
const visibleRolesForRow = (row) => {
const roles = row.roles || []
if (canManageClubAssignments.value) return roles
return roles.filter((r) => manageableClubIds.value.includes(r.club_id || ''))
}
// 权限状态
const hasPermission = ref(true)
const canManageClubAssignments = ref(false)
const manageableClubIds = ref([])
// 角色列表(用于筛选和添加)
const roleList = ref([])
@@ -474,14 +479,14 @@ const availableRolesForUser = computed(() => {
})
const roleBindClubOptions = computed(() => {
const fromAssign = (currentUserAssignments.value || [])
.filter((a) => a.club_id)
const source = (currentUserAssignments.value || [])
.filter((a) => a.club_id && canManageRolesForClub(a.club_id))
.map((a) => ({
club_id: a.club_id,
name: a.club_label || clubNameMap.value[a.club_id] || a.club_id,
}))
if (fromAssign.length) return fromAssign
return clubOptions.value
if (source.length) return source
return clubOptions.value.filter((c) => canManageRolesForClub(c.club_id))
})
const clubRoleBlocks = computed(() => {
@@ -520,6 +525,13 @@ const clubRoleBlocks = computed(() => {
return blocks
})
const visibleClubRoleBlocks = computed(() => {
if (canManageClubAssignments.value) {
return clubRoleBlocks.value
}
return clubRoleBlocks.value.filter((b) => canManageRolesForClub(b.club_id))
})
// 添加用户弹窗
const addUserDialogVisible = ref(false)
const newUserForm = ref({
@@ -532,13 +544,13 @@ const newUserRoleCodes = ref([])
const addingUser = ref(false)
// ==================== 接口调用 ====================
// 获取角色列表(全部俱乐部,用于分俱乐部绑角色
// 获取角色列表(集团高层拉全部俱乐部超管仅本俱乐部
const fetchRoleList = async () => {
try {
let res = await request.post('/houtai/hqyhjsgl', { username, all_clubs: true })
if (res.code !== 0) {
res = await request.post('/houtai/hqyhjsgl', { username })
}
const res = await request.post('/houtai/hqyhjsgl', {
username,
all_clubs: canManageClubAssignments.value,
})
if (res.code === 0) {
roleList.value = res.data.roles || []
return true
@@ -591,6 +603,7 @@ const fetchUserList = async () => {
userList.value = res.data.list || []
total.value = res.data.total || 0
canManageClubAssignments.value = !!res.data.can_manage_club_assignments
manageableClubIds.value = res.data.manageable_club_ids || []
} else {
ElMessage.error(res.msg || '获取用户列表失败')
}
@@ -846,10 +859,8 @@ onMounted(async () => {
return
}
await loadClubOptions()
const success = await fetchRoleList()
if (success) {
await fetchUserList()
}
await fetchUserList()
await fetchRoleList()
})
</script>