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

64 lines
1.7 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. Api api = Api(
  19. '/api/v1/mod/${skipIdentifier.toString()}',
  20. method: NetMethod.GET,
  21. );
  22. _loadData(await api.onCache());
  23. _securityStatus = Map<String, dynamic>.from(await _getStatus());
  24. _loadData(await api.onRequest());
  25. }
  26. // 获取授权状态等信息
  27. Future<Map> _getStatus() {
  28. Api api = Api(
  29. '/api/v1/settings/account/security',
  30. method: NetMethod.GET,
  31. );
  32. return api.onRequest();
  33. }
  34. void _loadData(dynamic data) {
  35. Map<String, dynamic> json = Map<String, dynamic>.from(data);
  36. if (json == null || json.length == 0) {
  37. return;
  38. }
  39. String d = json['data'];
  40. Map<String, dynamic> da = Map<String, dynamic>.from(convert.jsonDecode(d));
  41. _style = SecurityStyleModel.fromJson(da);
  42. if (_securityStatus != null) {
  43. _style.settings.forEach((item) {
  44. List<String> keys = item.dataKeys;
  45. if (keys.length > 0) {
  46. item.desc = _securityStatus[keys.first] ?? '';
  47. }
  48. });
  49. }
  50. _styleController.add(_style);
  51. }
  52. }