cusstarLoad method
加载自定义收藏列表,reload
为true时清除缓存重新加载,返回值EasyPacket.extra字段为true时表示已加载全部数据。
body1
为false时返回数据不包含CustomX.body1字段,body2
为false时返回数据不包含CustomX.body2字段,body3
为false时返回数据不包含CustomX.body3字段
Implementation
Future<EasyPacket<bool>> cusstarLoad({required ComPage<CustomX> comPage, required bool reload, bool body1 = false, bool body2 = false, bool body3 = false}) async {
if (reload) comPage.pgcache.clear(); //清除缓存
comPage.pgasync = DateTime.now().microsecondsSinceEpoch; //设置最近一次异步加载的识别号(防止并发加载导致数据混乱)
final response = await _aliveClient.websocketRequest('cusstarLoad', data: {'bsid': bsid, 'no': comPage.no, 'skip': comPage.pgcache.length, 'pgasync': comPage.pgasync, 'body1': body1, 'body2': body2, 'body3': body3});
if (response.ok) {
final pgasync = response.data!['pgasync'] as int;
final totalcnt = response.data!['totalcnt'] as int;
final customxList = response.data!['customxList'] as List;
final cusmarkList = response.data!['cusmarkList'] as List;
final cusstarList = response.data!['cusstarList'] as List;
if (pgasync == comPage.pgasync) {
final cusmarkMap = <ObjectId, Cusmark>{};
for (var data in cusmarkList) {
final cusmark = Cusmark.fromJson(data);
cusmarkMap[cusmark.rid] = cusmark;
}
final cusstarMap = <ObjectId, Cusstar>{};
for (var data in cusstarList) {
final cusstar = Cusstar.fromJson(data);
cusstarMap[cusstar.rid] = cusstar;
}
for (var data in customxList) {
final customx = CustomX.fromJson(data);
customx.cusmark = cusmarkMap[customx.id];
customx.cusstar = cusstarMap[customx.id];
comPage.append(customx, (a, b) => a.id == b.id);
}
comPage.total = totalcnt;
return response.cloneExtra(customxList.isEmpty || comPage.total == comPage.pgcache.length); //是否已加载全部数据
} else {
_aliveClient.logError(['cusstarLoad =>', '远程响应号已过期 $pgasync']);
return response.requestTimeoutError().cloneExtra(null); //说明本次响应不是最近一次异步加载,直接遗弃数据,当成超时错误处理
}
} else {
return response.cloneExtra(null);
}
}