2.0.11 • Published 9 months ago

@jswork/react-ant-abstract-curd v2.0.11

Weekly downloads
703
License
MIT
Repository
-
Last release
9 months ago

react-ant-abstract-curd

Antd abstract curd.

version license size download

installation

npm install -S @jswork/react-ant-abstract-curd

usage

  1. import css

    @import "~@jswork/react-ant-abstract-curd/dist/style.css";
    
    // or use sass
    @import "~@jswork/react-ant-abstract-curd/dist/style.scss";
    
    // customize your styles:
    $react-ant-abstract-curd-options: ()
  2. import js

    import * as React from 'react';
    import * as ReactDOM from 'react-dom';
    import { Card, Space } from 'antd';
    import { UnorderedListOutlined } from '@ant-design/icons';
    import ReactAntAbstractCurd from '@jswork/react-ant-abstract-curd';
    import '../../src/components/style.scss';
    import './style.css';
    import EventMitt from '@jswork/event-mitt';
    import nx from '@jswork/next';
    import '@jswork/next-param';
    import '@jswork/next-ant-column';
    
    // http://localhost:3000/#/?page=1&size=10
    
    class ApiService {
      static repos_index(inData) {
        var url = nx.param(inData, 'https://jsonplaceholder.typicode.com/posts');
        return fetch(url).then((res) => res.json());
      }
    
      static repos_destroy(inData): Promise<any> {
        return new Promise((resolve) => {
          console.log('call destroy api', inData);
          resolve(inData);
        });
      }
    }
    
    class RouteService {
      static push(inUrl) {
        console.log('push to:', inUrl);
      }
    }
    
    /**
     * apiService: nx.$api
     * eventService: nx.$event
     * routeService: nx.$route
     * engineType: nx.$local | nx.$session
     */
    
    class Index extends ReactAntAbstractCurd {
      apiService = ApiService; // nx.$api
      routeService = RouteService; // nx.$route
      eventService = nx.mix(this, EventMitt); // nx.$app
      resources = 'repos';
      searchable = true;
      pagination = {
        page: 'page',
        size: 'per_page',
        total: 'total'
      };
    
      get fields() {
        return [
          nx.antColumn('ID', 'id'),
          nx.antColumn('title', 'title'),
          nx.antColumn('body', 'body', (text) => String(text)),
          nx.antColumn('uid', 'userId')
        ];
      }
    
      setResponse(res) {
        return {
          rows: res,
          total: 100
        };
      }
    
      get titleView() {
        return (
          <Space>
            <UnorderedListOutlined />
            <span>列表管理</span>
          </Space>
        );
      }
    
      render() {
        return (
          <Card title={this.titleView} className="m10 react-ant-abstract-curd" extra={this.extraView}>
            {this.table()}
          </Card>
        );
      }
    }
    
    ReactDOM.render(<Index />, document.getElementById('root'));

preview

license

Code released under the MIT license.

2.0.9

9 months ago

2.0.8

10 months ago

2.0.11

9 months ago

2.0.10

9 months ago

2.0.7

12 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.1

1 year ago

1.2.13

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.9

1 year ago

1.2.12

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.0

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.16

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago