Home.js 16 KB

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