88 lines
3.2 KiB
Dart
88 lines
3.2 KiB
Dart
import 'package:aioa_mobile/core/auth/auth_session_controller.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:aioa_mobile/features/profile/application/device_controller.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:aioa_mobile/features/admin/application/admin_controller.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
class ProfilePage extends ConsumerWidget {
|
|
const ProfilePage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final devices = ref.watch(deviceListProvider);
|
|
final permissions =
|
|
ref.watch(currentPermissionsProvider).value ?? const <String>{};
|
|
return ListView(
|
|
padding: const EdgeInsets.all(18),
|
|
children: [
|
|
const Card(
|
|
child: ListTile(
|
|
leading: CircleAvatar(child: Icon(Icons.person_outline)),
|
|
title: Text('企业账号'),
|
|
subtitle: Text('身份由 Keycloak OIDC 管理'),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
if (permissions.contains('ORGANIZATION_MANAGE_TENANT')) ...[
|
|
FilledButton.icon(
|
|
onPressed: () => context.push('/admin'),
|
|
icon: const Icon(Icons.admin_panel_settings),
|
|
label: const Text('OA 管理中心'),
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
Text('登录设备', style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
...devices.when(
|
|
loading: () => const [Center(child: CircularProgressIndicator())],
|
|
error: (error, _) => [
|
|
Card(
|
|
child: ListTile(
|
|
title: const Text('设备列表加载失败'),
|
|
subtitle: Text('$error'),
|
|
),
|
|
),
|
|
],
|
|
data: (items) => items
|
|
.map(
|
|
(device) => Card(
|
|
child: ListTile(
|
|
leading: Icon(
|
|
device.platform == 'IOS'
|
|
? Icons.phone_iphone
|
|
: Icons.phone_android,
|
|
),
|
|
title: Text(device.name),
|
|
subtitle: Text(
|
|
'${device.status == 'ACTIVE' ? '已登录' : '已撤销'} · ${DateFormat('MM-dd HH:mm').format(device.lastSeenAt.toLocal())}',
|
|
),
|
|
trailing: device.status != 'ACTIVE'
|
|
? null
|
|
: IconButton(
|
|
tooltip: '撤销并退出',
|
|
icon: const Icon(Icons.logout),
|
|
onPressed: () => ref
|
|
.read(deviceListProvider.notifier)
|
|
.revoke(device.id),
|
|
),
|
|
),
|
|
),
|
|
)
|
|
.toList(),
|
|
),
|
|
const SizedBox(height: 12),
|
|
OutlinedButton.icon(
|
|
onPressed: ref.read(authSessionProvider.notifier).logout,
|
|
icon: const Icon(Icons.logout),
|
|
label: const Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 12),
|
|
child: Text('安全退出'),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|