Leon há 1 ano atrás
pai
commit
266a75526b
2 ficheiros alterados com 43 adições e 12 exclusões
  1. 16 11
      src/pages/clock/Clock.tsx
  2. 27 1
      src/utils/tools.ts

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

@@ -18,7 +18,7 @@ import { bigRingRadius, getBgRing, getCommon, getDot, getSchedule, ringWidth, sm
 import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
 import IndexConsole from "@/features/trackTimeDuration/components/IndexConsole";
 import Modal from '@/components/layout/Modal'
-import { rpxToPx } from "@/utils/tools";
+import { compareVersion, rpxToPx } from "@/utils/tools";
 import RecordFastSleep from "@/features/trackTimeDuration/components/RecordFastSleep";
 import DayLight from "@/features/trackTimeDuration/components/DayLight";
 import { getInfo, latestLocation } from "@/services/user";
@@ -176,16 +176,21 @@ export default function Page() {
     }
 
     function checkAddToMini() {
-        process.env.TARO_ENV == 'weapp' &&
-            wx.checkIsAddedToMyMiniProgram({
-                success: (res) => {
-                    if (!res.added) {
-                        setNeedShowAddTip(true)
+        if (process.env.TARO_ENV == 'weapp') {
+            const version = Taro.getAppBaseInfo().SDKVersion
+            if (compareVersion(version, '2.30.3') >= 0) {
+                wx.checkIsAddedToMyMiniProgram({
+                    success: (res) => {
+                        if (!res.added) {
+                            setNeedShowAddTip(true)
+                        }
+                    },
+                    fail: (e) => {
                     }
-                },
-                fail: (e) => {
-                }
-            });
+                });
+            }
+        }
+
     }
 
     useDidShow(() => {
@@ -664,7 +669,7 @@ export default function Page() {
                 }
 
                 {
-                    user.isLogin && !showErrorPage  && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
+                    user.isLogin && !showErrorPage && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
                         <Text className="discovery1" >周统计</Text>
                         <WeekCalendar />
                     </View>

+ 27 - 1
src/utils/tools.ts

@@ -56,4 +56,30 @@ export function vibrate(type?: string) {
             type: 'medium'
         })
     }
-}
+}
+
+export function compareVersion(v1, v2) {
+    v1 = v1.split('.')
+    v2 = v2.split('.')
+    const len = Math.max(v1.length, v2.length)
+  
+    while (v1.length < len) {
+      v1.push('0')
+    }
+    while (v2.length < len) {
+      v2.push('0')
+    }
+  
+    for (let i = 0; i < len; i++) {
+      const num1 = parseInt(v1[i])
+      const num2 = parseInt(v2[i])
+  
+      if (num1 > num2) {
+        return 1
+      } else if (num1 < num2) {
+        return -1
+      }
+    }
+  
+    return 0
+  }