accountInfo.js 4.6 KB
Newer Older
1 2 3 4 5 6 7 8
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';
import { Drawer} from 'antd';
import { registerTmpl } from 'nornj-react';
import { autobind } from 'core-decorators';
9 10
import JSONTree from 'react-json-tree';
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 43 44 45 46 47 48
//页面容器组件
@registerTmpl('AccountInfo')
@inject('store')
@observer
export default class AccountInfo extends Component {

  @observable kvData=[];
  @observable accountcount=0;  
  @observable accountcurrent=1;  
  @observable pageSize=10; 
  @observable visible=false;
  @observable valueinfo='';
49 50
  @observable valueinfotype='BYTES';
  @observable jsondata ='';
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  componentDidMount() {
    this.Search();
  }
  Search(){
    const { store: { account },accountData} = this.props;
    
    if (accountData&&accountData.address&&accountData.address.value) {
      const closeLoading = Message.loading('正在获取数据...', 0);
      let leader=this.props.store.common.getDefaultLedger(),
      param={
        fromIndex:(this.accountcurrent-1)*this.pageSize,
        count:this.pageSize,
      },
      address=accountData.address.value;
      Promise.all([
        account.getEntriescount(leader,address)     
      ]).then((data) => {
      if(data[0]>0){
        this.accountcount=data[0];
        Promise.all([ account.getEntries(leader,address,
          param
          ),
        ]).then((data) => {
          this.kvData=data[0];
          closeLoading();
        });
      }
      else{
        closeLoading();
      }
      });
    }
  }
  ////分页切换
  @autobind
  onPageChange(page, pageSize) {
    const { store: { account } } = this.props;
    this.accountcurrent=page;
    this.Search();
  }
  // 关闭详细信息
  @autobind
  onClose(visible){
    this.show=visible;
    
  }

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

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  isJsonString(str) {
    try {
      if (typeof JSON.parse(str) == "object") {
          return true;
      }
    } catch(e) {
    }
    return false;
  }

  Jsontree=()=>{
    if (this.isJsonString(this.jsondata)) {
      return <JSONTree  theme={theme}
        data={JSON.parse(this.jsondata)}
      />  
    }
    else{
      return <JSONTree   theme={theme}
        data={this.jsondata}
      />
    }

  };

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

  render() {
    const { store: { block },accountData } = this.props;
    
    return tmpls.container({
      components: {
        'ant-Drawer': Drawer,
195
        JSONTree
196 197 198 199 200 201 202
      }},this.props, this, {
      styles,
      block,
      accountData
    });
  }
}