新增 token自动提交
This commit is contained in:
@@ -22,6 +22,9 @@ abstract class DataBase {
|
|||||||
|
|
||||||
// 执行删除操作
|
// 执行删除操作
|
||||||
Future<void> delete(String table, dynamic condition);
|
Future<void> delete(String table, dynamic condition);
|
||||||
|
|
||||||
|
//查询数量
|
||||||
|
Future<int> count(String tbale, {dynamic condition});
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataBaseConfig {
|
class DataBaseConfig {
|
||||||
|
|||||||
@@ -50,4 +50,9 @@ class MongoDb implements DataBase {
|
|||||||
await getCollection(table)
|
await getCollection(table)
|
||||||
.update(condition, data, multiUpdate: multiUpdate);
|
.update(condition, data, multiUpdate: multiUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<int> count(String tbale, {dynamic condition}) async {
|
||||||
|
return await getCollection(tbale).count(condition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ class NacosDiscovery implements Discovery {
|
|||||||
'namespaceId': config.namespaceId,
|
'namespaceId': config.namespaceId,
|
||||||
});
|
});
|
||||||
print(rr);
|
print(rr);
|
||||||
|
//判断心跳是否发送成功
|
||||||
|
if(rr.data["code"]==20404){
|
||||||
|
//实例未注册 重新注册实例
|
||||||
|
healthCheck = false;
|
||||||
|
registerInstance(serviceName, ip, port,groupName: groupName);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class TraceDio {
|
|||||||
final Uuid uuid = Uuid();
|
final Uuid uuid = Uuid();
|
||||||
|
|
||||||
static late TraceDio _traceDio;
|
static late TraceDio _traceDio;
|
||||||
|
String? token;
|
||||||
|
|
||||||
TraceDio(Logger logger)
|
TraceDio(Logger logger)
|
||||||
: _dio = Dio(),
|
: _dio = Dio(),
|
||||||
@@ -48,6 +49,9 @@ class TraceDio {
|
|||||||
tag: "DIO",
|
tag: "DIO",
|
||||||
traceId: traceId,
|
traceId: traceId,
|
||||||
spanId: spanId);
|
spanId: spanId);
|
||||||
|
if (response.headers["token"] != null) {
|
||||||
|
token = response.headers["token"]?[0];
|
||||||
|
}
|
||||||
return handler.next(response); // 继续处理响应
|
return handler.next(response); // 继续处理响应
|
||||||
},
|
},
|
||||||
onError: (DioException e, handler) {
|
onError: (DioException e, handler) {
|
||||||
@@ -71,21 +75,29 @@ class TraceDio {
|
|||||||
|
|
||||||
Map<String, dynamic>? getHeader(
|
Map<String, dynamic>? getHeader(
|
||||||
{Map<String, dynamic>? headers, sf.Request? request}) {
|
{Map<String, dynamic>? headers, sf.Request? request}) {
|
||||||
|
headers ??= {};
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
return {
|
return {
|
||||||
|
...headers,
|
||||||
"X-Trace-ID": request.context['request_trace_id'] as String,
|
"X-Trace-ID": request.context['request_trace_id'] as String,
|
||||||
"X-Span-ID": request.context['request_span_id'] as String
|
"X-Span-ID": request.context['request_span_id'] as String
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
if (token != null) {
|
||||||
|
headers["token"] = token;
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起 GET 请求
|
// 发起 GET 请求
|
||||||
Future<Response> get(String url,
|
Future<Response> get(String url,
|
||||||
{Map<String, dynamic>? queryParameters, sf.Request? request}) async {
|
{Map<String, dynamic>? queryParameters,
|
||||||
|
sf.Request? request,
|
||||||
|
ResponseType? responseType}) async {
|
||||||
return await _dio.get(url,
|
return await _dio.get(url,
|
||||||
queryParameters: queryParameters,
|
queryParameters: queryParameters,
|
||||||
options: Options(headers: getHeader(request: request)));
|
options: Options(
|
||||||
|
headers: getHeader(request: request), responseType: responseType));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发起 POST 请求
|
// 发起 POST 请求
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class WebSocket {
|
|||||||
final channel = WebSocketChannel.connect(wsUrl);
|
final channel = WebSocketChannel.connect(wsUrl);
|
||||||
try {
|
try {
|
||||||
await channel.ready;
|
await channel.ready;
|
||||||
|
Future.delayed(Duration(seconds: 2), () {
|
||||||
|
if (_config.onOpen != null) {
|
||||||
|
_config.onOpen!();
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
//连接失败
|
//连接失败
|
||||||
@@ -73,6 +78,8 @@ class WebSocketConfig {
|
|||||||
String host;
|
String host;
|
||||||
bool reConnect;
|
bool reConnect;
|
||||||
void Function(String) messgae;
|
void Function(String) messgae;
|
||||||
|
void Function()? onOpen;
|
||||||
|
|
||||||
WebSocketConfig(this.host, this.messgae, {this.reConnect = true});
|
WebSocketConfig(this.host, this.messgae,
|
||||||
|
{this.reConnect = true, this.onOpen});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user