import React, {Component} from 'react'; import {StyleSheet, View, Text, DeviceEventEmitter, ScrollView, TouchableOpacity, Dimensions} from 'react-native'; import {Button} from '@ant-design/react-native'; import ReadUHF from "../../utils/ReadUHF"; import Barcode from "react-native-barcode-builder"; // import SyncStorage from "sync-storage"; import {SyncStorage} from '../../utils'; import QRCode from 'react-native-qrcode-svg'; let screenW = Dimensions.get('window').width; class DesktopHome extends Component { constructor(props) { super(props); this.state = { data: [ { kind: '高压计量装置', releaseDate: '20250516', userData: '高压计量装置', model: 'GJWZ-12', eddl: '630A', eddy: '10kV', firstCurrent: '200', edpl: '50Hz', ratedLoad: '10/15VA', senondCurrent: '5', assetID: '01234567890123456789', manufacturer: '郑州市凯贝特互感器有限公司', } ], userData: [], //防止重复扫描 no_begin: '8', no_length: '14', error: 0, isStart: true, timerID: [], }; } static navigationOptions = { headerRight: () => ( DeviceEventEmitter.emit('onSet')} style={{ fontSize: 18, color: '#fff', // marginRight: 5, }}>设置 ), }; async componentDidMount() { // ReadUHF.changeFlag(0) DeviceEventEmitter.addListener('onSet', (param) => { this.props.navigation.navigate("SetPower") }); DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode); DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown); const show_type = await SyncStorage.get('show_type') if (show_type === null) { SyncStorage.set('show_type', '1') } const zuhe_temp = await SyncStorage.get('zuhe_temp'); this.setState({zuhe_temp}); } _addCode = async (item) => { const str = JSON.parse(item) // 防止重复扫描 const show_type = await SyncStorage.get('show_type') // ?? '1' let {data, userData, error} = this.state; const product_index = userData.indexOf(str['userData']) if (product_index < 0) { // 只显示本类别,不显示错误信息 if (show_type == '1') { // 且没有错误 if (str['error'] == 0) { userData.push(str['userData']) data.unshift(str) } } else { // 全部都显示 if (str['error']) { error += 1 } userData.push(str['userData']) data.unshift(str) } this.setState({data, userData, error}) } } _start = async () => { const no_begin = await SyncStorage.get('no_begin') const no_length = await SyncStorage.get('no_length') if (no_begin && no_begin) { this.setState({no_begin, no_length}) } let {isStart} = this.state; ReadUHF.doRead() this.setState({isStart: !isStart}) } _clear = () => { this.setState({userData: [], data: [], error: 0}) } onKeyDown = async () => { const no_begin = await SyncStorage.get('no_begin') const no_length = await SyncStorage.get('no_length') if (no_begin && no_begin) { this.setState({no_begin, no_length}) } let {isStart} = this.state; this.setState({isStart: !isStart}) } dianYaRender = (item, index) => { const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1) const releaseDates = item.releaseDate.split('-') const releaseDate = releaseDates[0] + "年" + releaseDates[1] + "月" let districtText = '' if (parseInt(item.district) > 10000) { districtText = item.districtText } else { const len1 = item.districtText.split('-')[1].length districtText = "国网" + item.districtText.split('-')[1].slice(0, len1 - 1) + "电力" } return ( 计量{item.kind} 型号:{item.model} 电压等级:{item.voltageLevel}kV 绕组数量:{item.secondWindingCount} 二次电压 准确等级 功率因数 生产日期 {item.secondVoltage}kV {item.accuracy} {item.powerFactor} {releaseDate} 安装场所:{item.place} 额定负荷:{item.ratedLoad}VA 电压因数:{item.voltageFactor} {item.manufacturer} {districtText} NO.{assetID} {item.assetID} ) } dianLiuRender = (item, index) => { const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1) const releaseDates = item.releaseDate.split('-') const releaseDate = releaseDates[0] + "年" + releaseDates[1] + "月" let districtText = '' if (parseInt(item.district) > 10000) { districtText = item.districtText } else { const len1 = item.districtText.split('-')[1].length districtText = "国网" + item.districtText.split('-')[1].slice(0, len1 - 1) + "电力" } return ( 计量{item.kind} 型号:{item.model} 电压等级:{item.voltageLevel}kV 绕组数量:{item.secondWindingCount} 一次电流 二次电流 功率因数 生产日期 {item.firstCurrent}A {item.senondCurrent}A {item.powerFactor} {releaseDate} 安装场所:{item.place} 额定负荷:{item.ratedLoad}VA 准确等级:{item.accuracy} {item.manufacturer} {districtText} NO.{assetID} {item.assetID} ) } jiliangRender = (item, index) => { // 计量箱装置 // item.assetID = 'E280111420007916C123' const releaseDates = item.releaseDate.split('-') const releaseDate = releaseDates[0] + "年" + releaseDates[1] + "月" return ( 计量箱装置 装置型号 {item.model} 额定频率 50Hz 额定电流 {item.senondCurrent} A 制造年月 {releaseDate} {item.assetID.slice(0, 11)} {item.assetID.slice(11, 30)} {item.manufacturer} ) } gaoYaRender = (item, index) => { // 高压计量装置 return ( {item.kind} 装置型号 {item.model} 额定电压 {item.eddy} 额定电流 {item.eddl} 额定频率 {item.edpl} 额定负荷 {item.ratedLoad} 电 流 比 {item.firstCurrent}/{item.senondCurrent}A 资产编号 {item.assetID} 出厂日期 {item.releaseDate} {item.manufacturer} ) } errorRender = (item, index) => { return ( {item.error_msg} ) } render() { let {isStart, zuhe_temp} = 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) } else if (item.kind.indexOf('计量箱装置') > -1) { return this.jiliangRender(item, index) } else if (item.kind.indexOf('高压计量装置') > -1) { return this.gaoYaRender(item, index) } else { // 组合互感器,没有设置,默认用电压模板 if (zuhe_temp === '2') { return this.dianLiuRender(item, index) } else { return this.dianYaRender(item, index) } } }) } 合计:{this.state.data.length} 失败:{this.state.error} ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff' }, button: { borderRadius: 5, marginHorizontal: 10, marginBottom: 2, marginTop: 5, borderWidth: 0, backgroundColor: "#2b90ea" }, textColor: { color: '#333', textAlign: 'center', }, textColor3: { color: '#333', textAlign: 'center', width: (screenW - 9) / 3, }, textColor4: { color: '#333', textAlign: 'center', width: (screenW - 8) / 4, }, 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', }, centerWidth: { borderLeftWidth: 0.5, borderRightWidth: 0.5, borderLeftColor: '#7b7b7b', borderRightColor: '#7b7b7b', alignItems: 'center', flexDirection: 'row', }, centerView: { alignItems: 'center', flexDirection: 'row', }, rightWidth: { borderRightWidth: 0.5, borderRightColor: '#7b7b7b', alignItems: 'center', flexDirection: 'row', }, textColor31: { fontWeight: "bold", color: '#333', textAlign: 'center', width: (screenW - 9) * 0.25, }, JLModel: { fontWeight: "bold", borderWidth: 1, borderLeftColor: '#7b7b7b', color: '#333', textAlign: 'center', width: (screenW - 9) * 0.40, }, JLView: { flexDirection: 'row', marginBottom: 5 }, GYModel: { fontWeight: "bold", borderWidth: 1, borderLeftColor: '#7b7b7b', color: '#333', textAlign: 'center', width: (screenW - 9) * 0.70, }, }) export default DesktopHome;