Home.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Text, DeviceEventEmitter, ScrollView, TouchableOpacity, Dimensions} from 'react-native';
  3. import {Button} from '@ant-design/react-native';
  4. import ReadUHF from "../../utils/ReadUHF";
  5. import Barcode from "react-native-barcode-builder";
  6. // import SyncStorage from "sync-storage";
  7. import {SyncStorage} from '../../utils';
  8. let screenW = Dimensions.get('window').width;
  9. class DesktopHome extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. data: [],
  14. data2: [
  15. {
  16. barcode: "4330012800000003232126",
  17. orgType: "国网公司",
  18. model: "YJLSZ-JF-10-630",
  19. connection: "三相三线",
  20. windingCount: "1",
  21. transformer: "线性反应原理",
  22. insulation: "油浸式",
  23. ratedVoltage: "1000kV/√3",
  24. ratedFrequencyAndPlace: "100Hz,户外",
  25. powerFactor: "0.8",
  26. ratedCurrent1: "1000000/5",
  27. ratedCurrent2: "1000000/5",
  28. ratedCurrent3: "1000000/5",
  29. ratedSecondLoadTA: "17.5",
  30. overlightLoadTA: "18.5",
  31. precisionTA: "0.5SS",
  32. voltageChangeRate: "10000/√3/100/√3",
  33. ratedSecondLoadTV: "17.5",
  34. overlightLoadTV: "18.5",
  35. precisionTVoverlightLoadTV: "0.5SS",
  36. flagAndRight: "新,局属",
  37. encodeType: "国标",
  38. securityAndExpansionFactor: "10,1.2",
  39. releaseDate: "2023-07",
  40. assetProperty: "供电企业资产,营销",
  41. manufacturer: "武汉高压研究所新技术公司华电电气技术有限公司",
  42. assetAttribution: "国网天府新区供电公司客户服务中心",
  43. }
  44. ],
  45. userData: [], //防止重复扫描
  46. no_begin: '8',
  47. no_length: '14',
  48. error: 0,
  49. isStart: true,
  50. timerID: [],
  51. };
  52. }
  53. static navigationOptions = {
  54. headerRight: () => (
  55. <Text
  56. onPress={() => DeviceEventEmitter.emit('onSet')}
  57. style={{
  58. fontSize: 18,
  59. color: '#fff',
  60. // marginRight: 5,
  61. }}>设置</Text>
  62. ),
  63. };
  64. async componentDidMount() {
  65. // ReadUHF.changeFlag(0)
  66. DeviceEventEmitter.addListener('onSet', (param) => {
  67. this.props.navigation.navigate("SetPower")
  68. });
  69. DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
  70. DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
  71. const show_type = await SyncStorage.get('show_type')
  72. if (show_type === null) {
  73. SyncStorage.set('show_type', '1')
  74. }
  75. const zuhe_temp = await SyncStorage.get('zuhe_temp');
  76. this.setState({zuhe_temp});
  77. }
  78. _addCode = async (item) => {
  79. const str = JSON.parse(item)
  80. // 防止重复扫描
  81. const show_type = await SyncStorage.get('show_type') // ?? '1'
  82. let {data, userData, error} = this.state;
  83. const product_index = userData.indexOf(str['userData'])
  84. if (product_index < 0) {
  85. // 只显示本类别,不显示错误信息
  86. if (show_type == '1') {
  87. // 且没有错误
  88. if (str['error'] == 0) {
  89. userData.push(str['userData'])
  90. data.unshift(str)
  91. }
  92. } else {
  93. // 全部都显示
  94. if (str['error']) {
  95. error += 1
  96. }
  97. userData.push(str['userData'])
  98. data.unshift(str)
  99. }
  100. this.setState({data, userData, error})
  101. }
  102. }
  103. _start = async () => {
  104. const no_begin = await SyncStorage.get('no_begin')
  105. const no_length = await SyncStorage.get('no_length')
  106. if (no_begin && no_begin) {
  107. this.setState({no_begin, no_length})
  108. }
  109. let {isStart} = this.state;
  110. ReadUHF.doRead()
  111. this.setState({isStart: !isStart})
  112. }
  113. _clear = () => {
  114. this.setState({userData: [], data: [], error: 0})
  115. }
  116. onKeyDown = async () => {
  117. const no_begin = await SyncStorage.get('no_begin')
  118. const no_length = await SyncStorage.get('no_length')
  119. if (no_begin && no_begin) {
  120. this.setState({no_begin, no_length})
  121. }
  122. let {isStart} = this.state;
  123. this.setState({isStart: !isStart})
  124. }
  125. dianLiuRender = (item, index) => {
  126. return (
  127. <View
  128. key={item.barcode}
  129. style={styles.mainView}
  130. >
  131. <View style={{
  132. // marginHorizontal: 5,
  133. }}>
  134. <Barcode value={item.barcode} format="CODE128" height={35} width={1.1}/>
  135. <Text style={styles.textColor}>{item.barcode}</Text>
  136. </View>
  137. <View style={styles.betweenView}>
  138. <Text style={styles.textLeft50}>单位类别 <Text style={styles.textRed}>{item.orgType}</Text></Text>
  139. <Text style={styles.textLeft50}>产品名称 <Text style={styles.textRed}>电流电压组合互感器</Text></Text>
  140. </View>
  141. <View style={styles.betweenView}>
  142. <Text style={styles.textLeft50}>产品型号 <Text style={styles.textRed}>{item.model}</Text></Text>
  143. <Text style={styles.textLeft50}>接线方式 <Text style={styles.textRed}>{item.connection}</Text></Text>
  144. </View>
  145. <View style={styles.betweenView}>
  146. <Text style={[styles.textColor, {borderRightWidth: 0.5,textAlign: 'left', width: '30%'}]}>绕组配置 <Text
  147. style={styles.textRed}>{item.windingCount}</Text></Text>
  148. <Text style={[styles.textColor, {borderRightWidth: 0.5,textAlign: 'left', width: '40%'}]}>互感器原理 <Text
  149. style={styles.textRed}>{item.transformer}</Text></Text>
  150. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}>绝缘方式 <Text
  151. style={styles.textRed}>{item.insulation}</Text></Text>
  152. {/*<Text style={{borderRightColor}}>绝缘方式 <Text style={styles.textRed}>{item.insulation}</Text></Text>*/}
  153. </View>
  154. <View style={styles.betweenView}>
  155. <Text style={[styles.textColor, {borderRightWidth: 0.5,textAlign: 'left', width: '30%'}]}>额定电压 <Text
  156. style={styles.textRed}>{item.ratedVoltage}</Text></Text>
  157. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '40%'}]}>额定频率,安装场所 <Text
  158. style={styles.textRed}>{item.ratedFrequencyAndPlace}</Text></Text>
  159. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}>功率因数 <Text
  160. style={styles.textRed}>{item.powerFactor}</Text></Text>
  161. </View>
  162. <View style={styles.betweenView}>
  163. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>额定电流变化比(A)</Text>
  164. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>TA额定二次负荷(VA)</Text>
  165. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>TA轻载负荷(VA)</Text>
  166. <Text style={[styles.textColor, {width: '25%'}]}>TA精度</Text>
  167. </View>
  168. <View style={styles.betweenView}>
  169. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>电流变比1 <Text
  170. style={styles.textRed}>{item.ratedCurrent1}</Text></Text>
  171. <Text style={{borderRightWidth: 0.5, width: '25%'}}/>
  172. <Text style={{borderRightWidth: 0.5, width: '25%'}}/>
  173. <Text style={{width: '25%'}}/>
  174. </View>
  175. <View style={[styles.betweenView, {borderTopWidth: 0,}]}>
  176. <Text style={[styles.textColor, {
  177. borderRightWidth: 0.5,
  178. borderTopWidth: 0.5,
  179. width: '25%'
  180. }]}>电流变比2 <Text style={styles.textRed}>{item.ratedCurrent2}</Text></Text>
  181. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}><Text
  182. style={styles.textRed}>{item.ratedSecondLoadTA}</Text></Text>
  183. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}><Text
  184. style={styles.textRed}>{item.overlightLoadTA}</Text></Text>
  185. <Text style={[styles.textColor, {width: '25%'}]}><Text
  186. style={styles.textRed}>{item.precisionTA}</Text></Text>
  187. </View>
  188. <View style={[styles.betweenView, {borderTopWidth: 0,}]}>
  189. <Text style={[styles.textColor, {
  190. borderRightWidth: 0.5,
  191. borderTopWidth: 0.5,
  192. width: '25%'
  193. }]}>电流变比3 <Text style={styles.textRed}>{item.ratedCurrent3}</Text></Text>
  194. <Text style={{borderRightWidth: 0.5, width: '25%'}}/>
  195. <Text style={{borderRightWidth: 0.5, width: '25%'}}/>
  196. <Text style={{width: '25%'}}/>
  197. </View>
  198. <View style={styles.betweenView}>
  199. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>电压比</Text>
  200. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>TV额定二次负荷(VA)</Text>
  201. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}>TV轻载负荷(VA)</Text>
  202. <Text style={[styles.textColor, {width: '25%'}]}>TV精度</Text>
  203. </View>
  204. <View style={styles.betweenView}>
  205. <Text style={[styles.textColor, {
  206. borderRightWidth: 0.5,
  207. width: '25%'
  208. }]}><Text style={styles.textRed}>{item.voltageChangeRate}</Text></Text>
  209. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}><Text
  210. style={styles.textRed}>{item.ratedSecondLoadTV}</Text></Text>
  211. <Text style={[styles.textColor, {borderRightWidth: 0.5, width: '25%'}]}><Text
  212. style={styles.textRed}>{item.overlightLoadTV}</Text></Text>
  213. <Text style={[styles.textColor, {width: '25%'}]}><Text
  214. style={styles.textRed}>{item.precisionTVoverlightLoadTV}</Text></Text>
  215. </View>
  216. <View style={styles.betweenView}>
  217. <Text style={[styles.textColor, {
  218. borderRightWidth: 0.5,
  219. textAlign: 'left',
  220. width: '70%'
  221. }]}>新旧标志,电能设备计量产权 <Text style={styles.textRed}>{item.flagAndRight}</Text></Text>
  222. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}> 加密方式 <Text
  223. style={styles.textRed}>{item.encodeType}</Text></Text>
  224. </View>
  225. <View style={styles.betweenView}>
  226. <Text style={[styles.textColor, {
  227. borderRightWidth: 0.5,
  228. textAlign: 'left',
  229. width: '70%'
  230. }]}>仪表保安系数,额定一次电流扩大倍数 <Text style={styles.textRed}>{item.securityAndExpansionFactor}</Text></Text>
  231. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}> 出厂日期 <Text
  232. style={styles.textRed}>{item.releaseDate}</Text></Text>
  233. </View>
  234. <View style={styles.betweenView}>
  235. <Text style={[styles.textColor,]}>资产属性,资产归属 <Text style={styles.textRed}>{item.assetProperty}</Text></Text>
  236. </View>
  237. <View style={styles.betweenView}>
  238. <Text style={[styles.textColor,]}>生产厂家 <Text style={styles.textRed}>{item.manufacturer}</Text></Text>
  239. </View>
  240. <View style={styles.betweenView}>
  241. <Text style={[styles.textColor,]}>资产归属地 <Text style={styles.textRed}>{item.assetAttribution}</Text></Text>
  242. </View>
  243. </View>
  244. )
  245. }
  246. errorRender = (item, index) => {
  247. return (
  248. <View
  249. key={index}
  250. style={[styles.mainView, {padding: 10}]}
  251. >
  252. <Text style={{color: 'red'}}>{item.error_msg}</Text>
  253. </View>
  254. )
  255. }
  256. render() {
  257. let {isStart, zuhe_temp} = this.state;
  258. const start_text = isStart ? '开始识别' : '停止识别'
  259. return (
  260. <View style={styles.container}>
  261. <ScrollView style={styles.container}>
  262. {
  263. this.state.data.map((item, index) => {
  264. if (item.error) {
  265. return this.errorRender(item, index)
  266. }
  267. else {
  268. return this.dianLiuRender(item, index)
  269. }
  270. })
  271. }
  272. </ScrollView>
  273. <Text
  274. style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
  275. <View style={{flexDirection: 'row'}}>
  276. <Button onPress={() => this._start()}
  277. type="primary"
  278. style={[styles.button, {
  279. backgroundColor: isStart ? '#0099FF' : 'red',
  280. width: '65%'
  281. }]}
  282. >
  283. <Text style={{color: '#fff'}}>
  284. {start_text}
  285. </Text>
  286. </Button>
  287. <Button onPress={() => this._clear()}
  288. type="warning"
  289. style={{
  290. width: '25%',
  291. borderRadius: 5,
  292. marginHorizontal: 10,
  293. marginTop: 5,
  294. marginBottom: 2,
  295. borderWidth: 0,
  296. backgroundColor: "#de7642"
  297. }}
  298. >
  299. <Text style={{color: '#fff'}}>
  300. 清除
  301. </Text>
  302. </Button>
  303. </View>
  304. </View>
  305. );
  306. }
  307. }
  308. const styles = StyleSheet.create({
  309. container: {
  310. flex: 1,
  311. backgroundColor: '#fff'
  312. },
  313. button: {
  314. borderRadius: 5,
  315. marginHorizontal: 10,
  316. marginBottom: 2,
  317. marginTop: 5,
  318. borderWidth: 0,
  319. backgroundColor: "#2b90ea"
  320. },
  321. textLeft50: {
  322. color: '#333',
  323. fontSize: 11,
  324. width: '50%',
  325. textAlign: 'left',
  326. },
  327. textColor: {
  328. color: '#333',
  329. fontSize: 11,
  330. textAlign: 'center',
  331. },
  332. textRed: {
  333. color: 'red',
  334. },
  335. mainView: {
  336. margin: 5,
  337. borderWidth: 0.5,
  338. borderColor: '#7b7b7b',
  339. },
  340. betweenView: {
  341. flexDirection: 'row',
  342. justifyContent: 'space-between',
  343. borderTopWidth: 0.5,
  344. borderTopColor: '#7b7b7b',
  345. paddingHorizontal: 5,
  346. },
  347. centerWidth: {
  348. borderLeftWidth: 0.5,
  349. borderRightWidth: 0.5,
  350. borderLeftColor: '#7b7b7b',
  351. borderRightColor: '#7b7b7b',
  352. alignItems: 'center',
  353. flexDirection: 'row',
  354. },
  355. centerView: {
  356. alignItems: 'center',
  357. flexDirection: 'row',
  358. },
  359. rightWidth: {
  360. borderRightWidth: 0.5,
  361. borderRightColor: '#7b7b7b',
  362. alignItems: 'center',
  363. flexDirection: 'row',
  364. },
  365. })
  366. export default DesktopHome;