You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
993 B
26 lines
993 B
import '../../../data/models/goods.dart';
|
|
import '../../../data/services/network/api.dart';
|
|
import 'goods_base_controller.dart';
|
|
|
|
class GoodstransController extends GoodsBaseController {
|
|
@override
|
|
Future<List<DBGoods>> fetchProducts() async {
|
|
final resp = await Api.getGoods({'usagetype': UsageType.Translation.toInt});
|
|
if (resp == null || resp is! Map) return [];
|
|
if (resp.containsKey('error') || resp.containsKey('msg')) {
|
|
final msg = resp['error'] ?? resp['msg'] ?? '服务器错误';
|
|
throw Exception(msg);
|
|
}
|
|
final container =
|
|
(resp is Map && resp['data'] is Map) ? resp['data'] : resp;
|
|
final data = (container is Map)
|
|
? (container['goodss'] ?? container['goodes'] ?? container['goods'])
|
|
: null;
|
|
if (data is List) {
|
|
final list =
|
|
data.whereType<Map<String, dynamic>>().map(DBGoods.fromJson).toList();
|
|
return list.where((g) => g.usagetype == UsageType.Translation).toList();
|
|
}
|
|
return [];
|
|
}
|
|
}
|
|
|