Basic.js 1.82 KB
Newer Older
涂茜's avatar
涂茜 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
import React from 'react';
import PandaImageSelect from '../index';
import request from 'umi-request';

class Demo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      dataSource: [],
      Authorization: '',
    };
  }

  onSelect = (value) => {
    console.log(value, 'PandaImageSelect-value');
  };

  fetchData = (params = {}) => {
    const _this = this;
    const { Authorization } = this.state;
    request(baseUrl + '/Publish/OMS/FileCenter/GetImageOrderByPath', {
      headers: { Authorization },
      method: 'get',
      params: {
        path: 'assets/images/appMenu',
        maxLength: 279.1525423728813,
        fileName: params.fileName ? params.fileName : '',
      },
    }).then(function (response) {
      _this.setState({
        dataSource: response.data,
      });
    });
  };

  // 获取token
  componentDidMount() {
    const _this = this;
    request(baseUrl + '/Publish/GateWay/OMS/OMSLogin', {
      method: 'post',
      requestType: 'form',
      data: {
        userName: 'omsa',
        password: 'pandaomsa',
      },
    })
      .then(function (response) {
        if (response.data.token) {
          const { access_token, token_type } = response.data.token;
          _this.setState(
            {
              Authorization: token_type + ' ' + access_token,
            },
            () => {
              _this.fetchData();
            },
          );
        }
      })
      .catch(function (error) {
        console.log(error);
      });
  }

  render() {
    return (
      <PandaImageSelect
        onSearch={(params) => this.fetchData(params)}
        dataSource={this.state.dataSource}
        onSelect={(value) => this.onSelect(value)}
        url={baseUrl}
      />
    );
  }
}

export default Demo;

const baseUrl = 'http://192.168.10.150:8777'; // window.location.origin