c1ed81dfab
后端 - 新增 shop handler:GET/PUT /shop/info(管理员权限) - 新增 finance CloseByRef:按单据 ref_type+ref_id 结清账款 - 新增 inventory UpdateRemark:PUT /inventory/:id/remark - 入库/出库审批自动生成财务应付/应收记录(去除金额>0限制) - 种子数据 S001-S003 补充真实门店信息 前端 - 设置页新增「酒行信息」Tab,管理员可编辑门店名称/地址/电话/负责人 - 入库单列表新增结清按钮(含确认弹窗),出库单同步 - 入库表单:规格、系列、生产日期、供应商、商品名称改为提交必填 - 入库/出库列表新增入库时间、出库时间、创建时间列 - 商品标签标题改为读取 shop 表门店名,扫码文案改为「扫码溯源 · TRACE」 - 标签页脚显示门店地址和电话(从 API 读取,不再依赖编译时 dart-define) - 库存备注支持点击编辑,超4字截断显示+Hover展示全文 - ApiClient 新增 patch() 方法(已改用 PUT 规避 CORS) 文档 - 新增 docs/user-manual.md 完整用户操作手册(12章) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
142 lines
5.4 KiB
Dart
142 lines
5.4 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/partners/partners_screen.dart';
|
|
import '../../screens/finance/finance_screen.dart';
|
|
import '../../screens/products/products_screen.dart';
|
|
import '../../screens/products/product_detail_screen.dart';
|
|
import '../../screens/public/public_product_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 isPublicRoute = state.matchedLocation.startsWith('/product/');
|
|
final result = !authState.initialized
|
|
? null
|
|
: (!isLoggedIn && !isLoginRoute && !isPublicRoute)
|
|
? '/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: [
|
|
// Public route — no auth, no shell nav bar
|
|
GoRoute(
|
|
path: '/product/:public_id',
|
|
builder: (context, state) =>
|
|
PublicProductScreen(publicId: state.pathParameters['public_id']!),
|
|
),
|
|
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: '/partners',
|
|
pageBuilder: (_, __) => _noTransition(const PartnersScreen())),
|
|
GoRoute(
|
|
path: '/finance',
|
|
pageBuilder: (_, __) => _noTransition(const FinanceScreen())),
|
|
GoRoute(
|
|
path: '/products',
|
|
pageBuilder: (_, __) => _noTransition(const ProductsScreen())),
|
|
GoRoute(
|
|
path: '/products/:id',
|
|
pageBuilder: (_, state) => _noTransition(ProductDetailScreen(
|
|
productId: int.parse(state.pathParameters['id']!)))),
|
|
GoRoute(
|
|
path: '/settings',
|
|
pageBuilder: (_, __) => _noTransition(const SettingsScreen())),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
|
|
ref.onDispose(router.dispose);
|
|
|
|
return router;
|
|
});
|