feat(client): 商品基础数据加香型字典 tab(接后端 categories CRUD)
新增 ProductCategoryOption 模型 + repo(list/create/update/deleteCategory)+ provider(productCategoryListProvider),基础数据页加「香型」tab(增删改查、 搜索、导出,仅名称字段)。接通后端 /product-options/categories。 (原型 5-tab 整合是更大 IA 任务,本次先把香型管理补齐可用。) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
This commit is contained in:
@@ -281,3 +281,42 @@ class ProductDescriptionDocListNotifier extends AsyncNotifier<List<ProductDescri
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
// ── 香型 / 分类字典 ──────────────────────────────────────────────
|
||||
final productCategoryListProvider = AsyncNotifierProvider<
|
||||
ProductCategoryListNotifier, List<ProductCategoryOption>>(
|
||||
ProductCategoryListNotifier.new,
|
||||
);
|
||||
|
||||
class ProductCategoryListNotifier
|
||||
extends AsyncNotifier<List<ProductCategoryOption>> {
|
||||
@override
|
||||
Future<List<ProductCategoryOption>> build() async {
|
||||
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
||||
ref.watch(networkRecoveryCountProvider);
|
||||
return ref.read(productOptionRepositoryProvider).listCategories();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
state = const AsyncValue.loading();
|
||||
ref.read(productOptionRepositoryProvider).listCategories().then(
|
||||
(data) => state = AsyncValue.data(data),
|
||||
onError: (e, st) => state = AsyncValue.error(e, st),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> create(Map<String, dynamic> data) async {
|
||||
await ref.read(productOptionRepositoryProvider).createCategory(data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> updateItem(int id, Map<String, dynamic> data) async {
|
||||
await ref.read(productOptionRepositoryProvider).updateCategory(id, data);
|
||||
reload();
|
||||
}
|
||||
|
||||
Future<void> delete(int id) async {
|
||||
await ref.read(productOptionRepositoryProvider).deleteCategory(id);
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user