Leon 1 рік тому
батько
коміт
a15a3d2761

+ 2 - 1
ios/AppDelegate.mm

@@ -298,7 +298,8 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
     
     
     NSString *categoryIdentifier = response.notification.request.content.categoryIdentifier;
-    [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"notificationReceive" body:@{@"category_id":categoryIdentifier,@"action_id":response.actionIdentifier}];
+    NSString *identifier = response.notification.request.identifier;
+    [self.nativeBridge.bridge.eventDispatcher sendAppEventWithName:@"notificationReceive" body:@{@"category_id":categoryIdentifier,@"action_id":response.actionIdentifier,@"id":identifier}];
   }
   else {
     

+ 3 - 3
ios/NativeBridge.m

@@ -96,7 +96,7 @@ RCT_EXPORT_METHOD(addLocalPush:(id)detail){
     //设置通知内容
     UNMutableNotificationContent * content = [[UNMutableNotificationContent alloc] init];
     content.title = detail[@"title"];
-    content.body = detail[@"content"];
+    content.body = detail[@"body"];
     
     NSString *category_id = detail[@"category_id"];
     NSString *message_id = detail[@"id"];
@@ -146,7 +146,7 @@ RCT_EXPORT_METHOD(addLocalPush:(id)detail){
       UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
       
       
-      NSString * identifier = category_id;
+      NSString * identifier = message_id;
       UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
       [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
         
@@ -160,7 +160,7 @@ RCT_EXPORT_METHOD(addLocalPush:(id)detail){
       NSTimeInterval timeInterval = timestamp - [currentDate timeIntervalSince1970];
       
       UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:timeInterval repeats:NO];
-      NSString * identifier = category_id;
+      NSString * identifier = message_id;
       UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
       [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
         

+ 3 - 3
src/app.config.ts

@@ -1,7 +1,7 @@
 const appConfig = defineAppConfig({
   pages: [
     // 'pages/clock/Index',
-    'pages/clock/Clock',
+    'pages/clock/ClockMain',
     'pages/clock/Suggest',
     'pages/clock/SetGoal',
     'pages/demo',
@@ -28,7 +28,7 @@ const appConfig = defineAppConfig({
     'pages/explore/Index',
     'pages/clock/StreakDetail'
   ],
-  entryPagePath: 'pages/clock/Clock',
+  entryPagePath: 'pages/clock/ClockMain',
   subPackages: [
     {
       root: 'moduleA',
@@ -91,7 +91,7 @@ process.env.TARO_ENV === 'weapp' && (appConfig.tabBar = {
   list: [
     {
       // pagePath: 'pages/clock/Clock',
-      pagePath: 'pages/clock/Clock',
+      pagePath: 'pages/clock/ClockMain',
       text: '生物钟',
     },
     {

+ 1 - 1
src/components/navigation/TabBar.tsx

@@ -13,7 +13,7 @@ export default function Component(props: { index: number }) {
             case 0:
 
                 Taro.switchTab({
-                    url: '/pages/clock/Clock'
+                    url: '/pages/clock/ClockMain'
                 })
                 break;
             case 2:

+ 1 - 1
src/custom-tab-bar2/index.tsx

@@ -39,7 +39,7 @@ export default function TabBar() {
             case 0:
 
                 Taro.switchTab({
-                    url: '/pages/clock/Clock'
+                    url: '/pages/clock/ClockMain'
                 })
                 break;
             case 1:

+ 17 - 5
src/features/trackTimeDuration/components/IndexConsole.tsx

@@ -2,7 +2,7 @@ import { View, Text, Image, PageContainer } from '@tarojs/components'
 import './IndexConsole.scss'
 import { useTranslation } from 'react-i18next'
 import { useDispatch, useSelector } from 'react-redux';
-import { endFast, endSleep, startFast, startSleep } from "../actions/TrackTimeActions";
+import { endFast, endSleep, startFast, startSleep, uploadLocalPushInfo } from "../actions/TrackTimeActions";
 import { jumpPage } from '../hooks/Common';
 import { useContext, useEffect, useRef, useState } from 'react';
 import ConsolePicker from './ConsolePicker';
@@ -35,6 +35,8 @@ let max = 0
 let defaultTimestamp = 0
 let isTimeout = false
 let stageIndex = 0
+
+let nativePushListener = null
 export default function IndexConsole(props: { record: any, count: number }) {
     const user = useSelector((state: any) => state.user);
     const { status } = props.record.current_record;
@@ -71,14 +73,22 @@ export default function IndexConsole(props: { record: any, count: number }) {
 
     useEffect(() => {
         if (process.env.TARO_ENV == 'rn') {
+            console.error('current status',status)
             if (Taro.getSystemInfoSync().platform == 'ios') {
                 var Jto = require('react-native').NativeModules.NativeBridge;
                 var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter;
                 Jto.getNotificationAuthStatus()
-                NativeAppEventEmitter.addListener('notificationReceive', (data) => {
+                if (nativePushListener){
+                    (nativePushListener as any).remove()
+                }
+                nativePushListener = NativeAppEventEmitter.addListener('notificationReceive', (data) => {
                     console.log('notification receive action', data)
-                    const { category_id, action_id } = data
-                    debugger
+                    const { category_id, action_id,id } = data
+                    uploadLocalPushInfo({
+                        messageId:id
+                    })
+
+                    console.log(props.record)
                     switch (action_id) {
                         case 'START_TIMER_NOW':
                             {
@@ -130,7 +140,7 @@ export default function IndexConsole(props: { record: any, count: number }) {
                 })
             }
         }
-    }, [])
+    }, [props.record])
 
     useEffect(() => {
         if (currentRecord.fast) {
@@ -287,6 +297,7 @@ export default function IndexConsole(props: { record: any, count: number }) {
             jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
             return
         }
+        debugger
         if (status == 'WAIT_FOR_START') {
             Taro.showToast({
                 title: t('feature.track_time_duration.console.lock_fast_tip'),
@@ -478,6 +489,7 @@ export default function IndexConsole(props: { record: any, count: number }) {
     }
 
     function pickerConfirm(t1: number) {
+        debugger
         if (btnDisable) {
             return
         }

+ 0 - 1
src/features/trackTimeDuration/components/More.tsx

@@ -59,7 +59,6 @@ const Component = forwardRef((props, ref) => {
                         })
                         break;
                     case 1:
-                        debugger
                         Taro.navigateTo({
                             url: '/pages/clock/ChooseScenario'
                         })

+ 2 - 0
src/features/trackTimeDuration/components/Rings.rn.tsx

@@ -4,6 +4,7 @@ import Taro from "@tarojs/taro";
 import { useRef } from "react";
 import Svg, { Circle, Path, SvgUri, Image } from 'react-native-svg';
 import { useSelector } from "react-redux";
+import {NativeAppEventEmitter} from 'react-native';
 
 export type RingCommon = {
     useCase: string;
@@ -61,6 +62,7 @@ export default function Component(props: {
     const center = radius + lineWidth / 2 + 3; // 圆心坐标
 
     function drawContent() {
+        
         var time = new Date();
         var seconds = time.getHours() * 3600 + time.getMinutes() * 60 + time.getSeconds();
         if (props.currentDot && props.currentDot.offset)

+ 0 - 1
src/features/trackTimeDuration/components/TitleView.tsx

@@ -81,7 +81,6 @@ export default function Component(props: {
                         })
                         return;
                     }
-                    debugger
                     jumpPage('/pages/clock/ChooseScenario', 'ChooseScenario', navigation)
                     break;
             }

+ 1 - 1
src/pages/account/Setting.tsx

@@ -78,7 +78,7 @@ export default function Page() {
                     
                     if (process.env.TARO_ENV == 'weapp') {
                         Taro.switchTab({
-                            url: '/pages/clock/Clock'
+                            url: '/pages/clock/ClockMain'
                         })
                         //check
                         //退出到首页后,点击登录,会再次执行naviback函数

+ 11 - 161
src/pages/clock/Clock.tsx

@@ -149,104 +149,6 @@ export default function Page() {
 
     useEffect(() => {
 
-        // Taro.request({
-        //     url:'https://api.fast.dev.liveplus.fun/api/static-resource-urls',
-        //     method:'GET',
-        //     data:{},
-        //     timeout:20000,
-        //     success(result) {
-        //         showAlert({
-        //             title:'success',
-        //             content:JSON.stringify(result)
-        //         })
-        //     },
-        //     fail(res) {
-        //         showAlert({
-        //             title:'fail',
-        //             content:JSON.stringify(res)
-        //         })
-        //     },
-        // })
-
-        if (process.env.TARO_ENV == 'weapp') {
-            loadWXCache()
-        }
-        else {
-            loadRNCache()
-
-            // PushNotification.configure({
-            //     onRegister: function (token) {
-            //         console.log('TOKEN:', token);
-            //     },
-
-            //     onNotification: function (notification) {
-            //         console.log('NOTIFICATION:', notification);
-            //         // notification.finish(PushNotificationIOS.FetchResult.NoData);
-            //     },
-            //     popInitialNotification: true,
-            // });
-
-            // var channelId = "your-channel-id" + new Date().getTime()
-            // PushNotification.createChannel({
-            //     channelId: channelId, // (required)
-            //     channelName: "My channel", // (required)
-            //     channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
-            //     playSound: false, // (optional) default: true
-            //     soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
-            //     importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
-            //     vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
-            // }, (created) => {
-            //     console.log('create channel result',created)
-            //     PushNotification.localNotificationSchedule({
-            //         //... You can use all the options from localNotifications
-            //         channelId: channelId,
-            //         title: 'Leon test',
-            //         message: "Local notification push", // (required)
-            //         date: new Date(Date.now() + 10 * 1000), // in 60 secs
-            //         allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
-            //         // repeatType:'minute',
-            //         /* Android Only Properties */
-            //         // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
-            //     });
-            // })
-
-            // PushNotification.localNotificationSchedule({
-            //     //... You can use all the options from localNotifications
-            //     title: 'Leon test2',
-            //     message: "Local notification push2", // (required)
-            //     date: new Date(Date.now() + 15 * 1000), // in 60 secs
-            //     allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
-            //     // repeatType:'minute',
-            //     /* Android Only Properties */
-            //     // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
-            // });
-
-            // PushNotification.localNotificationSchedule({
-            //     //... You can use all the options from localNotifications
-            //     channelId: "your-channel-id"+new Date().getTime(),
-            //     title: 'Leon test',
-            //     message: "Local notification push", // (required)
-            //     date: new Date(Date.now() + 10 * 1000), // in 60 secs
-            //     allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
-            //     // repeatType:'minute',
-            //     /* Android Only Properties */
-            //     // repeatTime: 1, // (optional) Increment of configured repeatType. Check 'Repeating Notifications' section for more info.
-            // });
-
-            // PushNotification.localNotificationSchedule({
-            //     title: "My notification title",
-            //     message: "My notification message",
-            //     date: new Date(Date.now() + 10 * 1000), // first trigger in 30 secs
-            //     // channelId: 'DemoAppID',
-            //     repeatType: 'time',
-            //     repeatTime: 30 * 1000 // repeats every 30 seconds (value has to be defined in miliseconds when the repeatType is 'time')
-            //   });
-
-
-
-
-        }
-
         if (process.env.TARO_ENV == 'rn') {
             JPush.setBadge({
                 badge: 0,
@@ -260,31 +162,10 @@ export default function Page() {
             })
 
             AppState.addEventListener('change', handleAppStateChange);
-
-            /*
-            if (Taro.getSystemInfoSync().platform == 'ios') {
-                setTimeout(() => {
-                    var Jto = require('react-native').NativeModules.NativeBridge;
-                    // Jto.authNotification()
-                    Jto.getNotificationAuthStatus()
-                }, 5000)
-                NativeAppEventEmitter.addListener('notificationResult', (data) => {
-                    console.log(data)
-                    showAlert({
-                        title:'notification status',
-                        content:data
-                    })
-                })
-            }*/
-
-
         }
 
     }, [])
 
-    async function demo() {
-    }
-
     useEffect(() => {
         console.log(user.isLogin)
         getCheckData()
@@ -307,16 +188,15 @@ export default function Page() {
                 if (Taro.getSystemInfoSync().platform == 'ios') {
                     var Jto = require('react-native').NativeModules.NativeBridge;
                     Jto.getNotificationAuthStatus()
-                    Jto.rnPageLoaded()
+                    // Jto.rnPageLoaded()
                     NativeAppEventEmitter.addListener('notificationResult', (data) => {
                         console.log('notification auth result', data)
                         global.notification = data;
                         uploadPermissions()
                     })
-                    NativeAppEventEmitter.addListener('notificationReceive', (data) => {
-                        console.log('notification receive action 222', data)
-                        debugger
-                    })
+                    // NativeAppEventEmitter.addListener('notificationReceive', (data) => {
+                    //     console.log('notification receive action 222', data)
+                    // })
                 }
 
                 // uploadPermissions()
@@ -574,43 +454,6 @@ export default function Page() {
         })
     }
 
-    function loadWXCache() {
-        var showDayRing = Taro.getStorageSync('showDayRing') || false;
-        var showNightRing = Taro.getStorageSync('showNightRing') || false;
-        dispatch(showDay(showDayRing))
-        dispatch(showNight(showNightRing))
-        var gps = Taro.getStorageSync('gps')
-        if (gps) {
-            global.locationDetail = JSON.parse(gps)
-        }
-        var userData = Taro.getStorageSync('userData')
-        if (userData) {
-            dispatch(getInfoSuccess(JSON.parse(userData)));
-        }
-    }
-
-    async function loadRNCache() {
-        var showDayRing = await getStorage('showDayRing') || false;
-        var showNightRing = await getStorage('showNightRing') || false;
-        dispatch(showDay(showDayRing))
-        dispatch(showNight(showNightRing))
-        var gps = await getStorage('gps')
-        if (gps) {
-            global.locationDetail = JSON.parse(gps)
-        }
-        var userData = await getStorage('userData')
-        console.log(userData)
-        if (userData) {
-            dispatch(getInfoSuccess(JSON.parse(userData)));
-        }
-        // //测试直接登录
-        // else {
-        //     userData = '{"metrics_times":0,"ongoing":false,"id":"fe6641e66a0e411937a52511e19851cd","mobile_bind":false,"mobile":"","avatar":"https://api.fast.dev.liveplus.fun/api/avatars/fast_441b5a21.svg","nickname":"fast_441b5a21","type":"GENERAL","lv":1,"invite_code":"LVQ5","input_invite_code":true,"reg_time":1712838856000,"login_bind":{"wx":false,"wx_mp":false,"wx_pub":false,"qq":false,"weibo":false},"test_user":true,"manager_user":false,"web_user":false,"rjv_balance":0,"day_level":1,"scenario_select_count":77,"push_enabled":false,"is_new_user":true,"lang":"en","timezone":{},"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhY2NvdW50Iiwic3ViIjoiZmU2NjQxZTY2YTBlNDExOTM3YTUyNTExZTE5ODUxY2QiLCJpc3MiOiJmYXN0Iiwibmlja25hbWUiOiJmYXN0XzQ0MWI1YTIxIiwidHlwIjoiQmVhcmVyIiwic2Vzc2lvbl9zdGF0ZSI6IjA0NTcxOGYzN2Y5NTYzYjcxMTNkMWZhODI5NmE2MjQ2IiwiZXhwIjoxNzQ2Njg4NTYxLCJpYXQiOjE3MTUxNTI1NjF9.x1CguOILCTjT8lKcEdSEeuS9ACc5QK2G4Rxmcz9OMLQ","need_improve":false}'
-        //     dispatch(getInfoSuccess(JSON.parse(userData)));
-        // }
-    }
-
-
     function getCheckData() {
 
         Promise.all([getClocks(), getPlans()]).then((list) => {
@@ -635,6 +478,13 @@ export default function Page() {
                 }
             }
 
+            if (process.env.TARO_ENV == 'rn' && user.isLogin) {
+                if (Taro.getSystemInfoSync().platform == 'ios') {
+                    var Jto = require('react-native').NativeModules.NativeBridge;
+                    Jto.rnPageLoaded()
+                }
+            }
+
             setLoaded(true)
         }).catch((e) => {
             setErrorPage(true)

+ 75 - 0
src/pages/clock/ClockMain.tsx

@@ -0,0 +1,75 @@
+import { showDay } from "@/store/day";
+import { showNight } from "@/store/night";
+import { getInfoSuccess } from "@/store/user";
+import { View } from "@tarojs/components";
+import Taro from "@tarojs/taro";
+import { useEffect, useState } from "react";
+import { useDispatch } from "react-redux";
+import Clock from "./Clock";
+export default function ClockMain() {
+    const dispatch = useDispatch();
+    const [loaded, setLoaded] = useState(false)
+    useEffect(() => {
+        if (process.env.TARO_ENV == 'weapp') {
+            loadWXCache()
+        }
+        else {
+            loadRNCache()
+        }
+    }, [])
+
+    function loadWXCache() {
+        var showDayRing = Taro.getStorageSync('showDayRing') || false;
+        var showNightRing = Taro.getStorageSync('showNightRing') || false;
+        dispatch(showDay(showDayRing))
+        dispatch(showNight(showNightRing))
+        var gps = Taro.getStorageSync('gps')
+        if (gps) {
+            global.locationDetail = JSON.parse(gps)
+        }
+        var userData = Taro.getStorageSync('userData')
+        if (userData) {
+            dispatch(getInfoSuccess(JSON.parse(userData)));
+        }
+        setLoaded(true)
+    }
+
+    async function loadRNCache() {
+        var showDayRing = await getStorage('showDayRing') || false;
+        var showNightRing = await getStorage('showNightRing') || false;
+        dispatch(showDay(showDayRing))
+        dispatch(showNight(showNightRing))
+        var gps = await getStorage('gps')
+        if (gps) {
+            global.locationDetail = JSON.parse(gps)
+        }
+        var userData = await getStorage('userData')
+        console.log(userData)
+        if (userData) {
+            dispatch(getInfoSuccess(JSON.parse(userData)));
+        }
+
+        setLoaded(true)
+        // //测试直接登录
+        // else {
+        //     userData = '{"metrics_times":0,"ongoing":false,"id":"fe6641e66a0e411937a52511e19851cd","mobile_bind":false,"mobile":"","avatar":"https://api.fast.dev.liveplus.fun/api/avatars/fast_441b5a21.svg","nickname":"fast_441b5a21","type":"GENERAL","lv":1,"invite_code":"LVQ5","input_invite_code":true,"reg_time":1712838856000,"login_bind":{"wx":false,"wx_mp":false,"wx_pub":false,"qq":false,"weibo":false},"test_user":true,"manager_user":false,"web_user":false,"rjv_balance":0,"day_level":1,"scenario_select_count":77,"push_enabled":false,"is_new_user":true,"lang":"en","timezone":{},"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhY2NvdW50Iiwic3ViIjoiZmU2NjQxZTY2YTBlNDExOTM3YTUyNTExZTE5ODUxY2QiLCJpc3MiOiJmYXN0Iiwibmlja25hbWUiOiJmYXN0XzQ0MWI1YTIxIiwidHlwIjoiQmVhcmVyIiwic2Vzc2lvbl9zdGF0ZSI6IjA0NTcxOGYzN2Y5NTYzYjcxMTNkMWZhODI5NmE2MjQ2IiwiZXhwIjoxNzQ2Njg4NTYxLCJpYXQiOjE3MTUxNTI1NjF9.x1CguOILCTjT8lKcEdSEeuS9ACc5QK2G4Rxmcz9OMLQ","need_improve":false}'
+        //     dispatch(getInfoSuccess(JSON.parse(userData)));
+        // }
+    }
+
+    async function getStorage(key: string) {
+        try {
+            const res = await Taro.getStorage({ key });
+            return res.data;
+        } catch {
+            return '';
+        }
+    }
+
+    if (loaded) {
+        return <Clock />
+    }
+
+
+    return <View></View>
+}

+ 0 - 1
src/pages/index/index.tsx

@@ -80,7 +80,6 @@ export default function IndexPage() {
 
   function login() {
     if (user.isLogin) {
-      debugger
       Taro.navigateTo({
         url: '/pages/ChooseScenario'
       })

+ 1 - 1
src/pages/rn/RNMain.tsx

@@ -3,7 +3,7 @@ import { NavigationContainer } from '@react-navigation/native';
 import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
 import { createStackNavigator } from '@react-navigation/stack';
 
-import Clock from '../clock/Clock'
+import Clock from '../clock/ClockMain'
 import Metric from '../metric/Metric'
 import Workout from '../workout/Workout'
 import Profile from '../account/Profile'

+ 0 - 1
src/utils/push.tsx

@@ -59,7 +59,6 @@ export default function jgPush() {
     })
 
     if (Taro.getSystemInfoSync().platform == 'ios'){
-        debugger
         return;
     }