|
|
@@ -1,4 +1,4 @@
|
|
|
-import { View, Image, Text } from '@tarojs/components'
|
|
|
+import { View, Image, Text, Switch } from '@tarojs/components'
|
|
|
import './FoodConsole.scss'
|
|
|
import { rpxToPx } from '@/utils/tools'
|
|
|
import Taro from '@tarojs/taro'
|
|
|
@@ -16,8 +16,11 @@ if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
}
|
|
|
|
|
|
-export default function Component(props: { addItem: Function }) {
|
|
|
+export default function Component(props: { addItem: Function, firstItem: any }) {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
+ const [modeOn, setModeOn] = useState(false)
|
|
|
+ const [firstData, setFirstData] = useState(props.firstItem)
|
|
|
+ const [lastUnFinished, setLastUnFinished] = useState(false)
|
|
|
const { t } = useTranslation()
|
|
|
const [imgUrl, setImgUrl] = useState('')
|
|
|
let navigation;
|
|
|
@@ -26,10 +29,23 @@ export default function Component(props: { addItem: Function }) {
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
- var str = Taro.getStorageSync('pic')
|
|
|
- if (str && str.length > 0) {
|
|
|
- setImgUrl(str)
|
|
|
+ setFirstData(props.firstItem)
|
|
|
+ }, [props.firstItem])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (firstData && firstData.status == 'ONGOING' &&
|
|
|
+ firstData.mindful_mode == 'AWARE' &&
|
|
|
+ (!firstData.feel.post_meal || !firstData.feel.pre_meal)) {
|
|
|
+ setLastUnFinished(true)
|
|
|
+ setModeOn(true)
|
|
|
}
|
|
|
+ }, [firstData])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ // var str = Taro.getStorageSync('pic')
|
|
|
+ // if (str && str.length > 0) {
|
|
|
+ // setImgUrl(str)
|
|
|
+ // }
|
|
|
}, [])
|
|
|
|
|
|
function choose(isAlbum = true) {
|
|
|
@@ -59,7 +75,7 @@ export default function Component(props: { addItem: Function }) {
|
|
|
console.log(savedFilePath)
|
|
|
setImgUrl(savedFilePath as any)
|
|
|
|
|
|
- uploadFile(savedFilePath,isAlbum ? 'album' : 'camera')
|
|
|
+ uploadFile(savedFilePath, isAlbum ? 'album' : 'camera')
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -105,7 +121,7 @@ export default function Component(props: { addItem: Function }) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- function uploadFile(path,source) {
|
|
|
+ function uploadFile(path, source) {
|
|
|
Taro.showLoading({
|
|
|
title: '加载中'
|
|
|
})
|
|
|
@@ -123,10 +139,10 @@ export default function Component(props: { addItem: Function }) {
|
|
|
file_ext: fileExt
|
|
|
},
|
|
|
success: (rsp) => {
|
|
|
- if (rsp.statusCode!=200){
|
|
|
+ if (rsp.statusCode != 200) {
|
|
|
Taro.showToast({
|
|
|
- title:'操作失败,请检查网络',
|
|
|
- icon:'none'
|
|
|
+ title: '操作失败,请检查网络',
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
@@ -137,7 +153,7 @@ export default function Component(props: { addItem: Function }) {
|
|
|
formData: rsp.data.fields,
|
|
|
success: rlt => {
|
|
|
console.log(rlt)
|
|
|
- createData(rsp.data.view_url,source)
|
|
|
+ createData(rsp.data.view_url, source)
|
|
|
|
|
|
// uploadAvatar(rsp.data.view_url)
|
|
|
// _this.changeAvatar(rsp.data.view_url);
|
|
|
@@ -153,7 +169,7 @@ export default function Component(props: { addItem: Function }) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function createData(url,source) {
|
|
|
+ function createData(url, source) {
|
|
|
var date = new Date();
|
|
|
var time = date.getTime()
|
|
|
var strDate = (date.getFullYear() + '') + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
|
|
|
@@ -162,12 +178,13 @@ export default function Component(props: { addItem: Function }) {
|
|
|
media: [{
|
|
|
url,
|
|
|
type: url.indexOf('mp4') != -1 ? 'video' : 'image',
|
|
|
- source:source
|
|
|
+ source: source
|
|
|
}],
|
|
|
start: {
|
|
|
timestamp: time,
|
|
|
date: strDate
|
|
|
- }
|
|
|
+ },
|
|
|
+ mindful_mode: modeOn ? 'AWARE' : 'NORMAL'
|
|
|
|
|
|
}).then(res => {
|
|
|
props.addItem(res)
|
|
|
@@ -175,32 +192,48 @@ export default function Component(props: { addItem: Function }) {
|
|
|
setImgUrl('')
|
|
|
Taro.removeStorageSync('pic')
|
|
|
Taro.hideLoading()
|
|
|
+ setFirstData(res)
|
|
|
+ // if (modeOn) {
|
|
|
+ // setSwitchDisable(true)
|
|
|
+ // }
|
|
|
}).catch(e => {
|
|
|
Taro.hideLoading()
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function modeChange(e) {
|
|
|
+ setModeOn(e.detail.value)
|
|
|
+ }
|
|
|
+
|
|
|
return <View style={{ marginBottom: rpxToPx(60) }}>
|
|
|
- <View style={{ display: 'flex', width: rpxToPx(750), alignItems: 'center', justifyContent: 'center', flexDirection: 'column' }}>
|
|
|
- <View style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
- {/* <Slider /> */}
|
|
|
- {/* <View className='box11' onClick={()=>choose(true)}>{
|
|
|
- imgUrl && <Image style={{ width: '100%', height: '100%' }} src={imgUrl} mode="aspectFill" />
|
|
|
- }
|
|
|
- </View> */}
|
|
|
- <View className='camera_bg' onClick={() => choose(false)}>
|
|
|
- <Image src={require('@assets/images/camera2.png')} className='camera_icon' />
|
|
|
- <Text className='camera_text'>{t('feature.food.camera')}</Text>
|
|
|
- <Text className='album_text'>{t('feature.food.album')}</Text>
|
|
|
- <View className='album_bottom' onClick={(e) => { choose(true); e.stopPropagation() }} />
|
|
|
- </View>
|
|
|
- {/* <Slider /> */}
|
|
|
+ <View className='food_console_box'>
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
|
+ <Text className='food_console_title'>感知模式</Text>
|
|
|
+ <Switch disabled={lastUnFinished} checked={modeOn} color={ColorType.food} style={{ marginRight: rpxToPx(40), opacity: lastUnFinished ? 0.4 : 1 }} onChange={modeChange} />
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View className='food_console_desc'>
|
|
|
+ <View className='food_console_desc_point' style={{ backgroundColor: ColorType.food }} />
|
|
|
+ <Text>{t('feature.food.sence_desc')}</Text>
|
|
|
</View>
|
|
|
- {/* <IconShare color={ColorType.food} width={100} height={100} /> */}
|
|
|
- {/* <View className='demo1' /> */}
|
|
|
- {/* <Text style={{ color: '#fff',marginBottom:20 }} onClick={()=>choose(false)}>拍照</Text>
|
|
|
- <Text style={{ color: '#fff' }} onClick={uploadFile}>上传</Text> */}
|
|
|
|
|
|
</View>
|
|
|
+ {
|
|
|
+ !lastUnFinished && <View style={{ display: 'flex', width: rpxToPx(750), alignItems: 'center', justifyContent: 'center', flexDirection: 'column' }}>
|
|
|
+ <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
|
|
|
+ <View className='camera_bg' onClick={() => choose(false)}>
|
|
|
+ <Image src={require('@assets/images/camera2.png')} className='camera_icon' />
|
|
|
+ <Text className='camera_text'>{t('feature.food.camera')}</Text>
|
|
|
+ <Text className='album_text'>{t('feature.food.album')}</Text>
|
|
|
+ <View className='album_bottom' onClick={(e) => { choose(true); e.stopPropagation() }} />
|
|
|
+ </View>
|
|
|
+ {
|
|
|
+ modeOn && <View style={{ height: rpxToPx(60) }} />
|
|
|
+ }
|
|
|
+ {modeOn && <Slider />}
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ }
|
|
|
+
|
|
|
</View>
|
|
|
}
|