feat(client): 授权管理独立一级屏——授权/购买续费/订单管理三 tab(桌面+移动)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
// providers/license_purchase_provider.dart — 授权购买订单列表(订单管理 tab)。
|
||||
// 后端 GET /license/purchases 只支持 page/page_size/status 三个查询轴;
|
||||
// 套餐/关键词/下单时间筛选在列表屏做客户端过滤(当前页),与 stock_out 列表
|
||||
// 屏「仓库」筛选同一established 口径(server 端无对应参数)。
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../core/auth/auth_state.dart';
|
||||
import '../models/license.dart';
|
||||
import 'license_provider.dart' show licenseRepositoryProvider;
|
||||
|
||||
final purchaseListProvider =
|
||||
AsyncNotifierProvider<PurchaseListNotifier, PurchaseListResult>(
|
||||
PurchaseListNotifier.new,
|
||||
);
|
||||
|
||||
class PurchaseListNotifier extends AsyncNotifier<PurchaseListResult> {
|
||||
int _page = 1;
|
||||
int _pageSize = 10;
|
||||
String _status = ''; // '' | pending | paid | failed
|
||||
PurchaseListResult? _cache;
|
||||
|
||||
@override
|
||||
Future<PurchaseListResult> 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<PurchaseListResult> _fetch() {
|
||||
return ref.read(licenseRepositoryProvider).listPurchases(
|
||||
page: _page,
|
||||
pageSize: _pageSize,
|
||||
status: _status.isEmpty ? null : _status,
|
||||
);
|
||||
}
|
||||
|
||||
int get page => _page;
|
||||
int get pageSize => _pageSize;
|
||||
String get currentStatus => _status;
|
||||
|
||||
void reload() {
|
||||
// 保留上一次数据(isReloading)→ 屏幕可继续渲染旧内容 + 叠加半透明进度,不白屏。
|
||||
state = const AsyncValue<PurchaseListResult>.loading()
|
||||
.copyWithPrevious(state);
|
||||
_fetch().then((result) {
|
||||
_cache = result;
|
||||
state = AsyncValue.data(result);
|
||||
}, onError: (Object e, StackTrace st) {
|
||||
if (_cache != null) {
|
||||
state = AsyncValue.data(_cache!);
|
||||
} else {
|
||||
state = AsyncValue.error(e, st);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void setPage(int p) {
|
||||
_page = p;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setPageSize(int size) {
|
||||
_pageSize = size;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setStatus(String status) {
|
||||
_status = status;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user