Forráskód Böngészése

Enhancement account deletion logic.
https://dev.wormwood.com.sg/zentao/task-view-357.html

vbea 1 éve
szülő
commit
bbbd410c04

+ 2 - 2
Strides-APP/app/api/apiUser.js

@@ -79,8 +79,8 @@ export default user = {
   getCountryList: () => {
     return get('devicesApi/base/getCountries')
   },
-  deleteAccount: () => {
-    return get(prefix + 'delUser')
+  deleteAccount: (data) => {
+    return get(prefix + 'delUser', data)
   },
   getVehicleBrandList: () => {
     return get(prefix + "brands")

+ 29 - 4
Strides-APP/app/pages/home/Home.js

@@ -18,6 +18,7 @@ import MapUILumi from './MapUILumi';
 import storage from '../../utils/storage';
 
 const KEY_STORE_LIST = "map_stop_list"
+const KEY_STORE_GPS = "map_location_gps"
 
 export default class HomePage extends Component {
   constructor(props) {
@@ -29,6 +30,7 @@ export default class HomePage extends Component {
         latitudeDelta: 0.0922,
         longitudeDelta: 0.0421
       },
+      lastRegion: {},
       mapReady: false,
       showStation: false,
       stationId: "",
@@ -120,7 +122,7 @@ export default class HomePage extends Component {
   init() {
     if (this.state.stopList.length == 0 && !this.refresh) {
       storage.getStorage(KEY_STORE_LIST).then(data => {
-        console.log("获取站点缓存", "成功");
+        //console.log("获取站点缓存", "成功");
         if (data) {
           const list = JSON.parse(data);
           this.setState({
@@ -135,6 +137,16 @@ export default class HomePage extends Component {
         console.log("获取站点缓存-err", err);
         this.checkPermission2Geo(true);
       })
+      storage.getStorage(KEY_STORE_GPS).then(data => {
+        //console.log("获取GPS缓存", data);
+        if (data && data.latitude) {
+          this.setState({
+            lastRegion: data
+          });
+        }
+      }).catch(err => {
+        console.log("获取GPS缓存-err", err);
+      })
     }
   }
 
@@ -239,7 +251,12 @@ export default class HomePage extends Component {
     })
   }
 
-  checkPermission2Geo(refresh) {
+  checkPermission2Geo(refresh, button) {
+    if (button && this.state.lastRegion.latitude) {
+      this.setState({
+        region: {...this.state.lastRegion}
+      });
+    }
     if (this.refresh == refresh) {
       return;
     }
@@ -299,6 +316,7 @@ export default class HomePage extends Component {
           latitudeDelta: 0.0922,
           longitudeDelta: 0.0421
         }
+        this.saveGPSCache(region);
         //console.log("getGeoLocation", region);
         //if (this.state.stopList.length == 0) { //只加载一次
         let time = new Date().getTime();
@@ -501,6 +519,13 @@ export default class HomePage extends Component {
     })
   }
 
+  saveGPSCache(location) {
+    storage.setStorageJson(KEY_STORE_GPS, location);
+    this.setState({
+      lastRegion: location
+    });
+  }
+
   render() {
     return (
       <View style={ui.flex1}>
@@ -512,7 +537,7 @@ export default class HomePage extends Component {
             onMapReady={() => this.onMapReady()}
             onFavorite={() => this.favoriteSite()}
             onCloseInfo={() => this.onCloseInfo()}
-            onLocation={() => this.checkPermission2Geo(true)}
+            onLocation={() => this.checkPermission2Geo(true, true)}
             useApplesMap={this.settingInfo.useApplesMap}
             showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
             viewChargeStation={id => this.viewChargeStation(id)}/>
@@ -523,7 +548,7 @@ export default class HomePage extends Component {
             onMapReady={() => this.onMapReady()}
             onFavorite={() => this.favoriteSite()}
             onCloseInfo={() => this.onCloseInfo()}
-            onLocation={() => this.checkPermission2Geo(true)}
+            onLocation={() => this.checkPermission2Geo(true, true)}
             useApplesMap={this.settingInfo.useApplesMap}
             showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
             viewChargeStation={id => this.viewChargeStation(id)}

+ 20 - 7
Strides-APP/app/pages/my/ProfileV2.js

@@ -53,9 +53,11 @@ export default class ProfileV2 extends Component {
     })
   }
 
-  deleteMyAccount() {
+  deleteMyAccount(again=false) {
     Dialog.showProgressDialog();
-    apiUser.deleteAccount().then(res => {
+    apiUser.deleteAccount({
+      secondConfirm: again
+    }).then(res => {
       toastShort($t('profile.deleteAccountSuccess'))
       Dialog.dismissLoading();
       this.requestLogout();
@@ -66,11 +68,22 @@ export default class ProfileV2 extends Component {
       Dialog.dismissLoading();
       //toastShort(err)
       setTimeout(() => {
-        Dialog.showDialog({
-          title: $t("common.error"),
-          message: err.msg,
-          showCancel: false
-        });
+        if (err.code == 5334) {
+          Dialog.showDialog({
+            title: $t('profile.deleteAccount'),
+            message: err.msg,
+            ok: $t("nav.confirm"),
+            callback: button => {
+              if (button == Dialog.BUTTON_OK) {
+                setTimeout(() => {
+                  this.deleteMyAccount(true);
+                }, 500)
+              }
+            }
+          })
+        } else {
+          Dialog.showResultDialog(err.msg);
+        }
       }, 500);
     })
   }

+ 20 - 3
Strides-APP/app/pages/my/ProfileV3.js

@@ -69,9 +69,11 @@ export default class ProfileV3 extends Component {
     })
   }
 
-  deleteMyAccount() {
+  deleteMyAccount(again=false) {
     Dialog.showProgressDialog();
-    apiUser.deleteAccount().then(res => {
+    apiUser.deleteAccount({
+      secondConfirm: again
+    }).then(res => {
       toastShort($t('profile.deleteAccountSuccess'))
       Dialog.dismissLoading();
       this.requestLogout();
@@ -82,7 +84,22 @@ export default class ProfileV3 extends Component {
       Dialog.dismissLoading();
       //toastShort(err)
       setTimeout(() => {
-        Dialog.showResultDialog(err.msg);
+        if (err.code == 5334) {
+          Dialog.showDialog({
+            title: $t('profile.deleteAccount'),
+            message: err.msg,
+            ok: $t("nav.confirm"),
+            callback: button => {
+              if (button == Dialog.BUTTON_OK) {
+                setTimeout(() => {
+                  this.deleteMyAccount(true);
+                }, 500)
+              }
+            }
+          })
+        } else {
+          Dialog.showResultDialog(err.msg);
+        }
       }, 500);
     })
   }