Set.js 6.9 KB

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