Quellcode durchsuchen

添加token,添加跳转错误提示

tags/0.0.1
Weller vor 4 Jahren
Ursprung
Commit
670183a3b9
7 geänderte Dateien mit 135 neuen und 77 gelöschten Zeilen
  1. +18
    -46
      .idea/workspace.xml
  2. +21
    -0
      example/pubspec.lock
  3. +63
    -31
      lib/util/net_util.dart
  4. +6
    -0
      lib/util/router_util.dart
  5. +2
    -0
      lib/zhiying_comm.dart
  6. +21
    -0
      pubspec.lock
  7. +4
    -0
      zhiying_comm.iml

+ 18
- 46
.idea/workspace.xml Datei anzeigen

@@ -2,21 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0ff6f366-28dc-4efd-9bca-709f40bc6813" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/lib/pages/login_page.dart" afterDir="false" />
<change afterPath="$PROJECT_DIR$/lib/pages/login_page.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/libraries/Flutter_Plugins.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.idea/libraries/Flutter_Plugins.xml" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.idea/libraries/Flutter_Plugins.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/lib/util/net_util.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/lib/util/net_util.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/lib/util/router_util.dart" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/lib/util/router_util.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/zhiying_comm.iml" beforeDir="false" afterPath="$PROJECT_DIR$/example/ios/.symlinks/plugins/zhiying_comm/zhiying_comm.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/example/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/example/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/util/net_util.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/util/net_util.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/util/router_util.dart" beforeDir="false" afterPath="$PROJECT_DIR$/lib/util/router_util.dart" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pubspec.lock" beforeDir="false" afterPath="$PROJECT_DIR$/pubspec.lock" afterDir="false" />
<change beforePath="$PROJECT_DIR$/zhiying_comm.iml" beforeDir="false" afterPath="$PROJECT_DIR$/zhiying_comm.iml" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.dart_tool/" />
@@ -50,7 +38,7 @@
<entry file="file://$PROJECT_DIR$/lib/pages/empty_page.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
<caret line="13" selection-start-line="13" selection-end-line="13" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>
@@ -58,15 +46,6 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/pages/login_page.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/lib/main.dart">
<provider selected="true" editor-type-id="text-editor">
@@ -94,8 +73,8 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/util/router_util.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="79">
<caret line="5" column="16" selection-start-line="5" selection-start-column="6" selection-end-line="5" selection-end-column="16" />
<state relative-caret-position="126">
<caret line="6" column="79" selection-start-line="6" selection-start-column="79" selection-end-line="6" selection-end-column="79" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>
@@ -106,8 +85,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/models/user/user_info_model.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="39">
<caret line="4" column="19" selection-start-line="4" selection-start-column="6" selection-end-line="4" selection-end-column="19" />
<state relative-caret-position="60">
<caret line="5" column="19" selection-start-line="5" selection-start-column="19" selection-end-line="5" selection-end-column="19" />
</state>
</provider>
</entry>
@@ -115,8 +94,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/models/user/user_info_model_notifier.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="276">
<caret line="27" column="15" selection-start-line="27" selection-start-column="2" selection-end-line="27" selection-end-column="15" />
<state relative-caret-position="507">
<caret line="37" column="15" selection-start-line="37" selection-start-column="15" selection-end-line="37" selection-end-column="15" />
</state>
</provider>
</entry>
@@ -268,9 +247,8 @@
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="1920" height="1015" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2113951" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2113951" />
<window_info id="Captures" order="1" side_tool="true" />
<window_info id="Structure" order="2" side_tool="true" />
<window_info id="Image Layers" order="3" />
@@ -280,13 +258,13 @@
<window_info id="Capture Tool" order="7" />
<window_info id="Favorites" order="8" side_tool="true" />
<window_info anchor="bottom" id="Find" />
<window_info anchor="bottom" id="Messages" visible="true" weight="0.3296582" />
<window_info anchor="bottom" id="Messages" weight="0.3296582" />
<window_info anchor="bottom" id="Dart Analysis" order="0" weight="0.37375966" />
<window_info anchor="bottom" id="Run" order="1" />
<window_info anchor="bottom" id="TODO" order="2" />
<window_info anchor="bottom" id="Android Profiler" order="3" show_stripe_button="false" />
<window_info anchor="bottom" id="Logcat" order="4" />
<window_info anchor="bottom" id="Debug" order="5" />
<window_info anchor="bottom" id="Debug" order="5" weight="0.3296582" />
<window_info anchor="bottom" id="Terminal" order="6" />
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="8" />
@@ -359,8 +337,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/models/user/user_info_model.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="39">
<caret line="4" column="19" selection-start-line="4" selection-start-column="6" selection-end-line="4" selection-end-column="19" />
<state relative-caret-position="60">
<caret line="5" column="19" selection-start-line="5" selection-start-column="19" selection-end-line="5" selection-end-column="19" />
</state>
</provider>
</entry>
@@ -373,15 +351,15 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/models/user/user_info_model_notifier.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="276">
<caret line="27" column="15" selection-start-line="27" selection-start-column="2" selection-end-line="27" selection-end-column="15" />
<state relative-caret-position="507">
<caret line="37" column="15" selection-start-line="37" selection-start-column="15" selection-end-line="37" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/pages/empty_page.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
<caret line="13" selection-start-line="13" selection-end-line="13" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>
@@ -398,17 +376,11 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/pages/login_page.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/pages/login_page.dart" />
<entry file="file://$PROJECT_DIR$/lib/util/router_util.dart">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="79">
<caret line="5" column="16" selection-start-line="5" selection-start-column="6" selection-end-line="5" selection-end-column="16" />
<state relative-caret-position="126">
<caret line="6" column="79" selection-start-line="6" selection-start-column="79" selection-end-line="6" selection-end-column="79" />
<folding>
<element signature="e#0#39#0" expanded="true" />
</folding>


+ 21
- 0
example/pubspec.lock Datei anzeigen

@@ -36,6 +36,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
bloc:
dependency: transitive
description:
name: bloc
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
boolean_selector:
dependency: transitive
description:
@@ -230,6 +237,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_bloc:
dependency: transitive
description:
name: flutter_bloc
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.1"
flutter_cache_manager:
dependency: transitive
description:
@@ -576,6 +590,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.3"
shimmer:
dependency: transitive
description:
name: shimmer
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
sky_engine:
dependency: transitive
description: flutter


+ 63
- 31
lib/util/net_util.dart Datei anzeigen

@@ -47,7 +47,7 @@ class NetUtil {
if (_dio == null) {
var setting = await NativeUtil.getSetting();
String domain = setting['domain']; //'http://www.hairuyi.com/';
_config(domain, proxyUrl: '192.168.0.66:8866');
_config(domain, proxyUrl: '192.168.0.112:8888');
}
return _dio;
}
@@ -87,7 +87,9 @@ class NetUtil {

/// 同步请求
static Future<dynamic> post(String path,
{Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = false}) async {
{Map<String, dynamic> params,
NetMethod method = NetMethod.POST,
bool cache = false}) async {
if (params == null) {
params = {};
}
@@ -99,25 +101,32 @@ class NetUtil {
Response response;
try {
Dio dio = await NetUtil.getInstance().dio;
response = await dio.request(path, data: sign, options: Options(method: enumToString(method)));
response = await dio.request(path,
data: sign, options: Options(method: enumToString(method)));
} on DioError catch (e) {
_formatError(e);
}

try {
var result = response.data is Map ? response.data : jsonDecode(response.data);
var result =
response.data is Map ? response.data : jsonDecode(response.data);
// TODO 解密?
if (isSuccess(result)) {
// 缓存成功的数据
if(cache) {
_setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data);
}
return result;
// 缓存返回的数据
// 缓存成功的数据
if (cache) {
_setCallBackCacheData(cacheKey,
response.data is Map ? jsonEncode(response.data) : response.data);
}
return result;
// 缓存返回的数据
}

Logger.error('error: ' + result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]);
Fluttertoast.showToast(msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG], toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM,);
Fluttertoast.showToast(
msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG],
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
return result;
} catch (e) {
return null;
@@ -148,9 +157,20 @@ class NetUtil {

Response response;
try {
// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(
GlobalConfig.SHARED_KEY_TOKEN) ??
'';

const bool inProduction = const bool.fromEnvironment("dart.vm.product");
if (!inProduction && token != '') {
token = '7f7bdb785dcb02a4536bea2ffe299eda352e127f';
}
Dio dio = await NetUtil.getInstance().dio;
response = await dio.request(path,
data: sign, options: Options(method: enumToString(method)));
data: sign,
options:
Options(method: enumToString(method), headers: {'token': token}));
} on DioError catch (e) {
_formatError(e);
}
@@ -176,7 +196,11 @@ class NetUtil {
gravity: ToastGravity.BOTTOM,
);
if (onError != null) {
onError( !EmptyUtil.isEmpty(result) ? !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]) ? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG] : '未知错误' : '未知错误');
onError(!EmptyUtil.isEmpty(result)
? !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_MSG])
? result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]
: '未知错误'
: '未知错误');
}
} catch (e) {
Logger.error('error: ' + e.toString());
@@ -229,7 +253,9 @@ class NetUtil {

// 站长ID
String masterId = setting['master_id'];
if (null != masterId && masterId != '' && (!params.containsKey('master_id') || params['master_id'] == '')) {
if (null != masterId &&
masterId != '' &&
(!params.containsKey('master_id') || params['master_id'] == '')) {
params['master_id'] = masterId;
}

@@ -237,8 +263,9 @@ class NetUtil {
params['secret_key'] = setting['secret_key'];

// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN);
if(!EmptyUtil.isEmpty(token)){
String token = await SharedPreferencesUtil.getStringValue(
GlobalConfig.SHARED_KEY_TOKEN);
if (!EmptyUtil.isEmpty(token)) {
params['token'] = token;
}

@@ -274,7 +301,8 @@ class NetUtil {
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
GlobalConfig.RESPONSE_SUCCESS_CODE ||
cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
'${GlobalConfig.RESPONSE_SUCCESS_CODE}') && !EmptyUtil.isEmpty(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
'${GlobalConfig.RESPONSE_SUCCESS_CODE}') &&
!EmptyUtil.isEmpty(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
onCache(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
return;
}
@@ -287,30 +315,34 @@ class NetUtil {
}

/// 根据请求参数,获取缓存的数据
static Future<dynamic> getRequestCachedData(String url, {Map<String, dynamic> params}) async{
Map<String, dynamic> cacheMap = await SharedPreferencesUtil.getNetCacheResult(getRequestParamsCachedKey(params, url));
if (!EmptyUtil.isEmpty(cacheMap) &&
cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) &&
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
GlobalConfig.RESPONSE_SUCCESS_CODE ||
cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
'${GlobalConfig.RESPONSE_SUCCESS_CODE}') && !EmptyUtil.isEmpty(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
return cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA];
}
return null;
static Future<dynamic> getRequestCachedData(String url,
{Map<String, dynamic> params}) async {
Map<String, dynamic> cacheMap =
await SharedPreferencesUtil.getNetCacheResult(
getRequestParamsCachedKey(params, url));
if (!EmptyUtil.isEmpty(cacheMap) &&
cacheMap.containsKey(GlobalConfig.HTTP_RESPONSE_KEY_CODE) &&
(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
GlobalConfig.RESPONSE_SUCCESS_CODE ||
cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
'${GlobalConfig.RESPONSE_SUCCESS_CODE}') &&
!EmptyUtil.isEmpty(cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
return cacheMap[GlobalConfig.HTTP_RESPONSE_KEY_DATA];
}
return null;
}

/// 判断后台返回是否成功
static bool isSuccess(Map<String, dynamic> data){
static bool isSuccess(Map<String, dynamic> data) {
try {
if (!EmptyUtil.isEmpty(data) &&
(data[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
GlobalConfig.RESPONSE_SUCCESS_CODE ||
GlobalConfig.RESPONSE_SUCCESS_CODE ||
data[GlobalConfig.HTTP_RESPONSE_KEY_CODE] ==
'${GlobalConfig.RESPONSE_SUCCESS_CODE}')) {
return true;
}
}catch(e){
} catch (e) {
return false;
}
return false;


+ 6
- 0
lib/util/router_util.dart Datei anzeigen

@@ -12,6 +12,12 @@ class RouterUtil {
// 需要淘宝授权
String requiredTaobaoAuth = model['required_taobao_auth'].toString();

if (skipIdentifier == null || skipIdentifier == '') {
print('skipIdentifier 参数不存在,无法跳转页面');
return Future.error('skipIdentifier 参数不存在,无法跳转页面');
}
print('skipIdentifier: ${skipIdentifier}');

if (requiredLogin == '1') {
UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
print(user.toString());


+ 2
- 0
lib/zhiying_comm.dart Datei anzeigen

@@ -34,3 +34,5 @@ export 'native/native_router.dart';
// model
export 'models/base/widget_model.dart';
export 'models/base/skip_model.dart';
export 'models/user/user_info_model.dart';
export 'models/user/user_info_model_notifier.dart';

+ 21
- 0
pubspec.lock Datei anzeigen

@@ -36,6 +36,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
bloc:
dependency: transitive
description:
name: bloc
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.0"
boolean_selector:
dependency: transitive
description:
@@ -223,6 +230,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_bloc:
dependency: "direct main"
description:
name: flutter_bloc
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.1"
flutter_cache_manager:
dependency: transitive
description:
@@ -569,6 +583,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.3"
shimmer:
dependency: "direct main"
description:
name: shimmer
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
sky_engine:
dependency: transitive
description: flutter


+ 4
- 0
zhiying_comm.iml Datei anzeigen

@@ -11,12 +11,16 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/fluttertoast/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/fluttertoast/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/fluttertoast/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/zhiying_comm/example/ios/Flutter/App.framework/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />


Laden…
Abbrechen
Speichern