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>
105 lines
2.5 KiB
Dart
105 lines
2.5 KiB
Dart
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';
|
|
import 'inventory_provider.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;
|
|
PageResult<StockInOrder>? _cache;
|
|
|
|
@override
|
|
Future<PageResult<StockInOrder>> build() async {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
try {
|
|
final result = await _fetch();
|
|
_cache = result;
|
|
return result;
|
|
} catch (_) {
|
|
if (_cache != null) return _cache!;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
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) {
|
|
_cache = result;
|
|
state = AsyncValue.data(result);
|
|
}, onError: (e, st) {
|
|
if (_cache != null) {
|
|
state = AsyncValue.data(_cache!);
|
|
} else {
|
|
state = AsyncValue.error(e, st);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> createOrder(Map<String, dynamic> data) async {
|
|
await ref.read(stockInRepositoryProvider).create(data);
|
|
reload();
|
|
}
|
|
|
|
Future<void> deleteOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).delete(id);
|
|
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();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
|
|
Future<void> rejectOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).reject(id);
|
|
reload();
|
|
}
|
|
}
|