feat(client): 全模块 API 对接 + 修复登陆跳转 + 菜单 UI 优化
API 对接: - 入库/出库/库存/财务/往来单位/基础数据全部对接后端 REST API - 新增 repositories、providers、models 层,统一分层架构 - auth 从 flutter_secure_storage 迁移到 shared_preferences 登陆跳转修复: - 将 _RouterNotifier 提取为独立 Riverpod provider,appRouterProvider 使用 ref.read 避免依赖链导致 router 重建后跳回 /login - redirect 函数新增 initialized 守卫,防止 auth 未恢复时误重定向 - 添加调试日志(Router/Auth/ApiClient)定位 401 触发的 logout 链路 退出菜单 UI: - 去掉 ListTile,改用 Row + 自定义 padding,文字左对齐 - MouseRegion + AnimatedContainer 实现 hover 高亮(普通项蓝底/退出红底) - 菜单圆角 6px,elevation 8,分割线高度 1px Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/inventory.dart';
|
||||
import '../repositories/inventory_repository.dart';
|
||||
|
||||
final inventoryRepositoryProvider = Provider<InventoryRepository>((ref) {
|
||||
return InventoryRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final inventoryListProvider =
|
||||
AsyncNotifierProvider<InventoryListNotifier, PageResult<Inventory>>(
|
||||
InventoryListNotifier.new,
|
||||
);
|
||||
|
||||
class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
int _page = 1;
|
||||
int? _warehouseId;
|
||||
String _keyword = '';
|
||||
|
||||
@override
|
||||
Future<PageResult<Inventory>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<Inventory>> _fetch() {
|
||||
return ref.read(inventoryRepositoryProvider).listInventory(
|
||||
warehouseId: _warehouseId,
|
||||
keyword: _keyword.isEmpty ? null : _keyword,
|
||||
page: _page,
|
||||
pageSize: 50,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setWarehouseId(int? id) {
|
||||
_warehouseId = id;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setKeyword(String keyword) {
|
||||
_keyword = keyword;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final inventoryLogProvider =
|
||||
AsyncNotifierProvider<InventoryLogNotifier, PageResult<InventoryLog>>(
|
||||
InventoryLogNotifier.new,
|
||||
);
|
||||
|
||||
class InventoryLogNotifier extends AsyncNotifier<PageResult<InventoryLog>> {
|
||||
int _page = 1;
|
||||
|
||||
@override
|
||||
Future<PageResult<InventoryLog>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<InventoryLog>> _fetch() {
|
||||
return ref.read(inventoryRepositoryProvider).listLogs(
|
||||
page: _page,
|
||||
pageSize: 50,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/partner.dart';
|
||||
import '../repositories/partner_repository.dart';
|
||||
|
||||
final partnerRepositoryProvider = Provider<PartnerRepository>((ref) {
|
||||
return PartnerRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
// Supplier list provider for dropdowns
|
||||
final supplierListProvider =
|
||||
AsyncNotifierProvider<PartnerListNotifier, PageResult<Partner>>(
|
||||
() => PartnerListNotifier(type: 'supplier'),
|
||||
);
|
||||
|
||||
// Customer list provider
|
||||
final customerListProvider =
|
||||
AsyncNotifierProvider<PartnerListNotifier, PageResult<Partner>>(
|
||||
() => PartnerListNotifier(type: 'customer'),
|
||||
);
|
||||
|
||||
class PartnerListNotifier extends AsyncNotifier<PageResult<Partner>> {
|
||||
final String? type;
|
||||
int _page = 1;
|
||||
String _keyword = '';
|
||||
|
||||
PartnerListNotifier({this.type});
|
||||
|
||||
@override
|
||||
Future<PageResult<Partner>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<Partner>> _fetch() {
|
||||
return ref.read(partnerRepositoryProvider).list(
|
||||
type: type,
|
||||
keyword: _keyword.isEmpty ? null : _keyword,
|
||||
page: _page,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setKeyword(String keyword) {
|
||||
_keyword = keyword;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createPartner(Map<String, dynamic> data) async {
|
||||
await ref.read(partnerRepositoryProvider).create(data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> updatePartner(int id, Map<String, dynamic> data) async {
|
||||
await ref.read(partnerRepositoryProvider).update(id, data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> deletePartner(int id) async {
|
||||
await ref.read(partnerRepositoryProvider).delete(id);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/product.dart';
|
||||
import '../repositories/product_repository.dart';
|
||||
|
||||
final productRepositoryProvider = Provider<ProductRepository>((ref) {
|
||||
return ProductRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final productListProvider =
|
||||
AsyncNotifierProvider<ProductListNotifier, PageResult<Product>>(
|
||||
ProductListNotifier.new,
|
||||
);
|
||||
|
||||
class ProductListNotifier extends AsyncNotifier<PageResult<Product>> {
|
||||
int _page = 1;
|
||||
String _keyword = '';
|
||||
int? _categoryId;
|
||||
|
||||
@override
|
||||
Future<PageResult<Product>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<Product>> _fetch() {
|
||||
final repo = ref.read(productRepositoryProvider);
|
||||
return repo.list(
|
||||
page: _page,
|
||||
pageSize: 20,
|
||||
keyword: _keyword.isEmpty ? null : _keyword,
|
||||
categoryId: _categoryId,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setKeyword(String keyword) {
|
||||
_keyword = keyword;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setCategoryId(int? categoryId) {
|
||||
_categoryId = categoryId;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createProduct(Map<String, dynamic> data) async {
|
||||
final repo = ref.read(productRepositoryProvider);
|
||||
await repo.create(data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> updateProduct(int id, Map<String, dynamic> data) async {
|
||||
final repo = ref.read(productRepositoryProvider);
|
||||
await repo.update(id, data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> deleteProduct(int id) async {
|
||||
final repo = ref.read(productRepositoryProvider);
|
||||
await repo.delete(id);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/stock_in.dart';
|
||||
import '../repositories/stock_in_repository.dart';
|
||||
|
||||
final stockInRepositoryProvider = Provider<StockInRepository>((ref) {
|
||||
return StockInRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final stockInListProvider =
|
||||
AsyncNotifierProvider<StockInListNotifier, PageResult<StockInOrder>>(
|
||||
StockInListNotifier.new,
|
||||
);
|
||||
|
||||
class StockInListNotifier extends AsyncNotifier<PageResult<StockInOrder>> {
|
||||
int _page = 1;
|
||||
String _status = '';
|
||||
String? _startDate;
|
||||
String? _endDate;
|
||||
|
||||
@override
|
||||
Future<PageResult<StockInOrder>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<StockInOrder>> _fetch() {
|
||||
return ref.read(stockInRepositoryProvider).list(
|
||||
status: _status.isEmpty ? null : _status,
|
||||
startDate: _startDate,
|
||||
endDate: _endDate,
|
||||
page: _page,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setStatus(String status) {
|
||||
_status = status;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setDateRange(String? startDate, String? endDate) {
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createOrder(Map<String, dynamic> data) async {
|
||||
await ref.read(stockInRepositoryProvider).create(data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> submitOrder(int id) async {
|
||||
await ref.read(stockInRepositoryProvider).submit(id);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> approveOrder(int id) async {
|
||||
await ref.read(stockInRepositoryProvider).approve(id);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> rejectOrder(int id) async {
|
||||
await ref.read(stockInRepositoryProvider).reject(id);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/stock_out.dart';
|
||||
import '../repositories/stock_out_repository.dart';
|
||||
|
||||
final stockOutRepositoryProvider = Provider<StockOutRepository>((ref) {
|
||||
return StockOutRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final stockOutListProvider =
|
||||
AsyncNotifierProvider<StockOutListNotifier, PageResult<StockOutOrder>>(
|
||||
StockOutListNotifier.new,
|
||||
);
|
||||
|
||||
class StockOutListNotifier extends AsyncNotifier<PageResult<StockOutOrder>> {
|
||||
int _page = 1;
|
||||
String _status = '';
|
||||
String? _startDate;
|
||||
String? _endDate;
|
||||
|
||||
@override
|
||||
Future<PageResult<StockOutOrder>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return _fetch();
|
||||
}
|
||||
|
||||
Future<PageResult<StockOutOrder>> _fetch() {
|
||||
return ref.read(stockOutRepositoryProvider).list(
|
||||
status: _status.isEmpty ? null : _status,
|
||||
startDate: _startDate,
|
||||
endDate: _endDate,
|
||||
page: _page,
|
||||
);
|
||||
}
|
||||
|
||||
void setPage(int page) {
|
||||
_page = page;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setStatus(String status) {
|
||||
_status = status;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setDateRange(String? startDate, String? endDate) {
|
||||
_startDate = startDate;
|
||||
_endDate = endDate;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
_fetch().then(
|
||||
(result) => state = AsyncValue.data(result),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> createOrder(Map<String, dynamic> data) async {
|
||||
await ref.read(stockOutRepositoryProvider).create(data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> submitOrder(int id) async {
|
||||
await ref.read(stockOutRepositoryProvider).submit(id);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> approveOrder(int id) async {
|
||||
await ref.read(stockOutRepositoryProvider).approve(id);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> rejectOrder(int id) async {
|
||||
await ref.read(stockOutRepositoryProvider).reject(id);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../models/warehouse.dart';
|
||||
import '../repositories/warehouse_repository.dart';
|
||||
|
||||
final warehouseRepositoryProvider = Provider<WarehouseRepository>((ref) {
|
||||
return WarehouseRepository(ref.watch(apiClientProvider));
|
||||
});
|
||||
|
||||
final warehouseListProvider =
|
||||
AsyncNotifierProvider<WarehouseListNotifier, List<Warehouse>>(
|
||||
WarehouseListNotifier.new,
|
||||
);
|
||||
|
||||
class WarehouseListNotifier extends AsyncNotifier<List<Warehouse>> {
|
||||
@override
|
||||
Future<List<Warehouse>> build() {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
return ref.read(warehouseRepositoryProvider).list();
|
||||
}
|
||||
|
||||
Future<void> reload() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(
|
||||
() => ref.read(warehouseRepositoryProvider).list());
|
||||
}
|
||||
|
||||
Future<void> createWarehouse(Map<String, dynamic> data) async {
|
||||
await ref.read(warehouseRepositoryProvider).create(data);
|
||||
await reload();
|
||||
}
|
||||
|
||||
Future<void> updateWarehouse(int id, Map<String, dynamic> data) async {
|
||||
await ref.read(warehouseRepositoryProvider).update(id, data);
|
||||
await reload();
|
||||
}
|
||||
|
||||
Future<void> deleteWarehouse(int id) async {
|
||||
await ref.read(warehouseRepositoryProvider).delete(id);
|
||||
await reload();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user