import React from 'react'; import {Container, Segment, Table, Label, Checkbox} from 'semantic-ui-react'; import {getRequest} from '../../../../actions'; import ListItem from './ListItem'; class LocStatus extends React.Component{ state = { autoRefresh: false, list: [] } tick = null componentDidMount(){ this.getList(); } componentWillUnmount(){ clearInterval(this.tick); } changeRefresh = () => { this.setState({ autoRefresh: !this.state.autoRefresh }, ()=>{ this.checkRefresh(); }) } checkRefresh = () => { if(this.state.autoRefresh) { this.tick = setInterval(this.runTick, 2000); }else{ clearInterval(this.tick); } } runTick = () => { this.getList(); } getList = () => { let {toggleLoading, showDialog} = this.props; fetch('/api/wristband/getstatus', getRequest()) .then(response=>response.json()) .then(json => { if(json.status != 1) return showDialog(json.message); this.setState({ list: [...(json.data.record || [])] }) }); } render (){ let {i18n} = this.props; return ( {this.changeRefresh()}} label="自動更新" /> 手環ID 地點 步數 剩餘電量 HR SBP DBP 卡路里 時間 {/**/} { this.state.list.map((t,idx)=>( )) }
) } } export default LocStatus;