deploy.js 4.5 KB
Newer Older
vipcxj's avatar
vipcxj committed
1 2 3 4 5 6
/* eslint-disable no-undef,jsx-a11y/img-has-alt */
/**
 * Created by zhouhuan on 2017/11/21.
 */
import React from 'react';
import QRcode from 'qrcode';
7
import { Button, Table, Popconfirm, Modal, Divider } from 'antd';
vipcxj's avatar
vipcxj committed
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
import config from '../../../../utils/config';
import { encrypt } from '../../../../utils/helper';
import styles from './list.less';
import { thisPush } from '../../../../services/route';

class Deploy extends React.Component {
  state = {
    urls: '',
    visible: false,
    completeUrl: '',
  };
  componentDidMount() {
    this.props.dispatch({ type: 'appInfo/getTokens' });
    const { value } = this.props.location.state;
    // console.log(value);
    this.props.dispatch({ type: 'appInfo/getAppInfo', payload: { name: value.name } });
  }
  onDelete = (record) => {
    const id = record.id;
    const { value } = this.props.location.state;
    this.props.dispatch({ type: 'appInfo/removeDeployApp', payload: { id, name: value.name } });
  };
  onEdit = (record) => {
    const { value } = this.props.location.state;
    thisPush(this, { pathname: '../editDeploy', state: { record, value } });
  };
  onQrcode = (record) => {
    const { token } = this.props.appInfo;
    const tokens = encrypt(token);
    const uri = record.uri;
    const URL = `${config.apiContextPath}/resource/${tokens}/${encodeURIComponent(uri)}`;
    // console.log(document.location.href);
    const browerUrl = (document.location.href).split(`${config.contextPath}/main`)[0];
    const completeUrl = browerUrl + URL;
    this.setState({ completeUrl });
    // console.log(completeUrl);
    QRcode.toDataURL(completeUrl, (err, url) => {
      this.setState({ urls: url, visible: true });
    });
    // const w = window.open('about:blank');
    // w.location.href = URL;
  };
  onClick = () => {
    const { value } = this.props.location.state;
    thisPush(this, { pathname: '../addDeploy', state: { value } });
  };
  handleOk = () => {
    this.setState({
      visible: false,
    });
  };
  handleCancel = () => {
    this.setState({
      visible: false,
    });
  };
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  makeColumns = () => {
    return [{
      title: 'ID',
      dataIndex: 'id',
    }, {
      title: '更新时间',
      dataIndex: 'updateTime',
    }, {
      title: '状态',
      dataIndex: 'status',
    }, {
      title: '版本号',
      dataIndex: 'versionNumber',
    }, {
      title: '描述',
      dataIndex: 'description',
    }, {
      title: 'uri',
      dataIndex: 'uri',
    }, {
      title: '操作',
      dataIndex: 'operation',
      render: (text, record, index) => (
        <span>
          <Divider type="vertical" />
          <a onClick={() => this.onEdit(record, index)}>Edit</a>
          <Divider type="vertical" />
          <Popconfirm title="确定删除?" okText="Yes" cancelText="No" onConfirm={() => this.onDelete(record, index)}>
            <a>Delete</a>
          </Popconfirm>
          <Divider type="vertical" />
          <a onClick={() => this.onQrcode(record, index)}>qrcode</a>
        </span>
      ),
    }];
  };
vipcxj's avatar
vipcxj committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  render() {
    const { allAppInfo } = this.props.appInfo;
    const { urls, visible, completeUrl } = this.state;
    let data = [];
    if (allAppInfo.length !== 0) {
      allAppInfo.map(({ history }) => {
        data = history.map(({ id, updateTime, status, versionNumber, description, uri }) => {
          const date = (new Date(updateTime)).toLocaleString();
          return {
            key: updateTime,
            id,
            updateTime: date,
            status,
            versionNumber,
            description,
            uri,
          };
        });
        return data;
      });
    }
    return (
      <div className={styles.wrapper}>
        <div className={styles.container}>
          <div className={styles.divBtn}>
            <Button type="primary" icon="plus" onClick={this.onClick}>新增</Button>
          </div>
          <div className={styles.divTable}>
128
            <Table columns={this.makeColumns()} dataSource={data} />
vipcxj's avatar
vipcxj committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
          </div>
          <div>
            <Modal
              title="二维码"
              visible={visible}
              onOk={this.handleOk}
              onCancel={this.handleCancel}
              footer={null}
            >
              <div style={{ textAlign: 'center' }}>
                <img src={urls} alt="二维码" />
                <div>
                  <a href={completeUrl} className={styles.a}>{completeUrl}</a>
                </div>
              </div>
            </Modal>
          </div>
        </div>
      </div>
    );
  }
}

export default Deploy;