1.将部门修改为渠道,并且所有dice_表关联渠道表
2.将所有配置表,记录表设置关联渠道 3.优化后台页面设置
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
<template>
|
||||
<div class="art-full-height">
|
||||
<div class="box-border flex gap-4 h-full max-md:block max-md:gap-0 max-md:h-auto">
|
||||
<div class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5">
|
||||
<ElCard class="tree-card art-card-xs flex flex-col h-full mt-0" shadow="never">
|
||||
<div
|
||||
v-show="showChannelSidebar"
|
||||
class="flex-shrink-0 w-64 h-full max-md:w-full max-md:h-auto max-md:mb-5"
|
||||
>
|
||||
<ElCard
|
||||
class="tree-card art-card-xs flex flex-col h-full mt-0"
|
||||
shadow="never"
|
||||
v-loading="channelTreeLoading"
|
||||
>
|
||||
<template #header>
|
||||
<b>部门列表</b>
|
||||
<b>{{ $t('page.ui.channelList') }}</b>
|
||||
</template>
|
||||
<ElScrollbar>
|
||||
<ElTree
|
||||
:data="treeData"
|
||||
:props="{ children: 'children', label: 'label' }"
|
||||
node-key="id"
|
||||
:current-node-key="currentChannelId"
|
||||
default-expand-all
|
||||
highlight-current
|
||||
@node-click="handleNodeClick"
|
||||
@@ -136,10 +144,19 @@
|
||||
import WorkDialog from './modules/work-dialog.vue'
|
||||
import api from '@/api/system/user'
|
||||
import deptApi from '@/api/system/dept'
|
||||
import { isSuperAdminUser } from '@/utils/channelLayout'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const treeData = ref([])
|
||||
interface ChannelTreeNode {
|
||||
id: number
|
||||
label: string
|
||||
children?: ChannelTreeNode[]
|
||||
}
|
||||
|
||||
const treeData = ref<ChannelTreeNode[]>([])
|
||||
const channelTreeLoading = ref(false)
|
||||
const currentChannelId = ref<number | undefined>(undefined)
|
||||
|
||||
// 编辑框
|
||||
const { dialogType, dialogVisible, dialogData, showDialog, handleSelectionChange, deleteRow } =
|
||||
@@ -228,24 +245,79 @@
|
||||
const handleReset = () => {
|
||||
searchForm.value.dept_id = undefined
|
||||
resetSearchParams()
|
||||
if (isSuperAdminUser()) {
|
||||
currentChannelId.value = undefined
|
||||
} else {
|
||||
applyDefaultChannelSelection()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换部门
|
||||
* @param data
|
||||
*/
|
||||
const handleNodeClick = (data: any) => {
|
||||
const handleNodeClick = (data: ChannelTreeNode) => {
|
||||
currentChannelId.value = data.id
|
||||
searchParams.dept_id = data.id
|
||||
getData()
|
||||
}
|
||||
|
||||
/** 仅超管显示左侧渠道列表;渠道管理员固定本渠道,由后端过滤 */
|
||||
const showChannelSidebar = computed(() => isSuperAdminUser())
|
||||
|
||||
const normalizeChannelTree = (list: unknown[]): ChannelTreeNode[] => {
|
||||
if (!Array.isArray(list)) {
|
||||
return []
|
||||
}
|
||||
return list
|
||||
.map((item) => {
|
||||
const row = item as Record<string, unknown>
|
||||
const id = Number(row.id ?? row.value ?? 0)
|
||||
const label = String(row.label ?? row.name ?? '')
|
||||
return { id, label }
|
||||
})
|
||||
.filter((node) => node.id > 0 && node.label !== '')
|
||||
}
|
||||
|
||||
const fallbackChannelTree = (): ChannelTreeNode[] => {
|
||||
const dept = userStore.info?.department
|
||||
if (!dept || Number(dept.id) <= 0) {
|
||||
return []
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: Number(dept.id),
|
||||
label: String(dept.name ?? '')
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const applyDefaultChannelSelection = () => {
|
||||
if (treeData.value.length === 0 || isSuperAdminUser()) {
|
||||
return
|
||||
}
|
||||
const first = treeData.value[0]
|
||||
currentChannelId.value = first.id
|
||||
searchParams.dept_id = first.id
|
||||
getData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门数据
|
||||
* 获取可操作渠道(渠道管理员至少展示本渠道)
|
||||
*/
|
||||
const getDeptList = () => {
|
||||
deptApi.accessDept().then((data: any) => {
|
||||
treeData.value = data
|
||||
})
|
||||
const getDeptList = async () => {
|
||||
channelTreeLoading.value = true
|
||||
try {
|
||||
const data = await deptApi.accessDept()
|
||||
const nodes = normalizeChannelTree(Array.isArray(data) ? data : [])
|
||||
treeData.value = nodes.length > 0 ? nodes : fallbackChannelTree()
|
||||
applyDefaultChannelSelection()
|
||||
} catch {
|
||||
treeData.value = fallbackChannelTree()
|
||||
applyDefaultChannelSelection()
|
||||
} finally {
|
||||
channelTreeLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,6 +355,10 @@
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDeptList()
|
||||
if (isSuperAdminUser()) {
|
||||
getDeptList()
|
||||
} else {
|
||||
applyDefaultChannelSelection()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user