MainConsole.tsx 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  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 && active.status == 'WFS') {
  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. if (health.mode=='') return <View />
  927. return <View className="main-console-bg">
  928. <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
  929. <View className="main_summary">
  930. <View className="main_summary_time h30 bold" style={{
  931. marginTop: rpxToPx(14),
  932. }} >
  933. {polarCheck()}
  934. {getScenario(health.windows, health.mode).status == 'OG' ? ogTime() : getDuration(health.windows, health.mode)}
  935. </View>
  936. <Text className="main_summary_duration g01"
  937. style={{
  938. marginBottom: rpxToPx(30)
  939. }}>{getScenario(health.windows, health.mode).status == 'OG' ? getDuration(health.windows, health.mode) : getCountownTime(health.windows, health.mode)}
  940. </Text>
  941. <View className="border_footer_line" />
  942. </View>
  943. <View style={{ backgroundColor: '#fff', width: rpxToPx(750) }}>
  944. {
  945. detail()
  946. }
  947. </View>
  948. <View className="main_footer2">
  949. <View style={{ width: rpxToPx(316), height: rpxToPx(128), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  950. <NewButton
  951. type={NewButtonType.link}
  952. title={switchText()}
  953. onClick={tapSwitchBtn}
  954. >
  955. </NewButton>
  956. </View>
  957. {
  958. showMoreBtn() && <NewButton
  959. btnStyle={{
  960. position: 'absolute',
  961. top: rpxToPx(42),
  962. right: rpxToPx(40)
  963. }}
  964. type={NewButtonType.more}
  965. onClick={more}
  966. />
  967. }
  968. </View>
  969. {
  970. user.isLogin && (health.mode !='DAY' && health.mode !='NIGHT') && !hideGuideTip && !health.finish_setup && <View className="guide_tip h26" onClick={() => {
  971. tapGuide();
  972. setHideGuideTip(true)
  973. }}>{t('health.console_guide_tip')}
  974. <NewButton type={NewButtonType.img} btnStyle={{
  975. position: 'absolute',
  976. right: 0,
  977. top: 0,
  978. bottom: 0,
  979. width: rpxToPx(92)
  980. }} onClick={() => {
  981. setHideGuideTip(true)
  982. }}>
  983. <IconClose color={MainColorType.g03} width={rpxToPx(32)} height={rpxToPx(32)} />
  984. </NewButton>
  985. </View>
  986. }
  987. {/* {
  988. markDoneTip()
  989. } */}
  990. {/* {
  991. health.mode == 'ACTIVE' && <View>
  992. <View className="main_column_space" /><IconTitleCell
  993. icon={<IconActive width={rpxToPx(32)} color={MainColorType.active} />}
  994. title={t('health.move_more')}
  995. onClick={() => {
  996. jumpPage('/_health/pages/move')
  997. }}
  998. /></View>
  999. } */}
  1000. {/* {
  1001. (health.mode == 'FAST' || health.mode == 'SLEEP') && <View >
  1002. <View className="main_column_space" />
  1003. <IconTitleCell
  1004. onClick={() => {
  1005. if (health.long_fast.status == 'OG') {
  1006. showAlert({
  1007. title: '长断食进行中',
  1008. content: '当前有一个正在进行的长断食记录,要转换为间歇性断食吗?',
  1009. showCancel: true,
  1010. cancelText: '取消',
  1011. confirmText: '确定',
  1012. confirm: () => {
  1013. updateFast({ fast_type: 'IF' }).then(res => {
  1014. global.refreshWindow()
  1015. jumpPage('/_health/pages/fast_sleep')
  1016. })
  1017. }
  1018. })
  1019. return
  1020. }
  1021. setTimeout(() => {
  1022. setHideErrorTip(true)
  1023. }, 1000)
  1024. jumpPage('/_health/pages/fast_sleep')
  1025. }}
  1026. showLine={health.mode == 'FAST'}
  1027. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1028. title={t('health.fast_with_sleep')}
  1029. desc={<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  1030. {
  1031. fastWithSleepStatus()
  1032. }
  1033. {
  1034. !hideErrorTip && (health.fast_with_sleep.status == 'OG2_MISALIGNED' || health.fast_with_sleep.status == 'OG2_NO1') && <View style={{
  1035. backgroundColor: MainColorType.error,
  1036. width: rpxToPx(12),
  1037. height: rpxToPx(12),
  1038. borderRadius: rpxToPx(6),
  1039. marginLeft: rpxToPx(12),
  1040. marginRight: rpxToPx(0)
  1041. }} />
  1042. }
  1043. </View>}
  1044. />
  1045. </View>
  1046. } */}
  1047. {/* {
  1048. health.mode == 'FAST' && <IconTitleCell
  1049. onClick={() => {
  1050. jumpPage('/_health/pages/long_fast')
  1051. }}
  1052. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1053. title={t('health.long_fast')}
  1054. desc={
  1055. longFastStatus()
  1056. }
  1057. />
  1058. } */}
  1059. <View className="circle" />
  1060. {
  1061. durationPicker && <DurationPicker
  1062. done={(time) => {
  1063. updateDuration(time)
  1064. }}
  1065. dismiss={() => {
  1066. setDurationPicker(false)
  1067. }} time={getScenario(health.windows, health.mode).target.duration} />
  1068. }
  1069. {
  1070. showModal && <AddLabel labels={labels}
  1071. window='ACTIVE'
  1072. disMiss={() => setShowModal(false)}
  1073. op_page='SCHEDULE_ACTIVE_SLEEP'
  1074. // onlyCheck={true}
  1075. // schedules={[]}
  1076. confirm={(res) => {
  1077. setShowModal(false)
  1078. if ((res as any).result) {
  1079. global.refreshWindow()
  1080. // dispatch(setSchedules((res as any).schedules))
  1081. // dispatch(setFooter((res as any).footer))
  1082. // setList((res as any).schedules)
  1083. // setErrors([])
  1084. }
  1085. else {
  1086. jumpPage('/_health/pages/schedules?mode=' + health.mode + '&error=' + JSON.stringify(res))
  1087. // setList((res as any).schedules)
  1088. // dispatch(setFooter((res as any).footer))
  1089. // setErrors((res as any).error_messages ? (res as any).error_messages : [])
  1090. }
  1091. }}
  1092. color={MainColorType.active} />
  1093. }
  1094. </View >
  1095. }