From 99e5469386fd161100419366dc55b1c91792e88f Mon Sep 17 00:00:00 2001 From: powersir <1576775122@qq.com> Date: Fri, 22 Sep 2023 15:19:31 +0800 Subject: [PATCH] update: rm mock menu --- mock/menu.json | 343 -------------------------- src/layout/index.tsx | 33 +-- src/layout/slide/menus.tsx | 5 +- src/pages/system/menu/index.tsx | 2 +- src/pages/system/menu/menu-editor.tsx | 63 +++-- 5 files changed, 44 insertions(+), 402 deletions(-) delete mode 100644 mock/menu.json diff --git a/mock/menu.json b/mock/menu.json deleted file mode 100644 index d1b78c4..0000000 --- a/mock/menu.json +++ /dev/null @@ -1,343 +0,0 @@ -[ - { - "id": 1100, - "parentId": 0, - "name": "首页", - "icon": "HomeOutlined", - "type":0, - "path": "/dashboard", - "component": "/dashboard/index.tsx", - "keepAlive": false, - "visible":true - }, - { - "id": 1200, - "parentId": 0, - "name": "定制选品", - "icon": "BgColorsOutlined", - "type":0, - "path": "/custom", - "component": "", - "keepAlive": false, - "visible":true - }, - - { - "id": 1210, - "parentId": 1200, - "name": "定制商品", - "icon": "", - "type":2, - "path": "/product", - "component": "", - "orderNumber": 2, - "keepAlive": false, - "visible":true - }, - { - "id": 1211, - "parentId": 1210, - "name": "样机", - "icon": "", - "type":0, - "path": "/sample", - "component": "/custom/product/sample/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1212, - "parentId": 1210, - "name": "素材", - "icon": "", - "type":0, - "path": "/material", - "component": "/custom/product/material/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1213, - "parentId": 1210, - "name": "款式", - "icon": "", - "type":0, - "path": "/shape", - "component": "/custom/product/shape/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1214, - "parentId": 1210, - "name": "成品", - "icon": "", - "type":0, - "path": "/finished", - "component": "/custom/product/finished/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - - - { - "id": 1220, - "parentId": 1200, - "name": "模板配置", - "icon": "", - "type":2, - "path": "/template", - "component": "", - "orderNumber": 2, - "keepAlive": false, - "visible":true - }, - { - "id": 1221, - "parentId": 1220, - "name": "数据字典", - "icon": "", - "type":0, - "path": "/dict", - "component": "/custom/template/dict/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1222, - "parentId": 1220, - "name": "虾皮模板", - "icon": "", - "type":0, - "path": "/xiapi", - "component": "/custom/template/xiapi/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id":1223, - "parentId": 1220, - "name": "规则引擎", - "icon": "", - "type":0, - "path": "/rules", - "component": "/custom/template/rules/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - - - { - "id": 1230, - "parentId": 1200, - "name": "平台商品", - "icon": "", - "type":2, - "path": "/platform-product", - "component": "", - "orderNumber": 2, - "keepAlive": false, - "visible":true - }, - { - "id": 1231, - "parentId": 1230, - "name": "虾皮", - "icon": "", - "type":0, - "path": "/xiapi", - "component": "/custom/platform-product/xiapi/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1232, - "parentId": 1230, - "name": "亚马逊", - "icon": "", - "type":0, - "path": "/amazone", - "component": "/custom/platform-product/amazone/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - - { - "id": 1240, - "parentId": 1200, - "name": "SDS商品", - "icon": "", - "type":2, - "path": "/sds", - "component": "", - "orderNumber": 2, - "keepAlive": false, - "visible":true - }, - { - "id": 1241, - "parentId": 1240, - "name": "成品库", - "icon": "", - "type":0, - "path": "/finished-product-warehouse", - "component": "/custom/sds/finished-product-warehouse/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1242, - "parentId": 1240, - "name": "款式", - "icon": "", - "type":0, - "path": "/sds-shape", - "component": "/custom/sds/sds-shape/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1243, - "parentId": 1240, - "name": "图案素材", - "icon": "", - "type":0, - "path": "/pattern-material", - "component": "/custom/sds/pattern-material/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - - - { - "id": 1300, - "parentId": 0, - "name": "AI应用", - "icon": "HighlightOutlined", - "type":0, - "path": "/ai", - "component": "", - "keepAlive": false, - "visible":true - }, - { - "id": 1310, - "parentId": 1300, - "name": "AI 作图", - "icon": "", - "type":0, - "path": "/makeup", - "component": "/ai/makeup/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id":1320, - "parentId": 1300, - "name": "AI 画背景", - "icon": "", - "type":0, - "path": "/background", - "component": "/ai/background/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1330, - "parentId": 1300, - "name": "图片裂变", - "icon": "", - "type":0, - "path": "/fission", - "component": "/ai/fission/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1340, - "parentId": 1300, - "name": "轮廓出图", - "icon": "", - "type":0, - "path": "/outline", - "component": "/ai/outline/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1350, - "parentId": 1300, - "name": "一键白底", - "icon": "", - "type":0, - "path": "/white-background", - "component": "/ai/white-background/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1360, - "parentId": 1300, - "name": "AI P图", - "icon": "", - "type":0, - "path": "/ps", - "component": "/ai/ps/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1370, - "parentId": 1300, - "name": "AI 试装", - "icon": "", - "type":0, - "path": "/try", - "component": "/ai/try/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1380, - "parentId": 1300, - "name": "AI 作图2", - "icon": "", - "type":0, - "path": "/makeup2", - "component": "/ai/makeup2/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - }, - { - "id": 1390, - "parentId": 1300, - "name": "旺嘉智库", - "icon": "", - "type":0, - "path": "/smart-libs", - "component": "/ai/smart-libs/index.tsx", - "orderNumber": 3, - "keepAlive": false, - "visible":true - } -] diff --git a/src/layout/index.tsx b/src/layout/index.tsx index ab9378c..d04b16e 100644 --- a/src/layout/index.tsx +++ b/src/layout/index.tsx @@ -17,7 +17,7 @@ import TabsLayout from './tabs-layout'; import Content from './content'; import userService from '@/request/service/user'; import { useRequest } from "@/hooks/use-request"; -import menuData from '../../mock/menu.json' +// import menuData from '../../mock/menu.json' const BasicLayout: React.FC = () => { @@ -76,25 +76,7 @@ const BasicLayout: React.FC = () => { useEffect(() => { if (!currentUserProfile || !menuList?.data) return; - const menus:Array = menuData as Array ; - - const menuGroup = menus.reduce>((prev, menu) => { - if (!menu.parentId) { - return prev; - } - - if (!prev[menu.parentId]) { - prev[menu.parentId] = []; - } - - prev[menu.parentId].push(menu); - return prev; - }, {}); - const routes: Menu[] = []; - - const formatedMenus = formatMenus(menus.filter(o => !o.parentId), menuGroup, routes); - console.log(formatedMenus); console.log(menuList.data); const fixAndPushMenu = (item: Menu) => { @@ -105,18 +87,23 @@ const BasicLayout: React.FC = () => { if(!item.path.startsWith('/')) { item.path = `/${item.path}` } - item.path = [...item.parentPaths, item.path].join('') - item.component = `${item.path}/index.tsx` + const parentPath = item.parentPaths.join('') + if(!item.path.startsWith(parentPath)) { + item.path = [...item.parentPaths, item.path].join('') + } + + item.component = item.component ? (item.path.endsWith('/index.tsx') ? item.path : `${item.path}/index.tsx`) : item.component routes.push(item) if(item.children && item.children.length > 0) { + const parentPaths= item.path.replace('/index.tsx', '').split("/").filter(it => it!== '').map(it => `/${it}`) item.children.forEach(it => { - it.parentPaths = [...item.parentPaths||[], item.path] + it.parentPaths = parentPaths fixAndPushMenu(it) }) } } menuList.data.forEach(item => fixAndPushMenu(item)) - setMenus([...formatedMenus, ...menuList.data]); + setMenus(menuList.data) //([...formatedMenus, ...menuList.data]); console.log('components', components); replaceRoutes('*', [ ...routes.map(menu => ({ diff --git a/src/layout/slide/menus.tsx b/src/layout/slide/menus.tsx index bf6974f..1c330f7 100644 --- a/src/layout/slide/menus.tsx +++ b/src/layout/slide/menus.tsx @@ -283,10 +283,9 @@ const SlideMenu = () => { } const treeMenuData = useCallback((menus: MenuType[]): ItemType[] => { - return (menus) - .map((menu: MenuType) => { + return (menus).map((menu: MenuType) => { const children = menu?.children?.filter(menu => menu.visible) || []; - const type = menu.type === 2 ? "group": (menu.type === 3 ? "divider" : "") + const type = (children.length > 0 && (menu.parentPaths?.length??0 > 0)) ? 'group': '' return { type: type, key: menu.path, diff --git a/src/pages/system/menu/index.tsx b/src/pages/system/menu/index.tsx index 59c0d38..6e693a8 100644 --- a/src/pages/system/menu/index.tsx +++ b/src/pages/system/menu/index.tsx @@ -173,7 +173,7 @@ const MenuListPage: React.FC = () => {
- + - {icon2Element(value)} + {(value && girdItems.indexOf(value) >= 0) ? icon2Element(value) : <>} }; @@ -186,14 +190,14 @@ const MenuEditor: React.FC = (props) => { - = (props) => { - - + prevValues.type !== currentValues.type} + > + {({ getFieldValue }) => + getFieldValue('type') === 2 ? ( + + + + ) : null + } - { - // const checked = value !== 0; - // console.log(checked) - // return { checked } - // }} - valuePropName="checked" - // normalize={(value: boolean) => { - // // prevValues.status = value ? 0 : 1 - // return value ? 0 : 1 - // }} - > - + + + - - {/* - - */}