Home.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. // item.assetID = 'E280111420007916C123'
  270. return (
  271. <View
  272. key={item.userData}
  273. style={styles.mainView}
  274. >
  275. <Text style={[styles.textColor, {marginVertical: 10, fontWeight: "bold", fontSize: 18}]}>计量箱装置</Text>
  276. <View style={{
  277. flexDirection: 'row',
  278. }}>
  279. <View style={{width: (screenW - 10) / 3 * 2,}}>
  280. <View style={styles.JLView}>
  281. <Text style={styles.textColor31}>装置型号</Text>
  282. <Text style={styles.JLModel}>{item.model}</Text>
  283. </View>
  284. <View style={styles.JLView}>
  285. <Text style={styles.textColor31}>额定频率</Text>
  286. <Text style={styles.JLModel}>50Hz</Text>
  287. </View>
  288. <View style={styles.JLView}>
  289. <Text style={styles.textColor31}>额定电流</Text>
  290. <Text style={[styles.JLModel]}>{item.senondCurrent} A </Text>
  291. </View>
  292. <View style={styles.JLView}>
  293. <Text style={styles.textColor31}>制造年月</Text>
  294. <Text style={styles.JLModel}>{item.releaseDate}</Text>
  295. </View>
  296. </View>
  297. <View style={{
  298. width: (screenW - 10) / 3 * 1,
  299. textAlign: 'center',
  300. alignItems: 'center',
  301. flex: 1,
  302. }}>
  303. <QRCode
  304. value={item.assetID}//二维码内容
  305. logoBorderRadius={1}
  306. color={"#333333"}//二维码颜色
  307. backgroundColor={"#ffffff"}//背景色
  308. size={65}//二维码宽高
  309. />
  310. <Text style={[styles.textColor]}>{item.assetID.slice(0,10)}</Text>
  311. <Text style={[styles.textColor]}>{item.assetID.slice(10,20)}</Text>
  312. </View>
  313. </View>
  314. <Text style={[styles.textColor, {marginVertical: 10, fontWeight: "bold",}]}>{item.manufacturer}</Text>
  315. </View>
  316. )
  317. }
  318. errorRender = (item, index) => {
  319. return (
  320. <View
  321. key={index}
  322. style={[styles.mainView, {padding: 10}]}
  323. >
  324. <Text style={{color: 'red'}}>{item.error_msg}</Text>
  325. </View>
  326. )
  327. }
  328. render() {
  329. let {isStart, zuhe_temp} = this.state;
  330. const start_text = isStart ? '开始识别' : '停止识别'
  331. return (
  332. <View style={styles.container}>
  333. <ScrollView style={styles.container}>
  334. {
  335. this.state.data.map((item, index) => {
  336. if (item.error) {
  337. return this.errorRender(item, index)
  338. }
  339. else if (item.kind.indexOf('电压') > -1) {
  340. return this.dianYaRender(item, index)
  341. }
  342. else if (item.kind.indexOf('电流') > -1) {
  343. return this.dianLiuRender(item, index)
  344. }
  345. else if (item.kind.indexOf('计量箱装置') > -1) {
  346. return this.jiliangRender(item, index)
  347. }
  348. else {
  349. // 组合互感器,没有设置,默认用电压模板
  350. if (zuhe_temp === '2') {
  351. return this.dianLiuRender(item, index)
  352. } else {
  353. return this.dianYaRender(item, index)
  354. }
  355. }
  356. })
  357. }
  358. </ScrollView>
  359. <Text
  360. style={{marginLeft: 10, color: '#f77b22'}}>合计:{this.state.data.length} 失败:{this.state.error}</Text>
  361. <View style={{flexDirection: 'row'}}>
  362. <Button onPress={() => this._start()}
  363. type="primary"
  364. style={[styles.button, {
  365. backgroundColor: isStart ? '#0099FF' : 'red',
  366. width: '65%'
  367. }]}
  368. >
  369. <Text style={{color: '#fff'}}>
  370. {start_text}
  371. </Text>
  372. </Button>
  373. <Button onPress={() => this._clear()}
  374. type="warning"
  375. style={{
  376. width: '25%',
  377. borderRadius: 5,
  378. marginHorizontal: 10,
  379. marginTop: 5,
  380. marginBottom: 2,
  381. borderWidth: 0,
  382. backgroundColor: "#de7642"
  383. }}
  384. >
  385. <Text style={{color: '#fff'}}>
  386. 清除
  387. </Text>
  388. </Button>
  389. </View>
  390. </View>
  391. );
  392. }
  393. }
  394. const styles = StyleSheet.create({
  395. container: {
  396. flex: 1,
  397. backgroundColor: '#fff'
  398. },
  399. button: {
  400. borderRadius: 5,
  401. marginHorizontal: 10,
  402. marginBottom: 2,
  403. marginTop: 5,
  404. borderWidth: 0,
  405. backgroundColor: "#2b90ea"
  406. },
  407. textColor: {
  408. color: '#333',
  409. textAlign: 'center',
  410. },
  411. textColor3: {
  412. color: '#333',
  413. textAlign: 'center',
  414. width: (screenW - 9) / 3,
  415. },
  416. textColor4: {
  417. color: '#333',
  418. textAlign: 'center',
  419. width: (screenW - 8) / 4,
  420. },
  421. textColor2: {
  422. color: '#333',
  423. textAlign: 'center',
  424. width: (screenW - 10) / 2,
  425. },
  426. mainView: {
  427. margin: 5,
  428. borderWidth: 0.5,
  429. borderColor: '#7b7b7b',
  430. },
  431. betweenView: {
  432. flexDirection: 'row',
  433. justifyContent: 'space-between',
  434. borderTopWidth: 0.5,
  435. borderTopColor: '#7b7b7b',
  436. },
  437. centerWidth: {
  438. borderLeftWidth: 0.5,
  439. borderRightWidth: 0.5,
  440. borderLeftColor: '#7b7b7b',
  441. borderRightColor: '#7b7b7b',
  442. alignItems: 'center',
  443. flexDirection: 'row',
  444. },
  445. centerView: {
  446. alignItems: 'center',
  447. flexDirection: 'row',
  448. },
  449. rightWidth: {
  450. borderRightWidth: 0.5,
  451. borderRightColor: '#7b7b7b',
  452. alignItems: 'center',
  453. flexDirection: 'row',
  454. },
  455. textColor31: {
  456. fontWeight: "bold",
  457. color: '#333',
  458. textAlign: 'center',
  459. width: (screenW - 9) * 0.25,
  460. },
  461. JLModel: {
  462. fontWeight: "bold",
  463. borderWidth: 1,
  464. borderLeftColor: '#7b7b7b',
  465. color: '#333',
  466. textAlign: 'center',
  467. width: (screenW - 9) * 0.40,
  468. },
  469. JLView: {
  470. flexDirection: 'row',
  471. marginBottom: 5
  472. },
  473. })
  474. export default DesktopHome;