From eb501e3461d750d8fe445506ee3cf096c0329e22 Mon Sep 17 00:00:00 2001 From: chenos Date: Fri, 11 Dec 2020 15:00:33 +0800 Subject: [PATCH] fix: get pageTitle with first string field --- packages/plugin-pages/src/actions/getPageInfo.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/plugin-pages/src/actions/getPageInfo.ts b/packages/plugin-pages/src/actions/getPageInfo.ts index b994ba62f..d1725f827 100644 --- a/packages/plugin-pages/src/actions/getPageInfo.ts +++ b/packages/plugin-pages/src/actions/getPageInfo.ts @@ -1,13 +1,20 @@ import { ResourceOptions } from '@nocobase/resourcer'; import { Model, ModelCtor } from '@nocobase/database'; -import { get } from 'lodash'; export default async (ctx, next) => { const { resourceName, resourceKey } = ctx.action.params; const M = ctx.db.getModel(resourceName) as ModelCtor; const model = await M.findByPk(resourceKey); + const Field = ctx.db.getModel('fields') as ModelCtor; + const field = await Field.findOne({ + where: { + collection_name: resourceName, + type: 'string', + }, + order: [['sort', 'asc']], + }); ctx.body = { - pageTitle: model.title, + pageTitle: field ? model.get(field.get('name')) : model.get(M.primaryKeyAttribute), ...model.toJSON(), }; await next();