fix: missing pageInfo

This commit is contained in:
chenos 2021-02-01 13:27:41 +08:00
parent d83cebac56
commit 134f72f6e8
2 changed files with 11 additions and 8 deletions

View File

@ -28,7 +28,7 @@ export function CollectionSingle(props) {
const collection = collections[props.itemIndex]||{};
const { tabs = [] } = collection;
const { tabs = [], pageInfo = {} } = collection;
const activeTab = tabs.find(tab => tab.name == item.tabName)||{};
console.log({tabs, activeTab, item});
@ -39,7 +39,7 @@ export function CollectionSingle(props) {
return (
<div>
<Helmet>
<title>{collection.pageTitle}</title>
<title>{pageInfo.pageTitle}</title>
</Helmet>
<PageHeader
ghost={false}
@ -49,7 +49,7 @@ export function CollectionSingle(props) {
removeLastItem: true,
});
}}
title={collection.pageTitle}
title={pageInfo.pageTitle}
// subTitle="This is a subtitle"
extra={[
// <Button key="3">Operation</Button>,
@ -79,7 +79,7 @@ export function CollectionSingle(props) {
}
/>
<div className={'collection-content'}>
<CollectionTabPane {...props} collection={collection} loading={activing} activeTab={activeTab}/>
<CollectionTabPane {...props} pageInfo={pageInfo} collection={collection} loading={activing} activeTab={activeTab}/>
</div>
</div>
);

View File

@ -1,7 +1,7 @@
import { Model, ModelCtor } from '@nocobase/database';
import _ from 'lodash';
async function getPageTitle(ctx, {resourceName, resourceKey}) {
async function getPageInfo(ctx, {resourceName, resourceKey}) {
// const { resourceName, resourceKey } = ctx.action.params;
const M = ctx.db.getModel(resourceName) as ModelCtor<Model>;
const model = await M.findByPk(resourceKey);
@ -13,7 +13,10 @@ async function getPageTitle(ctx, {resourceName, resourceKey}) {
},
order: [['sort', 'asc']],
});
return field ? (model.get(field.get('name')) || `#${model.get(M.primaryKeyAttribute)} 无标题`) : model.get(M.primaryKeyAttribute);
return {
pageTitle: field ? (model.get(field.get('name')) || `#${model.get(M.primaryKeyAttribute)} 无标题`) : model.get(M.primaryKeyAttribute),
...model.toJSON(),
};
};
@ -89,7 +92,7 @@ export default async (ctx, next) => {
for (const item of items) {
const lastCollection = ctx.body[ctx.body.length-1];
lastCollection.pageTitle = await getPageTitle(ctx, {resourceName: lastCollection.name, resourceKey: item.itemId});
lastCollection.pageInfo = await getPageInfo(ctx, {resourceName: lastCollection.name, resourceKey: item.itemId});
const activeTab = _.find(lastCollection.tabs, tab => tab.name == item.tabName)||{};
if (activeTab && activeTab.type === 'association') {
// console.log(activeTab.associationField.target);
@ -99,7 +102,7 @@ export default async (ctx, next) => {
}
const lastCollection = ctx.body[ctx.body.length-1];
lastCollection.pageTitle = await getPageTitle(ctx, {resourceName: lastCollection.name, resourceKey: lastItem.itemId});
lastCollection.pageInfo = await getPageInfo(ctx, {resourceName: lastCollection.name, resourceKey: lastItem.itemId});
await next();
}