2021-10-29 09:29:16 +08:00
|
|
|
import { useRequest } from 'ahooks';
|
|
|
|
import { Spin } from 'antd';
|
|
|
|
import React, { useMemo } from 'react';
|
2021-11-08 19:32:59 +08:00
|
|
|
import { HashRouter as Router } from 'react-router-dom';
|
2021-10-29 09:29:16 +08:00
|
|
|
import {
|
|
|
|
createRouteSwitch,
|
|
|
|
RouteRedirectProps,
|
|
|
|
AdminLayout,
|
|
|
|
AuthLayout,
|
|
|
|
RouteSchemaRenderer,
|
|
|
|
ConfigProvider,
|
|
|
|
ClientSDK,
|
|
|
|
} from '@nocobase/client';
|
|
|
|
import { UseRequestProvider } from 'ahooks';
|
|
|
|
import { extend } from 'umi-request';
|
|
|
|
|
|
|
|
const request = extend({
|
2021-12-03 07:31:22 +08:00
|
|
|
prefix: process.env.API_BASE_URL,
|
2021-10-29 09:29:16 +08:00
|
|
|
timeout: 30000,
|
|
|
|
});
|
|
|
|
|
|
|
|
request.use(async (ctx, next) => {
|
|
|
|
const { headers } = ctx.req.options as any;
|
|
|
|
const token = localStorage.getItem('NOCOBASE_TOKEN');
|
|
|
|
if (token) {
|
|
|
|
headers['Authorization'] = `Bearer ${token}`;
|
|
|
|
}
|
2021-11-10 20:32:47 +08:00
|
|
|
headers['X-Hostname'] = window.location.hostname;
|
2021-10-29 09:29:16 +08:00
|
|
|
await next();
|
|
|
|
});
|
|
|
|
|
|
|
|
const client = new ClientSDK({
|
|
|
|
request,
|
|
|
|
});
|
|
|
|
|
|
|
|
const RouteSwitch = createRouteSwitch({
|
|
|
|
components: {
|
|
|
|
AdminLayout,
|
|
|
|
AuthLayout,
|
|
|
|
RouteSchemaRenderer,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
const { data, loading } = useRequest('routes:getAccessible', {
|
|
|
|
formatResult: (result) => result?.data,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <Spin size={'large'} className={'nb-spin-center'} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2021-11-08 19:32:59 +08:00
|
|
|
<Router>
|
2021-10-29 09:29:16 +08:00
|
|
|
<RouteSwitch routes={data} />
|
|
|
|
</Router>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => {
|
|
|
|
return (
|
|
|
|
<ConfigProvider client={client}>
|
|
|
|
<App />
|
|
|
|
</ConfigProvider>
|
|
|
|
);
|
|
|
|
};
|