import 'package:dio/dio.dart' as dio; import 'package:pj_supermarket_cloud/common/index.dart'; /// 终端 App 配置与版本接口入口,统一复用 HttpManage 的鉴权、租户和错误处理。 abstract class AppApi { /// /// 分页获取匹配 App 编码和平台的已发布版本。 /// /// [pa] 包含 appUniqueCode、platform、current 和 size;[silent] 为 true 时后台任务 /// 只记录异常,不弹业务 Toast。 static Future openCardList( dynamic pa, { bool silent = false, }) async { final res = await HttpManage().dio.get( "/integrated/app-version/ad/page", queryParameters: pa, options: dio.Options( extra: {if (silent) HttpManage.silentRequestKey: true}, ), ); if (res.data == null) return null; return ServiceAppVersionPage.fromJson(res.data); } /// Requery the same published record; never switch APK versions during a retry. static Future refreshPackageUrl(ServiceAppVersion version) async { if (version.id == null) throw StateError('缺少版本标识,请刷新版本列表'); final page = await openCardList({ 'id': version.id, 'appUniqueCode': version.appUniqueCode, 'platform': version.platform, 'current': 1, 'size': 1, }, silent: true); for (final item in page?.records ?? []) { if (item.id == version.id && item.versionCode == version.versionCode && item.appUniqueCode == version.appUniqueCode && item.platform == version.platform) { return item.downloadUrl ?? ''; } } throw StateError('该版本已下架,请刷新版本列表'); } }