setPower.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import React, {Component} from 'react';
  2. import {Text, TouchableOpacity, View, TextInput, StyleSheet} from 'react-native';
  3. import {Button, Slider, Provider, Toast,} from "@ant-design/react-native";
  4. import ReadUHF from "../../utils/ReadUHF";
  5. import SyncStorage from "sync-storage";
  6. import ComponentsStyles from "../../components/ComponentsStyles";
  7. import RadioModal from "../../components/RadioModal";
  8. class setPower extends Component {
  9. constructor(props) {
  10. super(props);
  11. let zuhe_temp = SyncStorage.get('zuhe_temp')
  12. zuhe_temp = zuhe_temp ? zuhe_temp.toString() : '1'
  13. this.state = {
  14. power: 30,
  15. no_begin: '8',
  16. no_length: '14',
  17. show_type: true,
  18. zuhe_temp: zuhe_temp,
  19. };
  20. }
  21. componentDidMount() {
  22. ReadUHF.getPower((ver) => {
  23. this.setState({
  24. power: parseInt(ver)
  25. })
  26. });
  27. const no_begin = SyncStorage.get('no_begin')
  28. const no_length = SyncStorage.get('no_length')
  29. if (no_begin && no_begin) {
  30. this.setState({no_begin, no_length})
  31. }
  32. const show_type = SyncStorage.get('show_type')
  33. this.setState({show_type})
  34. }
  35. onTypeChange = () => {
  36. this.setState({show_type: !this.state.show_type})
  37. }
  38. _savePower = () => {
  39. let {no_begin, no_length, show_type, zuhe_temp} = this.state;
  40. no_begin = parseInt(no_begin)
  41. no_length = parseInt(no_length)
  42. if (isNaN(no_begin) || isNaN(no_length)) {
  43. Toast.info('数字填写有误!')
  44. return
  45. }
  46. if (no_begin < 1 || no_begin > 20) {
  47. Toast.info('起始地址只能填1到20之间的数字!')
  48. return
  49. }
  50. if (no_length < 1 || no_length > 20) {
  51. Toast.info('长度只能填1到20之间数字!')
  52. return
  53. }
  54. SyncStorage.set('no_begin', no_begin.toString())
  55. SyncStorage.set('no_length', no_length.toString())
  56. SyncStorage.set('show_type', show_type)
  57. SyncStorage.set('zuhe_temp', zuhe_temp)
  58. ReadUHF.setPower(this.state.power)
  59. this.props.navigation.goBack();
  60. }
  61. render() {
  62. return (
  63. <Provider>
  64. <View style={{margin: 10}}>
  65. <Text style={styles.font14}>当前功率:{this.state.power}</Text>
  66. <Slider
  67. value={this.state.power}
  68. onChange={(value) => {
  69. this.setState({power: parseInt(value)})
  70. }}
  71. min={5}
  72. max={30}/>
  73. <View style={{flexDirection: 'row',}}>
  74. <View style={styles.titleCenter}>
  75. <Text style={styles.font14}>NO起始地址:</Text>
  76. </View>
  77. <TextInput
  78. style={styles.textinput}
  79. keyboardType={'numeric'}
  80. onChangeText={text => this.setState({no_begin: text})}
  81. value={this.state.no_begin}
  82. placeholder={'请输入'}
  83. />
  84. <View style={styles.titleCenter}>
  85. <Text style={styles.font14}>长度:</Text>
  86. </View>
  87. <TextInput
  88. style={styles.textinput}
  89. keyboardType={'numeric'}
  90. onChangeText={text => this.setState({no_length: text})}
  91. value={this.state.no_length}
  92. placeholder={'请输入'}
  93. />
  94. </View>
  95. <View style={{marginTop: 10}}>
  96. <TouchableOpacity
  97. activeOpacity={0.9}
  98. onPress={() => this.onTypeChange()}
  99. style={{
  100. marginHorizontal: 3,
  101. flexDirection: 'row',
  102. }}>
  103. {this.state.show_type ?
  104. <Text style={{
  105. borderWidth: 1,
  106. width: 18,
  107. height: 18,
  108. textAlign: 'center',
  109. color: 'red'
  110. }}>√</Text>
  111. :
  112. <Text style={{
  113. borderWidth: 1,
  114. width: 18,
  115. height: 18,
  116. }}/>
  117. }<Text style={styles.font14}> 只显示本类别芯片</Text>
  118. </TouchableOpacity>
  119. </View>
  120. <View style={{marginTop: 10, flexDirection:'row'}}>
  121. <View style={styles.titleCenter}>
  122. <Text style={styles.font14}>组合互感器模板:</Text>
  123. </View>
  124. <RadioModal
  125. selectedValue={this.state.zuhe_temp}
  126. onValueChange={id => this.setState({zuhe_temp: id})}
  127. style={ComponentsStyles.radioStyle}
  128. innerStyle={{
  129. width: 80,
  130. }}
  131. >
  132. <Text value="1">电压模板</Text>
  133. <Text value="2">电流模板</Text>
  134. </RadioModal>
  135. </View>
  136. <Button onPress={() => this._savePower()}
  137. type="primary"
  138. style={{
  139. marginTop: 20,
  140. backgroundColor: '#0099FF',
  141. borderWidth: 0,
  142. }}
  143. >
  144. <Text style={{color: '#fff'}}>
  145. 保存
  146. </Text>
  147. </Button>
  148. </View>
  149. </Provider>
  150. )
  151. }
  152. }
  153. const styles = StyleSheet.create({
  154. textinput: {
  155. width: 60,
  156. textAlign: "left",
  157. height: 45,
  158. borderBottomWidth: 1,
  159. borderBottomColor: '#878787',
  160. },
  161. font14: {
  162. color: '#333',
  163. fontSize: 14,
  164. },
  165. titleCenter: {
  166. justifyContent: 'center',
  167. },
  168. })
  169. export default setPower