chore: cleanup
This commit is contained in:
parent
b6cd540f72
commit
fd8c6f8e50
@ -5,11 +5,9 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nocobase/actions": "^0.4.0-alpha.0",
|
"@nocobase/actions": "^0.4.0-alpha.0",
|
||||||
"@nocobase/client": "^0.4.0-alpha.0",
|
|
||||||
"@nocobase/database": "^0.4.0-alpha.0",
|
"@nocobase/database": "^0.4.0-alpha.0",
|
||||||
"@nocobase/resourcer": "^0.4.0-alpha.0",
|
"@nocobase/resourcer": "^0.4.0-alpha.0",
|
||||||
"@nocobase/server": "^0.4.0-alpha.0",
|
"@nocobase/server": "^0.4.0-alpha.0",
|
||||||
"crypto-random-string": "^3.3.1",
|
"crypto-random-string": "^3.3.1"
|
||||||
"react": "16.14.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
export function CollectionLoader(props: any) {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
Collection Loader
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
export { PageLoader } from './page-loader';
|
|
||||||
export { TemplateLoader } from './template-loader';
|
|
||||||
export { CollectionLoader } from './collection-loader';
|
|
||||||
export { PageLoader as default } from './page-loader';
|
|
@ -1,24 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { TemplateLoader } from './template-loader';
|
|
||||||
import { useRequest, request } from '@nocobase/client';
|
|
||||||
|
|
||||||
export function PageLoader(props: any) {
|
|
||||||
const { path } = props.match.params;
|
|
||||||
const { data = {}, error, loading, run } = useRequest(() => request('/routes'));
|
|
||||||
const [first, setFirst] = useState(true);
|
|
||||||
// @ts-ignore
|
|
||||||
window.routesReload = async () => {
|
|
||||||
setFirst(false);
|
|
||||||
await run();
|
|
||||||
};
|
|
||||||
// const routes = pages2routes(data);
|
|
||||||
console.log(data);
|
|
||||||
return (
|
|
||||||
<TemplateLoader
|
|
||||||
{...props}
|
|
||||||
loading={loading && first}
|
|
||||||
pages={data.data||{}}
|
|
||||||
pathname={`/${path}`}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import get from 'lodash/get';
|
|
||||||
import { Spin, Redirect } from '@nocobase/client';
|
|
||||||
|
|
||||||
function getRoutes(path: string, pages: any) {
|
|
||||||
const keys = path.split('/');
|
|
||||||
const routes: Array<any> = [];
|
|
||||||
while(keys.length) {
|
|
||||||
const uri = keys.join('/');
|
|
||||||
if (pages[uri]) {
|
|
||||||
routes.push({...pages[uri], path: uri});
|
|
||||||
}
|
|
||||||
keys.pop();
|
|
||||||
}
|
|
||||||
if (path && pages['/']) {
|
|
||||||
routes.push({...pages['/'], path: '/'});
|
|
||||||
}
|
|
||||||
return routes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function TemplateLoader(props: any) {
|
|
||||||
const { loading, pathname, pages } = props;
|
|
||||||
if (loading) {
|
|
||||||
return <Spin size={'large'} className={'spinning--absolute'}></Spin>;
|
|
||||||
}
|
|
||||||
const redirect = get(pages, [pathname, 'redirect']);
|
|
||||||
if (redirect) {
|
|
||||||
return <Redirect to={redirect}/>
|
|
||||||
}
|
|
||||||
const routes = getRoutes(pathname, pages);
|
|
||||||
let component: any;
|
|
||||||
console.log(...routes);
|
|
||||||
const len = routes.length;
|
|
||||||
const componentProps = {...props};
|
|
||||||
while(routes.length) {
|
|
||||||
const route = routes.shift();
|
|
||||||
console.log(route.template);
|
|
||||||
const Component = require(route.template).default;
|
|
||||||
if (route.type === 'collection') {
|
|
||||||
componentProps.match.params['collection'] = route.collection;
|
|
||||||
}
|
|
||||||
if (len === routes.length+1) {
|
|
||||||
componentProps['lastPage'] = route;
|
|
||||||
}
|
|
||||||
componentProps['page'] = route;
|
|
||||||
component = <Component key={`page-${route.id}`} {...componentProps}>{component}</Component>;
|
|
||||||
if (route.inherit === false) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return component;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user