feat: menu sync & refresh

This commit is contained in:
chenos 2020-12-07 17:25:36 +08:00
parent efc51355dd
commit ae6ea41c52
5 changed files with 51 additions and 3 deletions

View File

@ -26,9 +26,14 @@ export function Details(props: any) {
const { actions = [], fields = [] } = props.schema;
return (
<Card bordered={false}>
<Actions {...props} onFinish={() => {
refresh();
}} style={{ marginBottom: 14 }} actions={actions}/>
<Actions
{...props}
onFinish={() => {
refresh();
}}
style={{ marginBottom: 14 }}
actions={actions}
/>
{loading ? <Spin/> : (
<Descriptions bordered column={1}>
{fields.map((field: any) => {

View File

@ -76,6 +76,8 @@ export const DrawerForm = forwardRef((props: any, ref) => {
});
}
setVisible(false);
// @ts-ignore
window.routesReload && window.routesReload();
onFinish && onFinish(values);
}}></Button>
]}

View File

@ -77,6 +77,9 @@ export function SimpleTable(props: SimpleTableProps) {
mode={'update'}
viewName={rowViewName}
reference={drawerRef}
onFinish={() => {
refresh();
}}
/>
<AntdTable
rowKey={rowKey}

View File

@ -3,6 +3,7 @@ import { TableOptions } from '@nocobase/database';
export default {
name: 'pages',
title: '页面配置',
model: 'BaseModel',
fields: [
{
interface: 'sort',

View File

@ -18,4 +18,41 @@ export default async function (options = {}) {
resourcer.registerActionHandler('getView', getView);
resourcer.registerActionHandler('getPageInfo', getPageInfo);
resourcer.registerActionHandler('pages:getRoutes', getRoutes);
const [Collection, Page] = database.getModels(['collections', 'pages']);
async function createCollectionPage(model) {
if (!model.get('showInDataMenu')) {
return;
}
const parent = await Page.findOne({
where: {
path: '/collections',
}
});
let page = await Page.findOne({
where: {
collection: model.get('name'),
path: `/collections/${model.get('name')}`,
},
});
if (!page) {
page = await Page.create({
type: 'collection',
collection: model.get('name'),
path: `/collections/${model.get('name')}`,
sort: 100,
parent_id: parent.id,
});
}
page.set({
title: model.get('title'),
icon: model.get('icon'),
showInMenu: model.get('showInDataMenu'),
});
page.save();
}
Collection.addHook('afterCreate', createCollectionPage);
Collection.addHook('afterUpdate', createCollectionPage);
}