mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:47:10 +00:00
feat(docs): add demo
This commit is contained in:
parent
eee96a4e4a
commit
51e83c1476
7
docs/develop.md
Normal file
7
docs/develop.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
sidemenu: false
|
||||
order: 1000
|
||||
hide: true
|
||||
---
|
||||
|
||||
<code src="./examples/demos/demo1.tsx"/>
|
72
docs/examples/demos/demo1.tsx
Normal file
72
docs/examples/demos/demo1.tsx
Normal file
@ -0,0 +1,72 @@
|
||||
import { useRequest } from 'ahooks';
|
||||
import { Spin } from 'antd';
|
||||
import React, { useMemo } from 'react';
|
||||
import { MemoryRouter as Router } from 'react-router-dom';
|
||||
import {
|
||||
createRouteSwitch,
|
||||
RouteRedirectProps,
|
||||
AdminLayout,
|
||||
AuthLayout,
|
||||
RouteSchemaRenderer,
|
||||
ConfigProvider,
|
||||
ClientSDK,
|
||||
} from '@nocobase/client';
|
||||
import { UseRequestProvider } from 'ahooks';
|
||||
import { extend } from 'umi-request';
|
||||
|
||||
const request = extend({
|
||||
prefix: process.env.API_URL,
|
||||
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}`;
|
||||
headers['X-Hostname'] = process.env.API_HOSTNAME;
|
||||
}
|
||||
await next();
|
||||
});
|
||||
|
||||
const client = new ClientSDK({
|
||||
request,
|
||||
});
|
||||
|
||||
console.log('process.env.API_URL', process.env.API_URL);
|
||||
|
||||
// console.log = () => {}
|
||||
|
||||
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>
|
||||
<Router initialEntries={['/admin']}>
|
||||
<RouteSwitch routes={data} />
|
||||
</Router>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default () => {
|
||||
return (
|
||||
<ConfigProvider client={client}>
|
||||
<App />
|
||||
</ConfigProvider>
|
||||
);
|
||||
};
|
Loading…
Reference in New Issue
Block a user