|
@@ -41,6 +41,7 @@ export default class HomePage extends Component {
|
|
|
permissionDenied: false,
|
|
permissionDenied: false,
|
|
|
pinMessages: []
|
|
pinMessages: []
|
|
|
};
|
|
};
|
|
|
|
|
+ this.isFirst = true;
|
|
|
this.denied = true;
|
|
this.denied = true;
|
|
|
this.backSeconds = 0;
|
|
this.backSeconds = 0;
|
|
|
this.refreshTime = 0;
|
|
this.refreshTime = 0;
|
|
@@ -73,14 +74,16 @@ export default class HomePage extends Component {
|
|
|
navigation.addListener('focus', () => {
|
|
navigation.addListener('focus', () => {
|
|
|
//console.log('------Home------', "Focus")
|
|
//console.log('------Home------', "Focus")
|
|
|
this.onCloseInfo();
|
|
this.onCloseInfo();
|
|
|
- SettingUtil.getSettings(set => {
|
|
|
|
|
- //console.log("获取设置信息", set);
|
|
|
|
|
- this.settingInfo = set;
|
|
|
|
|
- this.init();
|
|
|
|
|
- })
|
|
|
|
|
- this.setState({
|
|
|
|
|
- isHide: false
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (this.state.isHide) {
|
|
|
|
|
+ SettingUtil.getSettings(set => {
|
|
|
|
|
+ //console.log("获取设置信息", set);
|
|
|
|
|
+ this.settingInfo = set;
|
|
|
|
|
+ this.init();
|
|
|
|
|
+ })
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ isHide: false
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
/*if (!app.isWhitelabel) {
|
|
/*if (!app.isWhitelabel) {
|
|
|
MyStatusBar.setStatusBarThemes(MyStatusBar.DARK_STYLE, colorLight);
|
|
MyStatusBar.setStatusBarThemes(MyStatusBar.DARK_STYLE, colorLight);
|
|
|
}*/
|
|
}*/
|
|
@@ -116,6 +119,10 @@ export default class HomePage extends Component {
|
|
|
this.showUpdateDialog(this.forceUpdateDialog);
|
|
this.showUpdateDialog(this.forceUpdateDialog);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ SettingUtil.getSettings(set => {
|
|
|
|
|
+ //console.log("获取设置信息", set);
|
|
|
|
|
+ this.settingInfo = set;
|
|
|
|
|
+ })
|
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.toExit)
|
|
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.toExit)
|
|
|
this.checkUpdateVersion();
|
|
this.checkUpdateVersion();
|
|
|
this.getPinMessage();
|
|
this.getPinMessage();
|
|
@@ -135,23 +142,23 @@ export default class HomePage extends Component {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- init() {
|
|
|
|
|
|
|
+ init(init=false) {
|
|
|
if (this.state.stopList.length == 0 && !this.refresh) {
|
|
if (this.state.stopList.length == 0 && !this.refresh) {
|
|
|
storage.getStorage(KEY_STORE_LIST).then(data => {
|
|
storage.getStorage(KEY_STORE_LIST).then(data => {
|
|
|
- //console.log("获取站点缓存", "成功");
|
|
|
|
|
|
|
+ console.log("获取站点缓存", "成功");
|
|
|
if (data) {
|
|
if (data) {
|
|
|
const list = JSON.parse(data);
|
|
const list = JSON.parse(data);
|
|
|
this.setState({
|
|
this.setState({
|
|
|
stopList: list
|
|
stopList: list
|
|
|
}, () => {
|
|
}, () => {
|
|
|
- this.checkPermission2Geo(true);
|
|
|
|
|
|
|
+ this.checkPermission2Geo(init);
|
|
|
})
|
|
})
|
|
|
} else {
|
|
} else {
|
|
|
- this.checkPermission2Geo(true);
|
|
|
|
|
|
|
+ this.checkPermission2Geo(init);
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
console.log("获取站点缓存-err", err);
|
|
console.log("获取站点缓存-err", err);
|
|
|
- this.checkPermission2Geo(true);
|
|
|
|
|
|
|
+ this.checkPermission2Geo(init);
|
|
|
})
|
|
})
|
|
|
storage.getStorage(KEY_STORE_GPS).then(data => {
|
|
storage.getStorage(KEY_STORE_GPS).then(data => {
|
|
|
//console.log("获取GPS缓存", data);
|
|
//console.log("获取GPS缓存", data);
|
|
@@ -206,7 +213,7 @@ export default class HomePage extends Component {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
mapReady: true
|
|
mapReady: true
|
|
|
}, () => {
|
|
}, () => {
|
|
|
- this.init();
|
|
|
|
|
|
|
+ this.init(true);
|
|
|
});
|
|
});
|
|
|
}, 500);
|
|
}, 500);
|
|
|
}
|
|
}
|
|
@@ -265,6 +272,7 @@ export default class HomePage extends Component {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
hasPermission: true
|
|
hasPermission: true
|
|
|
});
|
|
});
|
|
|
|
|
+ this.refresh = false;
|
|
|
this.checkPermission2Geo();
|
|
this.checkPermission2Geo();
|
|
|
} else {
|
|
} else {
|
|
|
this.noPermissionSite();
|
|
this.noPermissionSite();
|
|
@@ -272,31 +280,30 @@ export default class HomePage extends Component {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- checkPermission2Geo(refresh, button) {
|
|
|
|
|
|
|
+ checkPermission2Geo(button) {
|
|
|
if (button && this.state.lastRegion.latitude) {
|
|
if (button && this.state.lastRegion.latitude) {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
region: {...this.state.lastRegion}
|
|
region: {...this.state.lastRegion}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- if (this.refresh == refresh) {
|
|
|
|
|
|
|
+ console.log("checkPermission2Geo", button, this.refresh);
|
|
|
|
|
+ if (this.refresh) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (refresh) {
|
|
|
|
|
- //避免关闭自动移动地图后无法点击按钮移动地图
|
|
|
|
|
- this.refresh = true
|
|
|
|
|
- }
|
|
|
|
|
- console.log("checkPermission2Geo", refresh, button);
|
|
|
|
|
|
|
+ //避免关闭自动移动地图后无法点击按钮移动地图
|
|
|
|
|
+ this.refresh = true
|
|
|
//this.checkGPS();
|
|
//this.checkGPS();
|
|
|
if (this.state.hasPermission) {
|
|
if (this.state.hasPermission) {
|
|
|
- this.infoGeoLocation();
|
|
|
|
|
|
|
+ this.infoGeoLocation(button);
|
|
|
} else {
|
|
} else {
|
|
|
LocationPermission.checkPermission((hasPermission, canRequestPermission) => {
|
|
LocationPermission.checkPermission((hasPermission, canRequestPermission) => {
|
|
|
if (hasPermission) {
|
|
if (hasPermission) {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
hasPermission: true
|
|
hasPermission: true
|
|
|
});
|
|
});
|
|
|
- this.infoGeoLocation();
|
|
|
|
|
|
|
+ this.infoGeoLocation(button);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ this.refresh = false;
|
|
|
if (canRequestPermission) {
|
|
if (canRequestPermission) {
|
|
|
if (this.denied) {
|
|
if (this.denied) {
|
|
|
this.denied = false;
|
|
this.denied = false;
|
|
@@ -342,15 +349,15 @@ export default class HomePage extends Component {
|
|
|
//if (this.state.stopList.length == 0) { //只加载一次
|
|
//if (this.state.stopList.length == 0) { //只加载一次
|
|
|
let time = new Date().getTime();
|
|
let time = new Date().getTime();
|
|
|
let interval = this.settingInfo.refreshInterval * 1000;//重复加载时间
|
|
let interval = this.settingInfo.refreshInterval * 1000;//重复加载时间
|
|
|
- let first = this.state.stopList.length == 0;//是否第一次加载
|
|
|
|
|
- if (first || this.refresh || time - this.refreshTime > interval) { //一分钟(10秒)加载一次
|
|
|
|
|
- this.getStationList(region, first || this.refresh);
|
|
|
|
|
|
|
+ if (this.isFirst || this.refresh || time - this.refreshTime > interval || region) { //一分钟(10秒)加载一次
|
|
|
|
|
+ this.getStationList(region, this.isFirst || this.refresh);
|
|
|
this.refreshTime = time;
|
|
this.refreshTime = time;
|
|
|
} else if (this.settingInfo.moveMyLocation) {
|
|
} else if (this.settingInfo.moveMyLocation) {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
region: region
|
|
region: region
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ this.refresh = false;
|
|
|
}, error => {
|
|
}, error => {
|
|
|
console.info("getGeoLocation", error);
|
|
console.info("getGeoLocation", error);
|
|
|
if (!again) {
|
|
if (!again) {
|
|
@@ -358,11 +365,10 @@ export default class HomePage extends Component {
|
|
|
this.infoGeoLocation(true);
|
|
this.infoGeoLocation(true);
|
|
|
}, 2000);
|
|
}, 2000);
|
|
|
}
|
|
}
|
|
|
|
|
+ this.refresh = false;
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- setTimeout(() => {
|
|
|
|
|
- this.infoGeoLocation(true);
|
|
|
|
|
- }, 1000);
|
|
|
|
|
|
|
+ this.refresh = false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -386,6 +392,7 @@ export default class HomePage extends Component {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
region: region
|
|
region: region
|
|
|
});
|
|
});
|
|
|
|
|
+ this.isFirst = false;
|
|
|
}
|
|
}
|
|
|
apiStation.getAllStation(this.filter).then(res => {
|
|
apiStation.getAllStation(this.filter).then(res => {
|
|
|
Dialog.dismissLoading();
|
|
Dialog.dismissLoading();
|
|
@@ -584,7 +591,7 @@ export default class HomePage extends Component {
|
|
|
onMapReady={() => this.onMapReady()}
|
|
onMapReady={() => this.onMapReady()}
|
|
|
onFavorite={() => this.favoriteSite()}
|
|
onFavorite={() => this.favoriteSite()}
|
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
|
- onLocation={() => this.checkPermission2Geo(true, true)}
|
|
|
|
|
|
|
+ onLocation={() => this.checkPermission2Geo(true)}
|
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
|
viewChargeStation={id => this.viewChargeStation(id)}/>
|
|
viewChargeStation={id => this.viewChargeStation(id)}/>
|
|
@@ -595,7 +602,7 @@ export default class HomePage extends Component {
|
|
|
onMapReady={() => this.onMapReady()}
|
|
onMapReady={() => this.onMapReady()}
|
|
|
onFavorite={() => this.favoriteSite()}
|
|
onFavorite={() => this.favoriteSite()}
|
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
|
- onLocation={() => this.checkPermission2Geo(true, true)}
|
|
|
|
|
|
|
+ onLocation={() => this.checkPermission2Geo(true)}
|
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
|
viewChargeStation={id => this.viewChargeStation(id)}
|
|
viewChargeStation={id => this.viewChargeStation(id)}
|