From 574e0f19e3b4c4c9c421409ea4cc04dd16ce416c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Thu, 25 Feb 2021 15:34:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E6=B7=98=E5=AE=9D=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=9A=84=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/user/user_info_model_notifier.dart | 6 +- .../auth_success_page/auth_success_page.dart | 133 ++++++++++++++++++ lib/util/taobao/taobao_auth.dart | 12 +- pubspec.yaml | 5 +- 4 files changed, 147 insertions(+), 9 deletions(-) create mode 100644 lib/pages/auth_page/auth_success_page/auth_success_page.dart diff --git a/lib/models/user/user_info_model_notifier.dart b/lib/models/user/user_info_model_notifier.dart index 4f82ff4..31ea5c2 100644 --- a/lib/models/user/user_info_model_notifier.dart +++ b/lib/models/user/user_info_model_notifier.dart @@ -66,9 +66,9 @@ class UserInfoNotifier with ChangeNotifier { void unLogin() async { _userInfo = null; // 清除缓存数据 - await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, ''); - await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_MOBILE, ''); - await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_USER_INFO, ''); + await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, null); + await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_MOBILE, null); + await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_USER_INFO, null); // 退出淘宝登录 FlutterAlibc.loginOut(); // 退出QQ登录 diff --git a/lib/pages/auth_page/auth_success_page/auth_success_page.dart b/lib/pages/auth_page/auth_success_page/auth_success_page.dart new file mode 100644 index 0000000..fa9f78e --- /dev/null +++ b/lib/pages/auth_page/auth_success_page/auth_success_page.dart @@ -0,0 +1,133 @@ +import 'package:flutter/material.dart'; +import 'package:zhiying_comm/zhiying_comm.dart'; + +///渠道授权成功页面 +class AuthSuccessPage extends StatefulWidget { + final AuthResultType authResultType; + + const AuthSuccessPage({Key key, this.authResultType}) : super(key: key); + + @override + _AuthSuccessPageState createState() => _AuthSuccessPageState(); +} + +class _AuthSuccessPageState extends State { + String title = ''; + String contentTitle = ''; + String content = ''; + String btntext = ''; + + @override + void initState() { + switch (widget.authResultType) { + case AuthResultType.success: + title = '授权成功'; + contentTitle = '恭喜您授权成功'; + content = '前往享受超多优惠吧'; + btntext = '知道了'; + break; + case AuthResultType.error: + title = '授权失败'; + contentTitle = '授权失败'; + content = '很抱歉,您的淘宝账号已经成为了合作方,如需申请渠道授权,您可更换其他淘宝账号'; + btntext = '重新授权'; + break; + } + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + brightness: Brightness.light, + leading: IconButton( + onPressed: () { + Navigator.pop(context); + }, + icon: Icon( + Icons.arrow_back_ios, + color: HexColor.fromHex("#FF333333"), + size: 18, + ), + ), + centerTitle: true, + elevation: 1, + backgroundColor: Colors.white, + title: Text( + title, + style: TextStyle(color: HexColor.fromHex("#FF333333"), fontSize: 17), + ), + ), + body: Container( + child: Center( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + height: 30, + ), + Image.asset( + "assets/images/auth/auth_success.png", + package: 'zhiying_base_widget', + width: 107, + height: 107, + fit: BoxFit.fill, + ), + SizedBox( + height: 30, + ), + Text( + contentTitle, + style: TextStyle(color: HexColor.fromHex("#FF333333"), fontSize: 15), + ), + Container( + margin: EdgeInsets.only(left: 56, right: 56), + child: Text( + content, + style: TextStyle(color: HexColor.fromHex("#FF999999"), fontSize: 13), + ), + ), + SizedBox( + height: 30, + ), + GestureDetector( + onTap: () { + onClick(); + }, + child: Container( + height: 46.5, + width: 265, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), + boxShadow: [BoxShadow(color: HexColor.fromHex("FFFF5500"), blurRadius: 1, spreadRadius: 2, offset: Offset(1, 4))], + gradient: LinearGradient(colors: [HexColor.fromHex("#FFFF8E00"), HexColor.fromHex("#FFFF5500")], begin: Alignment.topCenter, end: Alignment.bottomCenter)), + child: Center( + child: Text( + btntext, + style: TextStyle(color: HexColor.fromHex("#FFFFFFFF"), fontSize: 13), + ), + ), + ), + ) + ], + ), + ), + ), + ); + } + + ///点击事件 + void onClick() async { + if (widget.authResultType == AuthResultType.success) { + Navigator.maybePop(context); + } else if (widget.authResultType == AuthResultType.error) { + ///继续授权 + await TaobaoAuth.auth(context).then((value) { + Navigator.pop(context); + }); + } + } +} + +enum AuthResultType { success, error } diff --git a/lib/util/taobao/taobao_auth.dart b/lib/util/taobao/taobao_auth.dart index e27eb97..ea3370e 100644 --- a/lib/util/taobao/taobao_auth.dart +++ b/lib/util/taobao/taobao_auth.dart @@ -5,6 +5,7 @@ import 'package:flutter_alibc/alibc_model.dart'; import 'package:flutter_alibc/flutter_alibc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:zhiying_comm/models/profile/profile_model.dart'; +import 'package:zhiying_comm/pages/auth_page/auth_success_page/auth_success_page.dart'; import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'package:provider/provider.dart'; @@ -13,12 +14,12 @@ class TaobaoAuth { // static ProfileModel _profile; // 淘宝授权 - static auth(BuildContext context) async { + static Future auth(BuildContext context) async { bool isAuth = await TaobaoAuth.isAuth(); if (isAuth) { Fluttertoast.showToast(msg: '你已经授权过了'); Provider.of(context, listen: false).updateUserAuth(true); - return; + return null; } bool isConfirm = await showDialog( @@ -30,13 +31,18 @@ class TaobaoAuth { Map data = Map.from(await NetUtil.post('/api/v1/taobao/auth', method: NetMethod.GET)); Logger.debug(data); if (data['code'] != 1) { - return; + return null; } String url = data['data']['redirect_url']; print("授权链接" + url); TradeResult result; if (Platform.isAndroid) { result = await FlutterAlibc.openByUrl(url: url, backUrl: "alisdk://", isAuth: true); + if(result.errorCode=="0"){ + await Navigator.push(context,MaterialPageRoute(builder: (_)=>AuthSuccessPage(authResultType: AuthResultType.success,)) ); + }else{ + await Navigator.push(context,MaterialPageRoute(builder: (_)=>AuthSuccessPage(authResultType: AuthResultType.error,)) ); + } } else if (Platform.isIOS) { result = await FlutterAlibc.openByUrl(url: url); } diff --git a/pubspec.yaml b/pubspec.yaml index ea97b38..2fff0ba 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,9 +40,9 @@ dependencies: # app更新dialogUI(用于IOS,以便统一样式) flutter_update_dialog: 1.0.0 flutter_alibc: - #path: ../zhiying_flutter_alibc +# path: ../zhiying_flutter_alibc git: - ref: 0.0.4 + ref: 0.0.5 url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git url_launcher: ^5.6.0 #图片预览控件 @@ -74,7 +74,6 @@ dependencies: ref: '0.0.1' #文件夹路径管理 path_provider: ^1.4.0 - #保存文件到相册 save_image: git: