|
|
@@ -0,0 +1,108 @@
|
|
|
+import 'package:chicken_farm/stores/auth_store.dart';
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
+import 'package:getwidget/getwidget.dart';
|
|
|
+
|
|
|
+class ProfilePage extends ConsumerWidget {
|
|
|
+ const ProfilePage({super.key});
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context, WidgetRef ref) {
|
|
|
+ final authState = ref.watch(authStoreProvider);
|
|
|
+ final authStore = ref.read(authStoreProvider.notifier);
|
|
|
+
|
|
|
+ return Scaffold(
|
|
|
+ body: Padding(
|
|
|
+ padding: const EdgeInsets.all(16.0),
|
|
|
+ child: Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ const SizedBox(height: 20),
|
|
|
+ if (authState.state == AuthState.authenticated &&
|
|
|
+ authState.user != null) ...[
|
|
|
+ Card(
|
|
|
+ child: Padding(
|
|
|
+ padding: const EdgeInsets.all(16.0),
|
|
|
+ child: Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ ListTile(
|
|
|
+ leading: const CircleAvatar(
|
|
|
+ radius: 30,
|
|
|
+ child: Icon(Icons.person, size: 30),
|
|
|
+ ),
|
|
|
+ title: Text(
|
|
|
+ authState.user!.nickName ?? '未设置昵称',
|
|
|
+ style: const TextStyle(
|
|
|
+ fontSize: 20,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ subtitle: Text('用户名: ${authState.user!.userName}'),
|
|
|
+ ),
|
|
|
+ const Divider(),
|
|
|
+ const Text(
|
|
|
+ '基本信息',
|
|
|
+ style: TextStyle(fontWeight: FontWeight.bold),
|
|
|
+ ),
|
|
|
+ const SizedBox(height: 10),
|
|
|
+ _buildInfoRow(
|
|
|
+ '手机号码',
|
|
|
+ authState.user!.phonenumber ?? '未填写',
|
|
|
+ ),
|
|
|
+ _buildInfoRow('邮箱地址', authState.user!.email ?? '未填写'),
|
|
|
+ _buildInfoRow('部门', authState.user!.orgName ?? '未分配'),
|
|
|
+ _buildInfoRow(
|
|
|
+ '角色',
|
|
|
+ (authState.user!.roles
|
|
|
+ ?.map((r) => r.roleName)
|
|
|
+ .join(', ')) ??
|
|
|
+ '未分配',
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ const SizedBox(height: 20),
|
|
|
+ SizedBox(
|
|
|
+ width: double.infinity,
|
|
|
+ child: ElevatedButton.icon(
|
|
|
+ onPressed: () => authStore.logout(),
|
|
|
+ icon: const Icon(Icons.logout),
|
|
|
+ label: const Text('退出登录'),
|
|
|
+ style: ElevatedButton.styleFrom(
|
|
|
+ padding: const EdgeInsets.symmetric(
|
|
|
+ horizontal: 30,
|
|
|
+ vertical: 15,
|
|
|
+ ),
|
|
|
+ textStyle: const TextStyle(fontSize: 16),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ] else ...[
|
|
|
+ const Center(child: Text('加载中...')),
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _buildInfoRow(String label, String value) {
|
|
|
+ return Padding(
|
|
|
+ padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
|
+ child: Row(
|
|
|
+ children: [
|
|
|
+ SizedBox(
|
|
|
+ width: 80,
|
|
|
+ child: Text(
|
|
|
+ '$label:',
|
|
|
+ style: const TextStyle(fontWeight: FontWeight.w500),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(child: Text(value)),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|