feat: 多端邀请接入

This commit is contained in:
2026-01-19 07:21:28 -08:00
parent b441346630
commit 8e48a6ff8a
19 changed files with 476 additions and 71 deletions
+21 -20
View File
@@ -131,9 +131,11 @@ class HttpUtil {
}
}
/// request请求:T为转换的实体类, path:请求地址,query:请求参数, method: 请求方法, isShowLoading(可选): 是否显示加载中的状态,默认true显示, false为不显示
/// request请求:T为转换的实体类, path:请求地址,query:请求参数, method: 请求方法, isShowLoading(可选): 是否显示加载中的状态,默认true显示, false为不显示, silentInvite: 是否为静默邀请
Future<BaseResponse<T>> request<T>(String path, Map<String, dynamic> params,
{HttpMethod method = HttpMethod.POST, bool isShowLoading = true}) async {
{HttpMethod method = HttpMethod.POST,
bool isShowLoading = true,
bool isSilentInvite = false}) async {
try {
// 每次请求前更新baseUrl,确保使用最新的域名
updateBaseUrl();
@@ -148,43 +150,40 @@ class HttpUtil {
// 初始化请求头
final headers = _initHeader('signature', 'userId', 'token');
if (isSilentInvite) {
headers['X-Client-Mode'] = 'invite_silent';
}
final options = Options(
contentType: "application/json",
headers: headers,
extra: {'silentInvite': isSilentInvite},
);
Response<Map<String, dynamic>> responseTemp;
if (method == HttpMethod.GET) {
responseTemp = await _dio.get<Map<String, dynamic>>(
path,
queryParameters: map,
options: Options(
contentType: "application/json",
headers: headers, // 添加请求头
),
options: options,
);
} else if (method == HttpMethod.DELETE) {
responseTemp = await _dio.delete<Map<String, dynamic>>(
path,
data: map,
options: Options(
contentType: "application/json",
headers: headers, // 添加请求头
),
options: options,
);
} else if (method == HttpMethod.PUT) {
responseTemp = await _dio.put<Map<String, dynamic>>(
path,
data: map,
options: Options(
contentType: "application/json",
headers: headers, // 添加请求头
),
options: options,
);
} else {
responseTemp = await _dio.post<Map<String, dynamic>>(
path,
data: map,
options: Options(
contentType: "application/json",
headers: headers, // 添加请求头
),
options: options,
);
}
@@ -237,7 +236,8 @@ class HttpUtil {
msg = '${msg.isNotEmpty ? msg : 'unknown'} ($_pathOnly)';
final _ua =
(err.requestOptions.extra['__unknown_attempts'] as int?) ?? 0;
if (_ua >= 2) {
final bool isSilent = err.requestOptions.extra['silentInvite'] ?? false;
if (_ua >= 2 && !isSilent) {
KRCommonUtil.kr_showToast('请求失败($_pathOnly', timeout: 3500);
}
}
@@ -374,7 +374,8 @@ class _KRSimpleHttpInterceptor extends Interceptor {
return;
} else {
final now = DateTime.now().millisecondsSinceEpoch;
if (!(_lastPath == path && (now - _lastTsMs) < 2000)) {
final bool isSilent = err.requestOptions.extra['silentInvite'] ?? false;
if (!(_lastPath == path && (now - _lastTsMs) < 2000) && !isSilent) {
_lastPath = path;
_lastTsMs = now;
KRCommonUtil.kr_showToast('请求失败($path', timeout: 3500);