Commit e91e5ee5e301e2fa2002a9e872cce78c35b7e547

Authored by 常守达
1 parent 034b877b

feat(ui): 引导页授权;首页授权;微信登录

@@ -335,7 +335,42 @@ class TodayController extends GetxController with WidgetsBindingObserver { @@ -335,7 +335,42 @@ class TodayController extends GetxController with WidgetsBindingObserver {
335 335
336 Future<bool> requestHealthAuthorization( 336 Future<bool> requestHealthAuthorization(
337 {bool isFromNoPermissionPage = false}) async { 337 {bool isFromNoPermissionPage = false}) async {
338 - if (Platform.isIOS) { 338 + if (isOhos()) {
  339 + try {
  340 + await _checkHealthAuthStatus();
  341 + AppLogger.d("checkHealthAppAuthorization : $_currentStatus");
  342 + if (_currentStatus == 1) {
  343 + _refreshHealthDataAuthCardStatus(status: 1);
  344 + if (isFromNoPermissionPage) {
  345 + Get.back();
  346 + }
  347 + return true;
  348 + } else {
  349 + bool success = await _hostApi.requestHealthClientAuthorization();
  350 + AppLogger.d("requestHealthClientAuthorization : $success");
  351 + if (success) {
  352 + _currentStatus = 1;
  353 + _refreshHealthDataAuthCardStatus(status: 1);
  354 + // await LoadingService.instance.run(() async {
  355 + _performCaculateAndUpload();
  356 + // });
  357 + // result.status = 1;
  358 + // AppToast.show('刷新完成');
  359 + if (isFromNoPermissionPage) {
  360 + Get.back();
  361 + }
  362 + return true;
  363 + } else {
  364 + // Get.to(NoHealthDataPage(
  365 + // onRefresh: _performDataUpload,
  366 + // ));
  367 + }
  368 + return false;
  369 + }
  370 + } catch (e) {
  371 + AppToast.show(e.toString());
  372 + }
  373 + } else {
339 try { 374 try {
340 await _checkHealthAuthStatus(); 375 await _checkHealthAuthStatus();
341 AppLogger.d("checkHealthAppAuthorization : $_currentStatus"); 376 AppLogger.d("checkHealthAppAuthorization : $_currentStatus");
@@ -384,40 +419,79 @@ class TodayController extends GetxController with WidgetsBindingObserver { @@ -384,40 +419,79 @@ class TodayController extends GetxController with WidgetsBindingObserver {
384 _isHandlingHealthAuthorizationTap = true; 419 _isHandlingHealthAuthorizationTap = true;
385 ta.track('click_doublefeel_today_status', properties: {'ita': '授权访问健康数据'}); 420 ta.track('click_doublefeel_today_status', properties: {'ita': '授权访问健康数据'});
386 try { 421 try {
387 - if (_currentStatus == 1 && hrvChartData.isNotEmpty) {  
388 - return;  
389 - } else if (_currentStatus == 0) {  
390 - final success = await requestHealthAuthorization();  
391 - if (success) {  
392 - _currentStatus = 1;  
393 - _refreshHealthDataAuthCardStatus(status: 1); 422 + if (isOhos()) {
  423 + if (_currentStatus != 1) {
  424 + final success = await requestHealthAuthorization();
  425 + if (success) {
  426 + _currentStatus = 1;
  427 + _refreshHealthDataAuthCardStatus(status: 1);
  428 + }
  429 + } else {
  430 + if (hrvChartData.isNotEmpty) {
  431 + return;
  432 + }
  433 + await Get.to(() => NoHealthDataPage(
  434 + onRefresh: () {
  435 + refreshTab();
  436 + Future.delayed(const Duration(milliseconds: 800), () {
  437 + AppToast.show(l10n.refreshComplete);
  438 + });
  439 + },
  440 + onHelp: () {
  441 + if (environmentConfig.region.value == AppRegion.china) {
  442 + Get.toNamed(Routes.HELP);
  443 + } else {
  444 + final userId = Get.find<UserPreferencesStorage>()
  445 + .preferences
  446 + .value
  447 + .meUserInfo
  448 + ?.id ??
  449 + 0;
  450 + sendFeedbackEmail(
  451 + userId: userId.toString(),
  452 + pageName: 'No heart rate data available page',
  453 + );
  454 + }
  455 + },
  456 + ));
  457 + checkHealthDataAuthCardVisible();
394 } 458 }
395 } else { 459 } else {
396 - await Get.to(() => NoHealthDataPage(  
397 - onRefresh: () {  
398 - refreshTab();  
399 - Future.delayed(const Duration(milliseconds: 800), () {  
400 - AppToast.show(l10n.refreshComplete);  
401 - });  
402 - },  
403 - onHelp: () {  
404 - if (environmentConfig.region.value == AppRegion.china) {  
405 - Get.toNamed(Routes.HELP);  
406 - } else {  
407 - final userId = Get.find<UserPreferencesStorage>()  
408 - .preferences  
409 - .value  
410 - .meUserInfo  
411 - ?.id ??  
412 - 0;  
413 - sendFeedbackEmail(  
414 - userId: userId.toString(),  
415 - pageName: 'No heart rate data available page',  
416 - );  
417 - }  
418 - },  
419 - ));  
420 - checkHealthDataAuthCardVisible(); 460 + if (_currentStatus == 1 && hrvChartData.isNotEmpty) {
  461 + return;
  462 + } else if (_currentStatus == 0) {
  463 + final success = await requestHealthAuthorization();
  464 + if (success) {
  465 + _currentStatus = 1;
  466 + _refreshHealthDataAuthCardStatus(status: 1);
  467 + }
  468 + } else {
  469 + await Get.to(() => NoHealthDataPage(
  470 + onRefresh: () {
  471 + refreshTab();
  472 + Future.delayed(const Duration(milliseconds: 800), () {
  473 + AppToast.show(l10n.refreshComplete);
  474 + });
  475 + },
  476 + onHelp: () {
  477 + if (environmentConfig.region.value == AppRegion.china) {
  478 + Get.toNamed(Routes.HELP);
  479 + } else {
  480 + final userId = Get.find<UserPreferencesStorage>()
  481 + .preferences
  482 + .value
  483 + .meUserInfo
  484 + ?.id ??
  485 + 0;
  486 + sendFeedbackEmail(
  487 + userId: userId.toString(),
  488 + pageName: 'No heart rate data available page',
  489 + );
  490 + }
  491 + },
  492 + ));
  493 + checkHealthDataAuthCardVisible();
  494 + }
421 } 495 }
422 } finally { 496 } finally {
423 _isHandlingHealthAuthorizationTap = false; 497 _isHandlingHealthAuthorizationTap = false;
@@ -275,22 +275,11 @@ class UserOnboardingController extends GetxController { @@ -275,22 +275,11 @@ class UserOnboardingController extends GetxController {
275 try { 275 try {
276 final result = await _hostApi.checkHealthAppAuthorization(); 276 final result = await _hostApi.checkHealthAppAuthorization();
277 AppLogger.d("checkHealthAppAuthorization : $result"); 277 AppLogger.d("checkHealthAppAuthorization : $result");
278 - if (result.status == 0) { 278 + if (result.status != 1) {
279 bool success = await _hostApi.requestHealthClientAuthorization(); 279 bool success = await _hostApi.requestHealthClientAuthorization();
280 AppLogger.d("requestHealthClientAuthorization : $success"); 280 AppLogger.d("requestHealthClientAuthorization : $success");
281 - if (success) {  
282 - _performDataUpload();  
283 - return true;  
284 - } else {  
285 - // Get.to(NoHealthDataPage(  
286 - // onRefresh: _performDataUpload,  
287 - // ));  
288 - return false;  
289 - } 281 + return true;
290 } else { 282 } else {
291 - // status == 1: 已授权;status == 2: 已拒绝  
292 - // 两种情况都放行,已授权时额外上传数据  
293 - if (result.status == 1) _performDataUpload();  
294 return true; 283 return true;
295 } 284 }
296 } catch (error, stackTrace) { 285 } catch (error, stackTrace) {
@@ -130,7 +130,7 @@ class UserApi { @@ -130,7 +130,7 @@ class UserApi {
130 call: () async { 130 call: () async {
131 final response = await _dioClient.dio.post( 131 final response = await _dioClient.dio.post(
132 ApiPaths.userLogin, 132 ApiPaths.userLogin,
133 - data: {'code': code, 'login_type': 'wechat'}, 133 + data: {'wechat_code': code, 'login_type': 'wechat'},
134 options: _dioClient.noTokenOptions(), 134 options: _dioClient.noTokenOptions(),
135 ); 135 );
136 return LoginResponse.fromJson(response.data as Map<String, dynamic>); 136 return LoginResponse.fromJson(response.data as Map<String, dynamic>);