基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

73 lines
2.0 KiB

  1. import 'dart:async';
  2. import 'dart:convert' as convert;
  3. import 'package:zhiying_base_widget/pages/security_page/models/security_style_model.dart';
  4. import 'package:zhiying_comm/util/base_bloc.dart';
  5. import 'package:zhiying_comm/zhiying_comm.dart';
  6. class SecurityPageBloc extends BlocBase {
  7. SecurityStyleModel _style;
  8. Map<String, dynamic> securityStatus;
  9. StreamController<SecurityStyleModel> _styleController =
  10. StreamController<SecurityStyleModel>();
  11. Stream<SecurityStyleModel> get outData => _styleController.stream;
  12. @override
  13. void dispose() {
  14. _styleController.close();
  15. _styleController = null;
  16. }
  17. void loadData(String skipIdentifier) async {
  18. NetUtil.request('/api/v1/mod/${skipIdentifier.toString()}',
  19. method: NetMethod.GET, onCache: (data) {
  20. _loadData(data);
  21. }, onSuccess: (data) async {
  22. securityStatus = Map<String, dynamic>.from(await _getStatus());
  23. Logger.log(convert.json.encode(data));
  24. _loadData(data);
  25. });
  26. }
  27. // 获取授权状态等信息
  28. Future<Map> _getStatus() async {
  29. var result = await NetUtil.post(
  30. '/api/v1/settings/account/security',
  31. method: NetMethod.GET,
  32. );
  33. return result['data'];
  34. }
  35. void _loadData(dynamic data) {
  36. try {
  37. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  38. if (json == null || json.length == 0) {
  39. return;
  40. }
  41. List mods = json['mod_list'];
  42. if (mods.first != null) {
  43. json = Map<String, dynamic>.from(mods.first);
  44. String d = json['data'];
  45. Map<String, dynamic> da =
  46. Map<String, dynamic>.from(convert.jsonDecode(d));
  47. _style = SecurityStyleModel.fromJson(da);
  48. if (securityStatus != null) {
  49. _style.settings.forEach((item) {
  50. List<String> keys = item.dataKeys;
  51. if (keys.length > 0) {
  52. item.desc = securityStatus[keys.first] ?? '';
  53. }
  54. });
  55. }
  56. _styleController.add(_style);
  57. }
  58. } catch (err) {
  59. Logger.error(err);
  60. }
  61. }
  62. }