x_program_center.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:o2oa_all_platform/pages/home/apps/index.dart';
  5. import '../models/index.dart';
  6. import '../services/index.dart';
  7. import '../utils/index.dart';
  8. import '../widgets/index.dart';
  9. import 'x_attendance_assemble_control.dart';
  10. ///
  11. ///中心服务
  12. ///
  13. class ProgramCenterService extends GetxService {
  14. static ProgramCenterService get to => Get.find();
  15. // 内存中放置 后续使用
  16. AppStyle? _appStyle;
  17. AppStyle? get appStyle {
  18. if (_appStyle == null) {
  19. String style = SharedPreferenceService.to
  20. .getString(SharedPreferenceService.appStyleSpKey);
  21. OLogger.d("当前服务器的appStyle: $style");
  22. if (style.isNotEmpty) {
  23. _appStyle = AppStyle.fromJson(O2Utils.parseStringToJson(style));
  24. }
  25. }
  26. return _appStyle;
  27. }
  28. String baseUrl() {
  29. var centerUrl = O2ApiManager.instance.getCenterBaseUrl();
  30. if (centerUrl == null || centerUrl.isEmpty) {
  31. return '';
  32. }
  33. return centerUrl;
  34. }
  35. /// 执行脚本
  36. /// [scriptName] 脚本名称
  37. /// [body] 传入参数
  38. Future<dynamic> executeScript(String scriptName, Map<String, dynamic> body) async {
  39. try {
  40. ApiResponse response = await O2HttpClient.instance.post('${baseUrl()}jaxrs/invoke/$scriptName/execute', body);
  41. if (response.isSuccess()) {
  42. final value = ScriptExecuteResponse.fromJson(response.data);
  43. return value.value;
  44. }
  45. } catch (err, stackTrace) {
  46. OLogger.e('执行脚本失败', err, stackTrace);
  47. }
  48. return null;
  49. }
  50. /// 连接O2OA center服务器
  51. Future<bool> loadCenterServerOnline() async {
  52. var unit = O2ApiManager.instance.o2CloudServer;
  53. if (unit == null) {
  54. return false;
  55. }
  56. if (baseUrl().isEmpty) {
  57. return false;
  58. }
  59. try {
  60. var url =
  61. "${baseUrl()}jaxrs/distribute/webserver/assemble/source/${unit.centerHost}";
  62. ApiResponse response =
  63. await O2HttpClient.instance.get(url, needToken: false);
  64. if (response.data == null) {
  65. return false;
  66. }
  67. var dataJson = json.encode(response.data);
  68. OLogger.i("获取到服务器信息完成, $dataJson");
  69. await O2ApiManager.instance.putCenterServerJson2SP(dataJson);
  70. return true;
  71. } catch (err, stackTrace) {
  72. OLogger.e('连接服务器失败', err, stackTrace);
  73. return false;
  74. }
  75. }
  76. ///
  77. /// 在线获取移动app相关的配置
  78. ///
  79. Future<AppStyle?> loadCurrentStyle() async {
  80. try {
  81. ApiResponse response = await O2HttpClient.instance
  82. .get('${baseUrl()}jaxrs/appstyle/current/style', needToken: false);
  83. if (response.isSuccess()) {
  84. AppStyle appStyle = AppStyle.fromJson(response.data);
  85. _appStyle = appStyle;
  86. final needGrey = SharedPreferenceService.to.getBool(SharedPreferenceService.appStyleNeedGreyKey, defaultValue: false);
  87. final newNeedGrey = appStyle.needGray ?? false;
  88. if (needGrey != newNeedGrey) {
  89. OLogger.d('全局黑白的变化 ............');
  90. await SharedPreferenceService.to.putBool(SharedPreferenceService.appStyleNeedGreyKey, newNeedGrey);
  91. EventBus().emit(EventBus.greyColorChangeGlobalMsg); // 发送通知 重建 ui
  92. }
  93. _storeAppStyle2SP(appStyle);
  94. OLogger.d("请求完成,获取到appstyle!");
  95. return appStyle;
  96. }
  97. } catch (err, stackTrace) {
  98. OLogger.e('获取appStyle失败', err, stackTrace);
  99. }
  100. return null;
  101. }
  102. ///
  103. /// 把appStyle对象存储存储到sp
  104. ///
  105. Future<void> _storeAppStyle2SP(AppStyle appStyle) async {
  106. String jsonAppStyle = json.encode(appStyle.toJson());
  107. await SharedPreferenceService.to
  108. .putString(SharedPreferenceService.appStyleSpKey, jsonAppStyle);
  109. }
  110. ///
  111. /// 原生应用列表
  112. ///
  113. List<AppFrontData?> getCurrentNativeAppList() {
  114. var list = appStyle?.nativeAppList ?? [];
  115. List<AppFrontData?> ret = list
  116. .map<AppFrontData?>((e) {
  117. O2NativeAppEnum? appEnum = _getO2NativeWithKey(e.key);
  118. if (appEnum == null) {
  119. return null;
  120. }
  121. if (e.enable == false) {
  122. return null;
  123. }
  124. AppFrontData data = AppFrontData(
  125. name: appEnum.name,
  126. displayName: e.displayName,
  127. key: appEnum.key,
  128. type: O2AppTypeEnum.native,
  129. nativeEnum: appEnum);
  130. return data;
  131. })
  132. .where((element) => element != null)
  133. .toList();
  134. // && !AttendanceAssembleControlService.to.isV2() 暂时显示旧版打卡 后面版本将隐藏旧打卡
  135. if (ret.firstWhereOrNull((element) =>
  136. element != null && element.key == O2NativeAppEnum.attendance.key) !=
  137. null && !AttendanceAssembleControlService.to.closeOldAttendance()) {
  138. ret.add(AppFrontData(
  139. name: O2NativeAppEnum.attendanceOld.name,
  140. key: O2NativeAppEnum.attendanceOld.key,
  141. type: O2AppTypeEnum.native,
  142. nativeEnum: O2NativeAppEnum.attendanceOld));
  143. }
  144. return ret;
  145. }
  146. ///
  147. /// 门户应用
  148. ///
  149. List<AppFrontData?> getCurrentPortalAppList() {
  150. var list = appStyle?.portalList ?? [];
  151. return list
  152. .map<AppFrontData?>((e) {
  153. String? portalId = e.id;
  154. String? name = e.name;
  155. if (portalId == null || name == null) {
  156. return null;
  157. }
  158. AppFrontData data = AppFrontData(
  159. name: name,
  160. key: portalId,
  161. type: O2AppTypeEnum.portal,
  162. portalId: portalId);
  163. return data;
  164. })
  165. .where((element) => element != null)
  166. .toList();
  167. }
  168. O2NativeAppEnum? _getO2NativeWithKey(String? key) {
  169. if (key == null) {
  170. return null;
  171. }
  172. switch (key) {
  173. case "task":
  174. return O2NativeAppEnum.task;
  175. case "taskcompleted":
  176. return O2NativeAppEnum.taskcompleted;
  177. case "read":
  178. return O2NativeAppEnum.read;
  179. case "readcompleted":
  180. return O2NativeAppEnum.readcompleted;
  181. case "bbs":
  182. return O2NativeAppEnum.bbs;
  183. case "calendar":
  184. return O2NativeAppEnum.calendar;
  185. case "cms":
  186. return O2NativeAppEnum.cms;
  187. case "meeting":
  188. return O2NativeAppEnum.meeting;
  189. case "mindMap":
  190. return O2NativeAppEnum.mindMap;
  191. case "attendance":
  192. return O2NativeAppEnum.attendance;
  193. case "yunpan":
  194. return O2NativeAppEnum.yunpan;
  195. default:
  196. return null;
  197. }
  198. }
  199. ///
  200. /// 是否显示系统消息
  201. ///
  202. bool isShowSystemMessage() {
  203. if (appStyle != null) {
  204. return appStyle?.systemMessageSwitch ?? true;
  205. }
  206. return true;
  207. }
  208. ///
  209. /// 简易模式
  210. ///
  211. bool isSimpleMode() {
  212. if (appStyle != null) {
  213. return appStyle?.simpleMode ?? false;
  214. }
  215. return false;
  216. }
  217. /// 推广页invoke脚本
  218. String promotionPageScript() {
  219. if (appStyle != null) {
  220. return appStyle?.promotionPageScript ?? '';
  221. }
  222. return '';
  223. }
  224. /// 语音助手invoke脚本
  225. String speechScript() {
  226. if (appStyle != null) {
  227. return appStyle?.speechScript ?? '';
  228. }
  229. return '';
  230. }
  231. /// 扩展参数
  232. Map<String, dynamic> extendParam() {
  233. if (appStyle != null) {
  234. return appStyle?.extendParam ?? {};
  235. }
  236. return {};
  237. }
  238. /// 首页tab 门户 扩展参数
  239. ExtendParamHomeTabPortal? getExtendParamHomeTabPortal(String key) {
  240. final p = extendParam();
  241. if (p[key] != null) {
  242. return ExtendParamHomeTabPortal.fromJson(p[key]);
  243. }
  244. return null;
  245. }
  246. /// 首页居中,如果居中页面个数就固定了 5 个。appIndexPages无效了
  247. bool isIndexCentered() {
  248. if (appStyle != null) {
  249. return appStyle?.indexCentered ?? false;
  250. }
  251. return false;
  252. }
  253. /// 首页信息中心 过滤条件
  254. List<String> indexFilterCmsCategoryList () {
  255. return appStyle?.cmsCategoryFilterList ?? [];
  256. }
  257. /// 首页办公中心 过滤条件
  258. List<String> indexFilterProcessList () {
  259. return appStyle?.processFilterList ?? [];
  260. }
  261. /// 首页页面列表
  262. List<String> appIndexPages() {
  263. return appStyle?.appIndexPages ?? [];
  264. }
  265. ///
  266. /// 首页是显示门户还是默认的
  267. ///
  268. String? homeIndexPage() {
  269. if (appStyle != null &&
  270. appStyle?.indexType == 'portal' &&
  271. appStyle?.indexPortal?.isNotEmpty == true) {
  272. return appStyle!.indexPortal!;
  273. }
  274. return null;
  275. }
  276. ///启动 logo图
  277. Widget aboutLogoImageView() {
  278. return _commonAppImageView('launch_logo', 48, 48, 'icon_settings_about.png');
  279. }
  280. ///启动 logo图
  281. Widget launchLogoImageView() {
  282. return _commonAppImageView('launch_logo', 128, 128, 'icon_settings_about.png');
  283. }
  284. ///
  285. ///首页底部Home focus 图
  286. Widget homeFocusImageView() {
  287. return _commonAppImageView('index_bottom_menu_logo_focus', 48, 48, 'index_bottom_bar_selected.png');
  288. }
  289. ///
  290. ///首页底部Home blur 图
  291. Widget homeBlurImageView() {
  292. return _commonAppImageView('index_bottom_menu_logo_blur', 48, 48, 'index_bottom_bar_unselected.png');
  293. }
  294. ///登录页头像 图
  295. Widget loginAvatarImageView() {
  296. return _commonAppImageView('login_avatar', 76, 76, 'login_avatar.png');
  297. }
  298. /// 应用页面 图片 375
  299. Widget appPageImageView() {
  300. return _commonAppImageView('application_top', 375, 195, 'application_top.png');
  301. }
  302. ///流程图标 图
  303. // Uint8List? getProcessDefaultImage() {
  304. // return _getServerBase64Image('process_default');
  305. // }
  306. ///关于 图
  307. Widget setupAboutImageView() {
  308. return _commonAppImageView('setup_about_logo', 22, 22, 'icon_settings_about.png');
  309. }
  310. Widget _commonAppImageView(String keyName, double width, double height, String defaultAssetImage) {
  311. if (appStyle != null && appStyle!.images != null) {
  312. final element =
  313. appStyle?.images?.firstWhere((e) => e.name == keyName);
  314. if (element != null) {
  315. final webUrl = O2ApiManager.instance.webBaseUrl();
  316. if (element.path?.isNotEmpty == true && webUrl?.isNotEmpty == true) {
  317. final url = '$webUrl/${element.path!}';
  318. return Image.network(
  319. url,
  320. width: width,
  321. height: height,
  322. fit: BoxFit.fill,
  323. );
  324. } else if (element.value?.isNotEmpty == true) {
  325. return Image.memory(
  326. base64Decode(element.value!),
  327. width: width,
  328. height: height,
  329. fit: BoxFit.fill,
  330. );
  331. }
  332. }
  333. }
  334. return AssetsImageView(
  335. defaultAssetImage,
  336. width: width,
  337. height: height,
  338. fit: BoxFit.fill,
  339. );
  340. }
  341. }