Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

react
我设置的路由配置

import asyncComponent from './asyncComponent'
import { Console } from 'lwp-mini-tools'
const InstallationOfSP = asyncComponent(() => import('../view/InstallationOfSP/index'))
const ComponyMessage = asyncComponent(() => import('../view/InstallationOfSP/ComponyMessage'))
const EmptyRoute = asyncComponent(() => import('./EmptyRoute'))
const ProductManager = asyncComponent(() => import('../view/productManager/index.jsx'))
const ProductList = asyncComponent(() => import('../view/productManager/ProductList.jsx'))
const OrderList =asyncComponent(()=>import('../view/productManager/OrderList'))
const OrderAnalyze=asyncComponent(()=>import('../view/productManager/OrderAnalyze'))
const ProductPublish = asyncComponent(() => import('../view/productManager/ProductPublish.jsx'))
const ProductAnalyze =asyncComponent(()=>import('../view/productManager/ProductAnalyze.jsx'))
const ProductHistory = asyncComponent(() => import('../view/productManager/ProductHistory.jsx'))
const ClassifyManager = asyncComponent(() => import('../view/productManager/ClassifyManager.jsx'))
const ProductBlackList = asyncComponent(()=>import('../view/productManager/ProductBlackList'))
const ProviderAuthentication = asyncComponent(() => import('../view/ProviderAuthentication'))
//商品咨询
const AskList = asyncComponent(() => import('../view/ProductAsk/AskList'))
//店铺管理
const ProviderManager = asyncComponent(() => import('../view/ProviderManager/ProviderManager'))
//ProductAudit
const ProductAudit = asyncComponent(() => import('../view/productManager/ProductAudit'))
//需求管理
const NeedsSquare = asyncComponent(() => import('../view/needsManager/NeedsSquare'))
const myBidding = asyncComponent(() => import('../view/needsManager/myBidding'))
//系统管理
const OfficialManager = asyncComponent(() => import('../view/systemManager/OfficialManager'))
const ShufflingManager = asyncComponent(() => import('../view/systemManager/ShufflingManager'))
const ShufflingManagerForm =asyncComponent(()=>import('../view/systemManager/ShufflingManagerForm'))
const route = [
    {
        path: '/installationOfSP',
        id:'installationOfSP',
        name: '服务商入驻',
        icon: 'user',
        role: ['0'],
        component: InstallationOfSP,
        children: [
            {
                path: '/installationOfSP/connectMessage',
                id:'installationOfSP-connectMessage',
                name: '服务商入驻',
                role: ['0'],
                component: EmptyRoute,
            },
        ]

    },
    {
        path: '/productManager',
        id:'productManager',
        name: '商品管理',
        icon: 'laptop',
        component: ProductManager,
        role: ['1','2'],
        children: [
            {
                path: "/productManager/productList",
                name: '商品列表',
                id:'productManager-productList',
                role:['1'],
                component: ProductList,
            },
            {
                path: "/productManager/productPublish",
                name: '商品发布',
                id:'productManager-productPublish',

                hide:true,
                role:['1'],

                component: ProductPublish,
            },
            {
                path: "/productManager/productAnalyze",
                name: '商品分析',
                id:'productManager-productAnalyze',
                hide:true,
                role:['1'],
                component: ProductAnalyze,
            },
            {
                path: "/productManager/productHistory",
                id:'productManager-productHistory',

                name: '历史商品',
                role:['1'],

                component: ProductHistory,
            },
            {
                path: "/productManager/orderList",
                name: '订单',
                id:'productManager-orderList',
                role:['1'],
                component: OrderList,
            },
            // {
            //     path: "/productManager/orderAnalyze",
            //     name: '订单分析',
            //     id:'productManager-orderAnalyze',
            //     role:['1'],
            //     component: OrderAnalyze,
            // },
            {
                path: "/productManager/productAudit",
                id:'productManager-productAudit',

                name: '商品质量审核',
                role:['2'],
                component: ProductAudit,
            },
            {
                path: "/productManager/classifyManager",
                id:'productManager-classifyManager',

                name: '商品分类管理',
                role:['2'],
                component: ClassifyManager,
            },
            {
                path: "/productManager/productBlackList",
                id:'productManager-productBlackList',

                name: '商品关键词黑名单',
                role:['2'],
                component: ProductBlackList,
            },
            
        ]
    },
    {
        path: '/productAsk',
        id:'productAsk',
        name: '商品咨询',
        icon: 'laptop',
        component: EmptyRoute,
        role: ['1'],
        children: [
            {
                path: "/productAsk/askList",
                id:'productAsk-askList',
                name: '咨询列表',
                role: ['1'],
                component: AskList,
            },
        ]
    },
    {
        path: '/providerManager',
        id:'providerManager',
        name: '店铺管理',
        icon: 'laptop',
        component: EmptyRoute,
        role: ['1'],
        children: [
            {
                path: "/providerManager/providerManager",
                id:'providerManager-providerManager',
                name: '店铺管理',
                role: ['1'],
                component: ProviderManager,
            },
        ]
    },
    {
        path: '/provider/authentication',
        id:'provider-authentication',
        name: '企业认证',
        icon: 'laptop',
        component: EmptyRoute,
        role: ['2'],

        children: [
            {
                path: "/provider/authentication/list",
                id:'provider-authentication-list',
                name: '申请列表',
                component: ProviderAuthentication,
                role: ['2'],
            },
        ]
    },
    {
        path: '/needs/manager',
        id:'needs-manager',
        name: '需求管理',
        icon: 'laptop',
        component: EmptyRoute,
        role: ['1'],
        children: [
            {
                path: "/needs/square",
                id:'needs-square',
                name: '需求广场',
                component: NeedsSquare,
                role: ['1'],
            },{
                path: "/needs/myBidding",
                id:'needs-myBidding',
                name: '我的竞标',
                component: myBidding,
                role: ['1'],
            },
        ]
    },
    {
        path:'system/manager',
        id:'system-manager',
        name: '系统管理',
        icon: 'laptop',
        component: EmptyRoute,
        role: ['2'],
        children: [
            {
                path: "/official/manager",
                id:'official-manager',
                name: '官方信息管理',
                component: OfficialManager,
                role: ['2'],
            },
            {
                path: "/shuffling/manager",
                id:'shuffling-manager',
                name: '轮播图管理',
                component: ShufflingManager,
                role: ['2'],
            },
            {
                path: "/shuffling/managerform",
                id:'shuffling-manager-form',
                name: '轮播图管理详情页',
                component: ShufflingManagerForm,
                role: ['2'],
                hide:true
            }
        ]
    }
]
export default route

过滤方法

import route from './menuconfig'
function filterMenu(role) {
    console.log('route')
    console.log(route)
    return route.filter(item => {
        if(item.children) item.children=item.children.filter(i=>{
            switch (role) {
                case '0':
                    if (i.path === '/installationOfSP') {
                        return true
                    } else {
                        return false
                    }
                    break;
                case '1':
                    return i.role.indexOf('1') !== -1
                    break;
                case '2':
                    return i.role.indexOf('2') !== -1
                    break;
            }
        })
        switch (role) {
            case '0':
                if (item.path === '/installationOfSP') {
                    return true
                } else {
                    return false
                }
                break;
            case '1':
                return item.role.indexOf('1') !== -1
                break;
            case '2':
                return item.role.indexOf('2') !== -1
                break;
        }

    })
}
export default filterMenu
// route =

加载进来的children一开始是空的,得重新刷新一下才能有值,怎么破


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
388 views
Welcome To Ask or Share your Answers For Others

1 Answer

跟模块化没关系,children出不来,用深拷贝一下route就出来了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...