accountInfo.js 5.0 KB
Newer Older
1 2 3 4 5
import React, { Component } from 'react';
import { findDOMNode } from 'react-dom';
import { observable, computed, toJS } from 'mobx';
import { observer, inject } from 'mobx-react';
import nj from 'nornj';
J
jinlong12 已提交
6
import { Drawer } from 'antd';
7 8
import { registerTmpl } from 'nornj-react';
import { autobind } from 'core-decorators';
9
import JSONTree from 'react-json-tree';
J
jinlong12 已提交
10
import { utf8ToString } from '../../../utils/util';
11 12 13 14 15 16 17 18
import TransactionInfo from '../transactionInfo';
import AccountRootHash from '../../components/accountRootHash';
import 'flarej/lib/components/antd/table';
import Message from 'flarej/lib/components/antd/message';
import KvCount from '../../components/kvcount';
import styles from './accountInfo.m.scss';
import tmpls from './accountInfo.t.html';

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
const theme = {
  base00: '#272822',
  base01: '#383830',
  base02: '#49483e',
  base03: '#75715e',
  base04: '#a59f85',
  base05: '#f8f8f2',
  base06: '#f5f4f1',
  base07: '#f9f8f5',
  base08: '#f92672',
  base09: '#fd971f',
  base0A: '#f4bf75',
  base0B: '#a6e22e',
  base0C: '#a1efe4',
  base0D: '#66d9ef',
  base0E: '#ae81ff',
  base0F: '#cc6633'
};
37 38 39 40 41 42
//页面容器组件
@registerTmpl('AccountInfo')
@inject('store')
@observer
export default class AccountInfo extends Component {

J
jinlong12 已提交
43 44 45 46 47 48 49 50
  @observable kvData = [];
  @observable accountcount = 0;
  @observable accountcurrent = 1;
  @observable pageSize = 10;
  @observable visible = false;
  @observable valueinfo = '';
  @observable valueinfotype = 'BYTES';
  @observable jsondata = '';
51 52 53
  componentDidMount() {
    this.Search();
  }
J
jinlong12 已提交
54 55 56 57
  Search() {
    const { store: { account }, accountData } = this.props;

    if (accountData && accountData.address && accountData.address.value) {
58
      const closeLoading = Message.loading('正在获取数据...', 0);
J
jinlong12 已提交
59 60 61 62 63 64
      let leader = this.props.store.common.getDefaultLedger(),
        param = {
          fromIndex: (this.accountcurrent - 1) * this.pageSize,
          count: this.pageSize,
        },
        address = accountData.address.value;
65
      Promise.all([
J
jinlong12 已提交
66
        account.getEntriescount(leader, address)
67
      ]).then((data) => {
J
jinlong12 已提交
68 69 70 71
        if (data[0] > 0) {
          this.accountcount = data[0];
          Promise.all([account.getEntries(leader, address,
            param
72
          ),
J
jinlong12 已提交
73 74 75 76 77 78
          ]).then((data) => {
            this.kvData = data[0];
            closeLoading();
          });
        }
        else {
79
          closeLoading();
J
jinlong12 已提交
80
        }
81 82 83 84 85 86 87
      });
    }
  }
  ////分页切换
  @autobind
  onPageChange(page, pageSize) {
    const { store: { account } } = this.props;
J
jinlong12 已提交
88
    this.accountcurrent = page;
89 90 91 92
    this.Search();
  }
  // 关闭详细信息
  @autobind
J
jinlong12 已提交
93 94 95
  onClose(visible) {
    this.show = visible;

96 97 98 99
  }

  // 跳转到前置区块
  @autobind
J
jinlong12 已提交
100 101
  goBlock(e) {
    const { goPrev } = this.props;
102 103 104 105 106
    if (goPrev) {
      goPrev(e.target.innerText);
    }
  }

107 108 109
  isJsonString(str) {
    try {
      if (typeof JSON.parse(str) == "object") {
J
jinlong12 已提交
110
        return true;
111
      }
J
jinlong12 已提交
112
    } catch (e) {
113 114 115 116
    }
    return false;
  }

J
jinlong12 已提交
117
  Jsontree = () => {
118
    if (this.isJsonString(this.jsondata)) {
J
jinlong12 已提交
119
      return <JSONTree theme={theme}
120
        data={JSON.parse(this.jsondata)}
J
jinlong12 已提交
121
      />
122
    }
J
jinlong12 已提交
123 124
    else {
      return <JSONTree theme={theme}
125 126 127 128 129 130
        data={this.jsondata}
      />
    }

  };

131 132
  // 查看详细信息
  @autobind
J
jinlong12 已提交
133
  onShowBlockDetails(text, record) {
134
    this.onCloseblockDetails();
J
jinlong12 已提交
135 136 137
    if (record.type.toUpperCase() == 'BYTES') {
      this.valueinfo = utf8ToString(text);
      this.valueinfotype = 'BYTES';
138
    }
J
jinlong12 已提交
139 140
    else if (record.type.toUpperCase() == 'JSON') {
      this.valueinfotype = 'JSON';
141
      this.jsondata = text;
J
jinlong12 已提交
142 143 144 145
    }
    else {
      this.valueinfotype = 'other';
      this.valueinfo = text;
146
    }
147
  }
J
jinlong12 已提交
148 149 150 151
  // 关闭
  @autobind
  onCloseblockDetails() {
    this.visible = !this.visible;
152
  }
J
jinlong12 已提交
153 154 155 156 157 158 159 160 161
  //字符串限制长度
  strOfLength(str, l) {
    console.log(str, l)
    if (str.length > l) {
      return str.substring(0, l) + "...";
    }
    else {
      return str;
    }
162
  }
163 164 165 166 167
  // 交易列表
  @computed get tableColumns() {
    return [{
      title: '',
      dataIndex: 'key',
J
jinlong12 已提交
168 169
      key: 'key'
    }, {
170 171
      title: '',
      dataIndex: 'value',
J
jinlong12 已提交
172 173 174 175 176 177 178 179 180 181 182
      key: 'value',
      // render: (text, record, index) => nj`
      //   ${this.strOfLength(text || '', 50)}&nbsp;&nbsp;&nbsp;
      //   <a onClick=${() => this.onShowBlockDetails(text, record)}>详细</a>
      // `()
      render: (text, record, index) => (
        <div>
          {this.strOfLength(text || '', 50)}&nbsp;&nbsp;&nbsp;
          {text && (<a onClick={() => this.onShowBlockDetails(text, record)}>详细</a>) || null}
        </div>
      )
183 184 185
    }, {
      title: '版本',
      dataIndex: 'version',
J
jinlong12 已提交
186
      width: '10%',
187
      key: 'version',
J
jinlong12 已提交
188
    }, {
189 190
      title: '类型',
      dataIndex: 'type',
J
jinlong12 已提交
191
      width: '10%',
192 193 194 195 196
      key: 'type',
    }];
  }

  render() {
J
jinlong12 已提交
197 198
    const { store: { block }, accountData } = this.props;

199 200 201
    return tmpls.container({
      components: {
        'ant-Drawer': Drawer,
202
        JSONTree
J
jinlong12 已提交
203 204
      }
    }, this.props, this, {
205 206 207 208 209 210
      styles,
      block,
      accountData
    });
  }
}