4.1.3 • Published 1 year ago

shoplazza-sdk v4.1.3

Weekly downloads
490
License
MIT
Repository
gitlab
Last release
1 year ago

shoplazza sdk

此 SDK 包含 Shoplazza UI 组件规范(基于 ant design)以及嵌入 Admin 后台 app 的脚手架

应用此 SDK 能构建前端微服务高度模块化应用 EmbedAppSmartApp

shoplazza sdk 使用技术栈 React+ReatIntl+Mobx+ReactRouter+Webpack

Get started

启动实例

cd examples
npm i
npm run dev

应用模块开发

src 目录下每一个文件夹即一个模块.模块的构成包括 路由定义,mobox model 定义,多语言语料定义. 这些定义都放在模块入口index.js

demo : src/mymodule/index.js

export default ({ routes, models, messages, locale }) => {
  const rootRoute = routes.filter(r => r.path === '/')[0];
  rootRoute.routes = [
    {
      path: '/admin/smart_apps/abc',
      exact: true,
      component: () => <div>my component</div>
    }
  ].concat(rootRoute.routes);
  Object.assign(models, { mymodel });
  Object.assign(messages, require('./locale/' + locale).default);
};

App 启动入口 ShoplazzaApp

ShoplazzaApp 适用于 EmbedAppSmartApp 两种 app 形式入口,开发者可以无区别的开发应用模块.SmartApp 会有一些特殊的约定

下面是 SmartApp 项目文件示例 index.js

import React from 'react';
import ReactDOM from 'react-dom';
import { ShoplazzaApp } from 'shoplazza-sdk';

let basename = '/';
/* {{basename}} */
const modules = app => {
  /* {{modules}} */
};
const App = () => <ShoplazzaApp modules={modules} basename={basename} />;
App.displayName = 'Siamese';
window.Siamese = App;
window.INTEGRATION_ENV || ReactDOM.render(<App />, document.getElementById('root'));

/* {{basename}} */注释会在 webpack 中 loader 替换成 环境变量中的 basename /* {{modules}} */ 会被替换成系统模块的入口注册代码,module 可以在启动时指定(npm run dev -- --modules=module1,module2),默认全部启动

开发嵌入式应用 EmbedApp

  • EmbedApp 是以 iframe 方式嵌入到父窗口中,用于强隔离实现.
  • 部署后 app 是以 iframe 方式嵌入到主站中,通过 iframe post message 双向通信来控制顶部条
  • 开发嵌入式应用与主站 module 开发基本一致,详见主站开发文档

开发 SmartApp

  • SmartApp 是以 js 注入方式嵌入到主站中. 相比 SmartApp 需要遵循如下约定

  • 根组件需要全局暴露.而且所有路由必须以 /admin/smart_apps/{rootComponentName} 开头,这样跟主站的路由是一致的

  • 根组件条件 render,集成模式 window.INTEGRATION_ENV = true,根组件的生命周期由主站接管
  • webpack output 配置 防止多个 webpack 对象冲突 output: { jsonpFunction: 'webpackJsonp' + Math.random().toString(16).substr(2) },SmartApp 跟主站使用 package 是隔离的.除了 external 引入的 vendor lib
  • 样式隔离
    • 配置 style-loader { loader: 'style-loader', options: { attrs: { class: appName } } },给生成的 style 元素增加类名,SmartApp 卸载时将会移除其相关的样式,避免形成样式污染
    • 配置 prefixCls app.prefixCls = appName 替换 antd 的 class 前缀,防止对主站样式形成污染
    • 如需使用 loading 这个 model,需使用 import { request } from shoplazza-sdk

内置 model

内部 mobx model 使用与普通 model 无异

@inject('breadcrumb', 'loading')
export default class Detail extends Component {}

breadcrumb model: 预设置的主站行为

const defaultValues = {
  backStatus: false, // 是否显示返回按钮
  backClick: () => {}, // 返回点击事件
  breadcrumbName: '', // 返回文案

  onConfirmSave: () => {}, // 保存按钮事件回调
  onConfirmCancel: () => {}, // 取消更改按钮事件回调
  showButtonsWhenDirty: true, // 是否显示保存按钮
  isBreadCrumbDirty: false, // model 是否已经修改
  raw: '', // 原始数据

  // 自定义顶部按钮(尚未实现)
  extraButtons: [
    /*{ name:'btn1', children:"普通按钮" },{ name:'btn2', type:"primary", children:"首选按钮", disabled:true }*/
  ],
  onExtraButtonClick: () => {}
};

保存取消按钮部分逻辑建议使用方法修改.不需要直接访问,breadcrumb 提供的方法(withUnSavedWarning HOC 废弃)

@inject('breadcrumb', 'loading')
export default class Detail extends Component {
  componentDidMount() {
    const { breadcrumb } = this.props;
    breadcrumb.reset(); //所有状态恢复成默认值

    breadcrumb.setSnapshot(); //设置比较基准快照
    breadcrumb.getSnapshot(); //设置比较基准快照
    breadcrumb.resetSnapshot(); //设置比较基准快照

    breadcrumb.setSaveHandler(); //设置保存回调
    breadcrumb.setCancelHandler(); //设置取消保存回调

    breadcrumb.push(); //主站安全的跳转.参数同`history.push`
    breadcrumb.open(); //安全的打开窗口.参数从'window.open'
  }
}

loading model

intercept axios request,请求 url 作为 key, 记录请求是否 pending

@inject('breadcrumb', 'loading')
export default class Detail extends Component {
  async componentDidMount() {
    const { loading } = this.props;
    const res = await Axios.get('admin/data'); // loading['admin/data'] = true
  }

  render() {
    const { loading } = this.props;
    return loading['admin/data'] ? <div>loading</div> : null;
  }
}

注意请求 url 不能以/开头

默认的 axios baseURL 配置 request.defaults.baseURL = basename + 'api/';

定制组件详见src/index.js

发布 package 新版本

export NPM_TOKEN="xxxxxxxxx"
npm version patch
npm i
npm run build
nrm use npm
npm publish
5.1.0

1 year ago

5.2.0

1 year ago

5.3.2

1 year ago

5.3.1

1 year ago

5.3.0

1 year ago

6.1.0

1 year ago

5.4.1

1 year ago

5.4.0

1 year ago

4.1.3

1 year ago

4.1.0

1 year ago

4.1.2

1 year ago

4.1.1

1 year ago

6.0.23

1 year ago

4.0.27

1 year ago

5.0.71

1 year ago

3.0.31

1 year ago

6.0.22

2 years ago

6.0.21

2 years ago

4.0.26

2 years ago

4.0.25

2 years ago

5.0.70

2 years ago

5.0.68

2 years ago

5.0.69

2 years ago

3.0.30

2 years ago

6.0.20

2 years ago

6.0.19

2 years ago

6.0.18

2 years ago

6.0.17

2 years ago

5.0.61

2 years ago

5.0.62

2 years ago

5.0.63

2 years ago

5.0.64

2 years ago

5.0.65

2 years ago

5.0.66

2 years ago

5.0.67

2 years ago

3.0.27

2 years ago

3.0.28

2 years ago

3.0.29

2 years ago

6.0.16

2 years ago

4.0.23

2 years ago

4.0.24

2 years ago

5.0.60

2 years ago

3.0.26

2 years ago

5.0.57

2 years ago

5.0.58

2 years ago

5.0.59

2 years ago

6.0.15

3 years ago

6.0.14

3 years ago

6.0.13

3 years ago

6.0.12

3 years ago

3.0.25

3 years ago

6.0.11

3 years ago

6.0.10

3 years ago

5.0.53

3 years ago

5.0.54

3 years ago

5.0.55

3 years ago

5.0.56

3 years ago

5.0.52

3 years ago

5.0.51

3 years ago

3.0.24

3 years ago

5.0.50

3 years ago

5.0.49

3 years ago

5.0.46

3 years ago

5.0.47

3 years ago

5.0.48

3 years ago

5.0.45

3 years ago

4.0.22

3 years ago

6.0.9

3 years ago

3.0.23

3 years ago

5.0.44

3 years ago

6.0.8

3 years ago

5.0.43

3 years ago

5.0.42

3 years ago

5.0.41

3 years ago

5.0.36

3 years ago

5.0.37

3 years ago

5.0.38

3 years ago

5.0.39

3 years ago

5.0.40

3 years ago

4.0.21

4 years ago

6.0.7

4 years ago

3.0.22

4 years ago

6.0.6

4 years ago

5.0.35

4 years ago

3.0.20

4 years ago

5.0.34

4 years ago

6.0.1

4 years ago

6.0.3

4 years ago

6.0.4

4 years ago

5.0.32

4 years ago

5.0.33

4 years ago

5.0.31

4 years ago

5.0.30

4 years ago

5.0.29

4 years ago

5.0.28

4 years ago

5.0.24

4 years ago

5.0.25

4 years ago

5.0.26

4 years ago

5.0.27

4 years ago

5.0.22

4 years ago

5.0.23

4 years ago

5.0.21

4 years ago

5.0.20

4 years ago

5.0.19

4 years ago

5.0.11

4 years ago

5.0.12

4 years ago

5.0.13

4 years ago

5.0.14

4 years ago

5.0.15

4 years ago

5.0.16

4 years ago

5.0.17

4 years ago

5.0.18

4 years ago

5.0.10

4 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

4 years ago

5.0.6

4 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

3.0.18

4 years ago

3.0.19

4 years ago

3.0.13

4 years ago

3.0.16

4 years ago

3.0.17

4 years ago

3.0.14

4 years ago

3.0.15

4 years ago

4.0.19

4 years ago

4.0.18

4 years ago

3.0.12

4 years ago

3.0.11

4 years ago

4.0.17

4 years ago

3.0.10

4 years ago

4.0.16

4 years ago

3.0.8

4 years ago

4.0.15

4 years ago

4.0.12

4 years ago

4.0.14

4 years ago

4.0.13

4 years ago

3.0.9

4 years ago

4.0.10

4 years ago

4.0.11

4 years ago

4.0.9

4 years ago

4.0.8

4 years ago

3.0.7

4 years ago

4.0.7

4 years ago

4.0.6

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

4.0.5

4 years ago

3.0.4

4 years ago

4.0.4

4 years ago

3.0.3

4 years ago

4.0.3

4 years ago

3.0.2

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

4.0.0

4 years ago

2.0.0

4 years ago

1.8.25

4 years ago

1.8.24

4 years ago

1.8.23

4 years ago

1.8.22

4 years ago

1.8.21

4 years ago

1.8.20

4 years ago

1.7.54

4 years ago

1.7.53

4 years ago

1.7.51

4 years ago

1.7.52

4 years ago

1.7.50

4 years ago

1.7.49

4 years ago

1.7.47

4 years ago

1.7.46

4 years ago

1.8.17

4 years ago

1.8.18

4 years ago

1.8.19

4 years ago

1.7.45

4 years ago

1.8.16

4 years ago

1.7.44

4 years ago

1.7.43

4 years ago

1.7.42

4 years ago

1.7.41

4 years ago

1.7.39

4 years ago

1.7.40

4 years ago

1.7.38

4 years ago

1.7.37

4 years ago

1.8.15

4 years ago

1.7.36

4 years ago

1.8.14

4 years ago

1.7.35

4 years ago

1.7.34

4 years ago

1.7.33

4 years ago

1.7.32

4 years ago

1.7.31

4 years ago

1.7.30

4 years ago

1.7.29

4 years ago

1.7.28

4 years ago

1.7.27

4 years ago

1.7.26

4 years ago

1.7.25

4 years ago

1.7.24

4 years ago

1.7.20

4 years ago

1.7.21

4 years ago

1.7.22

4 years ago

1.7.23

4 years ago

1.8.13

4 years ago

1.8.12

4 years ago

1.8.10

4 years ago

1.8.11

4 years ago

1.8.9

4 years ago

1.8.8

4 years ago

1.8.7

4 years ago

1.7.19

4 years ago

1.7.18

4 years ago

1.7.17

4 years ago

1.7.14

4 years ago

1.7.15

4 years ago

1.7.16

4 years ago

1.8.6

4 years ago

1.8.5

4 years ago

1.8.4

4 years ago

1.8.3

4 years ago

1.7.13

5 years ago

1.8.2

5 years ago

1.8.0

5 years ago

1.7.12

5 years ago

1.7.11

5 years ago

1.7.10

5 years ago

1.7.9

5 years ago

1.7.8

5 years ago

1.7.7

5 years ago

1.7.6

5 years ago

1.7.5

5 years ago

1.7.4

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.20

5 years ago

1.6.19

5 years ago

1.6.18

5 years ago

1.6.17

5 years ago

1.6.16

5 years ago

1.6.15

5 years ago

1.6.14

5 years ago

1.6.13

5 years ago

1.6.12

5 years ago

1.6.11

5 years ago

1.6.10

5 years ago

1.6.9

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.0.0

6 years ago