leon 2 yıl önce
ebeveyn
işleme
1c020fa2ba

+ 7 - 0
src/pages/Activity.tsx

@@ -1,7 +1,14 @@
 import { View,Text } from "@tarojs/components";
 import Metric from '@/features/trackSomething/components/Metric'
+import { useReady } from "@tarojs/taro";
+import { activityCards } from "@/services/trackSomething";
 
 export default function Page(){
+    useReady(()=>{
+        activityCards().then(res=>{
+            
+        })
+    })
     return (
         <View className="container activity">
             <Text>Activity Page</Text>

+ 26 - 11
src/pages/RecordsHistory.tsx

@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
 import Schedule from '@/features/trackTimeDuration/components/Schedule'
 import MetricHistory from "@/features/trackSomething/components/MetricHistory";
 import ActivityHistory from "@/features/trackSomething/components/ActivityHistory";
+import { activityRecords } from "@/services/trackSomething";
 
 export default function Page() {
     const router = useRouter();
@@ -62,17 +63,31 @@ export default function Page() {
     }
 
     function getHistory() {
-        getClockRecords({
-            page: pageIndex,
-            page_size: pageSize,
-            only_finished: false
-        }).then(res => {
-            if (pageIndex == 1) {
-                setRecords((res as any).data)
-            } else {
-                setRecords(records.concat((res as any).data))
-            }
-        })
+        if (router.params.type == 'time') {
+            getClockRecords({
+                page: pageIndex,
+                limit: pageSize,
+                only_finished: false
+            }).then(res => {
+                if (pageIndex == 1) {
+                    setRecords((res as any).data)
+                } else {
+                    setRecords(records.concat((res as any).data))
+                }
+            })
+        }
+        else if (router.params.type == 'activity') {
+            activityRecords(
+                {
+                    page: pageIndex,
+                    limit: pageSize,
+                    code:'_walk'
+                }
+            ).then(res => {
+
+            })
+        }
+
     }
 
     function removeItem(item) {

+ 2 - 0
src/services/http/api.js

@@ -32,6 +32,8 @@ export const API_FAST_CALENDARS = `${baseUrl}/api/fast/calendars/`
 //track something
 export const API_CLOCK_RECORDS = `${baseUrl}/api/clock/records`
 export const API_UPLOAD_STEPS = `${baseUrl}/api/thirdparty/wx/we-run-data`
+export const API_ACTIVITY_CARDS = `${baseUrl}/api/activity/cards`
+export const API_ACTIVITY_RECORDS = `${baseUrl}/api/activity/records`
 
 //journal
 

+ 24 - 2
src/services/trackSomething.tsx

@@ -1,10 +1,32 @@
-import {  API_UPLOAD_STEPS } from './http/api';
+import { API_ACTIVITY_CARDS, API_ACTIVITY_RECORDS, API_UPLOAD_STEPS } from './http/api';
 import { request } from './http/request';
 
 export const uploadSteps = (params) => {
     return new Promise((resolve) => {
         request({
-            url: API_UPLOAD_STEPS, method: 'POST', data: {...params}
+            url: API_UPLOAD_STEPS, method: 'POST', data: { ...params }
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
+}
+
+export const activityCards = () => {
+    return new Promise((resolve) => {
+        request({
+            url: API_ACTIVITY_CARDS, method: 'GET', data: {}
+        }).then(res => {
+            resolve(res);
+            // dispatch(loginSuccess(res));
+        })
+    })
+}
+
+export const activityRecords = (params) => {
+    return new Promise((resolve) => {
+        request({
+            url: API_ACTIVITY_RECORDS, method: 'GET', data: { ...params }
         }).then(res => {
             resolve(res);
             // dispatch(loginSuccess(res));

+ 56 - 0
src/store/action_results.tsx

@@ -0,0 +1,56 @@
+import { createSlice } from "@reduxjs/toolkit";
+
+export enum ResultType {
+    idle = 'idle',
+    ing = 'ing',
+    success = 'success',
+    fail = 'fail',
+    countdown = 'countdown'
+
+}
+interface ResultState {
+    title: string | null;
+    type: any | ResultType.idle;
+    seconds: number | 0;
+}
+
+const initialState: ResultState = {
+    title: null,
+    type: null,
+    seconds: 0
+}
+
+const resultSlice = createSlice({
+    name: 'user',
+    initialState,
+    reducers: {
+        checkStart(state) {
+            state.title = 'Success';
+            state.type = ResultType.ing;
+        },
+        checkSuccess(state) {
+            state.title = 'Success';
+            state.type = ResultType.success;
+        },
+        checkFail(state) {
+            state.title = 'Fail';
+            state.type = ResultType.fail;
+        },
+        checkCountdown(state, action) {
+            state.type = ResultType.countdown;
+            state.seconds = action.payload;
+        },
+        checkCountdownEnd(state) {
+            state.type = ResultType.idle;
+            state.seconds = 0;
+        },
+        resetStatus(state) {
+            state.type = ResultType.idle;
+            state.seconds = 0;
+        }
+    }
+}
+);
+
+export const { checkStart, checkSuccess, checkFail, checkCountdownEnd, checkCountdown, resetStatus } = resultSlice.actions;
+export default resultSlice.reducer;

+ 2 - 0
src/store/common.tsx

@@ -20,9 +20,11 @@ const commonSlice = createSlice({
     name: 'permission',
     initialState,
     reducers: {
+        //静态资源
         setResources(state, action) {
             state.resources = action.payload;
         },
+        //time配置文件
         setConfigs(state, action) {
             state.configs = action.payload.data;
             if (state.configs) {

+ 3 - 0
src/store/store.tsx

@@ -4,6 +4,7 @@ import scenarioReducer from './scenario';
 import counterReducer from './demo';
 import permissionReducer from './permission';
 import commonReducer from './common';
+import resultReducer from './action_results';
 
 const store = configureStore({
   reducer: {
@@ -13,6 +14,8 @@ const store = configureStore({
     scenario: scenarioReducer,
     permission: permissionReducer,
     common: commonReducer,
+    checkResult: resultReducer,
+    codeResult: resultReducer
   },
 });