Home.js 19 KB

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