import React, {Component} from 'react'; import {Text, TouchableOpacity, View, TextInput, StyleSheet} from 'react-native'; import {Button, Slider, Provider, Toast,} from "@ant-design/react-native"; import ReadUHF from "../../utils/ReadUHF"; // import SyncStorage from "sync-storage"; import {SyncStorage} from "../../utils"; import ComponentsStyles from "../../components/ComponentsStyles"; import RadioModal from "../../components/RadioModal"; class SetPower extends Component { constructor(props) { super(props); this.state = { power: 30, no_begin: '8', no_length: '14', show_type: '1', zuhe_temp: '1', }; } async componentDidMount() { ReadUHF.getPower((ver) => { this.setState({ power: parseInt(ver) }) }); const no_begin = await SyncStorage.get('no_begin') const no_length = await SyncStorage.get('no_length') if (no_begin && no_begin) { this.setState({no_begin, no_length}) } let show_type = await SyncStorage.get('show_type') let zuhe_temp = await SyncStorage.get('zuhe_temp') zuhe_temp = zuhe_temp ? zuhe_temp.toString() : '1' show_type = show_type ? show_type.toString() : '1' this.setState({zuhe_temp, show_type}) } onTypeChange = () => { if (this.state.show_type == '1') { this.setState({show_type: '0'}) } else { this.setState({show_type: '1'}) } } _savePower = async () => { let {no_begin, no_length, show_type, zuhe_temp} = this.state; no_begin = parseInt(no_begin) no_length = parseInt(no_length) if (isNaN(no_begin) || isNaN(no_length)) { Toast.info('数字填写有误!') return } if (no_begin < 1 || no_begin > 20) { Toast.info('起始地址只能填1到20之间的数字!') return } if (no_length < 1 || no_length > 20) { Toast.info('长度只能填1到20之间数字!') return } SyncStorage.set('no_begin', no_begin.toString()) SyncStorage.set('no_length', no_length.toString()) SyncStorage.set('show_type', show_type) SyncStorage.set('zuhe_temp', zuhe_temp) ReadUHF.setPower(this.state.power) this.props.navigation.goBack(); } render() { return ( 当前功率:{this.state.power} { this.setState({power: parseInt(value)}) }} min={5} max={30}/> NO起始地址: this.setState({no_begin: text})} value={this.state.no_begin} placeholder={'请输入'} /> 长度: this.setState({no_length: text})} value={this.state.no_length} placeholder={'请输入'} /> this.onTypeChange()} style={{ marginHorizontal: 3, flexDirection: 'row', }}> {this.state.show_type === '1' ? : } 只显示本类别芯片 组合互感器模板: this.setState({zuhe_temp: id})} style={ComponentsStyles.radioStyle} innerStyle={{ width: 80, }} > 电压模板 电流模板 ) } } const styles = StyleSheet.create({ textinput: { width: 60, textAlign: "left", height: 45, borderBottomWidth: 1, borderBottomColor: '#878787', }, font14: { color: '#333', fontSize: 14, }, titleCenter: { justifyContent: 'center', }, }) export default SetPower