cc687ae0c3
- auth_state: 增加 refreshToken 字段 + flutter_secure_storage 持久化 - api_client: 增加 401 自动 refresh + retry 拦截器 - auth_repository: 封装 POST /api/v1/auth/login 调用,错误信息本地化 - login_screen: 增加门店编号字段,调真实 API,行内错误展示 - main: 启动时 restore 持久化登录态,避免每次重启都要重新登录 - 修复 app_shell: hotelName → hotelNo - 修复 widget_test: 移除失效的占位测试 测试账号:门店编号 H001 / 用户名 admin / 密码 password123 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
152 lines
4.5 KiB
Dart
152 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../core/theme/app_theme.dart';
|
|
|
|
class DataTableCard extends StatelessWidget {
|
|
final List<DataColumn> columns;
|
|
final List<DataRow> rows;
|
|
final Widget? toolbar;
|
|
final int? totalCount;
|
|
final int page;
|
|
final int pageSize;
|
|
final ValueChanged<int>? onPageChanged;
|
|
|
|
const DataTableCard({
|
|
super.key,
|
|
required this.columns,
|
|
required this.rows,
|
|
this.toolbar,
|
|
this.totalCount,
|
|
this.page = 1,
|
|
this.pageSize = 20,
|
|
this.onPageChanged,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
if (toolbar != null)
|
|
Container(
|
|
height: 52,
|
|
color: AppTheme.surface,
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
child: Row(
|
|
children: [
|
|
ConstrainedBox(
|
|
constraints: BoxConstraints(
|
|
minWidth: (MediaQuery.of(context).size.width - 212 - 24).clamp(0.0, double.infinity),
|
|
),
|
|
child: toolbar!,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (toolbar != null) const Divider(height: 1),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: DataTable(
|
|
headingRowColor: WidgetStateProperty.all(
|
|
const Color(0xFFF0F4FF)),
|
|
headingTextStyle: const TextStyle(
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppTheme.primaryDark,
|
|
),
|
|
dataTextStyle: const TextStyle(
|
|
fontSize: 13, color: AppTheme.textPrimary),
|
|
columnSpacing: 24,
|
|
horizontalMargin: 16,
|
|
dataRowMinHeight: 40,
|
|
dataRowMaxHeight: 48,
|
|
dividerThickness: 0.5,
|
|
columns: columns,
|
|
rows: rows,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
// Pagination
|
|
if (totalCount != null)
|
|
Container(
|
|
height: 48,
|
|
color: AppTheme.surface,
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'共 $totalCount 条记录',
|
|
style: const TextStyle(
|
|
fontSize: 13, color: AppTheme.textSecondary),
|
|
),
|
|
const Spacer(),
|
|
_PaginationBar(
|
|
page: page,
|
|
total: totalCount!,
|
|
pageSize: pageSize,
|
|
onPageChanged: onPageChanged,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PaginationBar extends StatelessWidget {
|
|
final int page;
|
|
final int total;
|
|
final int pageSize;
|
|
final ValueChanged<int>? onPageChanged;
|
|
|
|
const _PaginationBar({
|
|
required this.page,
|
|
required this.total,
|
|
required this.pageSize,
|
|
this.onPageChanged,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final totalPages = (total / pageSize).ceil().clamp(1, 9999);
|
|
return Row(
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.first_page, size: 18),
|
|
onPressed: page > 1 ? () => onPageChanged?.call(1) : null,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.chevron_left, size: 18),
|
|
onPressed: page > 1 ? () => onPageChanged?.call(page - 1) : null,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
|
),
|
|
Text('$page / $totalPages',
|
|
style: const TextStyle(fontSize: 13)),
|
|
IconButton(
|
|
icon: const Icon(Icons.chevron_right, size: 18),
|
|
onPressed:
|
|
page < totalPages ? () => onPageChanged?.call(page + 1) : null,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.last_page, size: 18),
|
|
onPressed: page < totalPages
|
|
? () => onPageChanged?.call(totalPages)
|
|
: null,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|