Leon 2 years ago
parent
commit
7131065b88

+ 3 - 1
src/app.config.ts

@@ -13,7 +13,9 @@ const appConfig = defineAppConfig({
     'pages/Profile',
     'pages/Metric',
     'pages/Activity',
-    'pages/RecordsHistory'
+    'pages/RecordsHistory',
+    'pages/ProfileSetting',
+    'pages/Setting'
   ],
   subPackages: [
     {

+ 1 - 0
src/components/LimitPickers.tsx

@@ -128,6 +128,7 @@ export default function Component(props: { limit: number, onChange: Function, on
     return <View style={{ backgroundColor: '#fff', color: '#000', position: 'relative' }}>
         <PickerView value={values}
             onChange={onPickerChange}
+            immediateChange={true}
             indicatorStyle='height: 50px;' style='width: 100%; height: 300px;'>
             <PickerViewColumn style='flex:0 0 45%'>
                 {days.map(item => {

+ 1 - 0
src/components/PickerViews.tsx

@@ -26,6 +26,7 @@ export default function Component(props: { value: any, onChange: Function, items
     return <View><PickerView value={v}
         onChange={onPickerChange}
         indicatorStyle='height: 50px;'
+        immediateChange={true}
         style={props.height ? `width: 100%; height: ${props.height}px;` : `width: 100%; height: 100px;`}>
         {
             props.items.map(item => {

+ 1 - 0
src/components/TimePickers.tsx

@@ -43,6 +43,7 @@ export default function Component(props: { time: string, content: string, change
         return <PickerView
             value={dt}
             onChange={onPickerChange}
+            immediateChange={true}
             indicatorStyle='height: 50px;' style='width: 100%; height: 100px;'>
             <PickerViewColumn>
                 {hours.map(item => {

+ 13 - 4
src/features/trackSomething/components/Activity.tsx

@@ -1,4 +1,4 @@
-import { View, Text } from "@tarojs/components";
+import { View, Text,ScrollView } from "@tarojs/components";
 import './Metric.scss'
 import { setAuth } from "../hooks/werun";
 import { useDidShow, useReady } from "@tarojs/taro";
@@ -24,7 +24,7 @@ export default function Component(props: any) {
     const [returnLoginData, setReturnLoginData] = useState(false)
     const [showErrorBadge, setShowErrorBadge] = useState(false)
     const [latestRecord, setLatestRecord] = useState(null)
-
+    const [triggered, setTriggered] = useState(true)
     const [showErrorPage, setErrorPage] = useState(false)
     // const [title, setTitle] = useState('打卡')
 
@@ -64,8 +64,10 @@ export default function Component(props: any) {
     }
 
     function getCards() {
+        setTriggered(true)
         activityCards().then(res => {
             setErrorPage(false)
+            setTriggered(false)
             checkAuth()
             setList((res as any).cards)
             for (var i = 0; i < (res as any).cards.length; i++) {
@@ -75,6 +77,7 @@ export default function Component(props: any) {
                 }
             }
         }).catch(e => {
+            setTriggered(false)
             if (list.length==0){
                 setErrorPage(true)
             }
@@ -233,7 +236,7 @@ export default function Component(props: any) {
         for (var i = 0; i < list.length; i++) {
             var obj = list[i];
             if ((obj as any).code == '_walk') {
-                (obj as any).latest_record = res
+                (obj as any).latest_record = res.latest_record
             }
         }
         // getCards();
@@ -380,6 +383,12 @@ export default function Component(props: any) {
         </View>
     }
 
-    return showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()
+    return <ScrollView style={{ backgroundColor: '#000',flex:1 }} scrollY refresherEnabled={true}
+        refresherThreshold={100} refresherBackground="#000"
+        refresherDefaultStyle="white" onRefresherRefresh={getCards}
+        refresherTriggered={triggered}>
+        {showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()}
+    </ScrollView>
+    // return showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()
 
 }

+ 4 - 0
src/features/trackSomething/components/Metric.config.ts

@@ -0,0 +1,4 @@
+export default definePageConfig({
+    pullRefresh: true,
+  })
+  

+ 3 - 0
src/features/trackSomething/components/Metric.scss

@@ -6,5 +6,8 @@
 }
 
 .space_width{
+    display: flex;
     width: 320px;
+    height: 100px;
+    flex-shrink: 0;
 }

+ 24 - 10
src/features/trackSomething/components/Metric.tsx

@@ -1,7 +1,7 @@
-import { View, Text } from "@tarojs/components";
+import { View, Text, ScrollView } from "@tarojs/components";
 import './Metric.scss'
 import { setAuth } from "../hooks/werun";
-import { useReady } from "@tarojs/taro";
+import { usePullDownRefresh, useReady } from "@tarojs/taro";
 import { useSelector } from "react-redux";
 import { useEffect, useState } from "react";
 import Taro from "@tarojs/taro";
@@ -32,7 +32,8 @@ export default function Component(props: any) {
 
     const [showErrorPage, setErrorPage] = useState(false)
 
-    const [setupTime,setSetupTime] = useState(0)
+    const [setupTime, setSetupTime] = useState(0)
+    const [triggered, setTriggered] = useState(true)
 
 
     //未登录<->已登录 状态切换时,执行一次授权检查
@@ -42,7 +43,6 @@ export default function Component(props: any) {
 
     const openModal = () => {
         setSetupTime(new Date().getTime())
-        debugger
         setIsModalOpen(true);
     };
 
@@ -55,14 +55,17 @@ export default function Component(props: any) {
     }
 
     function getCards() {
+        setTriggered(true)
         console.log('get Cards')
         metricCards().then(res => {
             setErrorPage(false)
             setList((res as any).cards)
+            setTriggered(false)
         }).catch(e => {
             if (list.length == 0) {
                 setErrorPage(true)
             }
+            setTriggered(false)
             // console.log('请求超时')
         })
     }
@@ -248,7 +251,7 @@ export default function Component(props: any) {
             timestamp: time,
             date: strDate,
             items: array,
-            extra:{
+            extra: {
                 set_time: setupTime,
                 confirm_time: new Date().getTime()
             }
@@ -296,7 +299,21 @@ export default function Component(props: any) {
                 })
             }
             <View className="space_width" />
-            {
+            
+        </View>
+    }
+
+    // return showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()
+
+    return <View style={{ display: 'flex', flex: 1, height: '100%' }}>
+        <ScrollView style={{ backgroundColor: '#000' }} scrollY refresherEnabled={true}
+            refresherThreshold={100} refresherBackground="#000"
+            refresherDefaultStyle="white" onRefresherRefresh={getCards}
+            refresherTriggered={triggered}>
+            {showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()}
+            <View style={{height:100}}/>
+        </ScrollView>
+        {
                 isModalOpen && <Modal dismiss={closeModal}>
                     <View style={{
                         backgroundColor: 'white',
@@ -337,9 +354,6 @@ export default function Component(props: any) {
                     }} />
                 </Modal>
             }
-        </View>
-    }
-
-    return showErrorPage ? <NoData refresh={() => { getCards() }} /> : detail()
+    </View>
 
 }

+ 11 - 1
src/features/trackTimeDuration/components/Console.tsx

@@ -122,6 +122,7 @@ export default function Component() {
         setShowModal(true)
         setIsOpen(true)
         global.set_time = new Date().getTime()
+        console.log(global.set_time)
     }
 
     function hidePicker() {
@@ -146,6 +147,16 @@ export default function Component() {
     }
 
     function pickerConfirm(t: number) {
+        debugger
+        console.log(t)
+        var date = new Date(t)
+        var setDate = new Date(global.set_time);
+        date.setMilliseconds(setDate.getMilliseconds());
+        date.setSeconds(setDate.getSeconds());
+
+        t = date.getTime();
+        console.log(t);
+
         if (isFast) {
             if (value == 'WAIT_FOR_START') {
                 // const duration = fastValues[0] * 3600 * 1000 + fastValues[1] * 60 * 1000
@@ -257,7 +268,6 @@ export default function Component() {
     }
 
     function minus() {
-        debugger
         if (isFast) {
             var count = fastDuration - 5 * 60 * 1000
             setFastDuration(count)

+ 20 - 0
src/features/trackTimeDuration/components/Dial.tsx

@@ -2,8 +2,10 @@ import Taro from '@tarojs/taro';
 import { Canvas, View } from '@tarojs/components';
 import { useEffect, useRef, useState } from 'react';
 import React from 'react';
+import { useSelector } from 'react-redux';
 
 const Component = (props) => {
+    const [scenario] = useState(useSelector((state: any) => state.scenario))
     const [currentContext, setCurrentContext] = useState(null)
     const canvasWidth: number = 200;
     const canvasHeight: number = 200;
@@ -35,6 +37,11 @@ const Component = (props) => {
     var strStart = current.start;
     var strEnd = current.end;
 
+    var needDrawFastRing = false;
+    if (scenario.name == 'FAST_SLEEP' && scenario.step == 'sleep'){
+        needDrawFastRing = true;
+    }
+
     useEffect(() => {
 
         const query = Taro.createSelectorQuery();
@@ -65,6 +72,14 @@ const Component = (props) => {
 
         ctx.clearRect(0, 0, canvasWidth, canvasHeight);
 
+        if(needDrawFastRing){
+            ctx.beginPath();
+        ctx.arc(centerX, centerY, radius+8, global.fast_start_angle, global.fast_end_angle);
+        ctx.strokeStyle = 'rgba(170, 255, 0, 0.3)';
+        ctx.lineWidth = 2;
+        ctx.stroke();
+        }
+
         ctx.beginPath();
         ctx.arc(centerX, centerY, radius, 0, 2 * Math.PI);
         ctx.strokeStyle = "rgba(0,0,0,0.5)";
@@ -77,6 +92,11 @@ const Component = (props) => {
         ctx.lineWidth = 10;
         ctx.stroke();
 
+        if (scenario.step == 'fast'){
+            global.fast_start_angle = startAngle;
+            global.fast_end_angle = endAngle;
+        }
+
         const pointX = centerX + Math.cos(startAngle) * radius;
         const pointY = centerY + Math.sin(startAngle) * radius;
 

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

@@ -45,6 +45,12 @@ const Component = forwardRef((props, ref) => {
                         if (scenario.name == 'FAST_SLEEP') {
                             dispatch(setStep(isFastFirst?'fast':'sleep'))
                         }
+                        else if (scenario.name == 'SLEEP'){
+                            dispatch(setStep('sleep'))
+                        }
+                        else {
+                            dispatch(setStep('fast'))
+                        }
                         Taro.navigateTo({
                             url: '/pages/SetSchedule'
                         })

+ 8 - 0
src/pages/Activity.config.ts

@@ -0,0 +1,8 @@
+export default definePageConfig({
+    usingComponents:{
+      // 'ec-canvas': '../../lib/ec-canvas/ec-canvas',
+      // 'demo':'../../components/demo'
+    },
+    "disableScroll": true
+  })
+  

+ 8 - 0
src/pages/Metric.config.ts

@@ -0,0 +1,8 @@
+export default definePageConfig({
+    usingComponents:{
+      // 'ec-canvas': '../../lib/ec-canvas/ec-canvas',
+      // 'demo':'../../components/demo'
+    },
+    "disableScroll": true
+  })
+  

+ 1 - 159
src/pages/Metric.tsx

@@ -1,169 +1,11 @@
-import { View, Text, CoverView, Button } from "@tarojs/components";
-import { useState } from "react";
-import Modal from "@/components/Modal";
-import PickerViews from "@/components/PickerViews";
-import LimitPickers from "@/components/LimitPickers";
+import { View, Text} from "@tarojs/components";
 import Metric from "@/features/trackSomething/components/Metric";
 
 export default function Page() {
-    const [isModalOpen, setIsModalOpen] = useState(false);
-    const [isTimePickerOpen, setIsTimePickerOpen] = useState(false);
-    const [pickerValue, setPickerValue] = useState([]);
-    const [pickerItems, setPickerItems] = useState([]);
-    const [isPoint, setIsPoint] = useState(false)
-
-    global.refresh=()=>{
-        console.log('refresh')
-    }
-
-
-    const openModal = () => {
-        setIsModalOpen(true);
-    };
-
-    const closeModal = () => {
-        setIsModalOpen(false);
-    };
-
-    function singlePicker() {
-        var min = 5
-        var max = 200
-        var step = 1
-        var value = 99
-
-        var items: number[] = []
-        for (var i = min; i <= max; i += step) {
-            if (i == value) {
-                setPickerValue([i - min] as any)
-            }
-            items.push(i)
-        }
-
-        setPickerItems([items] as any)
-        setIsPoint(false)
-
-        openModal()
-    }
-
-    function multiPicker() {
-        var min = 5
-        var max = 200
-        var step = 1
-        var value0 = 99
-        var value1 = 111
-
-        var items: number[] = []
-        var items2: number[] = []
-
-        var value0Index = 0
-        var value1Index = 0
-        for (var i = min; i <= max; i += step) {
-            if (i == value0) {
-                value0Index = i - min
-            }
-            if (i == value1) {
-                value1Index = i - min
-            }
-            items.push(i)
-            items2.push(i)
-        }
-
-        setPickerValue([value0Index, value1Index] as any)
-        setPickerItems([items, items2] as any)
-        setIsPoint(false)
-        openModal()
-    }
-
-    function pointPicker() {
-        var min = 5
-        var max = 200
-        var step = 0.1
-        var value = 88.7
-        var items: number[] = []
-        var items2: number[] = []
-
-        var value0Index = 0
-        var value1Index = 0
-
-        for (var i = min; i <= max; i++) {
-            if (i == Math.floor(value)) {
-                value0Index = i - min
-            }
-            items.push(i)
-            // items2.push(i)
-        }
-
-        for (var i = 0; i <= 9; i++) {
-            items2.push(i)
-        }
-        value1Index = 10 * (value - Math.floor(value));
-
-        setPickerValue([value0Index, value1Index] as any)
-        setPickerItems([items, items2] as any)
-        setIsPoint(true)
-
-        openModal()
-    }
-    function pickerChanged(e) {
-        console.log(e)
-        closeModal()
-    }
-
-    function showTimePicker() {
-        setIsTimePickerOpen(true)
-    }
-
 
     return <View className="container">
         <Text>Metric Page</Text>
             <Metric />
             <View style={{height:100,flexShrink:0,display:'flex'}}/>
         </View>
-
-    const limit = new Date().getTime() - 7 * 3600 * 1000 * 24;
-    return (
-        <View className="container">
-            <Text onClick={openModal}>Metric Page</Text>
-            <Text onClick={singlePicker}>单列Picker</Text>
-            <Text onClick={multiPicker}>双列Picker</Text>
-            <Text onClick={pointPicker}>小数1位Picker</Text>
-
-            {
-                isModalOpen && <Modal dismiss={closeModal}>
-                    <View style={{
-                        backgroundColor: 'white',
-                        display: 'flex', flexDirection: 'column',
-                        width: '100%', height: '50%', color: '#000'
-                    }}>
-                        <Text style={{ textAlign: 'center' }}>指标Title</Text>
-                        <Text style={{ textAlign: 'center' }} onClick={showTimePicker}>22:22</Text>
-                        <View style={{ position: 'relative' }}>
-                            <PickerViews onChange={pickerChanged}
-                                items={pickerItems}
-                                value={pickerValue}
-                                height={200} showBtns={true}
-                                onCancel={closeModal} />
-                            {isPoint && <View style={{
-                                position: 'absolute', width: '20%', height: 50, backgroundColor: 'transparent', left: '40%', top: 75,
-                                display: 'flex', alignItems: 'center', justifyContent: 'center'
-                            }}>
-                                <Text style={{ color: '#000', fontSize: 16, fontWeight: 'bold' }}>.</Text>
-                            </View>}
-                        </View>
-
-                    </View>
-                </Modal>
-            }
-            {
-                 
-                isTimePickerOpen && <Modal dismiss={() => setIsTimePickerOpen(false)}>
-                    <LimitPickers limit={limit} onCancel={()=>{setIsTimePickerOpen(false)}} onChange={(e) => {
-                         console.log(new Date(e))
-                        //  pickerConfirm(e)
-                        //  hidePicker()
-                     }} />
-                </Modal>
-            }
-        </View>
-    )
 }

+ 60 - 0
src/pages/Profile.scss

@@ -0,0 +1,60 @@
+.card{
+    display: flex;
+    flex-direction: column;
+    padding-left: 40px;
+    padding-right: 40px;
+    padding-top: 34px;
+    padding-bottom: 34px;
+    border-radius: 36px;
+    border-color: #323232;
+    border-width: 1px;
+    border-style: solid;
+    margin-left: 46px;
+    margin-right: 46px;
+    margin-bottom: 40px;
+    position: relative;
+}
+
+.profile_card{
+    align-items: center;
+}
+
+.avatar{
+    width: 180px;
+    height: 180px;
+    border-radius: 90px;
+    background-color: #fff;
+
+}
+
+.nickname{
+    font-size: 40px;
+    color: #fff;
+    margin-top: 24px;
+    line-height: 40px;
+    height: 40px;
+}
+
+.username{
+    color: #9E9E9E;
+    font-size: 28px;
+    line-height: 32px;
+    height: 32px;
+    margin-top: 10px;
+}
+
+.title{
+    font-size: 28px;
+    line-height: 28px;
+    color: #fff;
+
+}
+
+.desc{
+    margin-top: 20px;
+    color: #FFFFFF;
+    opacity: 0.4;
+    font-size: 24px;
+    line-height: 32px;
+    
+}

+ 56 - 23
src/pages/Profile.tsx

@@ -1,50 +1,83 @@
 import Buttons from "@/components/Buttons";
 import { delSession } from "@/services/common";
 import { clear, logout } from "@/services/user";
-import { View,Text } from "@tarojs/components";
+import { View, Text } from "@tarojs/components";
 import Taro from "@tarojs/taro";
 import { useDispatch, useSelector } from "react-redux";
+import './Profile.scss'
 
-export default function Page(){
+export default function Page() {
     const dispatch = useDispatch();
     const user = useSelector((state: any) => state.user);
-    
-    function logoutF(){
-        dispatch(logout() as any);
-    }
 
-    function clearF(){
-        dispatch(clear() as any);
-    }
+    
 
-    function tapLogin(){
+    function tapLogin() {
         Taro.navigateTo({
             url: '/pages/ChooseAuth'
         })
     }
 
-    function reset(){
-        delSession({type:'WX_MP'})
+    function reset() {
+        delSession({ type: 'WX_MP' })
     }
 
-    return <View  className="container">
-        {
-            user.isLogin&&<Text>用户名:{user.nickname}</Text>
+    function tapProfile() {
+        if (user.isLogin){
+            Taro.navigateTo({
+                url: '/pages/ProfileSetting'
+            })
         }
-        {
-            user.isLogin&&<Text>id:{user.id}</Text>
+        else {
+            Taro.navigateTo({
+                url: '/pages/Balance'
+            })
         }
-        {
-            user.isLogin?<Buttons title='退出登录' onClick={logoutF} style={{ width: 289, marginBottom: 30 }} />:
-            <Text onClick={tapLogin}>请登录</Text>
+    }
+
+    function tapBalance() {
+        if (user.isLogin){
+
+        }
+        else {
+            Taro.navigateTo({
+                url: '/pages/Balance'
+            })
         }
+        
+    }
+
+    function goSetting(){
+        Taro.navigateTo({
+            url: '/pages/Setting'
+        })
+    }
+
+    return <View className="container">
+        <View className="profile_card card" onClick={tapProfile}>
+            <View className="avatar" style={{ opacity: user.isLogin ? 1 : 0.4 }}>
+
+            </View>
+            <Text className="nickname">{user.isLogin ? user.nickname : '未登录'}</Text>
+            <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text>
+        </View>
+        <View  className="card" onClick={tapBalance}>
+            <Text className="title">逆龄石</Text>
+            <Text className="desc">{'会员体系升级中,期间指标记录限时免逆龄石记录\n敬请期待'}</Text>
+        </View>
+        {user.isLogin && <View className="card" onClick={goSetting}>
+            <Text className="title">设置</Text>
+        </View>}
         {
-            user.isLogin?<Buttons title='注销账号' onClick={clearF} style={{ width: 289, marginBottom: 30 }} />:
-            <Text></Text>
+            user.isLogin && <Text>用户名:{user.nickname}</Text>
         }
         {
-            user.isLogin&& <Buttons title='重置session' onClick={reset} style={{ width: 289, marginBottom: 30 }} />
+            user.isLogin && <Text>id:{user.id}</Text>
         }
         
+        {
+            user.isLogin && <Buttons title='重置session' onClick={reset} style={{ width: 289, marginBottom: 30 }} />
+        }
+
     </View>
 }

+ 23 - 0
src/pages/ProfileSetting.tsx

@@ -0,0 +1,23 @@
+import Buttons from "@/components/Buttons";
+import { clear, logout } from "@/services/user";
+import { View, Text } from "@tarojs/components";
+import { useDispatch } from "react-redux";
+
+export default function Page() {
+    const dispatch = useDispatch();
+    function logoutF() {
+        dispatch(logout() as any);
+    }
+
+    function clearF() {
+        dispatch(clear() as any);
+    }
+    
+    return <View>
+        <Buttons title='退出登录' onClick={logoutF} style={{ width: 289, marginBottom: 30 }} />
+
+        <Buttons title='注销账号' onClick={clearF} style={{ width: 289, marginBottom: 30 }} />
+
+
+    </View>
+}

+ 23 - 0
src/pages/Setting.tsx

@@ -0,0 +1,23 @@
+import Buttons from "@/components/Buttons";
+import { clear, logout } from "@/services/user";
+import { View,Text,Button } from "@tarojs/components";
+import { useDispatch } from "react-redux";
+
+export default function Page(){
+    const dispatch = useDispatch();
+    function logoutF() {
+        dispatch(logout() as any);
+    }
+
+    function clearF() {
+        dispatch(clear() as any);
+    }
+    
+    return <View>
+        <Buttons title='退出登录' onClick={logoutF} style={{ width: 289, marginBottom: 30 }} />
+
+        <Buttons title='注销账号' onClick={clearF} style={{ width: 289, marginBottom: 30 }} />
+
+
+    </View>
+}

+ 0 - 2
src/pages/clock.tsx

@@ -91,7 +91,6 @@ export default function IndexPage() {
     process.env.TARO_ENV == 'weapp' &&
       wx.checkIsAddedToMyMiniProgram({
         success: (res) => {
-          console.log(res.added);
           if (!res.added) {
             setNeedShowAddTip(true)
           }
@@ -276,7 +275,6 @@ export default function IndexPage() {
     // return <View />
   }
 
-
   return (
     <View style={{ flex: 1, flexDirection: 'column', display: 'flex', backgroundColor: '#000', color: '#fff' }}>
       {

+ 3 - 0
src/services/user.tsx

@@ -1,3 +1,4 @@
+import Taro from '@tarojs/taro'
 import { API_OAUTH_LOGIN, API_REGISTER,API_LOGIN, API_LOGOUT, API_CLEAR_USER, API_USER_INFO,API_CHECK_UNIQUE } from './http/api'
 import { request } from './http/request'
 import { clearSuccess, getInfoSuccess, loginSuccess, logoutSuccess, registerSuccess, updateSuccess } from '@/store/user'
@@ -67,6 +68,7 @@ export const logout = () => (dispatch: any) => {
         url: API_LOGOUT, method: 'GET', data: {}
     }).then(_ => {
         dispatch(logoutSuccess());
+        Taro.navigateBack();
     })
 }
 
@@ -75,6 +77,7 @@ export const clear = () => (dispatch: any) => {
         url: API_CLEAR_USER, method: 'DELETE', data: {}
     }).then(_ => {
         dispatch(clearSuccess());
+        Taro.navigateBack();
     })
 }
 

+ 1 - 2
src/store/permission.tsx

@@ -26,8 +26,7 @@ const permissionSlice = createSlice({
     initialState,
     reducers: {
         setWXFollow(state, action) {
-            state.wxPubFollow = true//action?true:false;
-            // state.wxPubFollow = action.payload;
+            state.wxPubFollow = action.payload;
         },
         setPushAllow(state, action) {
             state.pushAllow = action.payload;