Home.js 23 KB

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