Home.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. import QRCode from 'react-native-qrcode-svg';
  9. let screenW = Dimensions.get('window').width;
  10. class DesktopHome extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. data: [],
  15. userData: [], //防止重复扫描
  16. no_begin: '8',
  17. no_length: '14',
  18. error: 0,
  19. isStart: true,
  20. timerID: [],
  21. };
  22. }
  23. static navigationOptions = {
  24. headerRight: () => (
  25. <Text
  26. onPress={() => DeviceEventEmitter.emit('onSet')}
  27. style={{
  28. fontSize: 18,
  29. color: '#fff',
  30. // marginRight: 5,
  31. }}>设置</Text>
  32. ),
  33. };
  34. async componentDidMount() {
  35. // ReadUHF.changeFlag(0)
  36. DeviceEventEmitter.addListener('onSet', (param) => {
  37. this.props.navigation.navigate("SetPower")
  38. });
  39. DeviceEventEmitter.addListener('MsgFromAndroid', this._addCode);
  40. DeviceEventEmitter.addListener('onKeyDown', this.onKeyDown);
  41. const show_type = await SyncStorage.get('show_type')
  42. if (show_type === null) {
  43. SyncStorage.set('show_type', '1')
  44. }
  45. const zuhe_temp = await SyncStorage.get('zuhe_temp');
  46. this.setState({zuhe_temp});
  47. }
  48. _addCode = async (item) => {
  49. const str = JSON.parse(item)
  50. // 防止重复扫描
  51. const show_type = await SyncStorage.get('show_type') // ?? '1'
  52. let {data, userData, error} = this.state;
  53. const product_index = userData.indexOf(str['userData'])
  54. if (product_index < 0) {
  55. // 只显示本类别,不显示错误信息
  56. if (show_type == '1') {
  57. // 且没有错误
  58. if (str['error'] == 0) {
  59. userData.push(str['userData'])
  60. data.unshift(str)
  61. }
  62. } else {
  63. // 全部都显示
  64. if (str['error']) {
  65. error += 1
  66. }
  67. userData.push(str['userData'])
  68. data.unshift(str)
  69. }
  70. this.setState({data, userData, error})
  71. }
  72. }
  73. _start = async () => {
  74. const no_begin = await SyncStorage.get('no_begin')
  75. const no_length = await SyncStorage.get('no_length')
  76. if (no_begin && no_begin) {
  77. this.setState({no_begin, no_length})
  78. }
  79. let {isStart} = this.state;
  80. ReadUHF.doRead()
  81. this.setState({isStart: !isStart})
  82. }
  83. _clear = () => {
  84. this.setState({userData: [], data: [], error: 0})
  85. }
  86. onKeyDown = async () => {
  87. const no_begin = await SyncStorage.get('no_begin')
  88. const no_length = await SyncStorage.get('no_length')
  89. if (no_begin && no_begin) {
  90. this.setState({no_begin, no_length})
  91. }
  92. let {isStart} = this.state;
  93. this.setState({isStart: !isStart})
  94. }
  95. dianYaRender = (item, index) => {
  96. const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1)
  97. const releaseDates = item.releaseDate.split('-')
  98. const releaseDate = releaseDates[0] + "年" + releaseDates[1] + "月"
  99. let districtText = ''
  100. if (parseInt(item.district) > 10000) {
  101. districtText = item.districtText
  102. } else {
  103. const len1 = item.districtText.split('-')[1].length
  104. districtText = "国网" + item.districtText.split('-')[1].slice(0, len1 - 1) + "电力"
  105. }
  106. return (
  107. <View
  108. key={item.userData}
  109. style={styles.mainView}
  110. >
  111. <Text style={styles.textColor}>计量{item.kind}</Text>
  112. <View style={styles.betweenView}>
  113. <Text style={styles.textColor3}>型号:{item.model}</Text>
  114. <View style={styles.centerWidth}>
  115. <Text style={styles.textColor3}>电压等级:{item.voltageLevel}kV</Text>
  116. </View>
  117. <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
  118. </View>
  119. <View style={styles.betweenView}>
  120. <Text style={styles.textColor4}>二次电压</Text>
  121. <View style={styles.centerWidth}>
  122. <Text style={styles.textColor4}>准确等级</Text>
  123. </View>
  124. <View style={styles.rightWidth}>
  125. <Text style={styles.textColor4}>功率因数</Text>
  126. </View>
  127. <Text style={styles.textColor4}>生产日期</Text>
  128. </View>
  129. <View style={styles.betweenView}>
  130. <View style={styles.centerView}>
  131. <Text style={styles.textColor4}>{item.secondVoltage}kV</Text>
  132. </View>
  133. <View style={styles.centerWidth}>
  134. <Text style={styles.textColor4}>{item.accuracy}</Text>
  135. </View>
  136. <View style={styles.rightWidth}>
  137. <Text style={styles.textColor4}>{item.powerFactor}</Text>
  138. </View>
  139. <View style={styles.centerView}>
  140. <Text style={styles.textColor4}>{releaseDate}</Text>
  141. </View>
  142. </View>
  143. <View style={styles.betweenView}>
  144. <Text style={styles.textColor3}>安装场所:{item.place}</Text>
  145. <View style={styles.centerWidth}>
  146. <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}VA</Text>
  147. </View>
  148. <Text style={styles.textColor3}>电压因数:{item.voltageFactor}</Text>
  149. </View>
  150. <View style={styles.betweenView}>
  151. <View style={styles.centerView}>
  152. <Text style={styles.textColor3}>{item.manufacturer}</Text>
  153. </View>
  154. <View style={{
  155. width: (screenW - 10) / 3 * 2,
  156. borderLeftWidth: 0.5,
  157. borderLeftColor: '#7b7b7b',
  158. }}>
  159. <View style={{
  160. flexDirection: 'row',
  161. marginHorizontal: 3,
  162. }}>
  163. <View style={{
  164. flex: 1,
  165. }}>
  166. <Text style={[styles.textColor, {textAlign: 'left'}]}>{districtText}</Text>
  167. </View>
  168. <Text style={[styles.textColor, {textAlign: 'right', paddingRight: 5}]}>NO.{assetID}</Text>
  169. </View>
  170. <View style={{
  171. marginHorizontal: 5,
  172. }}>
  173. <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
  174. <Text style={styles.textColor}>{item.assetID}</Text>
  175. </View>
  176. </View>
  177. </View>
  178. </View>
  179. )
  180. }
  181. dianLiuRender = (item, index) => {
  182. const assetID = item.assetID.slice(parseInt(this.state.no_begin) - 1, parseInt(this.state.no_begin) + parseInt(this.state.no_length) - 1)
  183. const releaseDates = item.releaseDate.split('-')
  184. const releaseDate = releaseDates[0] + "年" + releaseDates[1] + "月"
  185. let districtText = ''
  186. if (parseInt(item.district) > 10000) {
  187. districtText = item.districtText
  188. } else {
  189. const len1 = item.districtText.split('-')[1].length
  190. districtText = "国网" + item.districtText.split('-')[1].slice(0, len1 - 1) + "电力"
  191. }
  192. return (
  193. <View
  194. key={item.userData}
  195. style={styles.mainView}
  196. >
  197. <Text style={styles.textColor}>计量{item.kind}</Text>
  198. <View style={styles.betweenView}>
  199. <Text style={styles.textColor3}>型号:{item.model}</Text>
  200. <View style={styles.centerWidth}>
  201. <Text style={styles.textColor3}>电压等级:{item.voltageLevel}kV</Text>
  202. </View>
  203. <Text style={styles.textColor3}>绕组数量:{item.secondWindingCount}</Text>
  204. </View>
  205. <View style={styles.betweenView}>
  206. <Text style={styles.textColor4}>一次电流</Text>
  207. <View style={styles.centerWidth}>
  208. <Text style={styles.textColor4}>二次电流</Text>
  209. </View>
  210. <View style={styles.rightWidth}>
  211. <Text style={styles.textColor4}>功率因数</Text>
  212. </View>
  213. <Text style={styles.textColor4}>生产日期</Text>
  214. </View>
  215. <View style={styles.betweenView}>
  216. <View style={styles.centerView}>
  217. <Text style={styles.textColor4}>{item.firstCurrent}A</Text>
  218. </View>
  219. <View style={styles.centerWidth}>
  220. <Text style={styles.textColor4}>{item.senondCurrent}A</Text>
  221. </View>
  222. <View style={styles.rightWidth}>
  223. <Text style={styles.textColor4}>{item.powerFactor}</Text>
  224. </View>
  225. <View style={styles.centerView}>
  226. <Text style={styles.textColor4}>{releaseDate}</Text>
  227. </View>
  228. </View>
  229. <View style={styles.betweenView}>
  230. <Text style={styles.textColor3}>安装场所:{item.place}</Text>
  231. <View style={styles.centerWidth}>
  232. <Text style={styles.textColor3}>额定负荷:{item.ratedLoad}VA</Text>
  233. </View>
  234. <Text style={styles.textColor3}>准确等级:{item.accuracy}</Text>
  235. </View>
  236. <View style={styles.betweenView}>
  237. <View style={styles.centerView}>
  238. <Text style={styles.textColor3}>{item.manufacturer}</Text>
  239. </View>
  240. <View style={{
  241. width: (screenW - 10) / 3 * 2,
  242. borderLeftWidth: 0.5,
  243. borderLeftColor: '#7b7b7b',
  244. }}>
  245. <View style={{
  246. flexDirection: 'row',
  247. marginHorizontal: 3,
  248. }}>
  249. <View style={{
  250. flex: 1,
  251. }}>
  252. <Text style={[styles.textColor, {textAlign: 'left'}]}>{districtText}</Text>
  253. </View>
  254. <Text style={[styles.textColor, {textAlign: 'right', paddingRight: 5}]}>NO.{assetID}</Text>
  255. </View>
  256. <View style={{
  257. marginHorizontal: 5,
  258. }}>
  259. <Barcode value={item.assetID} format="CODE128" height={35} width={1.1}/>
  260. <Text style={styles.textColor}>{item.assetID}</Text>
  261. </View>
  262. </View>
  263. </View>
  264. </View>
  265. )
  266. }
  267. jiliangRender = (item, index) => {
  268. // 计量箱装置
  269. return (
  270. <View
  271. key={item.userData}
  272. style={styles.mainView}
  273. >
  274. <Text style={[styles.textColor, {marginVertical: 10, fontWeight: "bold", fontSize: 18}]}>计量箱装置</Text>
  275. <View style={{
  276. flexDirection: 'row',
  277. }}>
  278. <View style={{width: (screenW - 10) / 3 * 2,}}>
  279. <View style={styles.JLView}>
  280. <Text style={styles.textColor31}>装置型号</Text>
  281. <Text style={styles.JLModel}>BX25</Text>
  282. </View>
  283. <View style={styles.JLView}>
  284. <Text style={styles.textColor31}>额定频率</Text>
  285. <Text style={styles.JLModel}>50Hz</Text>
  286. </View>
  287. <View style={styles.JLView}>
  288. <Text style={styles.textColor31}>额定电流</Text>
  289. <Text style={[styles.JLModel]}>5 A </Text>
  290. </View>
  291. <View style={styles.JLView}>
  292. <Text style={styles.textColor31}>制造年月</Text>
  293. <Text style={styles.JLModel}>202302</Text>
  294. </View>
  295. </View>
  296. <View style={{
  297. width: (screenW - 10) / 3 * 1,
  298. textAlign: 'center',
  299. alignItems: 'center',
  300. flex: 1,
  301. }}>
  302. <QRCode
  303. value={'3630002102200000001183'}//二维码内容
  304. logoBorderRadius={1}
  305. color={"#333333"}//二维码颜色
  306. backgroundColor={"#ffffff"}//背景色
  307. size={65}//二维码宽高
  308. />
  309. <Text style={[styles.textColor]}>36300021022</Text>
  310. <Text style={[styles.textColor]}>00000001183</Text>
  311. </View>
  312. </View>
  313. <Text style={[styles.textColor, {marginVertical: 10, fontWeight: "bold",}]}>郑州市凯贝特互感器有限公司</Text>
  314. </View>
  315. )
  316. }
  317. errorRender = (item, index) => {
  318. return (
  319. <View
  320. key={index}
  321. style={[styles.mainView, {padding: 10}]}
  322. >
  323. <Text style={{color: 'red'}}>{item.error_msg}</Text>
  324. </View>
  325. )
  326. }
  327. render() {
  328. let {isStart, zuhe_temp} = this.state;
  329. const start_text = isStart ? '开始识别' : '停止识别'
  330. return (
  331. <View style={styles.container}>
  332. <ScrollView style={styles.container}>
  333. {
  334. this.state.data.map((item, index) => {
  335. if (item.error) {
  336. return this.errorRender(item, index)
  337. }
  338. else if (item.kind.indexOf('电压') > -1) {
  339. return this.dianYaRender(item, index)
  340. }
  341. else if (item.kind.indexOf('电流') > -1) {
  342. return this.dianLiuRender(item, index)
  343. }
  344. else if (item.kind.indexOf('计量箱装置') > -1) {
  345. return this.jiliangRender(item, index)
  346. }
  347. else {
  348. // 组合互感器,没有设置,默认用电压模板
  349. if (zuhe_temp === '2') {
  350. return this.dianLiuRender(item, index)
  351. } else {
  352. return this.dianYaRender(item, index)
  353. }
  354. }
  355. })
  356. }
  357. </ScrollView>
  358. <Text
  359. style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
  360. <View style={{flexDirection: 'row'}}>
  361. <Button onPress={() => this._start()}
  362. type="primary"
  363. style={[styles.button, {
  364. backgroundColor: isStart ? '#0099FF' : 'red',
  365. width: '65%'
  366. }]}
  367. >
  368. <Text style={{color: '#fff'}}>
  369. {start_text}
  370. </Text>
  371. </Button>
  372. <Button onPress={() => this._clear()}
  373. type="warning"
  374. style={{
  375. width: '25%',
  376. borderRadius: 5,
  377. marginHorizontal: 10,
  378. marginTop: 5,
  379. marginBottom: 2,
  380. borderWidth: 0,
  381. backgroundColor: "#de7642"
  382. }}
  383. >
  384. <Text style={{color: '#fff'}}>
  385. 清除
  386. </Text>
  387. </Button>
  388. </View>
  389. </View>
  390. );
  391. }
  392. }
  393. const styles = StyleSheet.create({
  394. container: {
  395. flex: 1,
  396. backgroundColor: '#fff'
  397. },
  398. button: {
  399. borderRadius: 5,
  400. marginHorizontal: 10,
  401. marginBottom: 2,
  402. marginTop: 5,
  403. borderWidth: 0,
  404. backgroundColor: "#2b90ea"
  405. },
  406. textColor: {
  407. color: '#333',
  408. textAlign: 'center',
  409. },
  410. textColor3: {
  411. color: '#333',
  412. textAlign: 'center',
  413. width: (screenW - 9) / 3,
  414. },
  415. textColor4: {
  416. color: '#333',
  417. textAlign: 'center',
  418. width: (screenW - 8) / 4,
  419. },
  420. textColor2: {
  421. color: '#333',
  422. textAlign: 'center',
  423. width: (screenW - 10) / 2,
  424. },
  425. mainView: {
  426. margin: 5,
  427. borderWidth: 0.5,
  428. borderColor: '#7b7b7b',
  429. },
  430. betweenView: {
  431. flexDirection: 'row',
  432. justifyContent: 'space-between',
  433. borderTopWidth: 0.5,
  434. borderTopColor: '#7b7b7b',
  435. },
  436. centerWidth: {
  437. borderLeftWidth: 0.5,
  438. borderRightWidth: 0.5,
  439. borderLeftColor: '#7b7b7b',
  440. borderRightColor: '#7b7b7b',
  441. alignItems: 'center',
  442. flexDirection: 'row',
  443. },
  444. centerView: {
  445. alignItems: 'center',
  446. flexDirection: 'row',
  447. },
  448. rightWidth: {
  449. borderRightWidth: 0.5,
  450. borderRightColor: '#7b7b7b',
  451. alignItems: 'center',
  452. flexDirection: 'row',
  453. },
  454. textColor31: {
  455. fontWeight: "bold",
  456. color: '#333',
  457. textAlign: 'center',
  458. width: (screenW - 9) * 0.25,
  459. },
  460. JLModel: {
  461. fontWeight: "bold",
  462. borderWidth: 1,
  463. borderLeftColor: '#7b7b7b',
  464. color: '#333',
  465. textAlign: 'center',
  466. width: (screenW - 9) * 0.40,
  467. },
  468. JLView: {
  469. flexDirection: 'row',
  470. marginBottom: 5
  471. },
  472. })
  473. export default DesktopHome;