Leon преди 2 години
родител
ревизия
3894a48b00

+ 38 - 5
src/components/input/SlidngScale.tsx

@@ -214,9 +214,35 @@ export default function Component(props: {
     // console.log(svg2)
     // debugger
 
+    var svgLine = `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="${rpxToPx(28)}">`;
+    var svgNumber = `<svg xmlns="http://www.w3.org/2000/svg" width="${list.length * 10 - 8+60}" height="${rpxToPx(38)}">`;
+    for (var i = 0; i < 10; i++) {
+        var obj = list[i];
+        svgLine += `<line x1="${i * 10 + 1}" y1="0" x2="${i * 10 + 1}" y2="${obj.showBig ? rpxToPx(28) : obj.showMiddle ? rpxToPx(24) : rpxToPx(16)}" stroke="${props.themeColor}"  stroke-width="2"/>`
+        
+    }
+    for (var i = 0; i < list.length; i++) {
+        var obj = list[i];
+        if (obj.showBig) {
+            //字体设置参考 https://segmentfault.com/a/1190000006110417
+            svgNumber += `<text x="${i * 10+1+30}" y="${rpxToPx(2 + 36)}" text-anchor="middle" fill="white" font-family="PingFang SC,Helvetica Neue,Helvetica,Arial,Hiragino Sans GB,Heiti SC,Microsoft YaHei" font-size="${rpxToPx(36)}">${obj.value}</text>`
+        }
+    }
+    svgLine += `</svg>`
+    svgNumber += `</svg>`
+
+    var basestr = encodeURIComponent(svgLine)
+    var imgLines = `url("data:image/svg+xml,${basestr}");`
+    var basestr2 = encodeURIComponent(svgNumber)
+    var imgNum = `url("data:image/svg+xml,${basestr2}");`
+
+
+
+    const isLeonTest = true
+
     return <View className="slidng">
         <View className="number_bg" style={{ opacity: enableText ? 1 : 0.4 }}>
-            <Text className="number">{current}</Text>
+            <Text className="number" style={{fontFamily:"PingFang SC,Helvetica Neue, Helvetica, Arial, Hiragino Sans GB, Heiti SC, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif;"}}>{current}</Text>
             <Text className="unit">{props.unit}</Text>
         </View>
 
@@ -242,7 +268,7 @@ export default function Component(props: {
                     <View className="scrollPadding" style={{ width: rpxToPx(372) }} />
                     <View className="content">
                         {
-                            list.map((item, index) => {
+                            !isLeonTest && list.map((item, index) => {
                                 return <View className={(item as any).showBig ? 'slidng_item_big' : (item as any).showMiddle ? 'slidng_item_middle' : 'slidng_item'}
                                     style={{ width: 2, marginRight: list.length - 1 == index ? 0 : 8, backgroundColor: props.themeColor, zIndex: 0 }} key={index}>
                                     {
@@ -251,9 +277,16 @@ export default function Component(props: {
                                 </View>
                             })
                         }
-                        {/* <View style={{ width: list.length * 10 - 8, height: 200 }}>
-                            <mysvg src={svg2} />
-                        </View> */}
+                        {
+                            isLeonTest && <View>
+                                <View style={{ width: list.length * 10 - 8, height: 100 }}>
+                                    {/* <mysvg src={svg2} /> */}
+                                    <View style={{ width: list.length * 10 - 8, height: rpxToPx(28), backgroundImage: imgLines }} />
+                                    <View style={{ width: list.length * 10 - 8+60,marginLeft:-30, height: rpxToPx(38), backgroundImage: imgNum }} />
+                                </View>
+                            </View>
+                        }
+
                     </View>
                     <View className="scrollPadding" />
 

+ 3 - 0
src/context/locales/zh.js

@@ -19,6 +19,9 @@ export default {
         metric: {
             title: '指标',
         },
+        food:{
+            title:'饮食',
+        },
         more: {
             title: '更多',
             un_login:'未登录',

+ 7 - 0
src/features/food/FoodConsole.scss

@@ -0,0 +1,7 @@
+.box11{
+    width: 304px;
+    height: 304px;
+    margin-left: 40px;
+    margin-right: 40px;
+    background-color: #00ffff;
+}

+ 93 - 0
src/features/food/FoodConsole.tsx

@@ -0,0 +1,93 @@
+import { View, Image } from '@tarojs/components'
+import './FoodConsole.scss'
+import { rpxToPx } from '@/utils/tools'
+import Taro from '@tarojs/taro'
+import Slider from '@/components/input/Slider'
+import { useEffect, useState } from 'react'
+
+export default function Component() {
+    const [imgUrl, setImgUrl] = useState(null)
+
+    useEffect(()=>{
+        var str  = Taro.getStorageSync('pic')
+        if (str && str.length>0){
+            setImgUrl(str)
+        }
+    },[])
+
+    function choose() {
+        clearFile()
+        Taro.chooseImage({
+            count: 1,
+            sizeType: ['compressed'],
+            sourceType: ['album'],
+            success: function (res) {
+                console.log(res)
+                var tempFilePaths = res.tempFilePaths
+                Taro.saveFile({
+                    tempFilePath: tempFilePaths[0],
+                    apFilePath: '',
+                    success: function (res) {
+                        var savedFilePath = res.savedFilePath
+                        Taro.setStorageSync('pic', savedFilePath)
+                        console.log(savedFilePath)
+                        setImgUrl(savedFilePath as any)
+                    }
+                })
+            }
+        })
+    }
+
+
+    function clearFile() {
+        Taro.getSavedFileList({
+            success: function (res) {
+                if (res.fileList.length > 0) {
+                    Taro.removeSavedFile({
+                        filePath: res.fileList[0].filePath,
+                        complete: function (res) {
+                            console.log(res)
+                            console.log('remove success')
+                        }
+                    })
+                }
+            }
+        })
+    }
+
+    function getCache(key: string) {
+        var value = Taro.getStorageSync(key)
+        if (value) {
+            return JSON.parse(value)
+        }
+        return null;
+    }
+
+    function saveCache(key: string) {
+        var strList = Taro.getStorageSync('food_operate')
+        var list: any = []
+        if (strList) {
+            list = JSON.parse(strList)
+        }
+        list.add({
+            key,
+            timestamp: new Date().getTime()
+        })
+        Taro.setStorageSync('food_operate', JSON.stringify(list)
+        )
+    }
+
+    return <View >
+        <View style={{ display: 'flex', width: rpxToPx(750), alignItems: 'center', justifyContent: 'center' }}>
+            <View style={{ display: 'flex', flexDirection: 'row' }}>
+                <Slider />
+                <View className='box11' onClick={choose}>{
+                    imgUrl && <Image style={{width:'100%',height:'100%'}} src={imgUrl} mode="aspectFill"/>
+                }
+                </View>
+                <Slider />
+            </View>
+
+        </View>
+    </View>
+}

+ 0 - 0
src/features/food/FoodTimeline.scss


+ 8 - 0
src/features/food/FoodTimeline.tsx

@@ -0,0 +1,8 @@
+import { View } from '@tarojs/components'
+import './FoodTimeline.scss'
+
+export default function Component(){
+    return <View>
+        
+    </View>
+}

+ 1 - 0
src/pages/account/Profile.config.ts

@@ -4,5 +4,6 @@ export default definePageConfig({
       // 'demo':'../../components/demo'
     },
     // "disableScroll": true
+    "enablePullDownRefresh": true,
     "navigationBarTitleText": ""
   })

+ 25 - 4
src/pages/account/Profile.tsx

@@ -1,8 +1,8 @@
 import Buttons from "@/components/basic/Buttons";
 import { delSession } from "@/services/common";
-import { clear, logout } from "@/services/user";
+import { clear, getInfo, logout } from "@/services/user";
 import { View, Text, Image, Switch } from "@tarojs/components";
-import Taro, { useDidShow, useShareAppMessage } from "@tarojs/taro";
+import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage } from "@tarojs/taro";
 import { useDispatch, useSelector } from "react-redux";
 import './Profile.scss'
 import Box from "@/components/layout/Box";
@@ -13,6 +13,7 @@ import TableCell from "@/components/layout/TableCell";
 import { useEffect, useState } from "react";
 import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
 import Tabbar from "@/components/navigation/TabBar";
+import { getInfoSuccess } from "@/store/user";
 let useNavigation;
 if (process.env.TARO_ENV == 'rn') {
     useNavigation = require("@react-navigation/native").useNavigation
@@ -23,6 +24,7 @@ export default function Page() {
     const { t } = useTranslation()
     const user = useSelector((state: any) => state.user);
     const [switchOn, setSwitchOn] = useState(false)
+    const [triggered, setTriggered] = useState(true)
 
     let navigation;
     if (useNavigation) {
@@ -112,7 +114,22 @@ export default function Page() {
         }
     }
 
-    console.log(user.avatar)
+    usePullDownRefresh(() => {
+        refresh()
+    })
+
+    function refresh() {
+        setTriggered(true)
+        getInfo().then(res => {
+            console.log(res)
+            Taro.stopPullDownRefresh()
+            dispatch(getInfoSuccess(res))
+            setTriggered(false)
+        }).catch(e => {
+            Taro.stopPullDownRefresh()
+            setTriggered(false)
+        })
+    }
 
     function detail() {
         return <View className="container">
@@ -221,7 +238,11 @@ export default function Page() {
 
     return <View>
         <Layout title={t('page.more.title')}
-            titleShowStyle={NaviBarTitleShowType.scrollToShow} type={TemplateType.flex}>
+            titleShowStyle={NaviBarTitleShowType.scrollToShow}
+            type={TemplateType.flex}
+            triggered={triggered}
+            refresh={refresh}
+        >
             {
                 detail()
             }

+ 2 - 0
src/pages/clock/Clock.rn.tsx

@@ -173,7 +173,9 @@ export default function IndexPage() {
 
 
     useReady(async () => {
+        debugger
         const userData = await getStorage('userData');
+        debugger
         if (userData) {
             dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
             setTimeout(() => {

+ 9 - 0
src/pages/food/Food.config.ts

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

+ 31 - 2
src/pages/food/Food.tsx

@@ -1,9 +1,38 @@
 import { View } from "@tarojs/components";
 import Tabbar from "@/components/navigation/TabBar";
 import './Food.scss'
+import Layout from "@/components/layout/layout";
+import { useTranslation } from "react-i18next";
+import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
+import TitleView from "@/features/trackTimeDuration/components/TitleView";
+import FoodConsole from '@/features/food/FoodConsole';
+import FoodTimeline from "@/features/food/FoodTimeline";
 
-export default function Page(){
+export default function Page() {
+    const { t } = useTranslation()
+    function headerView() {
+        return <TitleView title={t('page.food.title')} subTitle="hello world" showAddBtn={false}>
+        </TitleView>
+    }
+    function detail() {
+        return <View>
+            {
+                <FoodConsole />
+            }
+            {
+                <FoodTimeline />
+            }
+        </View>
+    }
     return <View>
-        <Tabbar index={4}/>
+        <Layout children={detail()}
+            title={t('page.food.title')}
+            type={TemplateType.customHeader}
+            header={headerView()}
+            refresh={() => { }}
+            triggered={false}
+            titleShowStyle={NaviBarTitleShowType.scrollToShow}
+        />
+        <Tabbar index={4} />
     </View>
 }

+ 11 - 5
src/services/user.tsx

@@ -96,12 +96,18 @@ export const clear = () => (dispatch: any) => {
     })
 }
 
-export const getInfo = () => (dispatch: any) => {
-    request({
-        url: API_USER_INFO, method: 'GET', data: {}
-    }).then(res => {
-        dispatch(getInfoSuccess(res));
+export const getInfo = () => {
+    return new Promise((resolve, reject) => {
+        request({
+            url: API_USER_INFO, method: 'GET', data: {}
+        }).then(res => {
+            return resolve(res)
+            // dispatch(getInfoSuccess(res));
+        }).catch(e=>{
+            return reject(e)
+        })
     })
+    
 }
 
 

+ 12 - 4
src/store/user.tsx

@@ -77,16 +77,24 @@ const userSlice = createSlice({
             Taro.clearStorage();
         },
         getInfoSuccess(state, action: PayloadAction<any>) {
-            const {id, nickname, avatar, token,scenario_select_count,test_user } = action.payload;
+            const {id, nickname, avatar,scenario_select_count,test_user,token } = action.payload;
             state.id = id;
             state.nickname = nickname;
             state.avatar = avatar;
-            state.token = token;
+            // 
             state.scenario_select_count = scenario_select_count;
             state.isLogin = true;
             state.test_user = test_user;
-            global.token = token;
-            Taro.setStorage({ key: 'userData', data: JSON.stringify(action.payload) });
+
+            var obj = JSON.parse(JSON.stringify(action.payload))
+            if (token){
+                state.token = token;
+                global.token = token;
+            }
+            else {
+                obj.token = state.token;
+            }
+            Taro.setStorage({ key: 'userData', data: JSON.stringify(obj) });
         },
         updateSuccess(state, action: PayloadAction<any>) {
             const { nickname, avatar } = action.payload;