Merge branch 'master' into release-next

This commit is contained in:
ClarkXia 2020-12-02 18:23:24 +08:00
commit 98fbd6581d
8 changed files with 19 additions and 30 deletions

View File

@ -9,26 +9,7 @@ order: 9
- 操作权限:页面中的某些按钮或组件针对无权限的用户直接隐藏;
- 接口权限:当用户通过操作调用没有权限的接口时跳转到无权限页面。
## 使用权限插件
### 安装
```bash
# 安装权限插件
$ npm install build-plugin-ice-auth --save-dev
```
### 配置
`build.json` 中配置权限插件
```json
{
"plugins": [
"build-plugin-ice-auth"
]
}
```
> 框架默认内置权限插件,开发者无需安装。如果 ice.js 版本低于 1.11.2,需要自行安装 `build-plugin-ice-auth` 依赖,并在 `build.json` 中引入该插件。
## 初始化权限数据

View File

@ -53,8 +53,12 @@ runApp(appConfig);
- 服务端渲染时直接调用 `getInitialData` 获取数据并渲染应用,同时将数据注入到全局变量中
- 浏览器端渲染时不再调用 `getInitialData`,会直接通过全局变量获取初始数据
- 可以获取到当前请求的上下文 `ctx` 参数,包含以下字段
- `ctx.req`HTTP request 对象 仅在server端输出
- `ctx.res`HTTP response 对象 仅在server端输出
- `ctx.req`HTTP request 对象 (仅在 server 端输出)
- `ctx.res`HTTP response 对象 (仅在 server 端输出)
- `ctx.pathname`:当前路由路径
- `ctx.query`:请求参数对象
- `ctx.path`URL 路径(包括请求参数)
- `ctx.ssrError`:服务端渲染时错误信息(仅在 client 端输出)
未开启 SSR 的行为说明:
@ -107,8 +111,12 @@ SEO 场景下,需要访问每个页面时都能够返回实际的 DOM 节点
在页面级组件中通过 `Component.getInitialProps` 来获取页面初始数据,同时可以获取到当前请求的上下文 `ctx` 参数,包含以下字段:
- `ctx.req`HTTP request 对象 仅在server端输出
- `ctx.res`HTTP response 对象 仅在server端输出
- `ctx.req`HTTP request 对象 (仅在 server 端输出)
- `ctx.res`HTTP response 对象 (仅在 server 端输出)
- `ctx.pathname`:当前路由路径
- `ctx.query`:请求参数对象
- `ctx.path`URL 路径(包括请求参数)
- `ctx.ssrError`:服务端渲染时错误信息(仅在 client 端输出)
```diff
import { request } from 'ice';

View File

@ -131,12 +131,12 @@ const routerConfig = [
import { useAuth, Redirect } from 'ice';
const LoginWrapper = (WrappedComponent) => {
const Wrapped = () => {
const Wrapped = (props) => {
const [auth] = useAuth();
return (
<>
{
auth.isLogin ? <WrappedComponent {...props} /> : <Redirect to="/login" />;
auth.isLogin ? <WrappedComponent {...props} /> : <Redirect to="/login" />
}
</>
)

View File

@ -1,6 +1,7 @@
import React from 'react';
import { runApp, APP_MODE, IAppConfig, request } from 'ice';
console.log('APP_MODE', APP_MODE);
const appConfig: IAppConfig = {
app: {
rootId: 'ice-container',

View File

@ -22,7 +22,7 @@
},
"dependencies": {
"@alib/build-scripts": "^0.1.13",
"build-plugin-app-core": "0.1.25",
"build-plugin-app-core": "0.1.26",
"build-plugin-ice-auth": "1.7.2",
"build-plugin-ice-config": "1.7.1",
"build-plugin-ice-helpers": "1.7.1",

View File

@ -1,6 +1,6 @@
{
"name": "build-plugin-app-core",
"version": "0.1.25",
"version": "0.1.26",
"description": "the core plugin for icejs and raxjs.",
"author": "ice-admin@alibaba-inc.com",
"homepage": "",

View File

@ -1,8 +1,8 @@
import { runApp } from './runApp';
export { APP_MODE } from './appMode';
export * from './runApp';
export { lazy } from './lazy';
export * from './types';
export const APP_MODE = (global as any).__app_mode__ || process.env.APP_MODE;
export function createApp(appConfig, staticConfig?: any) {
console.warn('Detected that you are using createApp, please use runApp method, Visit https://ice.work/docs/guide/basic/api.');

View File

@ -1 +0,0 @@
export const APP_MODE = (global as any).__app_mode__ || process.env.APP_MODE;