MainConsole.tsx 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. import { WindowStatusType, WindowType } from "@/utils/types";
  2. import { View, Text, Image, Swiper, SwiperItem } from "@tarojs/components";
  3. import dayjs from "dayjs";
  4. import { useEffect, useRef, useState } from "react";
  5. import { useDispatch, useSelector } from "react-redux";
  6. import './MainConsole.scss'
  7. import { jumpPage } from "../trackTimeDuration/hooks/Common";
  8. import Modal from "@/components/layout/Modal.weapp";
  9. import { MainColorType } from "@/context/themes/color";
  10. import ConsolePicker from "../trackTimeDuration/components/ConsolePicker";
  11. import { clockTimes, delRecord, getLabelsEvent, makeDone, updateEventDuration, updateFast, updateSchedule, updateTarget } from "@/services/health";
  12. import TimePicker from "../common/TimePicker";
  13. import showActionSheet from "@/components/basic/ActionSheet";
  14. import { rpxToPx } from "@/utils/tools";
  15. import { setMode, setShowActionTip } from "@/store/health";
  16. import { getCountownTime, getDuration, getScenario, getThemeColor, getWindowStatus } from "./hooks/health_hooks";
  17. import { IconActive, IconArrow, IconCircle, IconClose, IconMiss, IconMore, IconNotification, IconNotificationOff, IconSwitch } from "@/components/basic/Icons";
  18. import DurationPicker from "@/_health/components/duration_picker";
  19. import Taro from "@tarojs/taro";
  20. import { systemLocation } from "@/services/common";
  21. import { TimeFormatter } from "@/utils/time_format";
  22. import { clearLocation } from "@/services/user";
  23. import OnBoard from "@/_health/components/onboard";
  24. import NewButton, { NewButtonType } from "@/_health/base/new_button";
  25. import showAlert from "@/components/basic/Alert";
  26. import { useTranslation } from "react-i18next";
  27. import Cell from "@/_health/base/cell";
  28. import ConsoleCell from "@/_health/components/console_cell";
  29. import IconTitleCell from "@/_health/components/icon_title_cell";
  30. import StatusIndicator, { StatusType } from "@/_health/base/status_indicator";
  31. import AddLabel from "@/_health/components/add_label";
  32. let useNavigation;
  33. let min = 0
  34. let max = 0
  35. let defaultTimestamp = 0
  36. let lastFastSleepStatus = ''
  37. if (process.env.TARO_ENV == 'rn') {
  38. useNavigation = require("@react-navigation/native").useNavigation
  39. }
  40. export default function MainConsole(props: { type: WindowType }) {
  41. const health = useSelector((state: any) => state.health);
  42. const user = useSelector((state: any) => state.user);
  43. const [durationPicker, setDurationPicker] = useState(false)
  44. const [btnDisable, setBtnDisable] = useState(false)
  45. const [selItem, setSelItem] = useState<any>(null)
  46. const [hideGuideTip, setHideGuideTip] = useState(false)
  47. const [hideErrorTip, setHideErrorTip] = useState(false)
  48. const [labels, setLabels] = useState<any>([])
  49. const [showModal, setShowModal] = useState(false)
  50. const [hideEatArchiveTip, setHideEatArchiveTip] = useState(false)
  51. const [hideActiveArchiveTip, setHideActiveArchiveTip] = useState(false)
  52. const [hideFastTip, setHideFastTip] = useState(false)
  53. const [hideSleepTip, setHideSleepTip] = useState(false)
  54. const { t } = useTranslation()
  55. const dispatch = useDispatch()
  56. let navigation, showActionSheetWithOptions;
  57. if (useNavigation) {
  58. navigation = useNavigation()
  59. }
  60. useEffect(() => {
  61. getLabelsEvent({ window: 'ACTIVE' }).then(res => {
  62. setLabels((res as any).labels)
  63. })
  64. }, [])
  65. useEffect(() => {
  66. if (health.fast_with_sleep.status == 'OG2_MISALIGNED' || health.fast_with_sleep.status == 'OG2_NO1') {
  67. if (lastFastSleepStatus != health.fast_with_sleep.status) {
  68. setHideErrorTip(false)
  69. }
  70. }
  71. lastFastSleepStatus = health.fast_with_sleep.status
  72. }, [health.fast_with_sleep.status])
  73. global.chooseLocation = () => {
  74. chooseLocation()
  75. }
  76. global.postMomentSuccess = () => {
  77. if (health.mode == 'ACTIVE') {
  78. setHideActiveArchiveTip(false)
  79. global.hideActiveArchiveTip = false
  80. }
  81. else {
  82. setHideEatArchiveTip(false)
  83. global.hideEatArchiveTip = false
  84. }
  85. }
  86. global.postFastBeginSuccess = () => {
  87. setHideFastTip(false)
  88. global.hideFastTip = false
  89. }
  90. global.postSleepBeginSuccess = () => {
  91. setHideSleepTip(false)
  92. global.hideSleepTip = false
  93. }
  94. function edit(item) {
  95. if (item.scenario != 'FAST' && item.scenario != 'SLEEP') {
  96. return
  97. }
  98. if (item.action == 'NA' || item.action == 'POST_MOMENT' || 'SLEEP_WAKE_UP' == item.action) {
  99. return;
  100. }
  101. if (!user.isLogin) {
  102. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  103. return
  104. }
  105. console.log(item)
  106. setSelItem(item)
  107. }
  108. function record(item) {
  109. if (!user.isLogin) {
  110. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  111. return
  112. }
  113. if ((item.event == 'FAST_START' || item.event == 'FAST_END') && health.long_fast.status == 'OG') {
  114. showAlert({
  115. title: '长断食进行中',
  116. content: '当前有一个正在进行的长断食记录,要转换为间歇性断食吗?',
  117. showCancel: true,
  118. cancelText: '取消',
  119. confirmText: '确定',
  120. confirm: () => {
  121. changeToIF();
  122. }
  123. })
  124. return
  125. }
  126. setSelItem(item)
  127. switch (item.action) {
  128. case 'START':
  129. {
  130. jumpPage(`/_health/pages/log_time?index=${health.mode == 'FAST' ? 0 : 1}&single=1&is_start=1&window=${health.mode}`)
  131. }
  132. return;
  133. case 'END':
  134. {
  135. var sceniaro = getScenario(health.windows, health.mode)
  136. jumpPage(`/_health/pages/log_time?type=home&index=${health.mode == 'FAST' ? 3 : 2}&single=${sceniaro.status == 'OG' ? 1 : 0}&is_start=0&window=${health.mode}`)
  137. }
  138. return;
  139. case 'MARK_DONE':
  140. {
  141. setBtnDisable(true)
  142. clockTimes({
  143. check_items: [{
  144. schedule_id: item.schedule_id,
  145. date: dayjs().format('YYYYMMDD'),
  146. timestamp: new Date().getTime()
  147. }]
  148. }).then(res => {
  149. Taro.showToast({
  150. title: '操作成功',
  151. icon: 'success'
  152. })
  153. global.refreshWindow()
  154. global.refreshHistory()
  155. }).catch(e => {
  156. })
  157. }
  158. return;
  159. }
  160. jumpPage(`/_health/pages/add_moment?moment=${JSON.stringify(item)}&title=${item.title}&schedule_id=${item.schedule_id}&event_id=${item.event_id}`)
  161. }
  162. function operateTitle(item) {
  163. return t('health.log')
  164. // switch (item.action) {
  165. // case 'START':
  166. // case 'END':
  167. // return '打卡'
  168. // case 'MARK_DONE':
  169. // return 'Action'
  170. // }
  171. // return '记录'
  172. }
  173. function itemTitle(item: any) {
  174. // if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  175. // return item.title
  176. // }
  177. if (item.real) {
  178. return TimeFormatter.dayjsFormat(item.real.timestamp)
  179. // return dayjs(item.real.timestamp).format('MM-DD HH:mm')
  180. }
  181. if (!item.target || !item.target.timestamp) {
  182. return item.time_label
  183. }
  184. return TimeFormatter.dayjsFormat(item.target.timestamp)
  185. // return dayjs(item.target.timestamp).format('MM-DD HH:mm')
  186. }
  187. function itemValue(item: any) {
  188. let themeColor: any = getThemeColor(health.mode)
  189. // const scenario = getScenario(health.windows, health.mode)
  190. // if (item.action == 'END' && !scenario.real) {
  191. // themeColor = MainColorType.g01
  192. // }
  193. if (item.target && item.target.timestamp >= new Date().getTime()) {
  194. themeColor = MainColorType.g02
  195. }
  196. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  197. return null
  198. }
  199. if (item.action && item.action != 'NA') {
  200. if (health.mode == 'FAST' || health.mode == 'SLEEP') {
  201. if (item.action == 'POST_MOMENT') {
  202. return <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
  203. }
  204. }
  205. // else if (health.mode == 'ACTIVE' && item.action == 'POST_MOMENT') {
  206. // return <NewButton
  207. // color={themeColor}
  208. // type={NewButtonType.border}
  209. // title={operateTitle(item)}
  210. // width={rpxToPx(128)}
  211. // height={rpxToPx(72)}
  212. // bold={true}
  213. // onClick={() => record(item)} />
  214. // }
  215. return <NewButton
  216. color={themeColor}
  217. type={item.target && item.target.timestamp >= new Date().getTime() ? NewButtonType.alpha2 : NewButtonType.alpha}
  218. title={operateTitle(item)}
  219. width={rpxToPx(128)}
  220. height={rpxToPx(72)}
  221. bold={true}
  222. onClick={() => record(item)} />
  223. }
  224. if (item.action && item.action == 'NA') {
  225. // if (health.mode == 'FAST' || health.mode == 'SLEEP') {
  226. if (item.moment && item.moment.media && item.moment.media.length > 0) {
  227. return <Image
  228. src={item.moment.media[0].url}
  229. mode="aspectFill"
  230. className="console_item_img" />
  231. }
  232. else {
  233. return <IconArrow width={rpxToPx(34)} color={MainColorType.g02} />
  234. }
  235. // }
  236. }
  237. return <View />
  238. }
  239. function canTap(item) {
  240. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  241. return false;
  242. }
  243. if (!user.isLogin) {
  244. return false
  245. }
  246. if (!item.event_id) {
  247. return false
  248. }
  249. return true
  250. }
  251. function tapTimeline(item, inex) {
  252. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  253. return;
  254. }
  255. if (!user.isLogin) {
  256. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  257. return
  258. }
  259. if (!item.event_id) {
  260. return
  261. }
  262. jumpPage(`/_health/pages/timeline_detail?event_id=${item.event_id}&schedule_id=${item.schedule_id}`)
  263. }
  264. function processIcon(index) {
  265. const time = new Date().getTime()
  266. const scenario = getScenario(health.windows, health.mode)
  267. const timeline = scenario.timeline[index]
  268. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  269. if (time > timeline.target.timestamp) {
  270. return <Image style={{ width: rpxToPx(24), height: rpxToPx(24) }} src={require('@assets/_health/checked.png')} />
  271. }
  272. return <IconCircle width={rpxToPx(32)} color={MainColorType.g02} />
  273. // return <View style={{width:rpxToPx(26),height:rpxToPx(26),borderRadius:rpxToPx(13),backgroundColor:'#fff'}}/>
  274. }
  275. // if (timeline.target.timestamp < new Date().getTime()) {
  276. // return <IconMiss color="#fff" width={rpxToPx(24)} />
  277. // }
  278. if (timeline.real) {
  279. return <Image style={{ width: rpxToPx(24), height: rpxToPx(24) }} src={require('@assets/_health/checked.png')} />
  280. }
  281. return <View style={{ width: rpxToPx(26), height: rpxToPx(26), borderRadius: rpxToPx(13), backgroundColor: '#fff' }} />
  282. // return timeline.reminder ? <IconNotification color="#fff" width={rpxToPx(24)} /> : <IconNotificationOff color="#fff" width={rpxToPx(24)} />
  283. }
  284. function timelineItem(item: any, index: number, count: number) {
  285. var strColor = ''
  286. if (item.real) {
  287. strColor = getThemeColor(health.mode)
  288. }
  289. else if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  290. const time = new Date().getTime()
  291. const scenario = getScenario(health.windows, health.mode)
  292. const timeline = scenario.timeline[index]
  293. if (time > timeline.target.timestamp) {
  294. strColor = getThemeColor(health.mode)
  295. }
  296. else {
  297. strColor = 'transparent'
  298. }
  299. }
  300. else {
  301. strColor = 'transparent'
  302. }
  303. function statusView() {
  304. return <StatusIndicator type={StatusType.console}
  305. color={strColor}
  306. fontColor={item.real ? getThemeColor(health.mode) : MainColorType.g01}
  307. bold={item.real ? true : false}
  308. // color={new Date().getTime()<item.target.timestamp?MainColorType.g02:getThemeColor(health.mode)}
  309. text={itemTitle(item)}
  310. fontSize={rpxToPx(24)}
  311. >{
  312. (item.real || (health.mode == 'DAY' || health.mode == 'NIGHT')) ? processIcon(index) : <IconCircle width={rpxToPx(32)} color={MainColorType.g02} />
  313. }</StatusIndicator>
  314. }
  315. return <ConsoleCell
  316. status={statusView()}
  317. title={(item.moment && item.moment.title) ? item.moment.title : item.title}
  318. description={item.moment ? item.moment.description : null}
  319. right={itemValue(item)}
  320. disable={!canTap(item)}
  321. onClick={() => tapTimeline(item, index)}
  322. showLine={true}
  323. fullLine={count - 1 == index}
  324. />
  325. }
  326. function changeToIF() {
  327. updateFast({ fast_type: 'IF' }).then(res => {
  328. global.refreshWindow()
  329. })
  330. }
  331. function actionList() {
  332. var list: any = []
  333. switch (health.mode) {
  334. case 'ACTIVE':
  335. {
  336. if (!health.finish_setup) {
  337. list.push(t('health.finish_setup'))
  338. }
  339. list.push(t('health.log_extra_activity'))
  340. var scenario = getScenario(health.windows, 'ACTIVE')
  341. if (scenario.status != 'WFS') {
  342. list.push(t('health.mark_done'))
  343. }
  344. if (health.finish_setup) {
  345. list.push(t('health.edit_schedule'))
  346. }
  347. }
  348. break;
  349. case 'EAT':
  350. {
  351. if (!health.finish_setup) {
  352. list.push(t('health.finish_setup'))
  353. }
  354. list.push(t('health.log_extra_meal'))
  355. var scenario = getScenario(health.windows, 'EAT')
  356. if (scenario.status != 'WFS') {
  357. list.push(t('health.mark_done'))
  358. }
  359. if (health.finish_setup) {
  360. list.push(t('health.edit_schedule'))
  361. }
  362. }
  363. break;
  364. case 'FAST':
  365. case 'SLEEP':
  366. {
  367. if (!health.finish_setup) {
  368. list.push(t('health.finish_setup'))
  369. }
  370. const obj = getScenario(health.windows, health.mode)
  371. if (obj.window_id) {
  372. list.push(t('health.delete_current_record'))
  373. }
  374. if (health.finish_setup) {
  375. list.push(t('health.edit_schedule'))
  376. }
  377. }
  378. break;
  379. case 'DAY':
  380. case 'NIGHT':
  381. {
  382. list = [t('health.change_location'), t('health.clear_location')]
  383. }
  384. break;
  385. }
  386. return list;
  387. }
  388. function more() {
  389. if (!user.isLogin) {
  390. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  391. return
  392. }
  393. var strTitle = ''
  394. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  395. strTitle = getLocation()
  396. }
  397. else if (health.mode == 'EAT' || health.mode == 'ACTIVE') {
  398. const scenario = getScenario(health.windows, health.mode)
  399. if (scenario.archive_timestamp) {
  400. /*"Today's logs will be archived at 23:59."
  401. "Today's logs will be archived at 03:10 tomorrow."
  402. "今日记录将于 23:59 归档"
  403. "今日记录将于明天 23:59 归档"*/
  404. var today = new Date().getDate()
  405. var date = new Date(scenario.archive_timestamp).getDate()
  406. strTitle = `今日记录将于${today == date ? '' : '明天'} ${dayjs(scenario.archive_timestamp).format('HH:mm')} 归档`
  407. }
  408. else {
  409. strTitle = t('health.more_actions')
  410. }
  411. }
  412. else {
  413. strTitle = t('health.more_actions')
  414. }
  415. showActionSheet({
  416. showActionSheetWithOptions: showActionSheetWithOptions,
  417. title: strTitle,
  418. itemList: actionList(),
  419. success: (res) => {
  420. tapActionSheet(res)
  421. }
  422. });
  423. }
  424. function getLocation() {
  425. var scenario = getScenario(health.windows, health.mode)
  426. if (!scenario.extra.choose_location) {
  427. return t('health.more_actions')
  428. }
  429. return `${getCity()}${Math.abs(parseInt(scenario.extra.lat))}°${parseInt(scenario.extra.lat) < 0 ? 'S' : 'N'} ${Math.abs(parseInt(scenario.extra.lng))}°${parseInt(scenario.extra.lng) < 0 ? 'W' : 'E'}`
  430. }
  431. function getCity() {
  432. var city = ''
  433. var scenario = getScenario(health.windows, health.mode)
  434. if (scenario.extra.address) {
  435. if (scenario.extra.address.city.length > 0) {
  436. city = scenario.extra.address.city
  437. }
  438. else if (scenario.extra.address.province.length > 0) {
  439. city = scenario.extra.address.province
  440. }
  441. else if (scenario.extra.address.country.length > 0) {
  442. city = scenario.extra.address.country
  443. }
  444. else {
  445. return ''
  446. // city = t('feature.track_time_duration.third_ring.unknown')
  447. }
  448. }
  449. else {
  450. return ''
  451. // city = t('feature.track_time_duration.third_ring.unknown')
  452. }
  453. return city +' | '
  454. }
  455. function tapActionSheet(index) {
  456. var title = actionList()[index]
  457. switch (title) {
  458. case t('health.finish_setup'):
  459. tapGuide();
  460. break;
  461. case t('health.log_extra_activity'):
  462. jumpPage(`/_health/pages/add_moment?title=&is_temp=${true}`)
  463. break;
  464. case t('health.log_extra_meal'):
  465. jumpPage(`/_health/pages/add_moment?title=加餐&is_temp=${true}`)
  466. break;
  467. case t('health.mark_done'):
  468. tapMakeDone()
  469. break
  470. case t('health.edit_schedule'):
  471. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  472. break
  473. case t('health.delete_current_record'):
  474. {
  475. const obj = getScenario(health.windows, health.mode)
  476. showAlert({
  477. title: 'del',
  478. content: '确认删除此记录?',
  479. showCancel: true,
  480. confirm: () => {
  481. delRecord({ ids: [obj.window_id] }).then(res => {
  482. global.refreshWindow()
  483. if ((res as any).status_change) {
  484. if ((res as any).status_change.previous != (res as any).status_change.current) {
  485. //灵动岛弹窗
  486. setTimeout(() => {
  487. dispatch(setShowActionTip({
  488. isShow: true,
  489. isCompleted: false
  490. }))
  491. }, 1000)
  492. }
  493. }
  494. })
  495. }
  496. })
  497. }
  498. break;
  499. case t('health.change_location'):
  500. chooseLocation()
  501. break
  502. case t('health.clear_location'):
  503. tapClearLocation()
  504. break
  505. }
  506. }
  507. function tapGuide() {
  508. jumpPage('/_health/pages/guide_begin')
  509. // showAlert({
  510. // title:'设置引导弹窗',
  511. // content:'设置引导描述',
  512. // showCancel:true,
  513. // cancelText:'稍后',
  514. // confirmText:'设置',
  515. // cancel:()=>{
  516. // },
  517. // confirm:()=>{
  518. // jumpPage('/_health/pages/guide_fast')
  519. // }
  520. // })
  521. }
  522. function tapMakeDone() {
  523. makeDone(getScenario(health.windows, health.mode).window_id).then(res => {
  524. global.refreshWindow()
  525. global.refreshHistory()
  526. if ((res as any).status_change) {
  527. if ((res as any).status_change.previous != (res as any).status_change.current) {
  528. //灵动岛弹窗
  529. setTimeout(() => {
  530. dispatch(setShowActionTip({
  531. isShow: true,
  532. isCompleted: false
  533. }))
  534. }, 1000)
  535. }
  536. }
  537. })
  538. }
  539. function detail() {
  540. const { day, night } = health.windows.night_day
  541. const { fast, eat } = health.windows.fast_eat
  542. const { sleep, active } = health.windows.sleep_active
  543. let list: any = []
  544. switch (health.mode) {
  545. case 'DAY':
  546. list = day.timeline
  547. if (day.extra.choose_location == false) {
  548. return <OnBoard title={t('health.sunrise_to_sunset')}
  549. desc={t('health.rise_to_set_desc')}
  550. btnTitle={t('health.choose_location')}
  551. onClick={chooseLocation}
  552. />
  553. }
  554. break;
  555. case 'NIGHT':
  556. list = night.timeline
  557. if (night.extra.choose_location == false) {
  558. return <OnBoard title={t('health.sunset_to_sunrise')}
  559. desc={t('health.set_to_rise_desc')}
  560. btnTitle={t('health.choose_location')}
  561. onClick={chooseLocation}
  562. />
  563. }
  564. break;
  565. case 'FAST':
  566. list = fast.timeline
  567. break;
  568. case 'EAT':
  569. list = eat.timeline
  570. break;
  571. case 'SLEEP':
  572. list = sleep.timeline
  573. break;
  574. case 'ACTIVE':
  575. list = active.timeline
  576. if (active.onboard == false) {
  577. var seconds = new Date().getSeconds()
  578. // return <Swiper autoplay>
  579. // {
  580. // list.map((item, index) => {
  581. // return <SwiperItem key={index}>
  582. // <OnBoard title={item.title}
  583. // desc={item.time_label}
  584. // btnTitle="Action"
  585. // onClick={() => {
  586. // if (!user.isLogin) {
  587. // jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  588. // return
  589. // }
  590. // jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(item))
  591. // }}
  592. // />
  593. // </SwiperItem>
  594. // })
  595. // }
  596. // </Swiper>
  597. return <OnBoard title={list[0].title}
  598. desc={list[0].time_label}
  599. btnTitle="Create My Activities"
  600. onClick={() => {
  601. if (!user.isLogin) {
  602. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  603. return
  604. }
  605. if (!health.finish_setup) {
  606. showAlert({
  607. title: '',
  608. content: '在整个日程中,创建您的活动安排',
  609. showCancel: true,
  610. cancelText: '稍后',
  611. confirmText: '立即设置',
  612. cancel: () => {
  613. global.showIndexAddActive(labels)
  614. },
  615. confirm: () => {
  616. tapGuide()
  617. }
  618. })
  619. return
  620. }
  621. global.showIndexAddActive(labels)
  622. // setShowModal(true)
  623. // jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
  624. }}
  625. />
  626. }
  627. break;
  628. }
  629. return <View>
  630. {
  631. list.map((item, index) => {
  632. return timelineItem(item, index, list.length)
  633. })
  634. }
  635. </View>
  636. }
  637. function switchText() {
  638. switch (health.mode) {
  639. case 'FAST':
  640. return t('health.switch_to', { scenario: t('health.eat') })
  641. case 'EAT':
  642. return t('health.switch_to', { scenario: t('health.fast') })
  643. case 'DAY':
  644. return t('health.switch_to', { scenario: t('health.night') })
  645. case 'NIGHT':
  646. return t('health.switch_to', { scenario: global.language == 'en' ? 'Daylight' : '白天' })//'Switch to Daylight'
  647. case 'SLEEP':
  648. return t('health.switch_to', { scenario: t('health.active') })
  649. case 'ACTIVE':
  650. return t('health.switch_to', { scenario: t('health.sleep') })
  651. }
  652. return ''
  653. }
  654. function tapSwitchBtn() {
  655. switch (health.mode) {
  656. case 'FAST':
  657. dispatch(setMode('EAT'));
  658. break
  659. case 'EAT':
  660. dispatch(setMode('FAST'));
  661. break
  662. case 'DAY':
  663. dispatch(setMode('NIGHT'));
  664. break
  665. case 'NIGHT':
  666. dispatch(setMode('DAY'));
  667. break
  668. case 'SLEEP':
  669. dispatch(setMode('ACTIVE'));
  670. break
  671. case 'ACTIVE':
  672. dispatch(setMode('SLEEP'));
  673. break
  674. }
  675. }
  676. function tapClearLocation() {
  677. Taro.showModal({
  678. title: '提示',
  679. content: '确认清除位置数据?',
  680. success: function (res) {
  681. if (res.confirm) {
  682. clearLocation().then(res => {
  683. global.refreshWindow()
  684. })
  685. } else if (res.cancel) {
  686. console.log('用户点击取消')
  687. }
  688. }
  689. })
  690. }
  691. function chooseLocation() {
  692. if (!user.isLogin) {
  693. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  694. return
  695. }
  696. var scenario = getScenario(health.windows, health.mode)
  697. Taro.chooseLocation({
  698. latitude: scenario.extra.choose_location ? parseFloat(scenario.extra.lat + '') : undefined,
  699. longitude: scenario.extra.choose_location ? parseFloat(scenario.extra.lng + '') : undefined,
  700. success: function (res) {
  701. uploadLocation(res)
  702. },
  703. fail(res) {
  704. Taro.showToast({
  705. title: '位置修改失败!\n请重新选择就近位置',
  706. icon: 'none'
  707. })
  708. },
  709. complete(res) {
  710. }
  711. })
  712. }
  713. function uploadLocation(res) {
  714. var today = new Date()
  715. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  716. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
  717. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  718. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  719. systemLocation({
  720. lat: res.latitude,
  721. lng: res.longitude,
  722. name: res.name,
  723. address: res.address,
  724. date_start: strYesterday,
  725. date_end: strTomorrow,
  726. coordinate_system_standard: process.env.TARO_ENV == 'weapp' ? 'GCJ-02' : 'WGS-84'
  727. }).then(data => {
  728. global.refreshWindow()
  729. })
  730. }
  731. function updateDuration(duration) {
  732. setDurationPicker(false)
  733. const scenario = getScenario(health.windows, health.mode)
  734. updateEventDuration(scenario.timeline[0].event_id, duration).then(res => {
  735. global.refreshWindow()
  736. })
  737. }
  738. function timePointClass() {
  739. if (getWindowStatus(health.windows, health.mode) == WindowStatusType.process) {
  740. return 'time_point time_point_animation'
  741. }
  742. return 'time_point'
  743. }
  744. function fastWithSleepStatus() {
  745. const { status } = health.fast_with_sleep
  746. var str = ''
  747. switch (status) {
  748. case 'OG1':
  749. str = t('health.fast_before_bed')
  750. break;
  751. case 'OG2_NO1':
  752. str = t('health.fast_missing')
  753. break;
  754. case 'OG2':
  755. str = t('health.fast_while_sleep')
  756. break;
  757. case 'OG2_MISALIGNED':
  758. str = t('health.misaligned')
  759. break;
  760. case 'OG3':
  761. str = t('health.fast_after_sleep')
  762. break
  763. }
  764. return <View className="H26" style={{ color: MainColorType.g02 }}>{str}</View>
  765. }
  766. function longFastStatus() {
  767. const { status } = health.long_fast
  768. return <View className="h26" style={{ color: MainColorType.g02 }}>{status == 'OG' ? 'In progress' : ''}</View>
  769. }
  770. function showMoreBtn() {
  771. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  772. if (!getScenario(health.windows, health.mode).extra.choose_location) {
  773. return false
  774. }
  775. }
  776. return true;
  777. }
  778. function getTitleColor() {
  779. if (getWindowStatus(health.windows, health.mode) == WindowStatusType.upcoming) {
  780. return MainColorType.g01
  781. }
  782. const scenario = getScenario(health.windows, health.mode)
  783. if (scenario.status == 'OG') {
  784. return getThemeColor(health.mode)
  785. }
  786. return '#000'
  787. }
  788. function polarCheck() {
  789. const scenario = getScenario(health.windows, health.mode)
  790. if (health.mode == 'DAY' && scenario.extra && scenario.extra.is_polar_day) {
  791. return <View className="console_tag_bg" style={{ backgroundColor: getThemeColor(health.mode) }}>
  792. <Image src={global.language == 'en' ? require('@assets/_health/tag_polar.png') : require('@assets/_health/tag_polar_day.png')} className="console_tag_img" />
  793. </View>
  794. }
  795. if (health.mode == 'NIGHT' && scenario.extra && scenario.extra.is_polar_night) {
  796. return <View className="console_tag_bg" style={{ backgroundColor: getThemeColor(health.mode) }}>
  797. <Image src={global.language == 'en' ? require('@assets/_health/tag_polar.png') : require('@assets/_health/tag_polar_night.png')} className="console_tag_img" />
  798. </View>
  799. }
  800. }
  801. function ogTime() {
  802. return <View className="time_count h30 bold" style={{
  803. backgroundColor: getThemeColor(health.mode)
  804. }}>
  805. {/* <View className="console_tag_bg" style={{backgroundColor:getThemeColor(health.mode)}}>
  806. <Image src={global.language=='en'?require('@assets/_health/tag_log.png'):require('@assets/_health/tag_record.png')} className="console_tag_img"/>
  807. </View> */}
  808. {
  809. getCountownTime(health.windows, health.mode)
  810. }
  811. </View>
  812. }
  813. function markDoneTip() {
  814. if (health.mode == 'DAY' && health.mode != 'NIGHT') return
  815. var scenario = getScenario(health.windows, health.mode)
  816. if (scenario.status != 'OG') return
  817. if (health.mode == 'EAT' && hideEatArchiveTip) return
  818. if (health.mode == 'ACTIVE' && hideActiveArchiveTip) return
  819. if (health.mode == 'FAST' && hideFastTip) return
  820. if (health.mode == 'SLEEP' && hideSleepTip) return
  821. function tipContent() {
  822. var strTime = ''
  823. var today = new Date().getDate()
  824. var date = new Date(scenario.archive_timestamp).getDate()
  825. if (today == date) {
  826. strTime = t('health.today_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  827. }
  828. else {
  829. strTime = t('health.tomorrow_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  830. }
  831. switch (health.mode) {
  832. case 'FAST':
  833. if (global.language == 'en') {
  834. return <Text className="h28">After you log <Text className="italic">End Fast</Text>,{'\n'}
  835. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  836. }
  837. return <Text className="h28">在您记录完 <Text className="italic">结束断食</Text> 之后,{'\n'}
  838. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  839. case 'SLEEP':
  840. if (global.language == 'en') {
  841. return <Text className="h28">After you log <Text className="italic">Wake Up</Text>,{'\n'}
  842. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  843. }
  844. return <Text className="h28">在您记录完 <Text className="italic">起床</Text> 之后,{'\n'}
  845. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  846. case 'EAT':
  847. if (global.language == 'en') {
  848. return <Text className="h28"><Text style={{ color: MainColorType.eat }}>{strTime}</Text> or after you <Text className="italic">Mark Done</Text>,{'\n'}
  849. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  850. }
  851. return <Text className="h28"><Text style={{ color: MainColorType.eat }}>{strTime}</Text> 或在您 <Text className="italic">标记完成</Text> 之后,{'\n'}
  852. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  853. case 'ACTIVE':
  854. if (global.language == 'en') {
  855. return <Text className="h28"><Text style={{ color: MainColorType.active }}>{strTime}</Text> or after you <Text className="italic">Mark Done</Text>,{'\n'}
  856. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  857. }
  858. return <Text className="h28"><Text style={{ color: MainColorType.active }}>{strTime}</Text> 或在您 <Text className="italic">标记完成</Text> 之后,{'\n'}
  859. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  860. }
  861. return <Text className="h28">1</Text>
  862. }
  863. return <View className="mark_done_tip" style={{
  864. backgroundColor: getThemeColor(health.mode) + '1A'
  865. }}>
  866. <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
  867. {
  868. tipContent()
  869. }
  870. </View>
  871. <NewButton type={NewButtonType.img} btnStyle={{
  872. height: rpxToPx(32),
  873. width: rpxToPx(32)
  874. }} onClick={() => {
  875. switch (health.mode) {
  876. case 'FAST':
  877. setHideFastTip(true)
  878. break;
  879. case 'EAT':
  880. setHideEatArchiveTip(true)
  881. break;
  882. case 'SLEEP':
  883. setHideSleepTip(true)
  884. break
  885. case 'ACTIVE':
  886. setHideActiveArchiveTip(true)
  887. break
  888. }
  889. }}>
  890. <IconClose color={MainColorType.g03} width={rpxToPx(32)} height={rpxToPx(32)} />
  891. </NewButton>
  892. </View>
  893. // var strTitle = ''
  894. // if (scenario.archive_timestamp) {
  895. // var today = new Date().getDate()
  896. // var date = new Date(scenario.archive_timestamp).getDate()
  897. // if (today == date) {
  898. // strTitle = t('health.tonight_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  899. // }
  900. // else {
  901. // strTitle = t('health.tomorrow_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  902. // }
  903. // }
  904. // return <View className="mark_done_tip" style={{
  905. // backgroundColor: getThemeColor(health.mode) + '1A'
  906. // }}>
  907. // <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
  908. // <Text className="h24 bold" style={{ color: getThemeColor(health.mode) }}>{strTitle}</Text>
  909. // <Text className="h24 bold">{t('health.all_logs', { scenario: health.mode == 'EAT' ? t('health.meals') : t('health.activities') })}<Text style={{ fontWeight: 'normal' }}>{t('health.will_collected')}</Text>{t('health.journal_end')}</Text>
  910. // </View>
  911. // <NewButton type={NewButtonType.img} btnStyle={{
  912. // height: rpxToPx(32),
  913. // width: rpxToPx(32)
  914. // }} onClick={() => {
  915. // if (health.mode == 'EAT') {
  916. // setHideEatArchiveTip(true)
  917. // }
  918. // else {
  919. // setHideActiveArchiveTip(true)
  920. // }
  921. // }}>
  922. // <IconClose color={MainColorType.g01} width={rpxToPx(32)} height={rpxToPx(32)} />
  923. // </NewButton>
  924. // </View>
  925. }
  926. return <View className="main-console-bg">
  927. <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
  928. <View className="main_summary">
  929. <View className="main_summary_time h30 bold" style={{
  930. marginTop: rpxToPx(14),
  931. }} >
  932. {polarCheck()}
  933. {getScenario(health.windows, health.mode).status == 'OG' ? ogTime() : getDuration(health.windows, health.mode)}
  934. </View>
  935. <Text className="main_summary_duration g01"
  936. style={{
  937. marginBottom: rpxToPx(30)
  938. }}>{getScenario(health.windows, health.mode).status == 'OG' ? getDuration(health.windows, health.mode) : getCountownTime(health.windows, health.mode)}
  939. </Text>
  940. <View className="border_footer_line" />
  941. </View>
  942. <View style={{ backgroundColor: '#fff', width: rpxToPx(750) }}>
  943. {
  944. detail()
  945. }
  946. </View>
  947. <View className="main_footer2">
  948. <View style={{ width: rpxToPx(316), height: rpxToPx(128), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  949. <NewButton
  950. type={NewButtonType.link}
  951. title={switchText()}
  952. onClick={tapSwitchBtn}
  953. >
  954. </NewButton>
  955. </View>
  956. {
  957. showMoreBtn() && <NewButton
  958. btnStyle={{
  959. position: 'absolute',
  960. top: rpxToPx(42),
  961. right: rpxToPx(40)
  962. }}
  963. type={NewButtonType.more}
  964. onClick={more}
  965. />
  966. }
  967. </View>
  968. {
  969. user.isLogin && (health.mode !='DAY' && health.mode !='NIGHT') && !hideGuideTip && !health.finish_setup && <View className="guide_tip h26" onClick={() => {
  970. tapGuide();
  971. setHideGuideTip(true)
  972. }}>{t('health.console_guide_tip')}
  973. <NewButton type={NewButtonType.img} btnStyle={{
  974. position: 'absolute',
  975. right: 0,
  976. top: 0,
  977. bottom: 0,
  978. width: rpxToPx(92)
  979. }} onClick={() => {
  980. setHideGuideTip(true)
  981. }}>
  982. <IconClose color={MainColorType.g03} width={rpxToPx(32)} height={rpxToPx(32)} />
  983. </NewButton>
  984. </View>
  985. }
  986. {/* {
  987. markDoneTip()
  988. } */}
  989. {/* {
  990. health.mode == 'ACTIVE' && <View>
  991. <View className="main_column_space" /><IconTitleCell
  992. icon={<IconActive width={rpxToPx(32)} color={MainColorType.active} />}
  993. title={t('health.move_more')}
  994. onClick={() => {
  995. jumpPage('/_health/pages/move')
  996. }}
  997. /></View>
  998. } */}
  999. {/* {
  1000. (health.mode == 'FAST' || health.mode == 'SLEEP') && <View >
  1001. <View className="main_column_space" />
  1002. <IconTitleCell
  1003. onClick={() => {
  1004. if (health.long_fast.status == 'OG') {
  1005. showAlert({
  1006. title: '长断食进行中',
  1007. content: '当前有一个正在进行的长断食记录,要转换为间歇性断食吗?',
  1008. showCancel: true,
  1009. cancelText: '取消',
  1010. confirmText: '确定',
  1011. confirm: () => {
  1012. updateFast({ fast_type: 'IF' }).then(res => {
  1013. global.refreshWindow()
  1014. jumpPage('/_health/pages/fast_sleep')
  1015. })
  1016. }
  1017. })
  1018. return
  1019. }
  1020. setTimeout(() => {
  1021. setHideErrorTip(true)
  1022. }, 1000)
  1023. jumpPage('/_health/pages/fast_sleep')
  1024. }}
  1025. showLine={health.mode == 'FAST'}
  1026. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1027. title={t('health.fast_with_sleep')}
  1028. desc={<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  1029. {
  1030. fastWithSleepStatus()
  1031. }
  1032. {
  1033. !hideErrorTip && (health.fast_with_sleep.status == 'OG2_MISALIGNED' || health.fast_with_sleep.status == 'OG2_NO1') && <View style={{
  1034. backgroundColor: MainColorType.error,
  1035. width: rpxToPx(12),
  1036. height: rpxToPx(12),
  1037. borderRadius: rpxToPx(6),
  1038. marginLeft: rpxToPx(12),
  1039. marginRight: rpxToPx(0)
  1040. }} />
  1041. }
  1042. </View>}
  1043. />
  1044. </View>
  1045. } */}
  1046. {/* {
  1047. health.mode == 'FAST' && <IconTitleCell
  1048. onClick={() => {
  1049. jumpPage('/_health/pages/long_fast')
  1050. }}
  1051. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1052. title={t('health.long_fast')}
  1053. desc={
  1054. longFastStatus()
  1055. }
  1056. />
  1057. } */}
  1058. <View className="circle" />
  1059. {
  1060. durationPicker && <DurationPicker
  1061. done={(time) => {
  1062. updateDuration(time)
  1063. }}
  1064. dismiss={() => {
  1065. setDurationPicker(false)
  1066. }} time={getScenario(health.windows, health.mode).target.duration} />
  1067. }
  1068. {
  1069. showModal && <AddLabel labels={labels}
  1070. window='ACTIVE'
  1071. disMiss={() => setShowModal(false)}
  1072. op_page='SCHEDULE_ACTIVE_SLEEP'
  1073. // onlyCheck={true}
  1074. // schedules={[]}
  1075. confirm={(res) => {
  1076. setShowModal(false)
  1077. if ((res as any).result) {
  1078. global.refreshWindow()
  1079. // dispatch(setSchedules((res as any).schedules))
  1080. // dispatch(setFooter((res as any).footer))
  1081. // setList((res as any).schedules)
  1082. // setErrors([])
  1083. }
  1084. else {
  1085. jumpPage('/_health/pages/schedules?mode=' + health.mode + '&error=' + JSON.stringify(res))
  1086. // setList((res as any).schedules)
  1087. // dispatch(setFooter((res as any).footer))
  1088. // setErrors((res as any).error_messages ? (res as any).error_messages : [])
  1089. }
  1090. }}
  1091. color={MainColorType.active} />
  1092. }
  1093. </View >
  1094. }