验证码倒计时重复点击bug

websocket地址更改
master
张萌 3 years ago
parent b99616a1ff
commit c5b447f38a

@ -10,6 +10,9 @@ class ClockTimerProvider extends ChangeNotifier{
void startTimer() { void startTimer() {
timerStart = true; timerStart = true;
if (timer != null) {
return;
}
timer = Timer.periodic(Duration(seconds: 1), (timer) { timer = Timer.periodic(Duration(seconds: 1), (timer) {
if (second > 0) { if (second > 0) {
second--; second--;

@ -27,7 +27,6 @@ class UserProvider extends ChangeNotifier {
await HiveStore.appBox!.put('login', true); await HiveStore.appBox!.put('login', true);
if (isLogin) { if (isLogin) {
await updateUserInfo(); await updateUserInfo();
WebSocketUtil().setUser(_userInfoModel!.id.toString());
WebSocketUtil().startWebSocket(); WebSocketUtil().startWebSocket();
await SignFunc.checkNameAndAccount(); await SignFunc.checkNameAndAccount();
} }

@ -1,11 +1,11 @@
import 'dart:async'; import 'dart:async';
import 'package:aku_new_community_manager/tools/user_tool.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/web_socket_channel.dart';
const String baseUri = 'wss://shop.kaidalai.cn/websocket/butlerApp';
enum SOCKETSTATUS { enum SOCKETSTATUS {
CONNECTED, // CONNECTED, //
BREAKOFF, // BREAKOFF, //
@ -17,13 +17,18 @@ class WebSocketUtil {
// //
WebSocketUtil._(); WebSocketUtil._();
// //
factory WebSocketUtil() => _socket; factory WebSocketUtil() => _socket;
IOWebSocketChannel? _webSocket; IOWebSocketChannel? _webSocket;
/// ///
String _user = 'admin';
static const String baseUri = 'wss://saas.kaidalai.cn/websocket/butlerApp';
String get urlAddress =>
'$baseUri/${UserTool.userProvider.userInfoModel?.communityName}/${UserTool.userProvider.userInfoModel?.nickName}';
/// ///
SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED; SOCKETSTATUS _socketStatus = SOCKETSTATUS.CLOSED;
@ -79,26 +84,23 @@ class WebSocketUtil {
print('——————————webSocket init ——————————'); print('——————————webSocket init ——————————');
} }
///
void setUser(String user) {
this._user = user;
}
///websocket ///websocket
void startWebSocket() { void startWebSocket() {
closeWebSocket(); closeWebSocket();
try { try {
_webSocket = IOWebSocketChannel.connect(Uri.parse('$baseUri/$_user')); _webSocket = IOWebSocketChannel.connect(Uri.parse(urlAddress));
print('webSocket已连接服务器$baseUri/$_user'); print('webSocket已连接服务器$urlAddress');
_socketStatus = SOCKETSTATUS.CONNECTED; _socketStatus = SOCKETSTATUS.CONNECTED;
endReconnect(); endReconnect();
onStart?.call(); onStart?.call();
_webSocket!.stream.listen( _webSocket!.stream.listen(
(event) => webSocketReceiveMessage(event as String), (event) => webSocketReceiveMessage(event as String),
onError: webSocketOnError, ); onError: webSocketOnError,
);
initHeartBeat(); initHeartBeat();
} catch (e) { } catch (e) {
BotToast.showText(text: 'webSocket连接失败'); BotToast.showText(text: 'webSocket连接失败');
print('webSocket连接失败');
onError?.call(e); onError?.call(e);
LoggerData.addData(e); LoggerData.addData(e);
} }

Loading…
Cancel
Save