Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter_clx_base
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
flutter_clx_base
Commits
43d99686
提交
43d99686
authored
9月 11, 2025
作者:
史晓晨
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:兼容阿里云网关鉴权,重新登录逻辑
上级
5418715c
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
45 行增加
和
8 行删除
+45
-8
build.gradle
example/android/app/build.gradle
+1
-1
build.gradle
example/android/build.gradle
+1
-1
gradle-wrapper.properties
example/android/gradle/wrapper/gradle-wrapper.properties
+2
-1
dio_utils.dart
example/lib/sample/dio/dio_utils.dart
+1
-1
dio_widget_test.dart
example/lib/sample/dio_widget_test.dart
+16
-4
pubspec.yaml
example/pubspec.yaml
+4
-0
base_dio.dart
lib/api/base_dio.dart
+20
-0
没有找到文件。
example/android/app/build.gradle
浏览文件 @
43d99686
...
...
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply
from:
"$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android
{
compileSdkVersion
3
3
compileSdkVersion
3
4
compileOptions
{
sourceCompatibility
JavaVersion
.
VERSION_11
...
...
example/android/build.gradle
浏览文件 @
43d99686
...
...
@@ -6,7 +6,7 @@ buildscript {
}
dependencies
{
classpath
'com.android.tools.build:gradle:7.
2
.0'
classpath
'com.android.tools.build:gradle:7.
3
.0'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
...
...
example/android/gradle/wrapper/gradle-wrapper.properties
浏览文件 @
43d99686
...
...
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-7.
5
-all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-7.
6.3
-all.zip
\ No newline at end of file
example/lib/sample/dio/dio_utils.dart
浏览文件 @
43d99686
...
...
@@ -10,7 +10,7 @@ class DioUtils extends BaseDio {
@override
String
setBaseUrl
()
{
return
"https://
api.clxkj.cn:8088
"
;
return
"https://
gateway.testclx.cn
"
;
}
@override
...
...
example/lib/sample/dio_widget_test.dart
浏览文件 @
43d99686
...
...
@@ -12,10 +12,9 @@ class DioWidgetTest extends StatefulWidget {
class
_DioWidgetTestState
extends
State
<
DioWidgetTest
>
{
static
const
String
getSystemVersionByNumber
=
'/
user-service/system/version/getSystemVersionByNumber
'
;
'/
clx-performance/lco/app/driver/orderChild/getGoingLatestOrderChild
'
;
String
_result
=
''
;
@override
Widget
build
(
BuildContext
context
)
{
return
MyScaffold
(
...
...
@@ -23,9 +22,9 @@ class _DioWidgetTestState extends State<DioWidgetTest> {
children:
[
Text
(
_result
),
TextButton
(
onPressed:
()
async
{
onPressed:
()
async
{
debugPrint
(
"=====11111"
);
DioUtils
.
instance
.
request
(
DioUtils
.
instance
.
request
(
requestUrl:
getSystemVersionByNumber
,
method:
Method
.
get
,
queryParameters:
{
...
...
@@ -48,6 +47,19 @@ class _DioWidgetTestState extends State<DioWidgetTest> {
debugPrint
(
"=====22222"
);
},
child:
const
Text
(
'dio请求'
)),
TextButton
(
onPressed:
()
async
{
debugPrint
(
"=====11111"
);
var
result
=
await
DioUtils
.
instance
.
requestSync
(
requestUrl:
getSystemVersionByNumber
,
method:
Method
.
get
,
queryParameters:
{
'versionNumber'
:
20
,
'productNo'
:
1
,
});
debugPrint
(
"=====22222 result =
$result
"
);
},
child:
const
Text
(
'dio请求 sync'
)),
],
);
}
...
...
example/pubspec.yaml
浏览文件 @
43d99686
...
...
@@ -33,6 +33,10 @@ dependencies:
cupertino_icons
:
^1.0.2
# rive: ^0.10.4
#重新依赖库版本 库版本冲突在这里修改,后续更新基础库时,需要注意
dependency_overrides
:
flutter_spinkit
:
5.2.1
dev_dependencies
:
flutter_test
:
sdk
:
flutter
...
...
lib/api/base_dio.dart
浏览文件 @
43d99686
...
...
@@ -108,6 +108,7 @@ abstract class BaseDio {
if
(
e
.
response
!=
null
)
{
logger
.
e
(
"请求错误:
${e.response!.statusCode}
${e.response!.requestOptions.path}
"
);
if
(
await
_httpExceptionReLogin
(
e
.
response
))
return
;
}
else
{
// Something happened in setting up or sending the request that triggered an Error
logger
.
e
(
"请求错误:
${e.error}
"
);
...
...
@@ -152,6 +153,9 @@ abstract class BaseDio {
if
(
e
.
response
!=
null
)
{
logger
.
e
(
"请求错误:
${e.response!.statusCode}
${e.response!.requestOptions.path}
"
);
if
(
await
_httpExceptionReLogin
(
e
.
response
))
{
return
{
"code"
:
401
,
"message"
:
"登录过期,请重新登录"
};
}
}
else
{
// Something happened in setting up or sending the request that triggered an Error
logger
.
e
(
"请求错误:
${e.error}
"
);
...
...
@@ -188,6 +192,22 @@ abstract class BaseDio {
await
errorCallback
?.
call
(
400
,
"数据解析错误"
);
}
}
/// 网关拦截重新登录
/// http状态码为401 & 返回体code为-100时,需重新登录 {"code":-100,"msg":"权限变更或登录过期,请重新登录"}
Future
<
bool
>
_httpExceptionReLogin
(
Response
?
response
)
async
{
var
httpCode
=
response
?.
statusCode
;
var
httpData
=
response
?.
data
;
if
(
httpData
!=
null
&&
httpData
!=
""
)
{
var
httpResult
=
await
jsonTransformer
.
parseJson
(
httpData
);
if
(
httpCode
==
401
&&
httpResult
[
"code"
]?.
toString
()
==
"-100"
)
{
logger
.
e
(
"登录过期:
${httpResult['msg']}
"
);
onLoginExpire
();
return
true
;
}
}
return
false
;
}
}
Options
_checkOptions
(
String
method
,
Options
?
options
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论