提交 46ee3137ebde7e637d5355358223cb84c888e535

作者 愚道
1 个父辈 b722388c

add a blank block

  1 +/yarn.lock
  2 +/package-lock.json
  3 +/dist
  4 +/node_modules
  5 +/pages
  6 +.umi
  7 +.umi-production
... ...
  1 +export default {
  2 + plugins: [
  3 + ['umi-plugin-block-dev', {
  4 + 'layout': 'ant-design-pro',
  5 + }],
  6 + ['umi-plugin-react', {
  7 + 'dva': true,
  8 + 'antd': true,
  9 + }]
  10 + ],
  11 +}
... ...
  1 +The MIT License (MIT)
  2 +
  3 +Copyright (c) 2018-present yutingzhao1991 (yutingzhao1991@sina.com)
  4 +
  5 +Permission is hereby granted, free of charge, to any person obtaining a copy
  6 +of this software and associated documentation files (the "Software"), to deal
  7 +in the Software without restriction, including without limitation the rights
  8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 +copies of the Software, and to permit persons to whom the Software is
  10 +furnished to do so, subject to the following conditions:
  11 +
  12 +The above copyright notice and this permission notice shall be included in
  13 +all copies or substantial portions of the Software.
  14 +
  15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21 +THE SOFTWARE.
... ...
  1 +# @umi-material/blank
  2 +
  3 +A blank block for quick start a umi page develop.
  4 +
  5 +## Usage
  6 +
  7 +```sh
  8 +umi block https://github.com/umijs/umi-blocks/tree/master/blank
  9 +```
  10 +
  11 +## LICENSE
  12 +
  13 +MIT
... ...
  1 +{
  2 + "name": "@umi-block/blank",
  3 + "version": "0.0.1",
  4 + "description": "A blank block for quick start a umi page develop.",
  5 + "main": "src/index.js",
  6 + "scripts": {
  7 + "dev": "umi dev"
  8 + },
  9 + "repository": {
  10 + "type": "git",
  11 + "url": "https://github.com/umijs/umi-blocks/blank"
  12 + },
  13 + "dependencies": {
  14 + "react": ">=16.0.0",
  15 + "umi-request": "^1.0.0"
  16 + },
  17 + "devDependencies": {
  18 + "umi": "^2.3.0-beta.1",
  19 + "umi-plugin-block-dev": "^1.0.0",
  20 + "umi-plugin-react": "^1.3.0-beta.1"
  21 + },
  22 + "authors": [
  23 + "yutingzhao1991 <yutingzhao1991@sina.com>"
  24 + ],
  25 + "license": "ISC"
  26 +}
... ...
  1 +export default {
  2 + 'GET /api/text': {
  3 + text: 'I am a blank block',
  4 + },
  5 +};
... ...
  1 +import React, { Component } from 'react';
  2 +import { Button } from 'antd';
  3 +import { connect } from 'dva';
  4 +
  5 +import styles from './style.less';
  6 +
  7 +// TODO: Page 修改为有意义的名称
  8 +@connect(({ page }) => page)
  9 +class Page extends Component {
  10 + componentDidMount() {
  11 + const { dispatch } = this.props;
  12 + dispatch({
  13 + type: 'page/fetch',
  14 + });
  15 + }
  16 +
  17 + render() {
  18 + const { text } = this.props;
  19 + return (
  20 + <div className={styles.container}>
  21 + <Button>{text}</Button>
  22 + </div>
  23 + );
  24 + }
  25 +}
  26 +
  27 +export default Page;
... ...
  1 +import { getText } from './service';
  2 +
  3 +export default {
  4 + namespace: 'page', // TODO: 修改为有意义的 namespace
  5 + state: {
  6 + text: 'loading...',
  7 + },
  8 +
  9 + effects: {
  10 + *fetch(_, { call, put }) {
  11 + const { text } = yield call(getText);
  12 + yield put({
  13 + type: 'save',
  14 + payload: {
  15 + text,
  16 + },
  17 + });
  18 + },
  19 + },
  20 +
  21 + reducers: {
  22 + save(state, { payload }) {
  23 + return {
  24 + ...state,
  25 + ...payload,
  26 + };
  27 + },
  28 + },
  29 +};
... ...
  1 +import request from 'umi-request';
  2 +
  3 +export function getText() {
  4 + return request('/api/text');
  5 +}
... ...
  1 +.container {
  2 + padding: 8px;
  3 +}
... ...
注册登录 后发表评论