add
This commit is contained in:
@@ -1,12 +1,56 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
// 定义功能和子功能数据模型
|
||||||
|
class FunctionItem {
|
||||||
|
final String name;
|
||||||
|
final List<SubFunctionItem> subFunctions;
|
||||||
|
|
||||||
|
FunctionItem({required this.name, required this.subFunctions});
|
||||||
|
}
|
||||||
|
|
||||||
|
class SubFunctionItem {
|
||||||
|
final String name;
|
||||||
|
final Widget page;
|
||||||
|
|
||||||
|
SubFunctionItem({required this.name, required this.page});
|
||||||
|
}
|
||||||
|
|
||||||
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomePage> createState() => _HomePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomePageState extends State<HomePage> {
|
||||||
|
// 功能列表数据 - 初始只包含"系统"功能
|
||||||
|
final List<FunctionItem> _functions = [
|
||||||
|
FunctionItem(
|
||||||
|
name: "系统",
|
||||||
|
subFunctions: [
|
||||||
|
SubFunctionItem(
|
||||||
|
name: "基本信息",
|
||||||
|
page: const Center(child: Text("系统基本信息页面内容")),
|
||||||
|
),
|
||||||
|
SubFunctionItem(
|
||||||
|
name: "参数设置",
|
||||||
|
page: const Center(child: Text("系统参数设置页面内容")),
|
||||||
|
),
|
||||||
|
SubFunctionItem(
|
||||||
|
name: "日志管理",
|
||||||
|
page: const Center(child: Text("系统日志管理页面内容")),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 选中状态跟踪
|
||||||
|
int _selectedFunctionIndex = 0;
|
||||||
|
int _selectedSubFunctionIndex = 0;
|
||||||
|
|
||||||
Future<void> _logout(BuildContext context) async {
|
Future<void> _logout(BuildContext context) async {
|
||||||
final prefs = await SharedPreferences.getInstance();
|
final prefs = await SharedPreferences.getInstance();
|
||||||
// 先确认需要清除的数据存在
|
|
||||||
final hasUserID = prefs.getString('user_id') != null;
|
final hasUserID = prefs.getString('user_id') != null;
|
||||||
|
|
||||||
if (hasUserID) {
|
if (hasUserID) {
|
||||||
@@ -14,33 +58,30 @@ class HomePage extends StatelessWidget {
|
|||||||
debugPrint('移除的用户ID: $hasUserID');
|
debugPrint('移除的用户ID: $hasUserID');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Web端强制刷新存储
|
|
||||||
await prefs.reload();
|
await prefs.reload();
|
||||||
|
|
||||||
// 检查组件是否已挂载
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
// 导航到登录页并清除路由栈(使用命名路由)
|
Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
|
||||||
Navigator.pushNamedAndRemoveUntil(
|
|
||||||
context,
|
|
||||||
'/login', // 目标命名路由
|
|
||||||
(route) => false, // 清除所有之前的路由
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// 获取当前选中的功能和子功能
|
||||||
|
final currentFunction = _functions[_selectedFunctionIndex];
|
||||||
|
final currentSubFunction =
|
||||||
|
currentFunction.subFunctions[_selectedSubFunctionIndex];
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: const Icon(Icons.settings),
|
icon: const Icon(Icons.settings),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// 点击事件处理
|
|
||||||
Navigator.pushNamed(context, '/setting_list');
|
Navigator.pushNamed(context, '/setting_list');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
title: const Text('首页'),
|
title: const Text(''),
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
actions: [
|
actions: [
|
||||||
@@ -50,12 +91,124 @@ class HomePage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: const Center(
|
body: Row(
|
||||||
child: Text(
|
children: [
|
||||||
'功能列表区域',
|
// 左侧功能导航栏
|
||||||
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 18),
|
Container(
|
||||||
|
width: 180,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||||
|
// 使用withValues替换withOpacity
|
||||||
|
border: Border(
|
||||||
|
right: BorderSide(
|
||||||
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.onSurface.withValues(alpha: 0.1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: _functions.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final function = _functions[index];
|
||||||
|
return ListTile(
|
||||||
|
title: Text(
|
||||||
|
function.name,
|
||||||
|
style: TextStyle(
|
||||||
|
color: _selectedFunctionIndex == index
|
||||||
|
? Theme.of(context).colorScheme.secondary
|
||||||
|
: Theme.of(context).colorScheme.onSurface,
|
||||||
|
fontWeight: _selectedFunctionIndex == index
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
selected: _selectedFunctionIndex == index,
|
||||||
|
// 使用withValues替换withOpacity
|
||||||
|
selectedTileColor: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.primary.withValues(alpha: 0.1),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedFunctionIndex = index;
|
||||||
|
_selectedSubFunctionIndex = 0; // 切换功能时默认选中第一个子功能
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 右侧内容区域
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
// 顶部子功能导航栏
|
||||||
|
Container(
|
||||||
|
height: 60,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.surfaceContainerHighest,
|
||||||
|
// 使用withValues替换withOpacity
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.onSurface.withValues(alpha: 0.1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: currentFunction.subFunctions.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final subFunction = currentFunction.subFunctions[index];
|
||||||
|
return InkWell(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
_selectedSubFunctionIndex = index;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 20,
|
||||||
|
vertical: 16,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: _selectedSubFunctionIndex == index
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: Colors.transparent,
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
subFunction.name,
|
||||||
|
style: TextStyle(
|
||||||
|
color: _selectedSubFunctionIndex == index
|
||||||
|
? Theme.of(context).colorScheme.primary
|
||||||
|
: Theme.of(
|
||||||
|
context,
|
||||||
|
).colorScheme.onSurfaceVariant,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// 子功能操作页面区域
|
||||||
|
Expanded(child: currentSubFunction.page),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user