fix: menu sort

This commit is contained in:
chenos 2020-12-29 11:31:19 +08:00
parent 3e75bbe6c3
commit e692d7bb5f
5 changed files with 69 additions and 8 deletions

View File

@ -24,7 +24,7 @@ export function CollectionLoader(props: any) {
tabName: match[2],
}));
props.match.params['items'] = items;
console.log(props.match, path);
console.log('props.match', props.match, path);
const { data = {}, error, loading, run } = useRequest(() => api.resource(collection).getCollection());
if (loading) {

View File

@ -40,6 +40,8 @@ export const components = ({data = {}, rowKey, mutate, onMoved}: Props) => {
});
const resourceKey = get(list, [newIndex, rowKey]);
await onMoved({resourceKey, target: {[rowKey]: targetIndex}});
// @ts-ignore
window.routesReload && window.routesReload();
}
}}
{...props}

View File

@ -2,6 +2,7 @@ import Database from '@nocobase/database';
import { ResourceOptions } from '@nocobase/resourcer';
import { flatToTree } from '../utils';
import { get } from 'lodash';
import { Op } from 'sequelize';
function pages2routes(pages: Array<any>) {
let routes: any = {};
@ -38,13 +39,65 @@ function pages2routes(pages: Array<any>) {
export default async function getRoutes(ctx, next) {
const database: Database = ctx.database;
const Page = database.getModel('pages');
let pages = await Page.findAll({
where: {
developerMode: ctx.state.developerMode,
const Collection = database.getModel('collections');
let pages = await Page.findAll(Page.parseApiJson({
filter: {
'developerMode': ctx.state.developerMode,
},
order: [['sort', 'asc']],
sort: ['sort'],
}));
const items = [];
for (const page of pages) {
items.push(page.toJSON());
if (page.get('path') === '/collections') {
const collections = await Collection.findAll(Collection.parseApiJson({
filter: {
developerMode: ctx.state.developerMode,
showInDataMenu: true,
},
sort: ['sort'],
}));
for (const collection of collections) {
const pageId = `collection-${collection.id}`;
items.push({
id: pageId,
type: 'collection',
collection: collection.get('name'),
title: collection.get('title'),
icon: collection.get('icon'),
path: `/collections/${collection.name}`,
parent_id: page.id,
showInMenu: true,
sort: collection.get('sort'),
});
const data = flatToTree(pages.map(row => row.toJSON()), {
const views = await collection.getViews({
where: {
[Op.or]: [
{ showInDataMenu: true },
{ default: true }
]
},
order: [['sort', 'asc']]
});
if (views.length > 1) {
for (const view of views) {
items.push({
id: `view-${view.get('id')}`,
type: 'collection',
collection: collection.get('name'),
title: view.title,
viewName: view.name,
path: `/collections/${collection.name}/views/${view.name}`,
parent_id: pageId,
showInMenu: true,
sort: view.get('sort'),
});
}
}
}
}
}
const data = flatToTree(items, {
id: 'id',
parentId: 'parent_id',
children: 'children',

View File

@ -219,6 +219,9 @@ export default async (ctx, next) => {
}
const viewType = view.get('type');
const actionDefaultParams:any = {};
if (resourceName === 'collections') {
actionDefaultParams.sort = ['sort'];
}
const appends = [];
for (const field of fields) {

View File

@ -18,7 +18,7 @@ export default async function (options = {}) {
resourcer.registerActionHandler('getView', getView);
resourcer.registerActionHandler('getPageInfo', getPageInfo);
resourcer.registerActionHandler('pages:getRoutes', getRoutes);
/*
const [Collection, Page, View] = database.getModels(['collections', 'pages', 'views']);
async function createCollectionPage(model, options) {
@ -61,6 +61,7 @@ export default async function (options = {}) {
await page.save({
transaction,
});
await Page.collectionPagesResort({transaction});
await transaction.commit();
}
@ -75,6 +76,7 @@ export default async function (options = {}) {
path: `/collections/${model.get('name')}`,
},
});
await Page.collectionPagesResort({transaction});
});
async function syncViewCollectionPage(model, options) {
@ -140,4 +142,5 @@ export default async function (options = {}) {
},
});
});
*/
}