vbea há 3 anos atrás
pai
commit
a95500fd91

+ 2 - 2
Strides-APP/android/app/version.properties

@@ -1,2 +1,2 @@
-#Fri Feb 10 17:42:26 CST 2023
-VERSION_CODE=106
+#Mon Feb 13 14:43:12 CST 2023
+VERSION_CODE=109

+ 4 - 0
Strides-APP/app/pages/Router.js

@@ -49,6 +49,7 @@ import PayPerUse from './payment/PayPerUse';
 import PaymentWeb from './payment/PaymentWeb';
 import Settings from './Settings';
 import ChargeAdapter from './chargeV2/ChargeAdapter';
+import { BridgePage } from '../utils/routeUtil';
 
 export var PageList = {
   'splash': {
@@ -58,6 +59,9 @@ export var PageList = {
     component: Home,
     options: TransitionPresets.FadeFromBottomAndroid
   },
+  'bridge': {
+    component: BridgePage
+  },
   'search': {
     title: 'Search',
     component: Search

+ 1 - 1
Strides-APP/app/pages/chargeV2/Charging.js

@@ -242,7 +242,7 @@ export const DashboardView = ({isCharging=false, connectorInfo={}}) => {
               style={styles.dashboardItemTitle}>Total kWh Delivered</Text>
           </View>
           <View style={styles.dashboardItemView}>
-          <Text style={styles.dashboardItemValueWeight}>{currency} {connectorInfo?.totalCharges ?? "0.0"}</Text>
+          <Text style={styles.dashboardItemValueWeight}>{currency} {utils.toFixed(connectorInfo?.totalCharges, 2) ?? "0.0"}</Text>
             <Text
               numberOfLines={1}
               ellipsizeMode="tail"

+ 39 - 5
Strides-APP/app/pages/home/Home.js

@@ -30,10 +30,12 @@ export default class HomePage extends Component {
       stopList: [],
       hasPermission: isIOS
     };
+    this.isHide = true;
     this.denied = true;
     this.backSeconds = 0;
     this.refreshTime = 0;
     this.settingInfo = {}
+    //this.unsubscribe = null;
     this.filter = {
       parkingFee: 'ALL',
       connectorType: ''
@@ -41,6 +43,7 @@ export default class HomePage extends Component {
   }
 
   componentDidMount() {
+    console.log("componentDidMount")
     const navigation = this.props.navigation;
     navigation.addListener('focus', () => {
       //toastShort('onResume')
@@ -52,30 +55,61 @@ export default class HomePage extends Component {
         this.settingInfo = set;
         this.checkPermission2Geo();
       })
-      
+      console.log("focus");
+      this.isHide = false;
     });
 
     navigation.addListener('blur', () => {
       //toastShort('onStop')
+      this.isHide = true;
       setTimeout(() => {
         navigation.closeDrawer();
       }, 200);
     });
 
-    navigation.addListener('beforeRemove', (e) => {
+    /*this.unsubscribe = navigation.addListener('beforeRemove', (e) => {
+      this.toExit(e);
+    });*/
+    BackHandler.addEventListener('hardwareBackPress', this.toExit)
+    this.isHide = false;
+  }
+
+  /*componentDidUpdate() {
+    console.log("componentDidUpdate", this.unsubscribe);
+    if (!this.unsubscribe) {
+      this.unsubscribe = this.props.navigation.addListener('beforeRemove', (e) => {
+        this.toExit(e);
+      });
+    }
+  }*/
+
+  componentWillUnmount() {
+    /*console.log("componentWillUnmount")
+    if (this.unsubscribe) {
+      this.unsubscribe();
+    }*/
+    this.backSeconds = 0;
+    BackHandler.removeEventListener("hardwareBackPress", this.toExit)
+  }
+
+  toExit = () => {
+    console.log("beforeRemove", this.isHide);
+    if (!this.isHide) {
       if (isIOS) {
-        e.preventDefault();
+        //e.preventDefault();
       } else {
         let time = new Date().getTime();
+        //console.log("beforeRemove2", time, this.backSeconds);
         if (time - this.backSeconds < 2000) {
           BackHandler.exitApp();
         } else {
           toastShort("Press the back button again to exit the program");
           this.backSeconds = time;
-          e.preventDefault();
+          //e.preventDefault();
         }
       }
-    });
+      return true;
+    }
   }
 
   getPermission() {

+ 3 - 4
Strides-APP/app/pages/my/ProfileV2.js

@@ -85,9 +85,8 @@ export default class ProfileV2 extends Component {
     apiUser.deleteAccount().then(res => {
       toastShort('Successfully deleted!')
       Dialog.dismissLoading();
-      setTimeout(() => {
-        startPage(PageList.login);
-      }, 500);
+      //startPage(PageList.login);
+      this.requestLogout();
     }).catch(err => {
       Dialog.dismissLoading();
       toastShort(err)
@@ -231,7 +230,7 @@ export default class ProfileV2 extends Component {
         </View> */}
         <Pressable
           style={styles.cardView}
-          onPress={() => startPage(PageList.changePassword)}>
+          onPress={() => startPage(PageList.changePassword, {action: "change"})}>
           <Image
             style={styles.cardIcon}
             source={require('../../images/user/card-account.png')}/>

+ 4 - 0
Strides-APP/app/pages/sign/RegisterV4.js

@@ -166,6 +166,10 @@ export default class RegisterV4 extends React.Component {
       toastShort('Email is incorrect format');
       return;
     }
+    if (!info.verificationCode) {
+      toastShort('Please enter verification code');
+      return;
+    }
     if (!info.phone) {
       toastShort('Please enter contact number');
       return;

+ 36 - 1
Strides-APP/app/pages/sign/ResetPasswordV2.js

@@ -5,9 +5,13 @@
 import React, { Component } from 'react';
 import { View, StyleSheet, ScrollView, Image, TextInput, Pressable } from 'react-native';
 import apiUser from '../../api/apiUser';
+import { setAccessToken } from '../../api/http';
 import Button from '../../components/Button';
 import Dialog from '../../components/Dialog';
 import { Styles } from '../../components/Toolbar';
+import routeUtil from '../../utils/routeUtil';
+import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
+import { PageList } from '../Router';
 import StrengthView from './StrengthView';
 
 export default class ResetPassword extends Component {
@@ -27,6 +31,17 @@ export default class ResetPassword extends Component {
       password: '',
       verificationCode: ''
     }
+    this.isChange = false;
+  }
+
+  componentDidMount() {
+    const action = this.props.route?.params?.action ?? "";
+    if (action == "change") {
+      this.isChange = true;
+      setTimeout(() => {
+        this.requestLogout();
+      }, 1000);
+    }
   }
 
   componentWillUnmount() {
@@ -144,13 +159,33 @@ export default class ResetPassword extends Component {
     apiUser.updatePassword(this.formInfo).then(res => {
       Dialog.dismissLoading()
       toastShort('Reset password successfully');
-      goBack();
+      if (this.isChange) {
+        this.requestLogout();
+      } else {
+       goBack();
+      }
     }).catch(err => {
       Dialog.dismissLoading()
       toastShort(err);
     });
   }
 
+  async requestLogout() {
+    const data = await getStorageJsonSync('loginData');
+    if (data && data.email) {
+      delete data.password
+      setStorageJson('loginData', data);
+      setStorage('RegisterTokenDate', "");
+    }
+    global.userInfo = {}
+    /*this.setState({
+      isLogin: false,
+      userInfo: {}
+    });*/
+    setAccessToken('');
+    routeUtil.bridge2Page(PageList.login);
+  }
+
   getStrengthStyle() {
     const persent = ((this.StrengthView.maxStrength - this.state.strength) / this.StrengthView.maxStrength) * 100
     return {

+ 118 - 0
Strides-APP/app/utils/routeUtil.js

@@ -0,0 +1,118 @@
+/**
+ * Route Util
+ * @邠心vbe on 2023/02/13
+ */
+import { CommonActions } from '@react-navigation/routers';
+import React, { Component } from 'react';
+import { View } from 'react-native';
+import { PagerList } from '../pages/chargeV2/ChargeAdapter';
+import { PageList } from '../pages/Router';
+
+const routeUtil = {
+  /**
+   * 重置路由并导航到首页
+   * @param {Object} props 页面道具
+   */
+  resetToHome: (props) => {
+    if (props.navigation) {
+      props.navigation.reset({
+        index: 0,
+        routes: [{
+          name: PageList.home
+        }]
+      });
+    }
+  },
+  /**
+   * 重置路由并导航到指定路由
+   * @param {Object} props 页面道具
+   * @param {Array} routes 指定路由
+   */
+  resetHome2Page: (props, routes=[]) => {
+    if (props.navigation) {
+      props.navigation.reset({
+        index: routes.length,
+        routes: [
+          {
+            name: PageList.home,
+          },
+          ...routes
+        ]
+      })
+    }
+  },
+  /**
+   * 跳转到新页面并清除当前页面
+   * @param {Object} props 页面道具
+   * @param {Object} route 需要导航的路由
+   */
+  redirectTo: (props, route) => {
+    if (props.navigation) {
+      props.navigation.dispatch(state => {
+        var routes = []
+        routes = JSON.parse(JSON.stringify(state.routes))
+        routes.pop();
+        routes.push(route);
+        return CommonActions.reset({
+          index: routes.length - 1,
+          routes: routes
+        })
+      });
+    }
+  },
+  /**
+   * 导航到中转页面
+   * @param {String} route 需要导航的路由名称
+   */
+  bridge2Page: (route) => {
+    startPage(PageList.bridge, {route: route})
+  },
+  /**
+   * 导航到中转页面
+   * @param {Array} routes 需要导航的路由
+   */
+  bridge2Pages: (routes=[]) => {
+    startPage(PageList.bridge, {routes: routes})
+  }
+}
+
+export default routeUtil;
+
+export class BridgePage extends Component {
+  constructor(props) {
+    super(props);
+    this.state = {
+      params: ""
+    };
+  }
+
+  componentDidMount() {
+    const routes = this.props.route?.params?.routes
+    const route = this.props.route?.params?.route
+    if (route) {
+      startPage(route);
+    } else if (routes) {
+      console.log('bridge', routes);
+      setTimeout(() => {
+        routeUtil.resetHome2Page(this.props, routes)
+      }, 500);
+    }
+    this.props.navigation.addListener('focus', e => {
+      console.log('bridge.focus', this.props.route?.params)
+      if (this.state.params) {
+        routeUtil.resetToHome(this.props)
+      } else {
+        this.setState({
+          params: true
+        })
+      }
+    });
+  }
+
+  render() {
+    return (
+      <View style={ui.flex1}>
+      </View>
+    );
+  }
+}

+ 13 - 0
Strides-APP/app/utils/utils.js

@@ -173,5 +173,18 @@ export default {
       });
     }
     return str;
+  },
+  /**
+   * 将给定数字保留任意位小数
+   * @param {*} text 
+   * @param {number} scape 
+   * @returns 小数
+   */
+  toFixed(text, scape) {
+    if (text) {
+      return Number(text).toFixed(scape);
+    } else {
+      return text;
+    }
   }
 }