From 5af31ed476573b3268fdd3383324542014134eaa Mon Sep 17 00:00:00 2001 From: PH2 <1293456824@qq.com> Date: Thu, 27 May 2021 16:57:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81H5=E4=B8=8EAPP=E7=9A=84Token=E5=85=B1?= =?UTF-8?q?=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/user/user_info_model_notifier.dart | 16 +++++++++++++++- lib/util/global_config.dart | 3 +++ pubspec.yaml | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/models/user/user_info_model_notifier.dart b/lib/models/user/user_info_model_notifier.dart index 36720e0..d31772b 100644 --- a/lib/models/user/user_info_model_notifier.dart +++ b/lib/models/user/user_info_model_notifier.dart @@ -4,12 +4,14 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_alibc/flutter_alibc.dart'; import 'package:zhiying_comm/models/user/user_info_model.dart'; +import 'package:zhiying_comm/util/empty_util.dart'; import 'package:zhiying_comm/util/event_util/event_util.dart'; import 'package:zhiying_comm/util/event_util/log_out.dart'; import 'package:zhiying_comm/util/global_config.dart'; import 'package:zhiying_comm/util/log/let_log.dart'; import 'package:zhiying_comm/util/mob_util/mob_util.dart'; import 'package:zhiying_comm/util/shared_prefe_util.dart'; +import 'package:zhiying_flutter_webview/zhiying_flutter_webview.dart'; /// /// 用户信息Provider @@ -62,6 +64,13 @@ class UserInfoNotifier with ChangeNotifier { await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_MOBILE, loginUser.mobile); await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_USER_INFO, jsonEncode(loginUser.toJson())); FlutterAlibc.loginOut(); + // 设置H5的Token + if(!EmptyUtil.isEmpty(loginUser?.token)) { + String domain = await SharedPreferencesUtil.getStringValue(GlobalConfig.H5_DOMAIN); + if (!EmptyUtil.isEmpty(domain)) { + ZhiyingFlutterWebview.registLocalStore({'TOKEN_KEY': loginUser?.token}, [domain]); + } + } notifyListeners(); } @@ -78,8 +87,13 @@ class UserInfoNotifier with ChangeNotifier { MobUtil.cancelQQAuth(); // 退出微信登录 MobUtil.cancelWeChatAuth(); + // 清除H5 Token + String domain = await SharedPreferencesUtil.getStringValue(GlobalConfig.H5_DOMAIN); + if (!EmptyUtil.isEmpty(domain)) { + ZhiyingFlutterWebview.registLocalStore({'TOKEN_KEY': ''}, [domain]); + } if(!reFresh){ - reFresh=true; + reFresh = true; Timer(Duration(milliseconds: 1000), (){ EventUtil.instance.fire(LogOut()); }); diff --git a/lib/util/global_config.dart b/lib/util/global_config.dart index b77415a..83c981f 100644 --- a/lib/util/global_config.dart +++ b/lib/util/global_config.dart @@ -53,4 +53,7 @@ class GlobalConfig { /// 用户协议显示 用户是否同意隐私协议 static String isShowPolicy = "is_show_policy"; + /// 用户H5的根域名 + static final String H5_DOMAIN = 'sp_h5_domain'; + } diff --git a/pubspec.yaml b/pubspec.yaml index bc640bd..8041535 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -113,6 +113,13 @@ dependencies: url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/flutter_clipboard_plugin.git' ref: '0.0.2' + + zhiying_flutter_webview: +# path: ../zhiying_flutter_webview + git: + url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_webview.git + ref: 0.0.6 + # flutter_bugly: ^0.3.2+1