393e227de5
后端: - 新增 product_images 表,支持每商品最多5张图(服务端压缩至1200px/JPEG85%) - products 表新增 public_id(UUID)、description 字段 - 新增商品详情接口、二维码接口、公开商品接口(无鉴权) - 修复 XLS 导入:OLE2 magic bytes 检测 + 临时文件解析,兼容 extrame/xls - 修复商品/名称/系列/规格三张表导入数据为0(LastCol()=0 bug) - 所有导入接口返回 total/imported/skipped 统计 - config 新增 StorageConfig,支持 STORAGE_* 环境变量覆盖 - 种子数据修复:products 补 public_id、新增 product_images TRUNCATE、schema.sql 表名修正 前端: - 商品详情页:图片上传/删除、描述内联编辑、二维码弹窗、公开链接复制 - 公开商品页:无鉴权路由 /product/:public_id,Flutter Web SPA - 商品详情列表(批次追踪)商品名超链接跳转详情页 - 导航「商品管理」改名「商品详情」 - 所有列表表格新增每页条数选择(10/20/50/100) - 表格列头内嵌筛选(FilterableColumnHeader) - 导出 Excel 功能(入库/出库/库存/财务/批次/往来单位) - 网络恢复自动刷新 + 离线缓存展示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
147 lines
5.6 KiB
Dart
147 lines
5.6 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/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: '/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: '/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;
|
|
});
|