bb4f17cf7a
后端: - 新增 GET /version 版本检查端点(version.go + version.yaml) - 新增 GET /license/info 接口,返回门店授权信息 - 修复 GenerateOrderNo 并发重复单号:事务内加 FOR UPDATE 行锁 - 修复 ApproveStockOut 超卖竞态:预检和库存更新均加 FOR UPDATE - 修复 Product Create 并发 code 冲突:加重试逻辑,schema 加 UNIQUE KEY - 修复 Product Update 全字段覆盖:改用 selective Updates() - 挂载 ReadOnly 中间件(全局)+ AdminOnly(用户管理路由) - version.go 配置缺失时返回 500 而非静默降级 前端: - 新增自动更新检测(update_provider.dart)+ shell 更新 banner/弹窗 - 新增系统设置"关于"标签页:版本、授权、开发信息、意见反馈 - 新增离线缓存:所有 AsyncNotifierProvider 支持断网浏览历史数据 - 新增门店信息弹窗(点击左上角 logo 或右上角门店号触发) - 提取 AppConfig 统一管理 BASE_URL,支持 --dart-define 注入 - update_provider.dart 加 kIsWeb 保护,修复 Web 平台崩溃 - dev.sh 新增 stop 命令,修复 stop 误杀前端进程问题 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
134 lines
4.9 KiB
Dart
134 lines
4.9 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-in/edit/:id',
|
|
pageBuilder: (_, state) => _noTransition(
|
|
StockInFormScreen(
|
|
editOrderId: int.parse(state.pathParameters['id']!)))),
|
|
GoRoute(
|
|
path: '/stock-out',
|
|
pageBuilder: (_, __) => _noTransition(const StockOutListScreen())),
|
|
GoRoute(
|
|
path: '/stock-out/new',
|
|
pageBuilder: (_, __) => _noTransition(const StockOutFormScreen())),
|
|
GoRoute(
|
|
path: '/stock-out/edit/:id',
|
|
pageBuilder: (_, state) => _noTransition(
|
|
StockOutFormScreen(
|
|
editOrderId: int.parse(state.pathParameters['id']!)))),
|
|
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;
|
|
});
|