feat: 商品详情页、XLS导入修复、分页选择器、导出功能
后端: - 新增 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>
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/exceptions.dart';
|
||||
import '../models/product_option.dart';
|
||||
|
||||
class ProductOptionRepository {
|
||||
final ApiClient _client;
|
||||
|
||||
const ProductOptionRepository(this._client);
|
||||
|
||||
// ── 名称 ────────────────────────────────────────────────────
|
||||
|
||||
Future<List<ProductNameOption>> listNames() async {
|
||||
try {
|
||||
final resp = await _client.get('/product-options/names');
|
||||
final data = (resp.data as Map<String, dynamic>)['data'] as List? ?? [];
|
||||
return data.map((e) => ProductNameOption.fromJson(e as Map<String, dynamic>)).toList();
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '获取名称列表失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createName(Map<String, dynamic> data) async {
|
||||
try {
|
||||
await _client.post('/product-options/names', data: data);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '创建失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteName(int id) async {
|
||||
try {
|
||||
await _client.delete('/product-options/names/$id');
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '删除失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 系列 ────────────────────────────────────────────────────
|
||||
|
||||
Future<List<ProductSeriesOption>> listSeries() async {
|
||||
try {
|
||||
final resp = await _client.get('/product-options/series');
|
||||
final data = (resp.data as Map<String, dynamic>)['data'] as List? ?? [];
|
||||
return data.map((e) => ProductSeriesOption.fromJson(e as Map<String, dynamic>)).toList();
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '获取系列列表失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createSeries(Map<String, dynamic> data) async {
|
||||
try {
|
||||
await _client.post('/product-options/series', data: data);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '创建失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteSeries(int id) async {
|
||||
try {
|
||||
await _client.delete('/product-options/series/$id');
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '删除失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
// ── 规格 ────────────────────────────────────────────────────
|
||||
|
||||
Future<List<ProductSpecOption>> listSpecs() async {
|
||||
try {
|
||||
final resp = await _client.get('/product-options/specs');
|
||||
final data = (resp.data as Map<String, dynamic>)['data'] as List? ?? [];
|
||||
return data.map((e) => ProductSpecOption.fromJson(e as Map<String, dynamic>)).toList();
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '获取规格列表失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createSpec(Map<String, dynamic> data) async {
|
||||
try {
|
||||
await _client.post('/product-options/specs', data: data);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '创建失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteSpec(int id) async {
|
||||
try {
|
||||
await _client.delete('/product-options/specs/$id');
|
||||
} on DioException catch (e) {
|
||||
throw AppException(e.response?.data?['error'] as String? ?? '删除失败',
|
||||
statusCode: e.response?.statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../core/api/api_client.dart';
|
||||
import '../core/exceptions.dart';
|
||||
import '../core/models/page_result.dart';
|
||||
import '../models/product.dart';
|
||||
import '../models/product_image.dart';
|
||||
|
||||
class ProductRepository {
|
||||
final ApiClient _client;
|
||||
@@ -71,4 +73,77 @@ class ProductRepository {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Product> getDetail(int id) async {
|
||||
try {
|
||||
final resp = await _client.get('/products/$id/detail');
|
||||
return Product.fromJson(
|
||||
(resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(
|
||||
e.response?.data?['error'] as String? ?? '获取商品详情失败',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<ProductImage> uploadImage(int productId, String filePath) async {
|
||||
try {
|
||||
final formData = FormData.fromMap({
|
||||
'file': await MultipartFile.fromFile(filePath),
|
||||
});
|
||||
final resp = await _client.post('/products/$productId/images', data: formData);
|
||||
return ProductImage.fromJson(
|
||||
(resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(
|
||||
e.response?.data?['error'] as String? ?? '上传图片失败',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List> getQRCodeBytes(int productId) async {
|
||||
try {
|
||||
final bytes = await _client.getBytes('/products/$productId/qrcode');
|
||||
return Uint8List.fromList(bytes);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(
|
||||
e.response?.data?['error'] as String? ?? '获取二维码失败',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteImage(int productId, int imageId) async {
|
||||
try {
|
||||
await _client.delete('/products/$productId/images/$imageId');
|
||||
} on DioException catch (e) {
|
||||
throw AppException(
|
||||
e.response?.data?['error'] as String? ?? '删除图片失败',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Product> findOrCreate({
|
||||
required String name,
|
||||
String series = '',
|
||||
String spec = '',
|
||||
}) async {
|
||||
try {
|
||||
final resp = await _client.post('/products/find-or-create', data: {
|
||||
'name': name,
|
||||
'series': series,
|
||||
'spec': spec,
|
||||
});
|
||||
return Product.fromJson(
|
||||
(resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>);
|
||||
} on DioException catch (e) {
|
||||
throw AppException(
|
||||
e.response?.data?['error'] as String? ?? '查找/创建商品失败',
|
||||
statusCode: e.response?.statusCode,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user