@abegalinov/backoffice-skeleton 中文文档教程

发布于 4年前 浏览 25 项目主页 更新于 3年前

Backoffice skeleton

简单的后台前端应用程序框架。

Getting Started

该框架基于react、redux和material-ui。 一种允许您构建管理界面并在从头开始时避免额外样板的框架。

它的灵感来自于 react-admin 和 admin-on-rest 框架。 然而,其动机是使其更具可定制性,并实际使用 React 和 Redux 构建应用程序,而不是配置一些东西来达到预期的结果。

它支持授权,导航菜单,基本上没有别的。

为了开始构建应用程序,您只需要将组件、redux reducer 和服务注入应用程序,从那时起您就可以专注于应用程序开发。 此外,它还支持服务注册中心,这是一种自排序的依赖注入机制,可以在其中注入服务以及覆盖现有服务。

Installing

只需简单地安装 npm 包就可以开始了:

npm install @abegalinov/backoffice-skeleton

Usage

import BackOfficeSkeleton from '@abegalinov/backoffice-skeleton';
import { AUTH_SERVICE } from '@abegalinov/services';

const app = new BackOfficeSkeleton();

app.addResource({ path: "/", component: YourComponent, icon: MaterialUIIconComponent, name: "Menu item", title: "Component title" });
app.getServiceRegistry().registerService(AUTH_SERVICE, new YourAuthService());
app.injectReducers({yourReducerNamespace: yourReducer});

const App = app.createComponent();

ReactDOM.render(<App />, document.getElementById('root'));

上面的简单设置使一个组件显示在导航菜单中,并将该组件安装在 / 路由上。 此外,它还注入了一个自定义授权服务,默认情况下是模拟的。 您可以查看模拟在 src/services/MockAuthService.js 中的工作原理,以了解概念以便编写真实的模拟。

同样在上面的示例中,它显示了如何将 reducer 注入到应用程序中,您可以为您的应用程序编写一个会影响存储状态的 reducer(实际上它是命名空间的一部分,因为 combineReducers() 是用过的)。

还有一件小事要提:在调度的动作(函数,因为 thunk 被使用)你可以访问 ServiceRegistry,它作为第三个参数传递给函数使用 dispatchgetState

更新:添加了一小部分功能,以便在应用程序主实例之外的不同服务中使用授权令牌,您现在可以简单地调用:

const app = new BackOfficeSkeleton();
const getToken = app.getAuthTokenCallback();

// and then in order to make an authorized request call the callback to get the authorization token:

const authToken = getToken();

License

该项目已根据 MIT 许可证获得许可 - 请参阅 LICENSE< /a> 详细信息文件

Backoffice skeleton

Simple backoffice frontend applications framework.

Getting Started

The framework is based on react, redux and material-ui. Kind of a skeleton that allows you to build admin interfaces and avoid additional boilerplate when starting from scratch.

It was inspired by react-admin and admin-on-rest frameworks. However, the motivation is to make it more customizable and actually build applications using react and redux, instead of configuring something to achieve desired results.

It supports authorization, navigation menu and basically nothing else.

In order to start building applications you just need to inject your components, redux reducers and services to the application and from that point on you can focus on your application development. Also, it supports the service registry which is self-sort of a dependency injection mechanism where services can be injected as well as the existing services can be overridden.

Installing

Just simply install the npm package and you are ready to go:

npm install @abegalinov/backoffice-skeleton

Usage

import BackOfficeSkeleton from '@abegalinov/backoffice-skeleton';
import { AUTH_SERVICE } from '@abegalinov/services';

const app = new BackOfficeSkeleton();

app.addResource({ path: "/", component: YourComponent, icon: MaterialUIIconComponent, name: "Menu item", title: "Component title" });
app.getServiceRegistry().registerService(AUTH_SERVICE, new YourAuthService());
app.injectReducers({yourReducerNamespace: yourReducer});

const App = app.createComponent();

ReactDOM.render(<App />, document.getElementById('root'));

The simple setup above makes a component to be shown in the navigation menu and also mounts the component on / route. Also, it injects a custom authorization service, which is mocked by default. You can have a look at how the mock works in src/services/MockAuthService.js to understand the concept in order to write a real one.

Also in the example above it is shown how a reducer getting injected in the application, you can write a reducer for your application which would affect the store state (actually its part by namespace, since combineReducers() is used).

One more small thing to mention: in the dispatched actions (functions, because thunk is being used) you can access ServiceRegistry, it is passed as the third argument to the function along with dispatch, getState.

Update: a small piece of functionality was added in order to use authorization token in different services outside the app main instance you can now simply call:

const app = new BackOfficeSkeleton();
const getToken = app.getAuthTokenCallback();

// and then in order to make an authorized request call the callback to get the authorization token:

const authToken = getToken();

License

This project is licensed under the MIT License - see the LICENSE file for details

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文