Przeglądaj źródła

1、网络库的修改

tags/0.0.1
PH2 4 lat temu
rodzic
commit
258dfddcde
2 zmienionych plików z 22 dodań i 14 usunięć
  1. +12
    -4
      lib/util/color.dart
  2. +10
    -10
      lib/util/net_util.dart

+ 12
- 4
lib/util/color.dart Wyświetl plik

@@ -10,13 +10,21 @@
import 'dart:ui';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:zhiying_comm/util/log/let_log.dart';

extension HexColor on Color {
/// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
static Color fromHex(String hexString) {
final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
buffer.write(hexString.replaceFirst('#', ''));
return Color(int.parse(buffer.toString(), radix: 16));
try{
final buffer = StringBuffer();
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
buffer.write(hexString.replaceFirst('#', ''));
return Color(int.parse(buffer.toString(), radix: 16));
}catch(e){
Logger.log(e);
}
return Colors.white;
}

static Color random() {


+ 10
- 10
lib/util/net_util.dart Wyświetl plik

@@ -46,7 +46,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.66:8866');
}
return _dio;
}
@@ -86,12 +86,12 @@ class NetUtil {

/// 同步请求
static Future<dynamic> post(String path,
{Map<String, dynamic> params, NetMethod method = NetMethod.POST}) async {
{Map<String, dynamic> params, NetMethod method = NetMethod.POST, bool cache = true}) async {
if (params == null) {
params = {};
}
// 根据请求参数,获取缓存的Key
String cacheKey = _getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(params, path);
// 参数签名 TODO 加密?
Map<String, dynamic> sign = await signParams(params);

@@ -108,7 +108,9 @@ class NetUtil {
// TODO 解密?
if (isSuccess(result)) {
// 缓存成功的数据
_setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data);
if(cache) {
_setCallBackCacheData(cacheKey, response.data is Map ? jsonEncode(response.data) : response.data);
}
return result;
// 缓存返回的数据
}
@@ -134,7 +136,7 @@ class NetUtil {
}

// 根据请求参数,获取缓存的Key
String cacheKey = _getRequestParamsCachedKey(params, path);
String cacheKey = getRequestParamsCachedKey(params, path);
// // 读取缓存回调
if (onCache != null) {
await _onCallBackCacheData(onCache, cacheKey);
@@ -226,9 +228,7 @@ class NetUtil {

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

@@ -289,7 +289,7 @@ class NetUtil {

/// 根据请求参数,获取缓存的数据
static Future<dynamic> getRequestCachedData(String url, {Map<String, dynamic> params}) async{
Map<String, dynamic> cacheMap = await SharedPreferencesUtil.getNetCacheResult(_getRequestParamsCachedKey(params, url));
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] ==
@@ -318,7 +318,7 @@ class NetUtil {
}

/// 根据请求参数,获取缓存的Key
static String _getRequestParamsCachedKey(
static String getRequestParamsCachedKey(
Map<String, dynamic> map, String path) {
if (EmptyUtil.isEmpty(map)) {
return EncodeUtil.generateMd5(path);


Ładowanie…
Anuluj
Zapisz