x_mind_assemble_control.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import 'dart:convert' show json;
  2. import 'package:flutter/material.dart';
  3. import '../../o2.dart';
  4. import '../../pages/mind_map/mind_map_data.dart';
  5. import '../models/api_response.dart';
  6. import '../models/mindmap/mind_folder.dart';
  7. import '../models/mindmap/mind_map.dart';
  8. import '../models/o2_api_module.dart';
  9. import 'http_client.dart';
  10. import 'o2_api_manager.dart';
  11. import 'o2_http_error.dart';
  12. class MindMapService {
  13. String baseUrl() {
  14. return O2ApiManager.instance
  15. .getModuleBaseUrl(O2DistributeModuleEnum.x_mind_assemble_control) ?? '';
  16. }
  17. ///
  18. /// 我的文件
  19. ///
  20. Future<List<MindFolder>> myFolderTree() async {
  21. ApiResponse response =
  22. await HttpClient.instance.get('${baseUrl()}jaxrs/folder/tree/my');
  23. if (response.type == o2_http_success) {
  24. var list = response.data == null ? [] : response.data as List;
  25. return list.map((folder) => MindFolder.fromJson(folder)).toList();
  26. } else {
  27. throw O2HttpError(message: response.message ?? '获取文件夹失败');
  28. }
  29. }
  30. ///
  31. /// 获取脑图详细信息
  32. ///
  33. Future<MindMap> mindMap(String id) async {
  34. ApiResponse response = await HttpClient.instance.get('${baseUrl()}jaxrs/mind/view/$id');
  35. if (response.type == o2_http_success) {
  36. return MindMap.fromJson(response.data);
  37. }else {
  38. throw O2HttpError(message: response.message ?? '获取脑图失败');
  39. }
  40. }
  41. ///
  42. /// 保存脑图数据
  43. ///
  44. Future<String> saveMindMap(MindMap? map, MindMapData? data) async {
  45. if(map == null || data == null) {
  46. throw O2ValidateError('无法保存,传入参数异常!');
  47. }
  48. String content = json.encode(data.toJson());
  49. map.content = content;
  50. // map.fileVersion = map.fileVersion + 1 ;//不需要后台已经加过了
  51. ApiResponse response = await HttpClient.instance.post('${baseUrl()}jaxrs/mind/save', map.toJson());
  52. if (response.type == o2_http_success) {
  53. String id = response.data['id'];
  54. debugPrintStack(label: '保存脑图成功:$id');
  55. return id;
  56. } else {
  57. throw O2HttpError(message: response.message ?? '保存脑图失败');
  58. }
  59. }
  60. ///
  61. /// 保存脑图数据
  62. ///
  63. Future<String> renameMindMap(MindMap? map) async {
  64. if(map == null ) {
  65. throw O2ValidateError('无法保存,传入参数异常!');
  66. }
  67. ApiResponse response = await HttpClient.instance.post('${baseUrl()}jaxrs/mind/save', map.toJson());
  68. if (response.type == o2_http_success) {
  69. String id = response.data['id'];
  70. return id;
  71. } else {
  72. throw O2HttpError(message: response.message ?? '保存脑图失败');
  73. }
  74. }
  75. ///
  76. /// 删除脑图文件
  77. ///
  78. Future<bool> deleteMindMap(String mapId) async {
  79. ApiResponse response = await HttpClient.instance.delete('${baseUrl()}jaxrs/mind/recycle/$mapId');
  80. if (response.type == o2_http_success) {
  81. return true;
  82. }else{
  83. throw O2HttpError(message: response.message ?? '删除脑图失败');
  84. }
  85. }
  86. ///
  87. /// 分页查询脑图列表
  88. /// @param lastId 上一页最后一个id
  89. /// @param folderId 所属文件夹
  90. ///
  91. Future<List<MindMap>> mindFilterByPage(String lastId, String folderId) async {
  92. Map<String, String> data = {};
  93. data['folderId'] = folderId;
  94. ApiResponse response = await HttpClient.instance.put(
  95. '${baseUrl()}jaxrs/mind/filter/list/$lastId/next/$default_page_size',
  96. data);
  97. if (response.type == o2_http_success) {
  98. var list = response.data == null ? [] : response.data as List;
  99. return list.map((folder) => MindMap.fromJson(folder)).toList();
  100. } else {
  101. throw O2HttpError(message: response.message ?? '获取脑图列表失败');
  102. }
  103. }
  104. ///
  105. /// 新增修改目录
  106. ///
  107. Future<String> saveMindFolder(String name, String parentId, {String? id}) async {
  108. Map<String, String> data = Map();
  109. data['name'] = name;
  110. data['parentId'] = parentId;
  111. if (id != null) {
  112. data['id'] = id;
  113. }
  114. ApiResponse response =
  115. await HttpClient.instance.post('${baseUrl()}jaxrs/folder/save', data);
  116. if (response.type == o2_http_success) {
  117. String id = response.data['id'];
  118. debugPrintStack(label: '保存目录成功:$id');
  119. return id;
  120. } else {
  121. throw O2HttpError(message: response.message ?? '保存目录失败');
  122. }
  123. }
  124. ///
  125. /// 删除目录
  126. ///
  127. Future<bool> deleteMindFolder(String id) async {
  128. ApiResponse response =
  129. await HttpClient.instance.delete('${baseUrl()}jaxrs/folder/$id');
  130. if (response.type == o2_http_success) {
  131. return true;
  132. }else {
  133. throw O2HttpError(message: response.message ?? '删除目录失败');
  134. }
  135. }
  136. }