Prechádzať zdrojové kódy

[feat]星座恋爱分析,实现今日分析列表

hezihao 8 mesiacov pred
rodič
commit
edabb42b07

+ 12 - 0
lib/data/api/atmob_api.dart

@@ -66,6 +66,7 @@ import 'package:keyboard/data/api/response/order_pay_response.dart';
 import 'package:keyboard/data/api/response/order_status_response.dart';
 import 'package:keyboard/data/api/response/user_info_response.dart';
 import 'package:keyboard/data/api/response/wechat_login_response.dart';
+import 'package:keyboard/data/api/response/zodiac_love_intimacy_response.dart';
 import 'package:keyboard/data/repository/config_repository.dart';
 import 'package:retrofit/error_logger.dart';
 import 'package:retrofit/http.dart';
@@ -324,4 +325,15 @@ abstract class AtmobApi {
   Future<BaseResponse<MemberNewUserResponse>> getMemberUserResponse(
     @Body() AppBaseRequest request,
   );
+
+  /// 星座恋爱分析-获取今日指数分析
+  @POST("/project/keyboard/v1/intimacy/today/index")
+  Future<BaseResponse<ZodiacLoveIntimacyResponse>> getZodiacLoveIntimacyToday(
+    @Body() AppBaseRequest request,
+  );
+
+  /// 星座恋爱分析-获取未来一周分析
+  @POST("/project/keyboard/v1/intimacy/future/week")
+  Future<BaseResponse<ZodiacLoveIntimacyResponse>>
+  getZodiacLoveIntimacyFutureWeek(@Body() AppBaseRequest request);
 }

+ 67 - 0
lib/data/api/atmob_api.g.dart

@@ -1511,6 +1511,73 @@ class _AtmobApi implements AtmobApi {
     return _value;
   }
 
+  @override
+  Future<BaseResponse<ZodiacLoveIntimacyResponse>> getZodiacLoveIntimacyToday(
+    AppBaseRequest request,
+  ) async {
+    final _extra = <String, dynamic>{};
+    final queryParameters = <String, dynamic>{};
+    final _headers = <String, dynamic>{};
+    final _data = <String, dynamic>{};
+    _data.addAll(request.toJson());
+    final _options = _setStreamType<BaseResponse<ZodiacLoveIntimacyResponse>>(
+      Options(method: 'POST', headers: _headers, extra: _extra)
+          .compose(
+            _dio.options,
+            '/project/keyboard/v1/intimacy/today/index',
+            queryParameters: queryParameters,
+            data: _data,
+          )
+          .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
+    );
+    final _result = await _dio.fetch<Map<String, dynamic>>(_options);
+    late BaseResponse<ZodiacLoveIntimacyResponse> _value;
+    try {
+      _value = BaseResponse<ZodiacLoveIntimacyResponse>.fromJson(
+        _result.data!,
+        (json) =>
+            ZodiacLoveIntimacyResponse.fromJson(json as Map<String, dynamic>),
+      );
+    } on Object catch (e, s) {
+      errorLogger?.logError(e, s, _options);
+      rethrow;
+    }
+    return _value;
+  }
+
+  @override
+  Future<BaseResponse<ZodiacLoveIntimacyResponse>>
+  getZodiacLoveIntimacyFutureWeek(AppBaseRequest request) async {
+    final _extra = <String, dynamic>{};
+    final queryParameters = <String, dynamic>{};
+    final _headers = <String, dynamic>{};
+    final _data = <String, dynamic>{};
+    _data.addAll(request.toJson());
+    final _options = _setStreamType<BaseResponse<ZodiacLoveIntimacyResponse>>(
+      Options(method: 'POST', headers: _headers, extra: _extra)
+          .compose(
+            _dio.options,
+            '/project/keyboard/v1/intimacy/future/week',
+            queryParameters: queryParameters,
+            data: _data,
+          )
+          .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
+    );
+    final _result = await _dio.fetch<Map<String, dynamic>>(_options);
+    late BaseResponse<ZodiacLoveIntimacyResponse> _value;
+    try {
+      _value = BaseResponse<ZodiacLoveIntimacyResponse>.fromJson(
+        _result.data!,
+        (json) =>
+            ZodiacLoveIntimacyResponse.fromJson(json as Map<String, dynamic>),
+      );
+    } on Object catch (e, s) {
+      errorLogger?.logError(e, s, _options);
+      rethrow;
+    }
+    return _value;
+  }
+
   RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
     if (T != dynamic &&
         !(requestOptions.responseType == ResponseType.bytes ||

+ 17 - 0
lib/data/api/response/zodiac_love_intimacy_response.dart

@@ -0,0 +1,17 @@
+import 'package:json_annotation/json_annotation.dart';
+
+import '../../bean/zodiac_love_intimacy_list.dart';
+
+part 'zodiac_love_intimacy_response.g.dart';
+
+/// 星座恋爱分析
+@JsonSerializable()
+class ZodiacLoveIntimacyResponse {
+  @JsonKey(name: "list")
+  List<ZodiacLoveIntimacyList> list;
+
+  ZodiacLoveIntimacyResponse(this.list);
+
+  factory ZodiacLoveIntimacyResponse.fromJson(Map<String, dynamic> json) =>
+      _$ZodiacLoveIntimacyResponseFromJson(json);
+}

+ 19 - 0
lib/data/api/response/zodiac_love_intimacy_response.g.dart

@@ -0,0 +1,19 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'zodiac_love_intimacy_response.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+ZodiacLoveIntimacyResponse _$ZodiacLoveIntimacyResponseFromJson(
+  Map<String, dynamic> json,
+) => ZodiacLoveIntimacyResponse(
+  (json['list'] as List<dynamic>)
+      .map((e) => ZodiacLoveIntimacyList.fromJson(e as Map<String, dynamic>))
+      .toList(),
+);
+
+Map<String, dynamic> _$ZodiacLoveIntimacyResponseToJson(
+  ZodiacLoveIntimacyResponse instance,
+) => <String, dynamic>{'list': instance.list};

+ 21 - 0
lib/data/bean/zodiac_love_intimacy_list.dart

@@ -0,0 +1,21 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'zodiac_love_intimacy_list.g.dart';
+
+/// 星座恋爱分析-星座列表
+@JsonSerializable()
+class ZodiacLoveIntimacyList {
+  @JsonKey(name: "title")
+  String title;
+
+  @JsonKey(name: "content")
+  String content;
+
+  @JsonKey(name: "iconUrl")
+  String iconUrl;
+
+  ZodiacLoveIntimacyList(this.title, this.content, this.iconUrl);
+
+  factory ZodiacLoveIntimacyList.fromJson(Map<String, dynamic> json) =>
+      _$ZodiacLoveIntimacyListFromJson(json);
+}

+ 23 - 0
lib/data/bean/zodiac_love_intimacy_list.g.dart

@@ -0,0 +1,23 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'zodiac_love_intimacy_list.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+ZodiacLoveIntimacyList _$ZodiacLoveIntimacyListFromJson(
+  Map<String, dynamic> json,
+) => ZodiacLoveIntimacyList(
+  json['title'] as String,
+  json['content'] as String,
+  json['iconUrl'] as String,
+);
+
+Map<String, dynamic> _$ZodiacLoveIntimacyListToJson(
+  ZodiacLoveIntimacyList instance,
+) => <String, dynamic>{
+  'title': instance.title,
+  'content': instance.content,
+  'iconUrl': instance.iconUrl,
+};

+ 23 - 0
lib/data/repository/zodiac_love_intimacy_repository.dart

@@ -0,0 +1,23 @@
+import 'package:injectable/injectable.dart';
+
+import '../../base/app_base_request.dart';
+import '../../utils/http_handler.dart';
+import '../api/atmob_api.dart';
+import '../api/response/zodiac_love_intimacy_response.dart';
+
+/// 星座恋爱分析Repository层
+@LazySingleton()
+class ZodiacLoveIntimacyRepository {
+  final String tag = "ZodiacLoveIntimacyRepository";
+
+  final AtmobApi atmobApi;
+
+  ZodiacLoveIntimacyRepository(this.atmobApi);
+
+  /// 星座恋爱分析-获取今日指数分析
+  Future<ZodiacLoveIntimacyResponse> getZodiacLoveIntimacyToday() async {
+    return await atmobApi
+        .getZodiacLoveIntimacyToday(AppBaseRequest())
+        .then(HttpHandler.handle(true));
+  }
+}

+ 9 - 3
lib/di/get_it.config.dart

@@ -26,6 +26,7 @@ import '../data/repository/file_upload_repository.dart' as _i815;
 import '../data/repository/intimacy_analyze_repository.dart' as _i283;
 import '../data/repository/keyboard_repository.dart' as _i274;
 import '../data/repository/store_repository.dart' as _i987;
+import '../data/repository/zodiac_love_intimacy_repository.dart' as _i779;
 import '../dialog/content/character_add_tab_controller.dart' as _i991;
 import '../dialog/content/character_tab_group_content_controller.dart' as _i293;
 import '../dialog/custom_character/custom_character_add_controller.dart'
@@ -171,9 +172,6 @@ extension GetItInjectableX on _i174.GetIt {
     gh.factory<_i109.ZodiacLoveFutureWeekController>(
       () => _i109.ZodiacLoveFutureWeekController(),
     );
-    gh.factory<_i630.ZodiacLoveTodayController>(
-      () => _i630.ZodiacLoveTodayController(),
-    );
     gh.lazySingleton<_i495.WechatLoginService>(
       () => _i495.WechatLoginService(),
     );
@@ -233,6 +231,9 @@ extension GetItInjectableX on _i174.GetIt {
     gh.lazySingleton<_i274.KeyboardRepository>(
       () => _i274.KeyboardRepository(gh<_i243.AtmobApi>()),
     );
+    gh.lazySingleton<_i779.ZodiacLoveIntimacyRepository>(
+      () => _i779.ZodiacLoveIntimacyRepository(gh<_i243.AtmobApi>()),
+    );
     gh.factoryParam<
       _i293.CharacterTabGroupContentController,
       _i96.CharacterGroupInfo,
@@ -296,6 +297,11 @@ extension GetItInjectableX on _i174.GetIt {
     gh.lazySingleton<_i779.PaymentStatusManager>(
       () => _i779.PaymentStatusManager(gh<_i987.StoreRepository>()),
     );
+    gh.factory<_i630.ZodiacLoveTodayController>(
+      () => _i630.ZodiacLoveTodayController(
+        gh<_i779.ZodiacLoveIntimacyRepository>(),
+      ),
+    );
     gh.factory<_i344.ProfileEditController>(
       () => _i344.ProfileEditController(
         gh<_i50.ConfigRepository>(),

+ 40 - 1
lib/module/zodiac_love_intimacy/tody/zodiac_love_today_controller.dart

@@ -1,6 +1,45 @@
+import 'package:get/get.dart';
 import 'package:injectable/injectable.dart';
 import 'package:keyboard/base/base_controller.dart';
+import 'package:keyboard/resource/string.gen.dart';
+import 'package:keyboard/utils/error_handler.dart';
+
+import '../../../data/api/response/zodiac_love_intimacy_response.dart';
+import '../../../data/repository/zodiac_love_intimacy_repository.dart';
+import '../../../utils/http_handler.dart';
+import '../../../utils/toast_util.dart';
+import '../../store/new_discount/new_discount_page.dart';
 
 /// 星座恋爱分析-今日Tab-Controller
 @injectable
-class ZodiacLoveTodayController extends BaseController {}
+class ZodiacLoveTodayController extends BaseController {
+  final ZodiacLoveIntimacyRepository zodiacLoveIntimacyRepository;
+
+  /// 分析列表
+  final Rxn<ZodiacLoveIntimacyResponse> zodiacLoveIntimacyResp =
+      Rxn<ZodiacLoveIntimacyResponse>();
+
+  ZodiacLoveTodayController(this.zodiacLoveIntimacyRepository);
+
+  @override
+  void onInit() {
+    super.onInit();
+    _getZodiacLoveIntimacyToday();
+  }
+
+  /// 星座恋爱分析-获取今日指数分析
+  void _getZodiacLoveIntimacyToday() async {
+    try {
+      ZodiacLoveIntimacyResponse resp =
+          await zodiacLoveIntimacyRepository.getZodiacLoveIntimacyToday();
+      zodiacLoveIntimacyResp.value = resp;
+    } catch (error) {
+      if (error is ServerErrorException && error.code == 1005) {
+        ToastUtil.show(StringName.needVipTip);
+        NewDiscountPage.start();
+      } else {
+        ErrorHandler.toastError(error);
+      }
+    }
+  }
+}

+ 84 - 1
lib/module/zodiac_love_intimacy/tody/zodiac_love_today_view.dart

@@ -1,7 +1,12 @@
+import 'package:cached_network_image/cached_network_image.dart';
 import 'package:flutter/Material.dart';
+import 'package:flutter_screenutil/flutter_screenutil.dart';
+import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
 import 'package:keyboard/module/zodiac_love_intimacy/tody/zodiac_love_today_controller.dart';
 
 import '../../../base/base_view.dart';
+import '../../../data/bean/zodiac_love_intimacy_list.dart';
+import '../../../resource/colors.gen.dart';
 
 /// 星座恋爱分析-今日Tab
 class ZodiacLoveTodayView extends BaseView<ZodiacLoveTodayController> {
@@ -14,6 +19,84 @@ class ZodiacLoveTodayView extends BaseView<ZodiacLoveTodayController> {
 
   @override
   Widget buildBody(BuildContext context) {
-    return Container(child: Center(child: Text("")));
+    return Container(
+      padding: EdgeInsets.symmetric(vertical: 16.h),
+      child: Obx(() {
+        var list = controller.zodiacLoveIntimacyResp.value?.list ?? [];
+        return ListView.builder(
+          physics: const ClampingScrollPhysics(),
+          padding: EdgeInsets.zero,
+          itemCount: list.length,
+          itemBuilder: (BuildContext context, int index) {
+            ZodiacLoveIntimacyList itemData = list[index];
+            return _buildListItem(index, itemData);
+          },
+        );
+      }),
+    );
+  }
+
+  /// 列表条目
+  Widget _buildListItem(int index, ZodiacLoveIntimacyList itemData) {
+    return Container(
+      padding: EdgeInsets.all(16.w),
+      margin: EdgeInsets.only(left: 16.w, right: 16.w, bottom: 16.h),
+      decoration: BoxDecoration(
+        color: ColorName.white,
+        borderRadius: BorderRadius.all(Radius.circular(16.r)),
+      ),
+      child: Column(
+        children: [
+          Row(
+            children: [
+              // 图标
+              CachedNetworkImage(
+                imageUrl: itemData.iconUrl,
+                height: 25.w,
+                width: 25.w,
+                fit: BoxFit.fill,
+              ),
+              SizedBox(width: 4.w),
+              // 标题
+              Stack(
+                // 不裁切子组件超出的区域
+                clipBehavior: Clip.none,
+                children: [
+                  // 横线
+                  Positioned(
+                    left: -16.w,
+                    right: 0,
+                    top: 10.h,
+                    child: Container(
+                      width: 2.w,
+                      height: 11.h,
+                      color: Color(0x21FF4BAE),
+                    ),
+                  ),
+                  Text(
+                    itemData.title,
+                    style: TextStyle(
+                      color: ColorName.black80,
+                      fontSize: 16.sp,
+                      fontWeight: FontWeight.w700,
+                    ),
+                  ),
+                ],
+              ),
+            ],
+          ),
+          SizedBox(height: 12.h),
+          // 内容
+          Text(
+            itemData.content,
+            style: TextStyle(
+              color: ColorName.black70,
+              fontSize: 13.sp,
+              fontWeight: FontWeight.w400,
+            ),
+          ),
+        ],
+      ),
+    );
   }
 }