Home.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Text, DeviceEventEmitter, TouchableOpacity, ToastAndroid, Dimensions} from 'react-native';
  3. import {Button} from '@ant-design/react-native';
  4. import ReadUHF from "../../utils/ReadUHF";
  5. import {ComponentsStyles} from "../../components"
  6. import Barcode from "react-native-barcode-builder";
  7. let screenW = Dimensions.get('window').width;
  8. class DesktopHome extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. data: [],
  13. userData: [],
  14. isStart: true,
  15. };
  16. }
  17. componentDidMount() {
  18. ReadUHF.changeFlag(1)
  19. DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
  20. DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
  21. }
  22. componentWillUnmount() {
  23. ReadUHF.stopRead()
  24. }
  25. _addCode = (item) => {
  26. const str = JSON.parse(item)
  27. // 防止重复扫描
  28. let {data, userData} = this.state;
  29. const product_index = userData.indexOf(str['userData'])
  30. if (product_index < 0) {
  31. userData.push(str['userData'])
  32. data.push(str)
  33. this.setState({data, userData})
  34. }
  35. }
  36. _start = () => {
  37. let {isStart} = this.state;
  38. ReadUHF.doRead()
  39. this.setState({isStart: !isStart})
  40. }
  41. onKeyDown = () => {
  42. let {isStart} = this.state;
  43. this.setState({isStart: !isStart})
  44. }
  45. dianYaRender = (item, index) => {
  46. const assetID = item.assetID.slice(7, 21)
  47. const districtText = item.districtText.split('-')[0]
  48. return (
  49. <View
  50. key={index}
  51. style={styles.mainView}
  52. >
  53. <Text style={styles.textColor}>计量{item.kind}</Text>
  54. <View style={styles.betweenView}>
  55. <Text style={styles.textColor3}>型号:{item.model}</Text>
  56. <View style={styles.centerWidth}>
  57. <Text style={styles.textColor3}>电压等级:{item.voltageLevel}</Text>
  58. </View>
  59. <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
  60. </View>
  61. <View style={styles.betweenView}>
  62. <Text style={styles.textColor3}>二次电压</Text>
  63. <View style={styles.centerWidth}>
  64. <Text style={styles.textColor3}>准确等级</Text>
  65. </View>
  66. <Text style={styles.textColor3}>生产日期</Text>
  67. </View>
  68. <View style={styles.betweenView}>
  69. <Text style={styles.textColor3}>{item.secondVoltage}</Text>
  70. <View style={styles.centerWidth}>
  71. <Text style={styles.textColor3}>{item.accuracy}</Text>
  72. </View>
  73. <Text style={styles.textColor3}>{item.releaseDate}</Text>
  74. </View>
  75. <View style={styles.betweenView}>
  76. <Text style={styles.textColor3}>安装场所:{item.place}</Text>
  77. <View style={styles.centerWidth}>
  78. <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}</Text>
  79. </View>
  80. <Text style={styles.textColor3}>电压因数:{item.voltageFactor}</Text>
  81. </View>
  82. <View style={styles.betweenView}>
  83. <Text style={styles.textColor3}>{item.manufacturer}</Text>
  84. <View style={{
  85. width: (screenW - 10) / 3 * 2,
  86. borderLeftWidth: 0.5,
  87. borderLeftColor: '#7b7b7b',
  88. }}>
  89. <View style={{
  90. flexDirection: 'row',
  91. marginHorizontal: 3,
  92. }}>
  93. <View style={{
  94. flex: 1,
  95. }}>
  96. <Text style={[styles.textColor, {textAlign: 'left'}]}>国网{districtText}电力</Text>
  97. </View>
  98. <Text style={[styles.textColor, {textAlign: 'right'}]}>NO.{assetID}</Text>
  99. </View>
  100. <View style={{
  101. marginHorizontal: 5,
  102. }}>
  103. <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
  104. <Text style={[styles.textColor]}>{item.assetID}</Text>
  105. </View>
  106. </View>
  107. </View>
  108. </View>
  109. )
  110. }
  111. dianLiuRender = (item, index) => {
  112. return (
  113. <Text>电流</Text>
  114. )
  115. }
  116. errorRender = (item, index) => {
  117. return (
  118. <View
  119. key={index}
  120. style={[styles.mainView,{padding:10}]}
  121. >
  122. <Text style={{color:'red'}}>{item.error_msg}</Text>
  123. </View>
  124. )
  125. }
  126. render() {
  127. let {isStart} = this.state;
  128. const start_text = isStart ? '开始识别' : '停止识别'
  129. return (
  130. <View style={styles.container}>
  131. <View style={styles.container}>
  132. {
  133. this.state.data.map((item, index) => {
  134. if (item.error) {
  135. return this.errorRender(item, index)
  136. }
  137. else if (item.kind.indexOf('电流') > -1) {
  138. return this.dianYaRender(item, index)
  139. }
  140. else if (item.kind.indexOf('电流') > -1) {
  141. return this.dianLiuRender(item, index)
  142. }
  143. })
  144. }
  145. </View>
  146. <Button onPress={() => this._start()}
  147. type="primary"
  148. style={[ComponentsStyles.button, {backgroundColor: isStart ? '#0099FF' : 'red',}]}
  149. >
  150. <Text style={{color: '#fff'}}>
  151. {start_text}
  152. </Text>
  153. </Button>
  154. </View>
  155. );
  156. }
  157. }
  158. const styles = StyleSheet.create({
  159. container: {
  160. flex: 1
  161. },
  162. textColor: {
  163. color: '#333',
  164. textAlign: 'center',
  165. },
  166. textColor3: {
  167. color: '#333',
  168. textAlign: 'center',
  169. width: (screenW - 9) / 3,
  170. },
  171. textColor2: {
  172. color: '#333',
  173. textAlign: 'center',
  174. width: (screenW - 10) / 2,
  175. },
  176. mainView: {
  177. margin: 5,
  178. borderWidth: 0.5,
  179. borderColor: '#7b7b7b',
  180. },
  181. betweenView: {
  182. flexDirection: 'row',
  183. justifyContent: 'space-between',
  184. borderTopWidth: 0.5,
  185. borderTopColor: '#7b7b7b',
  186. alignItems: 'center',
  187. },
  188. centerWidth: {
  189. borderLeftWidth: 0.5,
  190. borderRightWidth: 0.5,
  191. borderLeftColor: '#7b7b7b',
  192. borderRightColor: '#7b7b7b',
  193. },
  194. })
  195. export default DesktopHome;