import * as React from 'react'; import Tooltip from '@beisen/tool-tip'; interface Props { infoList:any[], width:number, resetInfoList:(row:number,colum:number,changeIndex:number)=>void, resetList:Item[] } interface Item{ keyName:string, valueText:string } export default class UserInfoCom extends React.Component{ state={ row:0, colum:0, changeIndex:0 } componentWillReceiveProps(nextProps:Props){ if(this.props.width != nextProps.width){ this.resetRow(nextProps) } } resetRow = (nextProps:Props) => { const {resetList,width} = nextProps; let row = Math.floor(width / 230); row = row === 0 ? 1 : row let last = width % 230; if(last < 20*(row-1)){ if(row === 1 ) return ; row -= 1 } let colum = Math.floor(resetList.length/row); let changeIndex = (resetList.length%row) - 1; this.setState({ row: row, colum:colum, changeIndex:changeIndex }) this.props.resetInfoList(row,colum,changeIndex); } componentDidMount(){ this.resetRow(this.props); } render(){ const {infoList,width} = this.props; return
{ infoList.map((item:Item[],index:number)=>{ return }) }
} // rowItem = (list:Item[],i:number) => { // return
// { // list.map((item:Item,index:number)=>{ // return
// // //
// }) // } //
// } } interface RowItemProps{ list:Item[], i:number, width:number } interface State { keyWidth:number } class RowItem extends React.Component { constructor(props:RowItemProps){ super(props) this.state={ keyWidth:0 } } refs:any componentDidMount(){ // this.resetWidth(); } componentWillReceiveProps(nextProps:RowItemProps){ if(this.props.width != nextProps.width){ this.setState({ keyWidth:0 }) this.resetWidth(); } } componentDidUpdate(){ this.resetWidth(); } index :any resetWidth = () => { const {list} = this.props; let lengths:any[] = []; list.map((item:Item,k:number)=>{ lengths.push(item.keyName.length) }) var max = Math.max.apply(null,lengths); const index = 'key' + lengths.indexOf(max) this.index = index; setTimeout(()=>{ const index = this.index ; const width = this.refs[index] ? this.refs[index].clientWidth < 12 ? 0 : this.refs[index].clientWidth : 78; this.state.keyWidth != max && this.setState({ keyWidth:width }) },0.5) } render(){ const {list,i} = this.props; const {keyWidth} = this.state; return
{ list.map((item:Item,index:number)=>{ return
{ item.keyName.length > 6 ? : }
}) }
} }