fix: get pageTitle with first string field
This commit is contained in:
parent
4f4064ad11
commit
eb501e3461
@ -1,13 +1,20 @@
|
|||||||
import { ResourceOptions } from '@nocobase/resourcer';
|
import { ResourceOptions } from '@nocobase/resourcer';
|
||||||
import { Model, ModelCtor } from '@nocobase/database';
|
import { Model, ModelCtor } from '@nocobase/database';
|
||||||
import { get } from 'lodash';
|
|
||||||
|
|
||||||
export default async (ctx, next) => {
|
export default async (ctx, next) => {
|
||||||
const { resourceName, resourceKey } = ctx.action.params;
|
const { resourceName, resourceKey } = ctx.action.params;
|
||||||
const M = ctx.db.getModel(resourceName) as ModelCtor<Model>;
|
const M = ctx.db.getModel(resourceName) as ModelCtor<Model>;
|
||||||
const model = await M.findByPk(resourceKey);
|
const model = await M.findByPk(resourceKey);
|
||||||
|
const Field = ctx.db.getModel('fields') as ModelCtor<Model>;
|
||||||
|
const field = await Field.findOne({
|
||||||
|
where: {
|
||||||
|
collection_name: resourceName,
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
order: [['sort', 'asc']],
|
||||||
|
});
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
pageTitle: model.title,
|
pageTitle: field ? model.get(field.get('name')) : model.get(M.primaryKeyAttribute),
|
||||||
...model.toJSON(),
|
...model.toJSON(),
|
||||||
};
|
};
|
||||||
await next();
|
await next();
|
||||||
|
Loading…
Reference in New Issue
Block a user