diff --git a/lib/main_page.dart b/lib/main_page.dart index b939c58b..5a432a99 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -105,13 +105,15 @@ class _MainPage extends State with WidgetsBindingObserver { if (Platform.isAndroid) { xgFlutterPlugin.getXgAndroidApi().addNativeEventHandler( - MyNativeEventHandler( - (String title, String message, String customContent, int type) { - print("xgPushClickAction2: $customContent"); - SharedPreferences.getInstance().then((value) { - value.setString("pushData", customContent); - }); - })); + MyNativeEventHandler( + (String title, String message, String customContent, int type) { + print("xgPushClickAction2: $customContent"); + SharedPreferences.getInstance().then((value) { + value.setString("pushData", customContent); + }); + }, + ), + ); } /// @typed: 1文章 2活动 3店铺 4积分商品 5订单 @@ -147,8 +149,7 @@ class _MainPage extends State with WidgetsBindingObserver { }, xgPushDidBindWithIdentifier: (event) async { print("xgPushDidBindWithIdentifier: ${event.toString()}"); return event; - } - ); + }); } pushRoute() async { @@ -203,9 +204,11 @@ class _MainPage extends State with WidgetsBindingObserver { SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); if (sharedPreferences.getString("token") == null || sharedPreferences.getString("token") == "") return; - BaseData baseDate = await ApiService(Dio(), - context: context, token: sharedPreferences.getString('token')) - .queryInfo(); + BaseData baseDate = await ApiService( + Dio(), + context: context, + token: sharedPreferences.getString('token'), + ).queryInfo().catchError((onError) {}); sharedPreferences.setString('user', jsonEncode(baseDate.data)); String mobile = baseDate.data.phone; diff --git a/lib/retrofit/min_api.dart b/lib/retrofit/min_api.dart index b6ad97de..d062a919 100644 --- a/lib/retrofit/min_api.dart +++ b/lib/retrofit/min_api.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/generated/l10n.dart'; +import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/view_widget/login_tips_dialog.dart'; import 'package:retrofit/retrofit.dart'; @@ -107,6 +108,5 @@ abstract class MinApiService { //剩余部分 print(msg); } - - + } \ No newline at end of file diff --git a/lib/retrofit/retrofit_api.dart b/lib/retrofit/retrofit_api.dart index a3fe779f..24a4ee97 100644 --- a/lib/retrofit/retrofit_api.dart +++ b/lib/retrofit/retrofit_api.dart @@ -274,11 +274,11 @@ abstract class ApiService { @GET("/home/brand") Future queryHomeBrand(); - ///小程序会员登录 + /// 小程序会员登录 @GET("/auth/mini/login/{storeId}") Future minLogin(@Path("storeId") String storeId); - /// + /// 各种消费记录 @POST("/member/listBill") Future>> queryBillInfo( @Body() Map param); diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index 975305de..2e41f84b 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -8,6 +8,8 @@ import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/activity.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/store_info.dart'; +import 'package:huixiang/retrofit/data/user_entity.dart'; +import 'package:huixiang/retrofit/min_api.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/store/store_view/store_activity.dart'; import 'package:huixiang/store/store_view/store_info.dart'; @@ -38,6 +40,7 @@ class _StoreOrderPage extends State with TickerProviderStateMixin /*, AutomaticKeepAliveClientMixin */ { TabController tabcontroller; ApiService apiService; + MinApiService minService; StoreInfo storeInfo; RefreshController refreshController; List _widgetOptions; @@ -63,9 +66,29 @@ class _StoreOrderPage extends State ), ]; + minLogin(); + queryStoreInfo(); } + minLogin() { + apiService.minLogin(storeInfo.id) + .catchError((onError){}).then((baseData) { + if (baseData != null && baseData.isSuccess) { + UserEntity userEntity = UserEntity.fromJson(baseData.data); + String minToken = userEntity.token; + SharedPreferences.getInstance().then((value) => { + value.setString('minToken', minToken), + }); + minService = MinApiService( + Dio(), + context: context, + token: minToken, + ); + } + }); + } + queryStoreInfo() async { final SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( @@ -73,7 +96,6 @@ class _StoreOrderPage extends State context: context, token: value.getString('token'), ); - BaseData baseData = await apiService .queryStoreInfo(widget.arguments["id"]) .catchError((error) { diff --git a/lib/view_widget/login_tips_dialog.dart b/lib/view_widget/login_tips_dialog.dart index f3b6e43f..9feeb194 100644 --- a/lib/view_widget/login_tips_dialog.dart +++ b/lib/view_widget/login_tips_dialog.dart @@ -5,7 +5,6 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'login_tips.dart'; class LoginTipsDialog { - static LoginTipsDialog _instance; factory LoginTipsDialog() { @@ -33,8 +32,10 @@ class LoginTipsDialog { value.setString("mobile", ""); value.setString("nick", ""); }); - Navigator.of(context).pushNamed('/router/login_page', - arguments: {"login": "login"}); + Navigator.of(context).pushNamed( + '/router/login_page', + arguments: {"login": "login"}, + ); }, ), onDismiss: () { @@ -43,5 +44,4 @@ class LoginTipsDialog { clickBgDismissTemp: false, ); } - -} \ No newline at end of file +}