import React, {Component} from 'react'; import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid, Dimensions} from 'react-native'; import {Button} from '@ant-design/react-native'; import ReadUHF from "../../utils/ReadUHF"; import {ComponentsStyles} from "../../components" import Barcode from "react-native-barcode-builder"; let screenW = Dimensions.get('window').width; class DesktopHome extends Component { constructor(props) { super(props); this.state = { data: [], userData: [], isStart: true, }; } componentDidMount() { ReadUHF.changeFlag(1) DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode); DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown); } componentWillUnmount() { ReadUHF.stopRead() } _addCode = (item) => { const str = JSON.parse(item) // 防止重复扫描 let {data, userData} = this.state; const product_index = userData.indexOf(str['userData']) if (product_index < 0) { userData.push(str['userData']) data.push(str) this.setState({data, userData}) } } _start = () => { let {isStart} = this.state; ReadUHF.doRead() this.setState({isStart: !isStart}) } onKeyDown = () => { let {isStart} = this.state; this.setState({isStart: !isStart}) } dianYaRender = (item, index) => { const assetID = item.assetID.slice(7, 21) const districtText = item.districtText.split('-')[0] return ( 计量{item.kind} 型号:{item.model} 电压等级:{item.voltageLevel} 绕组数量:{item.secondWindingCount} 二次电压 准确等级 生产日期 {item.secondVoltage} {item.accuracy} {item.releaseDate} 安装场所:{item.place} 额定负荷:{item.ratedLoad} 电压因数:{item.voltageFactor} {item.manufacturer} 国网{districtText}电力 NO.{assetID} {item.assetID} ) } dianLiuRender = (item, index) => { return ( 电流 ) } errorRender = (item, index) => { return ( {item.error_msg} ) } render() { let {isStart} = this.state; const start_text = isStart ? '开始识别' : '停止识别' return ( { this.state.data.map((item, index) => { if (item.error) { return this.errorRender(item, index) } else if (item.kind.indexOf('电流') > -1) { return this.dianYaRender(item, index) } else if (item.kind.indexOf('电流') > -1) { return this.dianLiuRender(item, index) } }) } ); } } const styles = StyleSheet.create({ container: { flex: 1 }, textColor: { color: '#333', textAlign: 'center', }, textColor3: { color: '#333', textAlign: 'center', width: (screenW - 9) / 3, }, textColor2: { color: '#333', textAlign: 'center', width: (screenW - 10) / 2, }, mainView: { margin: 5, borderWidth: 0.5, borderColor: '#7b7b7b', }, betweenView: { flexDirection: 'row', justifyContent: 'space-between', borderTopWidth: 0.5, borderTopColor: '#7b7b7b', alignItems: 'center', }, centerWidth: { borderLeftWidth: 0.5, borderRightWidth: 0.5, borderLeftColor: '#7b7b7b', borderRightColor: '#7b7b7b', }, }) export default DesktopHome;