ce1cbf404c
后端: - fix(backend): InventoryLog 增加 Product/Warehouse 关联,Logs 接口加 Preload 修复流水记录显示"-" - feat(backend): 新增 /inventory/batches 批次追踪接口 - feat(backend): 新增财务记录、编号规则接口(finance、number_rule handler) - fix(backend): service/stock_test.go 修复 model.Date 类型错误 前端: - feat(client): 入库/出库管理 Tab 调换顺序(审核在前),审核 Tab 加新建按钮,列表 Tab 无按钮 - feat(client): 入库单/出库单增加详情弹窗,显示完整单据信息和商品明细 - feat(client): 完善出库单新建表单(StockOutFormScreen),支持选客户/仓库/商品 - fix(client): StockInItem/StockOutItem.fromJson 修复读取嵌套 product 对象而非平铺字段 - feat(client): 批次追踪页面(BatchTrackingScreen)及侧边栏入口 - feat(client): 财务管理、盘点、编号规则接入真实后端 API - fix(client): 入库/出库审核通过后 invalidate inventoryListProvider 刷新库存 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
124 lines
4.5 KiB
Dart
124 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../screens/auth/login_screen.dart';
|
|
import '../../screens/shell/app_shell.dart';
|
|
import '../../screens/stock_in/stock_in_list_screen.dart';
|
|
import '../../screens/stock_in/stock_in_form_screen.dart';
|
|
import '../../screens/stock_out/stock_out_list_screen.dart';
|
|
import '../../screens/stock_out/stock_out_form_screen.dart';
|
|
import '../../screens/inventory/inventory_list_screen.dart';
|
|
import '../../screens/inventory/inventory_check_screen.dart';
|
|
import '../../screens/inventory/batch_tracking_screen.dart';
|
|
import '../../screens/partners/partners_screen.dart';
|
|
import '../../screens/finance/finance_screen.dart';
|
|
import '../../screens/products/products_screen.dart';
|
|
import '../../screens/settings/settings_screen.dart';
|
|
import '../auth/auth_state.dart';
|
|
|
|
Page<void> _noTransition(Widget child) =>
|
|
NoTransitionPage<void>(child: child);
|
|
|
|
/// ChangeNotifier that bridges Riverpod auth state → GoRouter refreshListenable.
|
|
class _RouterNotifier extends ChangeNotifier {
|
|
final Ref _ref;
|
|
|
|
_RouterNotifier(this._ref) {
|
|
_ref.listen<AuthState>(authStateProvider, (prev, next) {
|
|
debugPrint('[Router] authState changed:'
|
|
' initialized=${next.initialized}'
|
|
' isLoggedIn=${next.isLoggedIn}'
|
|
' user=${next.user?.username}');
|
|
notifyListeners();
|
|
});
|
|
}
|
|
|
|
String? redirect(BuildContext context, GoRouterState state) {
|
|
final authState = _ref.read(authStateProvider);
|
|
final isLoggedIn = authState.isLoggedIn;
|
|
final isLoginRoute = state.matchedLocation == '/login';
|
|
final result = !authState.initialized
|
|
? null
|
|
: (!isLoggedIn && !isLoginRoute)
|
|
? '/login'
|
|
: (isLoggedIn && isLoginRoute)
|
|
? '/stock-in'
|
|
: null;
|
|
debugPrint('[Router] redirect: location=${state.matchedLocation}'
|
|
' initialized=${authState.initialized}'
|
|
' isLoggedIn=$isLoggedIn'
|
|
' → ${result ?? "null (no redirect)"}');
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/// Separate provider so that appRouterProvider has NO dependencies and
|
|
/// is never rebuilt when auth state changes (prevents router reset to /login).
|
|
final _routerNotifierProvider = Provider<_RouterNotifier>((ref) {
|
|
final notifier = _RouterNotifier(ref);
|
|
ref.onDispose(notifier.dispose);
|
|
return notifier;
|
|
});
|
|
|
|
final appRouterProvider = Provider<GoRouter>((ref) {
|
|
// Use ref.read (not ref.watch) so appRouterProvider never rebuilds on auth change.
|
|
final notifier = ref.read(_routerNotifierProvider);
|
|
|
|
final router = GoRouter(
|
|
initialLocation: '/login',
|
|
refreshListenable: notifier,
|
|
redirect: notifier.redirect,
|
|
routes: [
|
|
GoRoute(
|
|
path: '/login',
|
|
builder: (context, state) => const LoginScreen(),
|
|
),
|
|
ShellRoute(
|
|
builder: (context, state, child) => AppShell(child: child),
|
|
routes: [
|
|
GoRoute(
|
|
path: '/stock-in',
|
|
pageBuilder: (_, __) => _noTransition(const StockInListScreen())),
|
|
GoRoute(
|
|
path: '/stock-in/new',
|
|
pageBuilder: (_, __) => _noTransition(const StockInFormScreen())),
|
|
GoRoute(
|
|
path: '/stock-out',
|
|
pageBuilder: (_, __) => _noTransition(const StockOutListScreen())),
|
|
GoRoute(
|
|
path: '/stock-out/new',
|
|
pageBuilder: (_, __) => _noTransition(const StockOutFormScreen())),
|
|
GoRoute(
|
|
path: '/inventory',
|
|
pageBuilder: (_, __) =>
|
|
_noTransition(const InventoryListScreen())),
|
|
GoRoute(
|
|
path: '/inventory/check',
|
|
pageBuilder: (_, __) =>
|
|
_noTransition(const InventoryCheckScreen())),
|
|
GoRoute(
|
|
path: '/batches',
|
|
pageBuilder: (_, __) =>
|
|
_noTransition(const BatchTrackingScreen())),
|
|
GoRoute(
|
|
path: '/partners',
|
|
pageBuilder: (_, __) => _noTransition(const PartnersScreen())),
|
|
GoRoute(
|
|
path: '/finance',
|
|
pageBuilder: (_, __) => _noTransition(const FinanceScreen())),
|
|
GoRoute(
|
|
path: '/products',
|
|
pageBuilder: (_, __) => _noTransition(const ProductsScreen())),
|
|
GoRoute(
|
|
path: '/settings',
|
|
pageBuilder: (_, __) => _noTransition(const SettingsScreen())),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
|
|
ref.onDispose(router.dispose);
|
|
|
|
return router;
|
|
});
|