mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 04:38:15 +08:00
fix: view can be displayed in data menu
This commit is contained in:
parent
67e18352b6
commit
b2801a00dc
@ -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 && (
|
||||
<Menu.Item key={item.path}>
|
||||
<Link to={item.path}><Icon type={item.icon}/> {item.title}</Link>
|
||||
</Menu.Item>
|
||||
))}
|
||||
{items.map(item => {
|
||||
if (!item.showInMenu) {
|
||||
return null;
|
||||
}
|
||||
const { children = [] } = item;
|
||||
const subItems = children.filter(child => child.showInMenu);
|
||||
if (!hideChildren && subItems.length > 1) {
|
||||
return (
|
||||
<Menu.SubMenu key={`${item.path}`} title={<><Icon type={item.icon}/> {item.title}</>}>
|
||||
{subItems.map((child: any) => (
|
||||
<Menu.Item key={child.path}>
|
||||
<Link to={child.path}>{child.title}</Link>
|
||||
</Menu.Item>
|
||||
))}
|
||||
</Menu.SubMenu>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Menu.Item key={item.path}>
|
||||
<Link to={item.path}><Icon type={item.icon}/> {item.title}</Link>
|
||||
</Menu.Item>
|
||||
)
|
||||
})}
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
|
@ -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) {
|
||||
<div className={'collection-content'}>
|
||||
<ViewFactory
|
||||
{...props}
|
||||
viewName={viewName||defaultViewName}
|
||||
viewName={lastPage.viewName||viewName||defaultViewName}
|
||||
resourceName={collection}
|
||||
/>
|
||||
</div>
|
||||
|
@ -12,7 +12,7 @@ export function TopMenuLayout(props: any) {
|
||||
<Layout style={{ height: '100vh' }}>
|
||||
<Layout.Header style={{height: 48, lineHeight: '48px', padding: 0}} className="nb-header">
|
||||
<div className="logo" style={{width: 200, height: 20, float: 'left'}}><CodeOutlined /> NocoBase</div>
|
||||
<Menu items={menu} className={'noco-top-menu'} style={{float: 'left'}} theme="dark" mode="horizontal">
|
||||
<Menu hideChildren={true} items={menu} className={'noco-top-menu'} style={{float: 'left'}} theme="dark" mode="horizontal">
|
||||
</Menu>
|
||||
<AvatarDropdown/>
|
||||
</Layout.Header>
|
||||
|
@ -87,6 +87,8 @@ export function SimpleTable(props: SimpleTableProps) {
|
||||
},
|
||||
});
|
||||
await refresh();
|
||||
// @ts-ignore
|
||||
window.routesReload && window.routesReload();
|
||||
console.log('destroy.onTrigger', selectedRowKeys);
|
||||
},
|
||||
}}
|
||||
|
@ -88,6 +88,8 @@ export function Table(props: TableProps) {
|
||||
},
|
||||
});
|
||||
await refresh();
|
||||
// @ts-ignore
|
||||
window.routesReload && window.routesReload();
|
||||
console.log('destroy.onTrigger', selectedRowKeys);
|
||||
}
|
||||
}}
|
||||
|
@ -10,10 +10,10 @@ function pages2routes(pages: Array<any>) {
|
||||
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 => ({
|
||||
|
@ -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: {
|
||||
|
@ -182,6 +182,15 @@ export default {
|
||||
type: 'drawerSelect',
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'number',
|
||||
type: 'integer',
|
||||
name: 'viewId',
|
||||
title: '视图ID',
|
||||
component: {
|
||||
type: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'json',
|
||||
type: 'json',
|
||||
|
@ -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'),
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user