Home.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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: "100,户外",
  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. precisionTV: "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: '45%'}]}>互感器原理 <Text
  149. style={styles.textRed}>{item.transformer}</Text></Text>
  150. <Text style={[styles.textColor, {textAlign: 'left', width: '25%'}]}>绝缘方式 <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: '45%'}]}>额定频率(Hz),安装场所 <Text
  158. style={styles.textRed}>{item.ratedFrequencyAndPlace}</Text></Text>
  159. <Text style={[styles.textColor, {textAlign: 'left', width: '25%'}]}>功率因数 <Text
  160. style={styles.textRed}>{item.powerFactor}</Text></Text>
  161. </View>
  162. <View style={styles.betweenView}>
  163. <Text style={styles.textColor1}>额定电流变比(A)</Text>
  164. <Text style={styles.textColor2}>TA额定二次负荷(VA)</Text>
  165. <Text style={styles.textColor3}>TA轻载负荷(VA)</Text>
  166. <Text style={styles.textColor4}>TA精度</Text>
  167. </View>
  168. <View style={styles.betweenView}>
  169. <Text style={styles.textColor1}>电流变比1 <Text
  170. style={styles.textRed}>{item.ratedCurrent1}</Text></Text>
  171. <Text style={{borderRightWidth: 0.5, width: '31%'}}/>
  172. <Text style={{borderRightWidth: 0.5, width: '26%'}}/>
  173. <Text style={{width: '16%'}}/>
  174. </View>
  175. <View style={[styles.betweenView, {borderTopWidth: 0,}]}>
  176. <Text style={[styles.textColor1, {
  177. borderTopWidth: 0.5,
  178. }]}>电流变比2 <Text style={styles.textRed}>{item.ratedCurrent2}</Text></Text>
  179. <Text style={styles.textColor2}><Text
  180. style={styles.textRed}>{item.ratedSecondLoadTA}</Text></Text>
  181. <Text style={styles.textColor3}><Text
  182. style={styles.textRed}>{item.overlightLoadTA}</Text></Text>
  183. <Text style={styles.textColor4}><Text
  184. style={styles.textRed}>{item.precisionTA}</Text></Text>
  185. </View>
  186. <View style={[styles.betweenView, {borderTopWidth: 0,}]}>
  187. <Text style={[styles.textColor1, {
  188. borderTopWidth: 0.5,
  189. }]}>电流变比3 <Text style={styles.textRed}>{item.ratedCurrent3}</Text></Text>
  190. <Text style={{borderRightWidth: 0.5, width: '31%'}}/>
  191. <Text style={{borderRightWidth: 0.5, width: '26%'}}/>
  192. <Text style={{width: '16%'}}/>
  193. </View>
  194. <View style={styles.betweenView}>
  195. <Text style={styles.textColor1}>电压比</Text>
  196. <Text style={styles.textColor2}>TV额定二次负荷(VA)</Text>
  197. <Text style={styles.textColor3}>TV轻载负荷(VA)</Text>
  198. <Text style={styles.textColor4}>TV精度</Text>
  199. </View>
  200. <View style={styles.betweenView}>
  201. <Text style={styles.textColor1}><Text style={styles.textRed}>{item.voltageChangeRate}</Text></Text>
  202. <Text style={styles.textColor2}><Text
  203. style={styles.textRed}>{item.ratedSecondLoadTV}</Text></Text>
  204. <Text style={styles.textColor3}><Text
  205. style={styles.textRed}>{item.overlightLoadTV}</Text></Text>
  206. <Text style={styles.textColor4}><Text
  207. style={styles.textRed}>{item.precisionTV}</Text></Text>
  208. </View>
  209. <View style={styles.betweenView}>
  210. <Text style={[styles.textColor, {
  211. borderRightWidth: 0.5,
  212. textAlign: 'left',
  213. width: '70%'
  214. }]}>新旧标志,电能设备计量产权 <Text style={styles.textRed}>{item.flagAndRight}</Text></Text>
  215. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}> 加密方式 <Text
  216. style={styles.textRed}>{item.encodeType}</Text></Text>
  217. </View>
  218. <View style={styles.betweenView}>
  219. <Text style={[styles.textColor, {
  220. borderRightWidth: 0.5,
  221. textAlign: 'left',
  222. width: '70%'
  223. }]}>仪表保安系数,额定一次电流扩大倍数 <Text style={styles.textRed}>{item.securityAndExpansionFactor}</Text></Text>
  224. <Text style={[styles.textColor, {textAlign: 'left', width: '30%'}]}> 出厂日期 <Text
  225. style={styles.textRed}>{item.releaseDate}</Text></Text>
  226. </View>
  227. <View style={styles.betweenView}>
  228. <Text style={[styles.textColor,]}>资产属性,资产归属 <Text style={styles.textRed}>{item.assetProperty}</Text></Text>
  229. </View>
  230. <View style={styles.betweenView}>
  231. <Text style={[styles.textColor,]}>生产厂家 <Text style={styles.textRed}>{item.manufacturer}</Text></Text>
  232. </View>
  233. <View style={styles.betweenView}>
  234. <Text style={[styles.textColor,]}>资产归属地 <Text style={styles.textRed}>{item.assetAttribution}</Text></Text>
  235. </View>
  236. </View>
  237. )
  238. }
  239. errorRender = (item, index) => {
  240. return (
  241. <View
  242. key={index}
  243. style={[styles.mainView, {padding: 10}]}
  244. >
  245. <Text style={{color: 'red'}}>{item.error_msg}</Text>
  246. </View>
  247. )
  248. }
  249. render() {
  250. let {isStart, zuhe_temp} = this.state;
  251. const start_text = isStart ? '开始识别' : '停止识别'
  252. return (
  253. <View style={styles.container}>
  254. <ScrollView style={styles.container}>
  255. {
  256. this.state.data.map((item, index) => {
  257. if (item.error) {
  258. return this.errorRender(item, index)
  259. }
  260. else {
  261. return this.dianLiuRender(item, index)
  262. }
  263. })
  264. }
  265. </ScrollView>
  266. <Text
  267. style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
  268. <View style={{flexDirection: 'row'}}>
  269. <Button onPress={() => this._start()}
  270. type="primary"
  271. style={[styles.button, {
  272. backgroundColor: isStart ? '#0099FF' : 'red',
  273. width: '65%'
  274. }]}
  275. >
  276. <Text style={{color: '#fff'}}>
  277. {start_text}
  278. </Text>
  279. </Button>
  280. <Button onPress={() => this._clear()}
  281. type="warning"
  282. style={{
  283. width: '25%',
  284. borderRadius: 5,
  285. marginHorizontal: 10,
  286. marginTop: 5,
  287. marginBottom: 2,
  288. borderWidth: 0,
  289. backgroundColor: "#de7642"
  290. }}
  291. >
  292. <Text style={{color: '#fff'}}>
  293. 清除
  294. </Text>
  295. </Button>
  296. </View>
  297. </View>
  298. );
  299. }
  300. }
  301. const styles = StyleSheet.create({
  302. container: {
  303. flex: 1,
  304. backgroundColor: '#fff'
  305. },
  306. button: {
  307. borderRadius: 5,
  308. marginHorizontal: 10,
  309. marginBottom: 2,
  310. marginTop: 5,
  311. borderWidth: 0,
  312. backgroundColor: "#2b90ea"
  313. },
  314. textLeft50: {
  315. color: '#333',
  316. fontSize: 11,
  317. width: '50%',
  318. textAlign: 'left',
  319. },
  320. textColor: {
  321. color: '#333',
  322. fontSize: 11,
  323. textAlign: 'center',
  324. },
  325. textColor1: {
  326. color: '#333',
  327. fontSize: 11,
  328. textAlign: 'center',
  329. borderRightWidth: 0.5,
  330. width: '27%'
  331. },
  332. textColor2: {
  333. color: '#333',
  334. fontSize: 11,
  335. textAlign: 'center',
  336. borderRightWidth: 0.5,
  337. width: '31%'
  338. },
  339. textColor3: {
  340. color: '#333',
  341. fontSize: 11,
  342. textAlign: 'center',
  343. borderRightWidth: 0.5,
  344. width: '26%'
  345. },
  346. textColor4: {
  347. color: '#333',
  348. fontSize: 11,
  349. textAlign: 'center',
  350. width: '16%'
  351. },
  352. textRed: {
  353. color: 'red',
  354. },
  355. mainView: {
  356. margin: 5,
  357. borderWidth: 0.5,
  358. borderColor: '#7b7b7b',
  359. },
  360. betweenView: {
  361. flexDirection: 'row',
  362. justifyContent: 'space-between',
  363. borderTopWidth: 0.5,
  364. borderTopColor: '#7b7b7b',
  365. paddingHorizontal: 5,
  366. },
  367. centerWidth: {
  368. borderLeftWidth: 0.5,
  369. borderRightWidth: 0.5,
  370. borderLeftColor: '#7b7b7b',
  371. borderRightColor: '#7b7b7b',
  372. alignItems: 'center',
  373. flexDirection: 'row',
  374. },
  375. centerView: {
  376. alignItems: 'center',
  377. flexDirection: 'row',
  378. },
  379. rightWidth: {
  380. borderRightWidth: 0.5,
  381. borderRightColor: '#7b7b7b',
  382. alignItems: 'center',
  383. flexDirection: 'row',
  384. },
  385. })
  386. export default DesktopHome;