90f318e246
Deploy Client / build-windows (push) Failing after 21s
Deploy Client / build-client-web (push) Successful in 42s
Deploy Client / build-macos (push) Successful in 2m8s
Deploy Client / build-android (push) Successful in 1m25s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Has been skipped
设备/状态管理屏(查看本店在线设备/会话,管理员可强制下线)、登录携带设备信息、 会话心跳(/auth/ping)、被踢下线/会话失效提示、顶栏精简 + 用户名移至左侧栏底部。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.4 KiB
Dart
52 lines
1.4 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/auth/auth_state.dart';
|
|
import '../models/session.dart';
|
|
import '../repositories/session_repository.dart';
|
|
|
|
final sessionRepositoryProvider = Provider<SessionRepository>((ref) {
|
|
return SessionRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final sessionListProvider =
|
|
AsyncNotifierProvider<SessionListNotifier, List<DeviceSession>>(
|
|
SessionListNotifier.new,
|
|
);
|
|
|
|
class SessionListNotifier extends AsyncNotifier<List<DeviceSession>> {
|
|
List<DeviceSession> _cache = [];
|
|
|
|
@override
|
|
Future<List<DeviceSession>> build() async {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
try {
|
|
final result = await ref.read(sessionRepositoryProvider).list();
|
|
_cache = result;
|
|
return result;
|
|
} catch (_) {
|
|
if (_cache.isNotEmpty) return _cache;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<void> reload() async {
|
|
state = const AsyncValue.loading();
|
|
try {
|
|
final result = await ref.read(sessionRepositoryProvider).list();
|
|
_cache = result;
|
|
state = AsyncValue.data(result);
|
|
} catch (e, st) {
|
|
if (_cache.isNotEmpty) {
|
|
state = AsyncValue.data(_cache);
|
|
} else {
|
|
state = AsyncValue.error(e, st);
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> forceLogout(int id) async {
|
|
await ref.read(sessionRepositoryProvider).forceLogout(id);
|
|
await reload();
|
|
}
|
|
}
|