diff --git a/packages/app/src/components/menu/index.tsx b/packages/app/src/components/menu/index.tsx index 811fde396..5e335a70c 100644 --- a/packages/app/src/components/menu/index.tsx +++ b/packages/app/src/components/menu/index.tsx @@ -11,7 +11,7 @@ function pathcamp(path1: string, path2: string) { } export default (props: any) => { - const { items = [], ...restProps } = props; + const { items = [], hideChildren, ...restProps } = props; const location = useLocation(); let paths = items.map(item => item.path); return ( @@ -20,11 +20,29 @@ export default (props: any) => { defaultOpenKeys={paths.filter(path => pathcamp(location.pathname, path)).concat(location.pathname)} {...restProps} > - {items.map(item => item.showInMenu && ( - - {item.title} - - ))} + {items.map(item => { + if (!item.showInMenu) { + return null; + } + const { children = [] } = item; + const subItems = children.filter(child => child.showInMenu); + if (!hideChildren && subItems.length > 1) { + return ( + {item.title}}> + {subItems.map((child: any) => ( + + {child.title} + + ))} + + ) + } + return ( + + {item.title} + + ) + })} ); }; diff --git a/packages/app/src/components/pages/CollectionLoader/CollectionIndex.tsx b/packages/app/src/components/pages/CollectionLoader/CollectionIndex.tsx index de8b5ffb6..d66dc8dcd 100644 --- a/packages/app/src/components/pages/CollectionLoader/CollectionIndex.tsx +++ b/packages/app/src/components/pages/CollectionLoader/CollectionIndex.tsx @@ -5,6 +5,7 @@ import { useRequest, request, Spin } from '@nocobase/client'; import { getPathName } from './utils'; export function CollectionIndex(props) { + const { lastPage } = props; const { viewName, collection } = props.match.params; const { title, defaultViewName } = props.collection; @@ -31,7 +32,7 @@ export function CollectionIndex(props) {
diff --git a/packages/app/src/components/pages/TopMenuLayout/index.tsx b/packages/app/src/components/pages/TopMenuLayout/index.tsx index 9266b42b4..e45f4cd90 100644 --- a/packages/app/src/components/pages/TopMenuLayout/index.tsx +++ b/packages/app/src/components/pages/TopMenuLayout/index.tsx @@ -12,7 +12,7 @@ export function TopMenuLayout(props: any) {
NocoBase
- + diff --git a/packages/app/src/components/views/SimpleTable.tsx b/packages/app/src/components/views/SimpleTable.tsx index a4d67187a..c723d43f0 100644 --- a/packages/app/src/components/views/SimpleTable.tsx +++ b/packages/app/src/components/views/SimpleTable.tsx @@ -87,6 +87,8 @@ export function SimpleTable(props: SimpleTableProps) { }, }); await refresh(); + // @ts-ignore + window.routesReload && window.routesReload(); console.log('destroy.onTrigger', selectedRowKeys); }, }} diff --git a/packages/app/src/components/views/Table.tsx b/packages/app/src/components/views/Table.tsx index e4b2cea01..18d32ac3b 100644 --- a/packages/app/src/components/views/Table.tsx +++ b/packages/app/src/components/views/Table.tsx @@ -88,6 +88,8 @@ export function Table(props: TableProps) { }, }); await refresh(); + // @ts-ignore + window.routesReload && window.routesReload(); console.log('destroy.onTrigger', selectedRowKeys); } }} diff --git a/packages/plugin-pages/src/actions/getRoutes.ts b/packages/plugin-pages/src/actions/getRoutes.ts index 252e993cd..21be91a21 100644 --- a/packages/plugin-pages/src/actions/getRoutes.ts +++ b/packages/plugin-pages/src/actions/getRoutes.ts @@ -10,10 +10,10 @@ function pages2routes(pages: Array) { const route: any = { ...restProps, }; - if (page.type === 'layout' && !page.redirect && children.length) { + // page.type === 'layout' && + if (!page.redirect && children.length) { const items = children.sort((a, b) => a.order - b.order); - const segmentId = get(items, [0, 'segments', 0, 'id']); - route.redirect = segmentId ? `${items[0].path}/segments/${segmentId}` : items[0].path; + route.redirect = items[0].path; } if (page.type === 'layout' && children.length) { route.menu = children.map(child => ({ diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 24f660884..4a2541dac 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -153,7 +153,10 @@ export default async (ctx, next) => { ['sort', 'asc'], ] }); - const actionNames = view.get('actionNames') || []; + let actionNames = view.get('actionNames') || []; + if (actionNames.length === 0) { + actionNames = ['filter', 'create', 'destroy']; + } if (view.get('type') === 'table') { const defaultTabs = await collection.getTabs({ where: { diff --git a/packages/plugin-pages/src/collections/pages.ts b/packages/plugin-pages/src/collections/pages.ts index a760c0f74..588977618 100644 --- a/packages/plugin-pages/src/collections/pages.ts +++ b/packages/plugin-pages/src/collections/pages.ts @@ -182,6 +182,15 @@ export default { type: 'drawerSelect', }, }, + { + interface: 'number', + type: 'integer', + name: 'viewId', + title: '视图ID', + component: { + type: 'number', + }, + }, { interface: 'json', type: 'json', diff --git a/packages/plugin-pages/src/server.ts b/packages/plugin-pages/src/server.ts index 7e47fe7eb..b64318a2d 100644 --- a/packages/plugin-pages/src/server.ts +++ b/packages/plugin-pages/src/server.ts @@ -19,7 +19,7 @@ export default async function (options = {}) { resourcer.registerActionHandler('getPageInfo', getPageInfo); resourcer.registerActionHandler('pages:getRoutes', getRoutes); - const [Collection, Page] = database.getModels(['collections', 'pages']); + const [Collection, Page, View] = database.getModels(['collections', 'pages', 'views']); async function createCollectionPage(model, options) { // const { @@ -76,4 +76,69 @@ export default async function (options = {}) { }, }); }); + + async function syncViewCollectionPage(model, options) { + const transaction = await database.sequelize.transaction(); + const parentPath = `/collections/${model.get('collection_name')}`; + const currentPath = `${parentPath}/views/${model.get('name')}`; + try { + const parent = await Page.findOne({ + transaction, + where: { + path: parentPath, + }, + }); + if (!parent) { + await transaction.rollback(); + return; + } + let page = await Page.findOne({ + transaction, + where: { + collection: model.get('collection_name'), + path: currentPath, + }, + }); + if (!page) { + page = await Page.create({ + type: 'collection', + collection: model.get('collection_name'), + path: currentPath, + sort: 100, + parent_id: parent.id, + }, { + transaction, + }); + } + page.set({ + title: model.get('title'), + viewName: model.get('name'), + viewId: model.get('id'), + // icon: model.get('icon'), + showInMenu: !!model.get('showInDataMenu'), + }); + await page.save({ + transaction, + }); + } catch (error) { + await transaction.rollback(); + console.error(error); + } + await transaction.commit(); + } + View.addHook('beforeValidate', (model) => { + console.log('beforeValidate'); + if (model.get('default')) { + model.set('showInDataMenu', true); + } + }); + View.addHook('afterCreate', syncViewCollectionPage); + View.addHook('afterUpdate', syncViewCollectionPage); + View.addHook('afterDestroy', async (model, options) => { + await Page.destroy({ + where: { + viewId: model.get('id'), + }, + }); + }); }