Browse Source

增加服务器异常判断

daxu0403 7 năm trước cách đây
mục cha
commit
e674bbd1e9

BIN
android/.gradle/4.10.2/fileHashes/fileHashes.bin


BIN
android/.gradle/4.10.2/fileHashes/fileHashes.lock


BIN
android/.gradle/4.10.2/taskHistory/taskHistory.bin


BIN
android/.gradle/4.10.2/taskHistory/taskHistory.lock


BIN
android/.gradle/buildOutputCleanup/buildOutputCleanup.lock


+ 9 - 19
lib/login_page.dart

@@ -3,7 +3,8 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'util/session.dart';
 import 'home_page.dart';
 import 'util/api.dart';
-import 'showAlert.dart';
+import 'util/util.dart';
+import 'util/models.dart';
 
 
 class LoginPage extends StatefulWidget {
@@ -105,34 +106,23 @@ class _LoginPageState extends State < LoginPage > {
                       if(phone=='' || password==''){
                         return;
                       }
+                      if(!loginStatus) return;//防止重复提交
                       setState(() {
                         loginStatus = false;
                       });
                       login(phone,password).then((resp){
-                        if(resp.success){
-                          setKey('token', resp.data.token);
+                        if(isNotError(context, resp)){
+                          Login loginObj = Login.fromJson(resp.data);
+                          setKey('token', loginObj.data.token);
                           setKey('phone',phone);
                           setKey('password',password);
-                          setKey('nickName',resp.data.nickName);
+                          setKey('nickName',loginObj.data.nickName);
                           Navigator.pushReplacement(context, MaterialPageRoute(builder: (context){
                             return HomePage();
                           }));
                         }else{
-                          showDialog < Null > (
-                          context: context, //BuildContext对象
-                          barrierDismissible: false,
-                          builder: (BuildContext context) {
-                            return new LoadingDialog( //调用对话框
-                              text: '手机号或密码错误', childCallback: (val) {
-                                if (val) {
-                                  setState(() {
-                                    loginStatus = true;
-                                  });
-                                } else {
-                                  return;
-                                }
-                              },
-                            );
+                         setState(() {
+                            loginStatus = true;
                           });
                         }
                       });

+ 5 - 7
lib/pages/my_page.dart

@@ -7,6 +7,7 @@ import '../login_page.dart';
 import '../util/api.dart';
 import '../util/models.dart';
 import '../util/session.dart';
+import '../util/util.dart';
 
 class MyPage extends StatefulWidget {
   final Widget child;
@@ -31,11 +32,10 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
 
   @override
   void initState() {
-    // TODO: implement initState
     super.initState();
     getStationList().then((resp) {
-      if (resp.success && resp.code == 1) {
-        stationObj = resp;
+      if (isNotError(context, resp)) {
+        stationObj = Station.fromJson(resp.data);
         List < String > tempList = [];
         for (int i = 0; i < stationObj.data.length; i++) {
           tempList.add(stationObj.data[i].name.toString());
@@ -47,11 +47,9 @@ class _MyPageState extends State < MyPage > with AutomaticKeepAliveClientMixin {
             _siteName = tempList[0];
           });
         });
+        print(stationObj.data[0].id.toString());
         setKey('stationId', stationObj.data[0].id.toString());
-      } else {
-
-      }
-
+      } 
     });
   }
 

+ 14 - 26
lib/pages/my_page/revise_password_page.dart

@@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
 import '../../util/session.dart';
 import '../../showAlert.dart';
 import '../../util/api.dart';
+import '../../util/util.dart';
 
 class RevisePasswordPage extends StatefulWidget {
   final Widget child;
@@ -82,18 +83,18 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                         borderRadius: BorderRadius.circular(4),
                       ),
                       child: Center(
-                        child:Row(
+                        child: Row(
                           mainAxisAlignment: MainAxisAlignment.center,
-                          children: <Widget>[
-                              Offstage(
-                                offstage: loginStatus,
-                                child: SizedBox(
-                                  width: ScreenUtil.getInstance().setWidth(45),
-                                  height: ScreenUtil.getInstance().setHeight(45),
-                                  child: Image.asset('lib/images/loading.gif'),
-                                ),
+                          children: < Widget > [
+                            Offstage(
+                              offstage: loginStatus,
+                              child: SizedBox(
+                                width: ScreenUtil.getInstance().setWidth(45),
+                                height: ScreenUtil.getInstance().setHeight(45),
+                                child: Image.asset('lib/images/loading.gif'),
                               ),
-                             Text('登录', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
+                            ),
+                            Text('登录', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
                           ],
                         )
                       ),
@@ -117,8 +118,8 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                           setState(() {
                             loginStatus = false;
                           });
-                          updataPasswrod(oldPassword, newPassword).then((resp){
-                            if(resp.success && resp.code==1){
+                          updataPasswrod(oldPassword, newPassword).then((resp) {
+                            if (isNotError(context, resp)) {
                               setKey('password', newPassword);
                               showDialog < Null > (
                                 context: context, //BuildContext对象
@@ -126,7 +127,7 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                                 builder: (BuildContext context) {
                                   return new LoadingDialog( //调用对话框
                                     text: '修改成功', childCallback: (val) {
-                                      if(val){
+                                      if (val) {
                                         setState(() {
                                           loginStatus = true;
                                         });
@@ -135,19 +136,6 @@ class _RevisePasswordPageState extends State < RevisePasswordPage > {
                                     },
                                   );
                                 });
-                            }else{
-                              showDialog < Null > (
-                                context: context, //BuildContext对象
-                                barrierDismissible: false,
-                                builder: (BuildContext context) {
-                                  return new LoadingDialog( //调用对话框
-                                    text: resp.msg, childCallback: (val) {
-                                      if(val){
-                                        Navigator.pop(context);
-                                      }
-                                    },
-                                  );
-                                });
                             }
                           });
                         }

+ 0 - 1
lib/pages/order_management_page.dart

@@ -71,7 +71,6 @@ class _QueryWidgetState extends State < QueryWidget > {
 
   @override
   void initState() {
-    // TODO: implement initState
     super.initState();
     _scrollController.addListener((){
       if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {

+ 17 - 16
lib/pages/order_taking_page.dart

@@ -5,6 +5,7 @@ import '../util/api.dart';
 import '../util/models.dart';
 import '../showDialog.dart';
 import '../util/session.dart';
+import '../util/util.dart';
 
 class OrderTakingPage extends StatefulWidget {
 
@@ -35,10 +36,10 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
       });
       getLine(value).then((childValue) {
         getOrderList(value, lineIdStr, page).then((resp) {
-          if (resp.success && resp.code == 1) {
+          if (isNotError(context, resp)) {
             setState(() {
-              orderList = resp.data.items;
-              hasNextPage = resp.data.hasNextPage;
+              orderList = OrderListObj.fromJson(resp.data).data.items;
+              hasNextPage = OrderListObj.fromJson(resp.data).data.hasNextPage;
             });
           }
         });
@@ -49,7 +50,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
         setState(() {
           showLineStatus = true;
         });
-        switchLine();
+        switchLine(context);
       }
       if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
         print('滑动到底部了');
@@ -71,12 +72,12 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
   }
 
 
-  Future getLine(value) async {
+  Future getLine(String value) async {
     await getLineFromStation(value).then((resp) {
-      if (resp.success && resp.code == 1) {
+      if (isNotError(context, resp)) {
         setState(() {
           checkStatusList = [];
-          lineList = resp.data;
+          lineList = StationLine.fromJson(resp.data).data;
           for (int i = 0; i < lineList.length; i++) {
             checkStatusList.add(true);
             if (i < lineList.length - 1) {
@@ -87,7 +88,6 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
           }
           stationId = value;
         });
-        print(lineIdStr);
         return lineIdStr;
       }
     });
@@ -119,7 +119,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                     }
                   });
                 } else {
-                  switchLine();
+                  switchLine(context);
                 }
               }, )
           ]
@@ -154,7 +154,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
                   setState(() {
                     showLineStatus = true;
                   });
-                  switchLine();
+                  switchLine(context);
                 },
               ),
             ),
@@ -287,7 +287,7 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     });
   }
 
-  void switchLine() { //切换线路
+  void switchLine(BuildContext context) { //切换线路
     setState(() {
       orderList = [];
       hasNextPage =true;
@@ -300,11 +300,12 @@ class _OrderTakingPageState extends State < OrderTakingPage > with AutomaticKeep
     }
     lineIdStr = lineIdStr.substring(0, lineIdStr.length - 1);
     getOrderList(stationId, lineIdStr, page).then((resp) {
-      if (resp.success && resp.code == 1) {
-        setState(() {
-          orderList = resp.data.items;
-          hasNextPage = resp.data.hasNextPage;
-        });
+      if(isNotError(context, resp)){
+          OrderListObj tempObj =OrderListObj.fromJson(resp.data);
+          setState(() {
+            orderList = tempObj.data.items;
+            hasNextPage = tempObj.data.hasNextPage;
+          });
       }
     });
   }

+ 22 - 17
lib/util/api.dart

@@ -8,35 +8,40 @@ Future login(phone, passwrod) async {
     "phone": phone,
     "password": passwrod
   });
-  var loginResp = Login.fromJson(response);
-  return loginResp;
+  return response;
 }
 
 //获取接单列表
-Future getOrderList(String stationId,String lineId,int page) async {
- var response = await Http().post('app/order/wait_order_list_pages',data: {'stationId':stationId,'lineId':lineId,'limit':limit,'page':page});
-  var result = OrderListObj.fromJson(response);
-  return result;
+Future getOrderList(String stationId, String lineId, int page) async {
+  var response = await Http().post('app/order/wait_order_list_pages', data: {
+    'stationId': stationId,
+    'lineId': lineId,
+    'limit': limit,
+    'page': page
+  });
+  return response;
 }
 
 
 //获取所有站点
-Future getStationList() async{
+Future getStationList() async {
   var response = await Http().get('app/station/station_list');
-  var stationList = Station.fromJson(response);
-  return stationList;
+  return response;
 }
 
 //根据站点获取线路
-Future getLineFromStation(String stationId)async{
-  var response  =await Http().get('app/station/station_line_all_list',data:{'stationId':stationId});
-  var lineList = StationLine.fromJson(response);
-  return lineList;
+Future getLineFromStation(String stationId) async {
+  var response = await Http().get('app/station/station_line_all_list', data: {
+    'stationId': stationId
+  });
+  return response;
 }
 
 //修改密码
-Future updataPasswrod(oldPassword,newPassword)async{
-  var response = await Http().post('app/uzer/logistics/update_password',data: {'oldPassword':oldPassword,'newPassword':newPassword});
-  var result =UpdataPasswrod.fromJson(response);
-  return result;
+Future updataPasswrod(oldPassword, newPassword) async {
+  var response = await Http().post('app/uzer/logistics/update_password', data: {
+    'oldPassword': oldPassword,
+    'newPassword': newPassword
+  });
+  return response;
 }

+ 101 - 71
lib/util/models.dart

@@ -1,19 +1,24 @@
 //登录
-class Login{
+class Login {
   bool success;
   int code;
   String msg;
   LoginMap data;
 
-  Login({this.success,this.code,this.msg,this.data});
+  Login({
+    this.success,
+    this.code,
+    this.msg,
+    this.data
+  });
 
-  factory Login.fromJson(Map<String,dynamic> json){
+  factory Login.fromJson(Map < String, dynamic > json) {
     LoginMap tempData = LoginMap.fromJson(json['data']);
     return Login(
       success: json['success'],
-      code:json['code'],
-      msg:json['msg'],
-      data:tempData
+      code: json['code'],
+      msg: json['msg'],
+      data: tempData
     );
   }
 }
@@ -55,24 +60,24 @@ class OrderListObj {
   OrderListData data;
 
   OrderListObj({
-   this.success,
-   this.code,
-   this.msg,
-   this.data
+    this.success,
+    this.code,
+    this.msg,
+    this.data
   });
 
   factory OrderListObj.fromJson(Map < String, dynamic > json) {
     return OrderListObj(
       success: json['success'],
-      code:json['code'],
-      msg:json['msg'],
-      data:OrderListData.fromJson(json['data'])
+      code: json['code'],
+      msg: json['msg'],
+      data: OrderListData.fromJson(json['data'])
     );
   }
 }
-class OrderListData{
+class OrderListData {
   bool hasNextPage;
-  List<OrderList> items;
+  List < OrderList > items;
   int limit;
   int page;
   int totalCount;
@@ -87,14 +92,14 @@ class OrderListData{
     this.totalPage
   });
 
-  factory OrderListData.fromJson(Map<String,dynamic>json){
+  factory OrderListData.fromJson(Map < String, dynamic > json) {
     List list = json['items'] as List;
     List < OrderList > tempOrderList = list.map((i) => OrderList.fromJson(i)).toList();
     return OrderListData(
       hasNextPage: json['hasNextPage'],
-      items:tempOrderList,
+      items: tempOrderList,
       limit: json['limit'],
-      page:json['page'],
+      page: json['page'],
       totalCount: json['totalCount'],
       totalPage: json['totalPage']
     );
@@ -112,70 +117,81 @@ class OrderList {
   String sendCompanyName;
   String sendCompanyPhone;
   OrderList({
-   this.orderNo,
-   this.createTime,
-   this.goods,
-   this.goodsQuantity,
-   this.receiptCompanyAddress,
-   this.receiptCompanyName,
-   this.receiptCompanyPhone,
-   this.sendCompanyAddress,
-   this.sendCompanyName,
-   this.sendCompanyPhone
+    this.orderNo,
+    this.createTime,
+    this.goods,
+    this.goodsQuantity,
+    this.receiptCompanyAddress,
+    this.receiptCompanyName,
+    this.receiptCompanyPhone,
+    this.sendCompanyAddress,
+    this.sendCompanyName,
+    this.sendCompanyPhone
   });
 
   factory OrderList.fromJson(Map < String, dynamic > json) {
     return OrderList(
-     orderNo: json['orderNo'],
-     createTime: json['createTime'],
-     goods: json['goods'],
-     goodsQuantity: json['goodsQuantity'],
-     receiptCompanyAddress: json['receiptCompanyAddress'],
-     receiptCompanyName:json['receiptCompanyName'],
-     receiptCompanyPhone:json['receiptCompanyPhone'],
-     sendCompanyAddress:json['sendCompanyAddress'],
-     sendCompanyName:json['sendCompanyName'],
-     sendCompanyPhone:json['sendCompanyPhone']
+      orderNo: json['orderNo'],
+      createTime: json['createTime'],
+      goods: json['goods'],
+      goodsQuantity: json['goodsQuantity'],
+      receiptCompanyAddress: json['receiptCompanyAddress'],
+      receiptCompanyName: json['receiptCompanyName'],
+      receiptCompanyPhone: json['receiptCompanyPhone'],
+      sendCompanyAddress: json['sendCompanyAddress'],
+      sendCompanyName: json['sendCompanyName'],
+      sendCompanyPhone: json['sendCompanyPhone']
     );
   }
 }
 
 //获取站点
-class Station{
+class Station {
   bool success;
   int code;
   String msg;
-  List<StationList> data;
+  List < StationList > data;
 
-  Station({this.success,this.code,this.msg,this.data});
+  Station({
+    this.success,
+    this.code,
+    this.msg,
+    this.data
+  });
 
-  factory Station.fromJson(Map<String,dynamic> json){
+  factory Station.fromJson(Map < String, dynamic > json) {
     List list = json['data'] as List;
     print(list.toString());
-    List<StationList> tempList = list.map((i)=>StationList.fromJson(i)).toList();
+    List < StationList > tempList = list.map((i) => StationList.fromJson(i)).toList();
     return Station(
       success: json['success'],
-      code:json['code'],
-      msg:json['msg'],
-      data:tempList
+      code: json['code'],
+      msg: json['msg'],
+      data: tempList
     );
   }
 }
 
-class StationList{
+class StationList {
   String code;
   int id;
   String name;
   int stationStatus;
   int status;
 
-  StationList({this.code,this.id,this.name,this.stationStatus,this.status});
+  StationList({
+    this.code,
+    this.id,
+    this.name,
+    this.stationStatus,
+    this.status
+  });
 
-  factory StationList.fromJson(Map<String,dynamic> json){
+  factory StationList.fromJson(Map < String, dynamic > json) {
     return StationList(
-      code:json['code'],
-      id:json['id'],
-      name:json['name'],
+      code: json['code'],
+      id: json['id'],
+      name: json['name'],
       stationStatus: json['stationStatus'],
       status: json['status']
     );
@@ -183,58 +199,72 @@ class StationList{
 }
 
 //站点线路
-class StationLine{
+class StationLine {
   bool success;
   int code;
   String msg;
-  List<LineObj> data;
+  List < LineObj > data;
 
-  StationLine({this.success,this.code,this.msg,this.data});
+  StationLine({
+    this.success,
+    this.code,
+    this.msg,
+    this.data
+  });
 
-  factory StationLine.fromJson(Map<String,dynamic> json){
+  factory StationLine.fromJson(Map < String, dynamic > json) {
     var list = json['data'] as List;
-    List<LineObj> tempList = list.map((i)=>LineObj.fromJson(i)).toList();
+    List < LineObj > tempList = list.map((i) => LineObj.fromJson(i)).toList();
 
     return StationLine(
       success: json['success'],
-      code:json['code'],
-      msg:json['msg'],
-      data:tempList
+      code: json['code'],
+      msg: json['msg'],
+      data: tempList
     );
   }
 }
 
-class LineObj{
+class LineObj {
   String code;
   int id;
   String name;
 
-  LineObj({this.code,this.name,this.id});
+  LineObj({
+    this.code,
+    this.name,
+    this.id
+  });
 
-  factory LineObj.fromJson(Map<String,dynamic> json){
+  factory LineObj.fromJson(Map < String, dynamic > json) {
     return LineObj(
-      code:json['code'],
-      id:json['id'],
-      name:json['name']
+      code: json['code'],
+      id: json['id'],
+      name: json['name']
     );
   }
 }
 
 //修改密码
-class UpdataPasswrod{
+class UpdataPasswrod {
   bool success;
   int code;
   String msg;
   String data;
 
-  UpdataPasswrod({this.success,this.code,this.msg,this.data});
+  UpdataPasswrod({
+    this.success,
+    this.code,
+    this.msg,
+    this.data
+  });
 
-  factory UpdataPasswrod.fromJson(Map<String,dynamic> json){
+  factory UpdataPasswrod.fromJson(Map < String, dynamic > json) {
     return UpdataPasswrod(
       success: json['success'],
       code: json['code'],
-      msg:json['msg'],
-      data:json['data']
+      msg: json['msg'],
+      data: json['data']
     );
   }
 }

+ 5 - 4
lib/util/request.dart

@@ -1,8 +1,8 @@
 import 'package:dio/dio.dart';
-
 import 'config.dart'; //用于配置公用常量
 import 'session.dart';
 
+
 class Http {
   static Http instance;
   static String token;
@@ -74,9 +74,10 @@ class Http {
       } else {
         print('get请求发生错误:$e----$url');
       }
+      return e;
     }
     //print(response);
-    return response.data;
+    return response;
   }
 
   // post请求封装
@@ -102,8 +103,8 @@ class Http {
       } else {
         print('post请求发生错误:$e');
       }
+      return e;
     }
-    print(response);
-    return response.data;
+    return response;
   }
 }

+ 1 - 1
lib/util/session.dart

@@ -8,7 +8,7 @@ void setKey(key,value) async{
 
 Future<String> getKey(key) async{
   SharedPreferences prefs = await SharedPreferences.getInstance();
-  String value = await prefs.getString(key);
+  String value = prefs.getString(key);
   return value;
 }
 

+ 28 - 0
lib/util/util.dart

@@ -0,0 +1,28 @@
+import 'package:flutter/material.dart';
+import 'package:dio/dio.dart';
+import '../showAlert.dart';
+bool isNotError(BuildContext context,json){
+  print('-----------${json}----------');
+  if(json is DioError){
+    alertError(context, json.toString());
+    return false;
+  }else if( json.data['success']&& json.data['code']==1){
+    return true;
+  }else{
+    alertError(context, json.data['msg']);
+    return false;
+  }
+}
+
+alertError(BuildContext context,String str){
+  showDialog < Null > (
+  context: context, //BuildContext对象
+  barrierDismissible: false,
+  builder: (BuildContext context) {
+    return new LoadingDialog( //调用对话框
+      text: str, childCallback: (val) {
+        
+      },
+    );
+  });
+}