fix 修复面包树错误,部门树

This commit is contained in:
yxh 2024-09-13 17:01:05 +08:00
parent 4cab8e452e
commit c905456c10
3 changed files with 48 additions and 17 deletions

View File

@ -8,7 +8,7 @@
/>
<el-breadcrumb class="layout-navbars-breadcrumb-hide">
<transition-group name="breadcrumb">
<el-breadcrumb-item v-for="(v, k) in breadcrumbList" :key="!v.meta.tagsViewName ? v.meta.title : v.meta.tagsViewName">
<el-breadcrumb-item v-for="(v, k) in breadcrumbList" :key="v.path">
<span v-if="k === breadcrumbList.length - 1" class="layout-navbars-breadcrumb-span">
<SvgIcon :name="v.meta.icon" class="layout-navbars-breadcrumb-iconfont" v-if="themeConfig.isBreadcrumbIcon" />
<div v-if="!v.meta.tagsViewName">{{ $t(v.meta.title) }}</div>
@ -24,10 +24,9 @@
</template>
<script setup lang="ts">
import { toRefs, reactive, computed, onMounted, defineComponent } from 'vue';
import { toRefs, reactive, computed, onMounted } from 'vue';
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router';
import { Local } from '/@/utils/storage';
import other from '/@/utils/other';
import { storeToRefs } from 'pinia';
import { useThemeConfig } from '/@/stores/themeConfig';
import { useRoutesList } from '/@/stores/routesList';
@ -78,17 +77,49 @@ const setLocalThemeConfig = () => {
};
//
const getBreadcrumbList = (arr: Array<string>) => {
arr.forEach((item: any) => {
state.routeSplit.forEach((v: any, k: number, arrs: any) => {
if (state.routeSplitFirst === item.path) {
state.routeSplitFirst += `/${arrs[state.routeSplitIndex]}`;
state.breadcrumbList.push(item);
state.routeSplitIndex++;
if (item.children) getBreadcrumbList(item.children);
let parents :any[] = []
arr.map((item:any)=>{
parents.push(...getBreadcrumbParent(item,route.path,null))
if(parents.length>0){
return
}
})
parents.push(route)
parents = uniqueByPath(parents)
state.breadcrumbList = parents
};
const getBreadcrumbParent = (item:any,path:string,parent:any)=>{
const parents:any[] = []
if(item.path==path){
if(parent){
parents.push(parent)
}
return parents
}
if(item.children){
for(let i=0;i<item.children.length;i++){
const res = getBreadcrumbParent(item.children[i],path,item)
if(res && res.length>0){
parents.push(item,...res)
return parents
}
}
}
return parents
}
const uniqueByPath = (arr:any[]) => {
let seen:any = {}; // name
let result:any[] = []; //
arr.forEach(item => {
if (!seen[item.path]) { // name
seen[item.path] = true; //
result.push(item); //
}
});
});
};
return result;
}
//
const initRouteSplit = (path: string) => {
if (!themeConfig.value.isBreadcrumb) return false;
@ -98,8 +129,8 @@ const initRouteSplit = (path: string) => {
state.routeSplitFirst = `/${state.routeSplit[0]}`;
state.routeSplitIndex = 1;
getBreadcrumbList(routesList.value);
if (route.name === 'home' || (route.name === 'notFound' && state.breadcrumbList.length > 1)) state.breadcrumbList.shift();
if (state.breadcrumbList.length > 0) state.breadcrumbList[state.breadcrumbList.length - 1].meta.tagsViewName = other.setTagsViewNameI18n(route);
//if (route.name === 'home' || (route.name === 'notFound' && state.breadcrumbList.length > 1)) state.breadcrumbList.shift();
//if (state.breadcrumbList.length > 0) state.breadcrumbList[state.breadcrumbList.length - 1].meta.tagsViewName = other.setTagsViewNameI18n(route);
};
//
onMounted(() => {

View File

@ -131,7 +131,7 @@ const { isShowDialog, ruleForm, deptData,rules } = toRefs(state);
const openDialog = (row?: RuleFormState|number) => {
resetForm()
getDeptList().then((res:any)=>{
state.deptData = proxy.handleTree(res.data.deptList??[], "deptId","parentId");
state.deptData = proxy.handleTree(res.data.deptList??[], "deptId","parentId",'children',true);
});
if(row && typeof row === "object"){
state.ruleForm = row;

View File

@ -108,7 +108,7 @@ const initTableData = () => {
};
const deptList = ()=>{
getDeptList(state.tableData.param).then((res:any)=>{
state.tableData.data = proxy.handleTree(res.data.deptList??[], "deptId","parentId");
state.tableData.data = proxy.handleTree(res.data.deptList??[], "deptId","parentId",'children',true);
});
};
//