mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 13:26:44 +00:00
feat: add application demo
This commit is contained in:
parent
29cf274a52
commit
50e13fe93a
5
packages/client/develop.md
Normal file
5
packages/client/develop.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
sidemenu: false
|
||||
---
|
||||
|
||||
<code src="./src/application/demos/demo2/index.tsx"/>
|
45
packages/client/src/application/demos/demo2/apiClient.ts
Normal file
45
packages/client/src/application/demos/demo2/apiClient.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { APIClient } from '@nocobase/client';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
|
||||
const apiClient = new APIClient({
|
||||
baseURL: `${location.protocol}//${location.host}/api/`,
|
||||
});
|
||||
|
||||
const mock = new MockAdapter(apiClient.axios);
|
||||
|
||||
mock.onGet('/app:getLang').reply(200, {
|
||||
data: { lang: 'en-US' },
|
||||
});
|
||||
|
||||
mock.onGet('/routes:getAccessible').reply(200, {
|
||||
data: [
|
||||
{
|
||||
type: 'redirect',
|
||||
from: '/',
|
||||
to: '/admin',
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
type: 'route',
|
||||
uiSchemaKey: 'qqzzjakwkwl',
|
||||
path: '/admin/:name(.+)?',
|
||||
component: 'AdminLayout',
|
||||
title: 'NocoBase',
|
||||
},
|
||||
{
|
||||
type: 'route',
|
||||
component: 'AuthLayout',
|
||||
routes: [
|
||||
{
|
||||
type: 'route',
|
||||
uiSchemaKey: 'dtf9j0b8p9u',
|
||||
path: '/signin',
|
||||
component: 'RouteSchemaComponent',
|
||||
title: '{{t("Sign in")}}',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export default apiClient;
|
42
packages/client/src/application/demos/demo2/index.tsx
Normal file
42
packages/client/src/application/demos/demo2/index.tsx
Normal file
@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { HashRouter } from 'react-router-dom';
|
||||
import {
|
||||
i18n,
|
||||
compose,
|
||||
useRequest,
|
||||
AuthLayout,
|
||||
AdminLayout,
|
||||
APIClientProvider,
|
||||
RouteSwitch,
|
||||
RouteSwitchProvider,
|
||||
AntdConfigProvider,
|
||||
SchemaComponentProvider,
|
||||
} from '@nocobase/client';
|
||||
import { I18nextProvider } from 'react-i18next';
|
||||
import { Spin } from 'antd';
|
||||
import apiClient from './apiClient';
|
||||
|
||||
const providers = [
|
||||
[HashRouter, {}],
|
||||
[APIClientProvider, { apiClient }],
|
||||
[I18nextProvider, { i18n }],
|
||||
[AntdConfigProvider, { remoteLocale: true }],
|
||||
[SchemaComponentProvider, { components: {} }],
|
||||
[RouteSwitchProvider, { components: { AuthLayout, AdminLayout } }],
|
||||
];
|
||||
|
||||
const App = compose(...providers)(() => {
|
||||
const { data, loading } = useRequest({
|
||||
url: 'routes:getAccessible',
|
||||
});
|
||||
if (loading) {
|
||||
return <Spin />;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<RouteSwitch routes={data?.data || []} />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export default App;
|
@ -11,4 +11,6 @@ group:
|
||||
|
||||
## compose
|
||||
|
||||
<code src="./demos/demo1.tsx"/>
|
||||
<code src="./demos/demo1/index.tsx"/>
|
||||
|
||||
<code src="./demos/demo2/index.tsx"/>
|
||||
|
Loading…
Reference in New Issue
Block a user