zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    redux & connect

    import React, {
      Component,
      // useState,
      // useEffect,
    } from 'react';
    
    import { bindActionCreators } from 'redux';
    import { connect } from 'dva';
    
    import dashboardRegionActions from '../actions/dashboard.region.action';
    
    // import { MapChart } from "../MapChart";
    import { SelectOption } from "./SelectOption";
    import { SearchInput } from "./SearchInput";
    
    import * as Provinces from "../Region/provinces.json";
    
    import './index.less';
    
    import {
      Row,
      Col,
      // Input,
      // Icon,
      // Tag,
      // Select,
      // Tooltip,
      // Tabs,
      // Radio,
      // Checkbox,
      // Table,
      // Pagination,
    } from "antd";
    
    const mapStateToProps = ({ dashboard }) => ({
      regionData: dashboard.regionData,
      // mapLoading: dashboard?.mapLoading,
    });
    
    const mapDispatchToProps = dispatch => ({
      actions: bindActionCreators(dashboardRegionActions, dispatch),
    });
    
    @connect(mapStateToProps, mapDispatchToProps,)
    class SelectableIndexList extends Component {
      constructor(props) {
        super(props);
        this.state = {
          placeholder: "请输入省份名或其拼音",
          provincesList: this.selectedFilter(Provinces.default),
          initProvincesList: this.selectedFilter(Provinces.default),
        };
      }
      selectedFilter = (provinces = []) => {
        return provinces.map(obj => {
          if (obj.key === "all") {
            obj.selected = true;
          } else {
            obj.selected = false;
          }
          return obj;
        });
      };
      formatAdcode = (code = "all") => {
        let adcode = 100000;
        if (code !== "all") {
          adcode = Number(`${code}0000`);
        }
        return adcode;
      };
      provincesFilter = (provincesList, key) => {
        const result = provincesList.map(({name, key: code,}) => {
          if (code === key) {
            return {
              name,
              key: code,
              selected: true,
            };
          } else {
            return {
              name,
              key: code,
              selected: false,
            };
          }
        }) || [];
        return result;
      }
      clickCheck = (key) => {
        const {
          // regionData,
          actions: {
            changeRegion,
          },
        } = this.props;
        const {
          provincesList,
          initProvincesList,
        } = this.state;
        const newProvincesList = this.provincesFilter(provincesList, key);
        const newInitProvincesList = this.provincesFilter(initProvincesList, key);
        this.setState({
          provincesList: newProvincesList,
          initProvincesList: newInitProvincesList,
        }, () => {
          // const code = this.formatAdcode(key);
          // changeRegion(code);
          changeRegion(`${key}`);
        });
      };
      handleCheckableTagChange = (value) => {
        const {
          // provincesList,
          initProvincesList: provincesList,
        } = this.state;
        let newProvincesList = provincesList.filter(({name, key, selected}) => {
          if (name.includes(value)) {
            return {
              name,
              key,
              selected,
            };
          }
        }) || [];
        this.setState({
          provincesList: newProvincesList,
        });
      };
      inputChangeHandle = (e) => {
        let value = e.target.value;
        this.handleCheckableTagChange(value);
      };
      render() {
        const {
          placeholder,
          provincesList,
        } = this.state;
        return (
          <>
            <Row className="selectable-index-list">
              <Col span={24} className="input-box">
                {
                  SearchInput({
                    placeholder: placeholder,
                    inputChangeHandle: this.inputChangeHandle,
                  })
                }
              </Col>
              <Col span={24} className="option-box">
                <SelectOption
                  provincesList={provincesList}
                  clickCheck={this.clickCheck}
                />
              </Col>
            </Row>
          </>
        );
      }
    }
    
    export {
      SelectableIndexList,
    };
    
    export default SelectableIndexList;
    
    
    

    const mapStateToProps = ({ dashboard }) => ({
      regionData: dashboard.regionData,
      // mapLoading: dashboard?.mapLoading,
    });
    
    const mapDispatchToProps = dispatch => ({
      actions: bindActionCreators(dashboardRegionActions, dispatch),
    });
    
    // export default connect(
    //   mapStateToProps,
    //   mapDispatchToProps,
    // )(RegionChart);
    // @connect(mapStateToProps, mapDispatchToProps,)
    
    

  • 相关阅读:
    jquery正则表达式验证:正整数(限制长度)
    H5页面快速搭建之高级字体应用实践
    如何用Python写一个贪吃蛇AI
    HashMap多线程并发问题分析
    为RecyclerView打造通用Adapter 让RecyclerView更加好用
    学好Mac常用命令,助力iOS开发
    使用 Realm 和 Swift 创建 ToDo 应用
    看Facebook是如何优化React Native性能
    利用github搭建个人maven仓库
    Objective-C Runtime之着魔的UIAlertView
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/11680002.html
Copyright © 2011-2022 走看看