基础组件库
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.
 
 
 
 
 

72 line
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. _loadData(data);
  24. });
  25. }
  26. // 获取授权状态等信息
  27. Future<Map> _getStatus() async {
  28. var result = await NetUtil.post(
  29. '/api/v1/settings/account/security',
  30. method: NetMethod.GET,
  31. );
  32. return result['data'];
  33. }
  34. void _loadData(dynamic data) {
  35. try {
  36. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  37. if (json == null || json.length == 0) {
  38. return;
  39. }
  40. List mods = json['mod_list'];
  41. if (mods.first != null) {
  42. json = Map<String, dynamic>.from(mods.first);
  43. String d = json['data'];
  44. Map<String, dynamic> da =
  45. Map<String, dynamic>.from(convert.jsonDecode(d));
  46. _style = SecurityStyleModel.fromJson(da);
  47. if (securityStatus != null) {
  48. _style.settings.forEach((item) {
  49. List<String> keys = item.dataKeys;
  50. if (keys.length > 0) {
  51. item.desc = securityStatus[keys.first] ?? '';
  52. }
  53. });
  54. }
  55. _styleController.add(_style);
  56. }
  57. } catch (err) {
  58. Logger.error(err);
  59. }
  60. }
  61. }