1.优化运维管理中渠道列表选择渠道的筛选错误问题

2.优化渠道运维管理目录菜单权限
This commit is contained in:
2026-05-19 15:31:04 +08:00
parent 5628af683f
commit 37c0035bfc
9 changed files with 115 additions and 8 deletions

View File

@@ -25,8 +25,8 @@
</div>
<div class="flex flex-col flex-grow min-w-0 min-h-0">
<div v-if="selectedDeptLabel" class="channel-banner mb-3 text-sm text-g-500">
{{ bannerLabel }}<b>{{ selectedDeptLabel }}</b>
<div v-if="selectedDisplayLabel" class="channel-banner mb-3 text-sm text-g-500">
{{ bannerLabel }}<b>{{ selectedDisplayLabel }}</b>
</div>
<div class="flex flex-col flex-1 min-h-0 min-w-0">
<slot />
@@ -66,10 +66,10 @@
treeData,
selectedDeptId,
loadingChannels,
selectedDeptLabel,
handleChannelClick,
provideScope,
isConfigScope,
isAllChannelScope,
showDefaultTemplate
} = useChannelDeptScope()
@@ -82,11 +82,17 @@
const defaultLabel = isRoleChannelRoute(route)
? t('common.channelScope.defaultRoleTemplate')
: t('common.channelScope.defaultTemplate')
const emptyNodeLabel = isAllChannelScope.value ? t('common.channelScope.allChannels') : defaultLabel
return nodes.map((node) =>
node.id === DEFAULT_CHANNEL_ID && !node.label ? { ...node, label: defaultLabel } : node
node.id === DEFAULT_CHANNEL_ID && !node.label ? { ...node, label: emptyNodeLabel } : node
)
})
const selectedDisplayLabel = computed(() => {
const item = displayTreeData.value.find((node) => node.id === selectedDeptId.value)
return item?.label ?? ''
})
const bannerLabel = computed(() => {
if (isConfigScope.value) {
return t('common.channelScope.currentConfig')

View File

@@ -1,8 +1,15 @@
import type { InjectionKey, Ref, ComputedRef } from 'vue'
import { useRoute } from 'vue-router'
import deptApi from '@/api/system/dept'
import { router } from '@/router'
import { useUserStore } from '@/store/modules/user'
import { isConfigChannelRoute, isRoleChannelRoute, isSuperAdminUser } from '@/utils/channelLayout'
import {
isAllChannelScopeRoute,
isConfigChannelRoute,
isNoChannelLayoutRoute,
isRoleChannelRoute,
isSuperAdminUser
} from '@/utils/channelLayout'
export interface ChannelTreeNode {
id: number
@@ -21,6 +28,7 @@ export interface ChannelDeptScopeContext {
selectedDeptLabel: Ref<string>
deptQueryParams: ComputedRef<{ dept_id: number }>
isConfigScope: ComputedRef<boolean>
isAllChannelScope: ComputedRef<boolean>
showDefaultTemplate: ComputedRef<boolean>
}
@@ -68,6 +76,7 @@ export function useChannelDeptScope() {
const isConfigScope = computed(() => isConfigChannelRoute(route))
const isRoleScope = computed(() => isRoleChannelRoute(route))
const isAllChannelScope = computed(() => isAllChannelScopeRoute(route))
const showDefaultTemplate = computed(() => isConfigScope.value || isRoleScope.value)
const isSuperAdmin = computed(() => isSuperAdminUser())
@@ -90,6 +99,9 @@ export function useChannelDeptScope() {
const deptQueryParams = computed(() => {
const id = selectedDeptId.value
if (isAllChannelScope.value && id <= 0) {
return { dept_id: 0 }
}
if (!showDefaultTemplate.value && id <= 0) {
return { dept_id: 0 }
}
@@ -106,7 +118,7 @@ export function useChannelDeptScope() {
label: String(item.label ?? item.name ?? item.id)
}))
if (isSuperAdmin.value) {
if (showDefaultTemplate.value) {
if (showDefaultTemplate.value || isAllChannelScope.value) {
treeData.value = [{ id: DEFAULT_CHANNEL_ID, label: '' }, ...nodes]
if (!treeData.value.some((n) => n.id === selectedDeptId.value)) {
selectedDeptId.value = DEFAULT_CHANNEL_ID
@@ -143,6 +155,7 @@ export function useChannelDeptScope() {
selectedDeptLabel,
deptQueryParams,
isConfigScope,
isAllChannelScope,
showDefaultTemplate
}
@@ -170,6 +183,11 @@ export function bindChannelDeptToSearchParams(
}
const apply = (deptId: number) => {
if (channel.isAllChannelScope.value && deptId <= 0) {
delete searchParams.dept_id
refresh()
return
}
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
@@ -197,6 +215,10 @@ export function useChannelDeptReload(loadFn: () => void | Promise<void>) {
watch(
() => channel.selectedDeptId.value,
(deptId) => {
if (channel.isAllChannelScope.value && deptId <= 0) {
void loadFn()
return
}
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return
}
@@ -209,8 +231,15 @@ export function useChannelDeptReload(loadFn: () => void | Promise<void>) {
/** 请求参数:业务页附带 dept_id渠道管理员固定本渠道 */
export function getChannelDeptRequestParams(): { dept_id?: number } {
const channel = useInjectedChannelDept()
const route = getCurrentInstance() ? useRoute() : router.currentRoute.value
if (isNoChannelLayoutRoute(route)) {
return {}
}
if (channel?.isSuperAdmin.value) {
const deptId = channel.selectedDeptId.value
if (channel.isAllChannelScope.value && deptId <= 0) {
return {}
}
if (!channel.showDefaultTemplate.value && deptId <= 0) {
return {}
}

View File

@@ -42,6 +42,7 @@
"listTitle": "Channels",
"defaultTemplate": "Default template",
"defaultRoleTemplate": "Default role template",
"allChannels": "All",
"currentConfig": "Current config",
"currentChannel": "Current channel",
"currentRole": "Current roles"

View File

@@ -42,6 +42,7 @@
"listTitle": "渠道列表",
"defaultTemplate": "默认配置模板",
"defaultRoleTemplate": "默认角色模板",
"allChannels": "全部",
"currentConfig": "当前配置",
"currentChannel": "当前渠道",
"currentRole": "当前角色范围"

View File

@@ -7,6 +7,22 @@ const BUILTIN_CHANNEL_LAYOUT_PATHS = [
'/system/dept'
]
/** 运维页里不需要按渠道分栏的页面 */
const NO_CHANNEL_LAYOUT_PATHS = [
'/safeguard/dict',
'/safeguard/attachment',
'/safeguard/database',
'/safeguard/server',
'/safeguard/cache',
'/safeguard/email-log'
]
/** 日志页左侧首项为「全部」dept_id=0 表示不按渠道过滤 */
const ALL_CHANNEL_SCOPE_PATHS = [
'/safeguard/login-log',
'/safeguard/oper-log'
]
export function isSuperAdminUser(): boolean {
const userStore = useUserStore()
return Number(userStore.info?.id ?? 0) === 1
@@ -28,6 +44,20 @@ export function isRoleChannelRoute(route: Pick<RouteLocationNormalized, 'path' |
return route.path.startsWith('/system/role')
}
export function isAllChannelScopeRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.channelScope === 'all') {
return true
}
return ALL_CHANNEL_SCOPE_PATHS.some((item) => route.path.startsWith(item))
}
export function isNoChannelLayoutRoute(route: Pick<RouteLocationNormalized, 'path' | 'meta'>): boolean {
if (route.meta?.noChannelLayout === true) {
return true
}
return NO_CHANNEL_LAYOUT_PATHS.some((item) => route.path.startsWith(item))
}
export function shouldWrapSuperAdminChannelLayout(route: RouteLocationNormalized): boolean {
if (!isSuperAdminUser()) {
return false
@@ -35,10 +65,10 @@ export function shouldWrapSuperAdminChannelLayout(route: RouteLocationNormalized
if (route.meta?.isFullPage) {
return false
}
if (route.meta?.noChannelLayout === true) {
const path = route.path
if (isNoChannelLayoutRoute(route)) {
return false
}
const path = route.path
for (let i = 0; i < BUILTIN_CHANNEL_LAYOUT_PATHS.length; i++) {
if (path.startsWith(BUILTIN_CHANNEL_LAYOUT_PATHS[i])) {
return false