feat: add application demo

This commit is contained in:
chenos 2022-01-17 15:28:28 +08:00
parent 29cf274a52
commit 50e13fe93a
8 changed files with 95 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
sidemenu: false
---
<code src="./src/application/demos/demo2/index.tsx"/>

View 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;

View 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;

View File

@ -11,4 +11,6 @@ group:
## compose ## compose
<code src="./demos/demo1.tsx"/> <code src="./demos/demo1/index.tsx"/>
<code src="./demos/demo2/index.tsx"/>