Home.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid} from 'react-native';
  3. import {Button} from '@ant-design/react-native';
  4. import ReadUHF from "../../utils/ReadUHF";
  5. class DesktopHome extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. data: [3, 4, 5],
  10. };
  11. }
  12. componentDidMount() {
  13. ReadUHF.changeFlag(0)
  14. DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
  15. }
  16. componentWillUnmount() {
  17. ReadUHF.stopRead()
  18. }
  19. _addCode = (item) => {
  20. console.log(111111111111,item)
  21. // let str = '{"userData":"6a173f0fd2a140cf20204fbaa6d1c0158518031da248f306535dc6d10026a7c985671ae611afb4c151feb5712eba3d52",' +
  22. // '"assetID":"4330012800000002178203" ,"model":"002型","manufacturer":"北京公司","kind":"电压互感器"}'
  23. // let str = '{"name": "cxh", "sex": "man" }';
  24. // console.log(2333333333,str)
  25. const str = JSON.parse(item)
  26. console.log(22222222222,str, str['kind'])
  27. let {data} = this.state;
  28. data.push(item)
  29. this.setState({data})
  30. }
  31. _start = () => {
  32. let {isStart} = this.state;
  33. ReadUHF.doRead()
  34. this.setState({isStart: !isStart})
  35. }
  36. render() {
  37. return (
  38. <View style={styles.container}>
  39. {
  40. this.state.data.map((item, index) => {
  41. return (
  42. <Text key={index}>{item}</Text>
  43. )
  44. })
  45. }
  46. <Button onPress={() => this._start()}
  47. type="primary"
  48. >
  49. 开始
  50. </Button>
  51. </View>
  52. );
  53. }
  54. }
  55. const styles = StyleSheet.create({
  56. container: {
  57. flex: 1
  58. },
  59. userContainer: {
  60. height: 50,
  61. backgroundColor: '#7ff0ed',
  62. flexDirection: 'row',
  63. },
  64. userImg: {
  65. fontFamily: 'iconfont',
  66. color: '#fff',
  67. paddingLeft: 10,
  68. paddingTop: 5,
  69. fontSize: 35,
  70. },
  71. userInfo: {
  72. marginBottom: 5,
  73. paddingTop: 5,
  74. paddingLeft: 10,
  75. flex: 1
  76. },
  77. userInfoText: {
  78. color: '#fff',
  79. },
  80. loginOut: {
  81. flexDirection: 'row',
  82. width: 80,
  83. paddingTop: 15,
  84. justifyContent: 'center',
  85. backgroundColor: '#23d1ff'
  86. },
  87. loginOutText: {
  88. color: '#fff',
  89. fontSize: 16,
  90. },
  91. gridView: {
  92. marginTop: 0,
  93. flex: 0,
  94. padding: 0
  95. },
  96. itemContainer: {
  97. justifyContent: 'flex-end',
  98. padding: 20,
  99. alignItems: 'center',
  100. textAlign: 'center',
  101. borderRightWidth: 1,
  102. borderBottomWidth: 1,
  103. borderColor: '#eaeaea'
  104. },
  105. iconFont: {
  106. color: '#5eafe4',
  107. fontFamily: 'iconfont',
  108. fontSize: 30,
  109. textAlign: 'center',
  110. marginBottom: 5
  111. },
  112. sizeFont: {
  113. color: 'black',
  114. fontFamily: 'iconfont',
  115. fontSize: 12,
  116. textAlign: 'center',
  117. marginBottom: 5
  118. },
  119. })
  120. export default DesktopHome;