|
|
@@ -1,6 +1,6 @@
|
|
|
import { View, Image, Text, Switch } from '@tarojs/components'
|
|
|
import './FoodConsole.scss'
|
|
|
-import { rpxToPx } from '@/utils/tools'
|
|
|
+import { rpxToPx, vibrate } from '@/utils/tools'
|
|
|
import Taro from '@tarojs/taro'
|
|
|
import Slider from '@/components/input/Slider'
|
|
|
import { useEffect, useState } from 'react'
|
|
|
@@ -12,6 +12,7 @@ import { IconShare } from '@/components/basic/Icons'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import { ColorType } from '@/context/themes/color'
|
|
|
import { clearFoodCache, getFoodCache, saveFoodCache } from './hooks/ExtraData'
|
|
|
+import { async } from 'q'
|
|
|
let useNavigation;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
@@ -43,8 +44,8 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
useEffect(() => {
|
|
|
if (firstData &&
|
|
|
firstData.mindful_mode == 'AWARE' &&
|
|
|
- (firstData.status != 'PART_COMPLETED' && firstData.status!='COMPLETED')
|
|
|
- ) {
|
|
|
+ (firstData.status != 'PART_COMPLETED' && firstData.status != 'COMPLETED')
|
|
|
+ ) {
|
|
|
setLastUnFinished(true)
|
|
|
setModeOn(true)
|
|
|
}
|
|
|
@@ -74,7 +75,7 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
// }
|
|
|
}, [])
|
|
|
|
|
|
- function choose(isAlbum = true) {
|
|
|
+ async function choose(isAlbum = true) {
|
|
|
if (!user.isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return;
|
|
|
@@ -87,66 +88,64 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
|
|
|
saveFoodCache('create', params)
|
|
|
|
|
|
- clearFile()
|
|
|
- Taro.chooseMedia({
|
|
|
- count: 1,
|
|
|
- sizeType: ['compressed'],
|
|
|
- mediaType: ['image'],
|
|
|
- sourceType: [isAlbum ? 'album' : 'camera'],
|
|
|
- success: function (res) {
|
|
|
- var params = {
|
|
|
- event: 'add_a_picture',
|
|
|
- value: isAlbum ? 'choose_from_album_confirm' : 'use_camera_confirm',
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ Taro.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ sourceType: [isAlbum ? 'album' : 'camera'],
|
|
|
+ success: function (res) {
|
|
|
+ chooseSuccess(res, isAlbum)
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ chooseFailed(res, isAlbum)
|
|
|
}
|
|
|
+ })
|
|
|
|
|
|
- saveFoodCache('create', params)
|
|
|
-
|
|
|
- var tempFilePath = res.tempFiles[0].tempFilePath
|
|
|
- // Taro.editImage({
|
|
|
- // src:tempFilePath,
|
|
|
- // success:function(res){
|
|
|
- // console.log(res)
|
|
|
- // }
|
|
|
- // })
|
|
|
- Taro.getFileSystemManager().saveFile({
|
|
|
- tempFilePath: tempFilePath,
|
|
|
- success: function (res) {
|
|
|
- var savedFilePath = res.savedFilePath
|
|
|
- Taro.setStorageSync('pic', savedFilePath)
|
|
|
- console.log(savedFilePath)
|
|
|
- setImgUrl(savedFilePath as any)
|
|
|
-
|
|
|
- uploadFile(savedFilePath, isAlbum ? 'album' : 'camera')
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- var params = {
|
|
|
- event: 'add_a_picture',
|
|
|
- value: isAlbum ? 'choose_from_album_cancel' : 'use_camera_cancel',
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Taro.chooseMedia({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ mediaType: ['image'],
|
|
|
+ sourceType: [isAlbum ? 'album' : 'camera'],
|
|
|
+ success: function (res) {
|
|
|
+ chooseSuccess(res, isAlbum)
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ chooseFailed(res, isAlbum)
|
|
|
}
|
|
|
-
|
|
|
- saveFoodCache('create', params)
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ async function chooseSuccess(res, isAlbum) {
|
|
|
+ var params = {
|
|
|
+ event: 'add_a_picture',
|
|
|
+ value: isAlbum ? 'choose_from_album_confirm' : 'use_camera_confirm',
|
|
|
+ }
|
|
|
+
|
|
|
+ saveFoodCache('create', params)
|
|
|
+
|
|
|
+ var savedFilePath = process.env.TARO_ENV=='rn'?res.tempFiles[0].path:res.tempFiles[0].tempFilePath
|
|
|
+
|
|
|
+ // var savedFilePath = res.savedFilePath
|
|
|
+ await Taro.setStorage({key:'pic', data:savedFilePath})
|
|
|
+ console.log(savedFilePath)
|
|
|
+ setImgUrl(savedFilePath as any)
|
|
|
+
|
|
|
+ uploadFile(savedFilePath, isAlbum ? 'album' : 'camera')
|
|
|
+
|
|
|
|
|
|
- function clearFile() {
|
|
|
- Taro.getFileSystemManager().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 chooseFailed(res, isAlbum) {
|
|
|
+ var params = {
|
|
|
+ event: 'add_a_picture',
|
|
|
+ value: isAlbum ? 'choose_from_album_cancel' : 'use_camera_cancel',
|
|
|
+ }
|
|
|
+
|
|
|
+ saveFoodCache('create', params)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
function uploadFile(path, source) {
|
|
|
Taro.showLoading({
|
|
|
@@ -195,11 +194,12 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function createData(url, source) {
|
|
|
+ async 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());
|
|
|
-
|
|
|
+ var event = await getFoodCache('create')
|
|
|
+ debugger
|
|
|
createFoodJournal({
|
|
|
media: [{
|
|
|
url,
|
|
|
@@ -212,42 +212,32 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
},
|
|
|
mindful_mode: modeOn ? 'AWARE' : 'NORMAL',
|
|
|
extra: {
|
|
|
- event: getFoodCache('create')
|
|
|
+ event: event
|
|
|
}
|
|
|
- // extra:getFoodCache('create')
|
|
|
|
|
|
}).then(res => {
|
|
|
props.addItem(res)
|
|
|
- clearFile()
|
|
|
setImgUrl('')
|
|
|
- Taro.removeStorageSync('pic')
|
|
|
+ Taro.removeStorage({key:'pic'})
|
|
|
Taro.hideLoading()
|
|
|
setFirstData(res)
|
|
|
clearFoodCache('create')
|
|
|
- // if (modeOn) {
|
|
|
- // setSwitchDisable(true)
|
|
|
- // }
|
|
|
}).catch(e => {
|
|
|
Taro.hideLoading()
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function modeChange(e) {
|
|
|
+ async function modeChange(e) {
|
|
|
+
|
|
|
setModeOn(e.detail.value)
|
|
|
- Taro.setStorageSync('food_switch', e.detail.value)
|
|
|
- // if (e.detail.value) {
|
|
|
- // Taro.showToast({
|
|
|
- // icon: 'success',
|
|
|
- // title: t('feature.food.mindful_switch_on'),
|
|
|
- // duration: 500
|
|
|
- // })
|
|
|
- // }
|
|
|
+ await Taro.setStorage({key:'food_switch', data:e.detail.value})
|
|
|
|
|
|
var params = {
|
|
|
event: 'switch_toggle',
|
|
|
value: e.detail.value ? 'on' : 'off',
|
|
|
}
|
|
|
|
|
|
+
|
|
|
saveFoodCache('create', params)
|
|
|
}
|
|
|
|
|
|
@@ -265,20 +255,12 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
}
|
|
|
else {
|
|
|
return props.firstItem ? 0 : rpxToPx(60)
|
|
|
- // if (modeOn){
|
|
|
- // return 0//-rpxToPx(60)
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // return 0
|
|
|
- // }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function clickSwitch() {
|
|
|
if (lastUnFinished) {
|
|
|
- Taro.vibrateShort({
|
|
|
- type: 'heavy'
|
|
|
- })
|
|
|
+ vibrate('heavy')
|
|
|
Taro.showModal({
|
|
|
title: t('feature.common.prompt'),
|
|
|
content: t('feature.food.disable_switch_modal_title'),
|
|
|
@@ -292,7 +274,12 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
<View className='food_console_box'>
|
|
|
<View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
|
<Text className='food_console_title'>感知模式</Text>
|
|
|
- <Switch className='myswitch' onClick={clickSwitch} disabled={lastUnFinished} checked={modeOn} color={props.firstItem && props.firstItem.status == 'WAIT_FOR_POSTMEAL' ?ColorType.food:ColorType.fast} style={{ marginRight: rpxToPx(40), opacity: lastUnFinished ? 0.4 : 1 }} onChange={modeChange} />
|
|
|
+ <Switch className='myswitch'
|
|
|
+ onClick={clickSwitch}
|
|
|
+ disabled={lastUnFinished} checked={modeOn}
|
|
|
+ color={props.firstItem && props.firstItem.status == 'WAIT_FOR_POSTMEAL' ? ColorType.food : ColorType.fast}
|
|
|
+ style={{ marginRight: rpxToPx(40), opacity: lastUnFinished ? 0.4 : 1 }}
|
|
|
+ onChange={modeChange} />
|
|
|
</View>
|
|
|
{
|
|
|
modeOn && <View className='food_console_desc'>
|
|
|
@@ -301,15 +288,12 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
backgroundColor: props.firstItem && props.firstItem.status == 'WAIT_FOR_POSTMEAL' ? ColorType.food : ColorType.fast,
|
|
|
marginTop: props.firstItem && props.firstItem.status == 'WAIT_FOR_POSTMEAL' ? rpxToPx(46 + 18) : rpxToPx(18)
|
|
|
}} />
|
|
|
- {/* <View className='food_console_desc_point' style={{ backgroundColor: ColorType.food }} /> */}
|
|
|
- <Text>{t('feature.food.sence_desc')}</Text>
|
|
|
+ <Text style={{ color: '#ffffff66' }}>{t('feature.food.sence_desc')}</Text>
|
|
|
</View>
|
|
|
}
|
|
|
{
|
|
|
!modeOn && <View className='food_console_desc_off'>
|
|
|
-
|
|
|
- <Text>{t('feature.food.sence_desc_off')}</Text>
|
|
|
- {/* <Text style={{ color: ColorType.food }} onClick={more}>{t('feature.food.learn_more')}</Text> */}
|
|
|
+ <Text style={{ color: '#ffffff66' }}>{t('feature.food.sence_desc_off')}</Text>
|
|
|
</View>
|
|
|
}
|
|
|
</View>
|
|
|
@@ -320,7 +304,12 @@ export default function Component(props: { addItem: Function, firstItem: any })
|
|
|
<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 className='album_bottom' onClick={(e) => {
|
|
|
+ choose(true);
|
|
|
+ if (process.env.TARO_ENV == 'weapp') {
|
|
|
+ e.stopPropagation()
|
|
|
+ }
|
|
|
+ }} />
|
|
|
</View>
|
|
|
{
|
|
|
modeOn && <View style={{ height: rpxToPx(60) }} />
|