From db103c50f0caa491978160f3b7a6e69d8cebd84d Mon Sep 17 00:00:00 2001 From: chenos Date: Sun, 28 Mar 2021 08:56:17 +0800 Subject: [PATCH] fix: page view sync --- packages/plugin-pages/src/server.ts | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/plugin-pages/src/server.ts b/packages/plugin-pages/src/server.ts index e4dd026e8..fc804bdde 100644 --- a/packages/plugin-pages/src/server.ts +++ b/packages/plugin-pages/src/server.ts @@ -64,6 +64,57 @@ export default async function (options = {}) { await next(); }); + resourcer.use(async (ctx, next) => { + await next(); + const { actionName, resourceName } = ctx.action.params; + if (resourceName === 'menus' && actionName === 'get') { + const menu = ctx.body; + const items = menu.get('views') || []; + const View = database.getModel('views_v2'); + for (const item of items) { + if (!(item.view && item.view.id)) { + continue; + } + const view = await View.findOne(View.parseApiJson({ + filter: { + id: item.view.id, + }, + fields: { + appends: ['collection', 'targetField', 'targetView'], + }, + })); + if (!view) { + continue; + } + const details = view.get(`options.x-${view.type}-props.details`); + if (!Array.isArray(details)) { + item.view = view; + continue; + } + for (const detail of details) { + if (!(detail.view && detail.view.id)) { + continue; + } + const detailView = await View.findOne(View.parseApiJson({ + filter: { + id: detail.view.id, + }, + fields: { + appends: ['collection', 'targetField', 'targetView'], + }, + })); + if (!detailView) { + continue; + } + detail.view = detailView; + } + view.set(`options.x-${view.type}-props.details`, details); + item.view = view; + } + menu.set('views', items); + } + }); + resourcer.registerActionHandler('getCollection', getCollection); resourcer.registerActionHandler('getView', getView); resourcer.registerActionHandler('getPageInfo', getPageInfo);