소스 검색

1.更新支付宝插件版本

2.优化缓存key的策略
tags/0.0.4+1
“yanghuaxuan” 3 년 전
부모
커밋
b5b3e28662
3개의 변경된 파일40개의 추가작업 그리고 24개의 파일을 삭제
  1. +1
    -1
      example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java
  2. +33
    -19
      lib/util/net_util.dart
  3. +6
    -4
      pubspec.yaml

+ 1
- 1
example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java 파일 보기

@@ -49,7 +49,7 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN

@Override
public void initSuccess() {
}

@Override


+ 33
- 19
lib/util/net_util.dart 파일 보기

@@ -93,12 +93,17 @@ class NetUtil {
}

/// 同步请求
static Future<dynamic> post(String path, {Map<String, dynamic> params, Map<String, dynamic> queryParameters, NetMethod method = NetMethod.POST, bool cache = false, bool showToast = true}) async {
if (params == null) {
params = {};
}
static Future<dynamic> post(String path,
{Map<String, dynamic> params, Map<String, dynamic> queryParameters, NetMethod method = NetMethod.POST, bool cache = false, bool showToast = true}) async {

var paramsData = {
'postData': params ?? {},
'queryParameters': queryParameters ?? {}
};


// 根据请求参数,获取缓存的Key
String cacheKey = getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(paramsData, path);
// 参数签名 TODO 加密?
// post请求的参数
Map<String, dynamic> bodyParams = params;
@@ -107,7 +112,9 @@ class NetUtil {

Response response;
try {
Dio dio = await NetUtil.getInstance().dio;
Dio dio = await NetUtil
.getInstance()
.dio;
response = await dio.request(
path,
data: !EmptyUtil.isEmpty(bodyParams) ? bodyParams : null,
@@ -130,12 +137,13 @@ class NetUtil {
// 缓存返回的数据
} else {
Logger.error('error: ' + result[GlobalConfig.HTTP_RESPONSE_KEY_MSG]);

///
/// 401000 验证用户失败(不提示Toast)
/// 404004 没有找到对应模块(跳空页面,不提示toast)
///
if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 401000 && result[GlobalConfig.HTTP_RESPONSE_KEY_CODE] != 404004) {
if(showToast) {
if (showToast) {
Fluttertoast.showToast(
msg: result[GlobalConfig.HTTP_RESPONSE_KEY_MSG],
toastLength: Toast.LENGTH_SHORT,
@@ -164,8 +172,7 @@ class NetUtil {
/// 403029 账号被禁用
/// 提示并且退出登录
///
if(result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403028' || result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403029') {

if (result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403028' || result[GlobalConfig.HTTP_RESPONSE_KEY_CODE]?.toString() == '403029') {
try {
// 提示
Fluttertoast.showToast(
@@ -191,20 +198,27 @@ class NetUtil {
}

/// 异步请求
static void request(String path, {NetMethod method = NetMethod.GET, Map<String, dynamic> params,Map<String, dynamic> queryParameters, OnSuccess onSuccess, OnError onError, OnCache onCache, bool showToast = true}) async {
if (params == null) {
params = {};
}
static void request(String path, {NetMethod method = NetMethod.GET, Map<String, dynamic> params, Map<String,
dynamic> queryParameters, OnSuccess onSuccess, OnError onError, OnCache onCache, bool showToast = true}) async {
var paramsData = {
'postData': params ?? {},
'queryParameters': queryParameters ?? {}
};

// 根据请求参数,获取缓存的Key
String cacheKey = getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(paramsData, path);
print("缓存Key"+cacheKey);
// // 读取缓存回调
if (onCache != null) {
await _onCallBackCacheData(onCache, cacheKey);
}

try {
Map result = await NetUtil.post(path, method: method, params: params, queryParameters: queryParameters, showToast: showToast, cache: onCache != null);
Map result = await NetUtil.post(path, method: method,
params: params,
queryParameters: queryParameters,
showToast: showToast,
cache: onCache != null);
// TODO 解密?
if (isSuccess(result)) {
if (onSuccess != null) {
@@ -355,10 +369,10 @@ class NetUtil {
// token 读取SP缓存中的用户token
String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN);

if(EmptyUtil.isEmpty(token)&&!bool.fromEnvironment("dart.vm.product")){
try{
token=setting['token'];
}catch(e,s){
if (EmptyUtil.isEmpty(token) && !bool.fromEnvironment("dart.vm.product")) {
try {
token = setting['token'];
} catch (e, s) {
print(s);
print(e);
}


+ 6
- 4
pubspec.yaml 파일 보기

@@ -40,9 +40,10 @@ dependencies:
# app更新dialogUI(用于IOS,以便统一样式)
flutter_update_dialog: 1.0.0
flutter_alibc:
git:
ref: 0.0.3
url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git
path: ../zhiying_flutter_alibc
# git:
# ref: 0.0.3
# url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git
url_launcher: ^5.6.0
#图片预览控件
photo_view: ^0.10.2
@@ -80,9 +81,10 @@ dependencies:
dio_cookie_manager: ^1.0.0
#支付宝支付flutterSDK
tobias:
# path: ../tobias
git:
url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/tobias.git'
ref: '0.0.1'
ref: '0.0.2'

event_bus: 1.1.1



불러오는 중...
취소
저장