track_dao.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import 'package:dio/dio.dart';
  2. import 'package:flutter_tracker/dio/api.dart';
  3. import 'package:flutter_tracker/model/submit_model.dart';
  4. import 'package:flutter_tracker/model/user_model.dart';
  5. /// Description:
  6. /// Time : 2021年12月03日 Friday
  7. /// Author : liuyuqi.gov@msncn
  8. class TrackDao {
  9. static Map<String, dynamic> params = <String, dynamic>{};
  10. static Future<SubmitEntity> uploadImg(
  11. String token, String filePath, String fileName) async {
  12. params.addAll({"token": token, "filePath": filePath, "fileName": fileName});
  13. try {
  14. var formData = FormData.fromMap({
  15. 'token': token,
  16. "file": await MultipartFile.fromFile(filePath, filename: fileName),
  17. });
  18. var response = await Dio().post(Api.uploadImgUrl, data: formData);
  19. return SubmitEntity.fromJson(response.data);
  20. } catch (e) {
  21. print(e);
  22. return null;
  23. }
  24. }
  25. static Future<SubmitModel> uploadTrack(String token, String username,
  26. String telphone, String address, int health, int submitid) async {
  27. params.addAll({
  28. "token": token,
  29. "username": username,
  30. "telphone": telphone,
  31. "address": address,
  32. "health": health,
  33. "submitid": submitid
  34. });
  35. await Dio().post(Api.uploadSubmitUrl, data: params).then((response) {
  36. return SubmitModel.fromJson(response.data);
  37. });
  38. return null;
  39. }
  40. // 返回最近15天用户的轨迹
  41. static Future<List<UserModel>> getContactList(String token) async {
  42. params.addAll({"token": token});
  43. await Dio().post(Api.getContactListUrl, data: params).then((response) {
  44. return UserModel.fromJson(response.data);
  45. });
  46. return null;
  47. }
  48. static Future<UserModel> uploadContact(String token, String id) async {
  49. params.addAll({"token": token});
  50. await Dio().post(Api.uploadContactUrl, data: params).then((response) {
  51. return UserModel.fromJson(response.data);
  52. });
  53. return null;
  54. }
  55. }