103 lines
3.0 KiB
Dart
103 lines
3.0 KiB
Dart
import 'package:dio/dio.dart' as dio;
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
abstract class UserApi {
|
|
/// 硬件管理登录
|
|
static Future<dynamic> login(dynamic pa) async {
|
|
final password = pa["password"] as String;
|
|
final loginPassword = Constants.loginPasswordEncryptionEnabled
|
|
? EncryptionTool.encryptLoginPassword(password)
|
|
: password;
|
|
final res = await HttpManage().dio.post(
|
|
"/auth/oauth2/token",
|
|
queryParameters: {
|
|
"username": pa["username"],
|
|
"randomStr": "",
|
|
"code": "",
|
|
"grant_type": pa["grant_type"],
|
|
"scope": pa["scope"],
|
|
},
|
|
data: {
|
|
"password": loginPassword,
|
|
},
|
|
options: dio.Options(
|
|
headers: {
|
|
"Authorization": EncryptionTool.getLoginAuthorization(),
|
|
"skipToken": true,
|
|
"content-type": "application/x-www-form-urlencoded",
|
|
},
|
|
),
|
|
);
|
|
return res.data;
|
|
}
|
|
|
|
/// 刷新token
|
|
static Future<ServiceBase<ServiceAuth>> refreshToken(dynamic pa) async {
|
|
final res = await HttpManage().dio.post(
|
|
"/refresh-token",
|
|
queryParameters: pa,
|
|
);
|
|
if (res.data?.data == null) {
|
|
return res.data;
|
|
}
|
|
final map = res.data!.data as Map<String, dynamic>;
|
|
final typeData = ServiceAuth.fromJson(map);
|
|
res.data?.data = typeData;
|
|
return res.data;
|
|
}
|
|
|
|
/// 获取人脸
|
|
static Future<List<ServiceAsyncFace>?> getFaceList(
|
|
dynamic formData,
|
|
) async {
|
|
final res = await HttpManage().dio.get(
|
|
"/admin/user-face/ad/find-face",
|
|
queryParameters: formData,
|
|
);
|
|
if (res.data == null) return null;
|
|
return res.data
|
|
?.map<ServiceAsyncFace>((e) => ServiceAsyncFace.fromJson(e))
|
|
.toList();
|
|
}
|
|
|
|
/// 获取人脸v2
|
|
static Future<List<ServiceAsyncFace>?> getFaceListV2(
|
|
dynamic formData,
|
|
) async {
|
|
final res = await HttpManage().dio.get(
|
|
"/admin/user-face/ad/v2/find-face",
|
|
queryParameters: formData,
|
|
);
|
|
if (res.data == null) return null;
|
|
return res.data
|
|
?.map<ServiceAsyncFace>((e) => ServiceAsyncFace.fromJson(e))
|
|
.toList();
|
|
}
|
|
|
|
/// 按固定主键上界游标读取本部门及子部门的 V3 人脸权威快照。
|
|
static Future<ServiceFaceSyncSnapshot> getFaceSyncSnapshot(
|
|
Map<String, dynamic> requestBody,
|
|
) async {
|
|
final res = await HttpManage().dio.post(
|
|
"/admin/user-face/ad/v3/sync-snapshot",
|
|
data: requestBody,
|
|
);
|
|
if (res.data is! Map) {
|
|
throw const FormatException('服务端未返回有效的人脸快照');
|
|
}
|
|
return ServiceFaceSyncSnapshot.fromJson(
|
|
Map<String, dynamic>.from(res.data as Map),
|
|
);
|
|
}
|
|
|
|
/// 获取租户列表
|
|
static Future<List<ServiceTenant>?> getTenantList() async {
|
|
final res = await HttpManage().dio.get("/admin/tenant/list");
|
|
if (res.data == null) return null;
|
|
return res.data
|
|
?.map<ServiceTenant>((e) => ServiceTenant.fromJson(e))
|
|
.toList();
|
|
}
|
|
}
|