|
@@ -18,6 +18,12 @@ export default class Control extends PureComponent {
|
|
|
|
|
|
componentWillMount() {
|
|
componentWillMount() {
|
|
this.getData();
|
|
this.getData();
|
|
|
|
+ this.interval = setInterval(() => this.getData(), 300000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //组件销毁的时候清除定时器就行
|
|
|
|
+ componentWillUnmount() {
|
|
|
|
+ clearInterval(this.interval);
|
|
}
|
|
}
|
|
|
|
|
|
// 获取数据
|
|
// 获取数据
|
|
@@ -60,16 +66,7 @@ export default class Control extends PureComponent {
|
|
axios.post("/api/v1/set_temp",{temp : temperature + 1}).then(res => {
|
|
axios.post("/api/v1/set_temp",{temp : temperature + 1}).then(res => {
|
|
const data = res?.data;
|
|
const data = res?.data;
|
|
if(data && data.code === 0){
|
|
if(data && data.code === 0){
|
|
- this.setState((prevState)=>{
|
|
|
|
- if(prevState && prevState.temperature > 30){
|
|
|
|
- this.toast('最高温度30度',2000);
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- return {
|
|
|
|
- temperature : prevState.temperature++,
|
|
|
|
- ...prevState
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ this.setState({temperature : temperature + 1});
|
|
}else {
|
|
}else {
|
|
this.toast(data.message,2000);
|
|
this.toast(data.message,2000);
|
|
}
|
|
}
|
|
@@ -88,12 +85,7 @@ export default class Control extends PureComponent {
|
|
axios.post("/api/v1/set_temp",{temp : temperature - 1}).then(res => {
|
|
axios.post("/api/v1/set_temp",{temp : temperature - 1}).then(res => {
|
|
const data = res?.data;
|
|
const data = res?.data;
|
|
if(data && data.code === 0){
|
|
if(data && data.code === 0){
|
|
- this.setState((prevState)=>{
|
|
|
|
- return {
|
|
|
|
- temperature : prevState.temperature--,
|
|
|
|
- ...prevState
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ this.setState({ temperature : temperature - 1})
|
|
}else {
|
|
}else {
|
|
this.toast(data.message,2000);
|
|
this.toast(data.message,2000);
|
|
}
|
|
}
|
|
@@ -165,7 +157,7 @@ export default class Control extends PureComponent {
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
|
|
|
- const { temperature , pattern , windSpeed , selectType , openVisible , data } = this.state;
|
|
|
|
|
|
+ const { pattern , windSpeed , openVisible , data } = this.state;
|
|
return (
|
|
return (
|
|
<div className="control">
|
|
<div className="control">
|
|
<div className='control_item'>
|
|
<div className='control_item'>
|
|
@@ -177,7 +169,7 @@ export default class Control extends PureComponent {
|
|
</div>
|
|
</div>
|
|
<div className='expected_temperature'>
|
|
<div className='expected_temperature'>
|
|
<div style={{ fontSize: '20px' }}>预计温度</div>
|
|
<div style={{ fontSize: '20px' }}>预计温度</div>
|
|
- <div style={{ fontSize: '50px', marginTop: '60px' }}>{temperature}℃</div>
|
|
|
|
|
|
+ <div style={{ fontSize: '50px', marginTop: '60px' }}>{this.state.temperature}℃</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div>
|
|
<div className='up' onClick={this.add}>
|
|
<div className='up' onClick={this.add}>
|