MainConsole.tsx 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  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. city = t('feature.track_time_duration.third_ring.unknown')
  446. }
  447. }
  448. else {
  449. city = t('feature.track_time_duration.third_ring.unknown')
  450. }
  451. return city
  452. }
  453. function tapActionSheet(index) {
  454. var title = actionList()[index]
  455. switch (title) {
  456. case t('health.finish_setup'):
  457. tapGuide();
  458. break;
  459. case t('health.log_extra_activity'):
  460. jumpPage(`/_health/pages/add_moment?title=&is_temp=${true}`)
  461. break;
  462. case t('health.log_extra_meal'):
  463. jumpPage(`/_health/pages/add_moment?title=加餐&is_temp=${true}`)
  464. break;
  465. case t('health.mark_done'):
  466. tapMakeDone()
  467. break
  468. case t('health.edit_schedule'):
  469. jumpPage('/_health/pages/schedules?mode=' + health.mode)
  470. break
  471. case t('health.delete_current_record'):
  472. {
  473. const obj = getScenario(health.windows, health.mode)
  474. showAlert({
  475. title: 'del',
  476. content: '确认删除此记录?',
  477. showCancel: true,
  478. confirm: () => {
  479. delRecord({ ids: [obj.window_id] }).then(res => {
  480. global.refreshWindow()
  481. if ((res as any).status_change) {
  482. if ((res as any).status_change.previous != (res as any).status_change.current) {
  483. //灵动岛弹窗
  484. setTimeout(() => {
  485. dispatch(setShowActionTip({
  486. isShow: true,
  487. isCompleted: false
  488. }))
  489. }, 1000)
  490. }
  491. }
  492. })
  493. }
  494. })
  495. }
  496. break;
  497. case t('health.change_location'):
  498. chooseLocation()
  499. break
  500. case t('health.clear_location'):
  501. tapClearLocation()
  502. break
  503. }
  504. }
  505. function tapGuide() {
  506. jumpPage('/_health/pages/guide_begin')
  507. // showAlert({
  508. // title:'设置引导弹窗',
  509. // content:'设置引导描述',
  510. // showCancel:true,
  511. // cancelText:'稍后',
  512. // confirmText:'设置',
  513. // cancel:()=>{
  514. // },
  515. // confirm:()=>{
  516. // jumpPage('/_health/pages/guide_fast')
  517. // }
  518. // })
  519. }
  520. function tapMakeDone() {
  521. makeDone(getScenario(health.windows, health.mode).window_id).then(res => {
  522. global.refreshWindow()
  523. global.refreshHistory()
  524. if ((res as any).status_change) {
  525. if ((res as any).status_change.previous != (res as any).status_change.current) {
  526. //灵动岛弹窗
  527. setTimeout(() => {
  528. dispatch(setShowActionTip({
  529. isShow: true,
  530. isCompleted: false
  531. }))
  532. }, 1000)
  533. }
  534. }
  535. })
  536. }
  537. function detail() {
  538. const { day, night } = health.windows.night_day
  539. const { fast, eat } = health.windows.fast_eat
  540. const { sleep, active } = health.windows.sleep_active
  541. let list: any = []
  542. switch (health.mode) {
  543. case 'DAY':
  544. list = day.timeline
  545. if (day.extra.choose_location == false) {
  546. return <OnBoard title={t('health.sunrise_to_sunset')}
  547. desc={t('health.rise_to_set_desc')}
  548. btnTitle={t('health.choose_location')}
  549. onClick={chooseLocation}
  550. />
  551. }
  552. break;
  553. case 'NIGHT':
  554. list = night.timeline
  555. if (night.extra.choose_location == false) {
  556. return <OnBoard title={t('health.sunset_to_sunrise')}
  557. desc={t('health.set_to_rise_desc')}
  558. btnTitle={t('health.choose_location')}
  559. onClick={chooseLocation}
  560. />
  561. }
  562. break;
  563. case 'FAST':
  564. list = fast.timeline
  565. break;
  566. case 'EAT':
  567. list = eat.timeline
  568. break;
  569. case 'SLEEP':
  570. list = sleep.timeline
  571. break;
  572. case 'ACTIVE':
  573. list = active.timeline
  574. if (active.onboard == false) {
  575. var seconds = new Date().getSeconds()
  576. // return <Swiper autoplay>
  577. // {
  578. // list.map((item, index) => {
  579. // return <SwiperItem key={index}>
  580. // <OnBoard title={item.title}
  581. // desc={item.time_label}
  582. // btnTitle="Action"
  583. // onClick={() => {
  584. // if (!user.isLogin) {
  585. // jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  586. // return
  587. // }
  588. // jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(item))
  589. // }}
  590. // />
  591. // </SwiperItem>
  592. // })
  593. // }
  594. // </Swiper>
  595. return <OnBoard title={list[0].title}
  596. desc={list[0].time_label}
  597. btnTitle="Create My Activities"
  598. onClick={() => {
  599. if (!user.isLogin) {
  600. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  601. return
  602. }
  603. if (!health.finish_setup) {
  604. showAlert({
  605. title: '',
  606. content: '在整个日程中,创建您的活动安排',
  607. showCancel: true,
  608. cancelText: '稍后',
  609. confirmText: '立即设置',
  610. cancel: () => {
  611. global.showIndexAddActive(labels)
  612. },
  613. confirm: () => {
  614. tapGuide()
  615. }
  616. })
  617. return
  618. }
  619. global.showIndexAddActive(labels)
  620. // setShowModal(true)
  621. // jumpPage('/_health/pages/active_plan?schedule=' + JSON.stringify(list.length > 0 ? list[0] : '{}'))
  622. }}
  623. />
  624. }
  625. break;
  626. }
  627. return <View>
  628. {
  629. list.map((item, index) => {
  630. return timelineItem(item, index, list.length)
  631. })
  632. }
  633. </View>
  634. }
  635. function switchText() {
  636. switch (health.mode) {
  637. case 'FAST':
  638. return t('health.switch_to', { scenario: t('health.eat') })
  639. case 'EAT':
  640. return t('health.switch_to', { scenario: t('health.fast') })
  641. case 'DAY':
  642. return t('health.switch_to', { scenario: t('health.night') })
  643. case 'NIGHT':
  644. return t('health.switch_to', { scenario: global.language == 'en' ? 'Daylight' : '白天' })//'Switch to Daylight'
  645. case 'SLEEP':
  646. return t('health.switch_to', { scenario: t('health.active') })
  647. case 'ACTIVE':
  648. return t('health.switch_to', { scenario: t('health.sleep') })
  649. }
  650. return ''
  651. }
  652. function tapSwitchBtn() {
  653. switch (health.mode) {
  654. case 'FAST':
  655. dispatch(setMode('EAT'));
  656. break
  657. case 'EAT':
  658. dispatch(setMode('FAST'));
  659. break
  660. case 'DAY':
  661. dispatch(setMode('NIGHT'));
  662. break
  663. case 'NIGHT':
  664. dispatch(setMode('DAY'));
  665. break
  666. case 'SLEEP':
  667. dispatch(setMode('ACTIVE'));
  668. break
  669. case 'ACTIVE':
  670. dispatch(setMode('SLEEP'));
  671. break
  672. }
  673. }
  674. function tapClearLocation() {
  675. Taro.showModal({
  676. title: '提示',
  677. content: '确认清除位置数据?',
  678. success: function (res) {
  679. if (res.confirm) {
  680. clearLocation().then(res => {
  681. global.refreshWindow()
  682. })
  683. } else if (res.cancel) {
  684. console.log('用户点击取消')
  685. }
  686. }
  687. })
  688. }
  689. function chooseLocation() {
  690. if (!user.isLogin) {
  691. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  692. return
  693. }
  694. var scenario = getScenario(health.windows, health.mode)
  695. Taro.chooseLocation({
  696. latitude: scenario.extra.choose_location ? parseFloat(scenario.extra.lat + '') : undefined,
  697. longitude: scenario.extra.choose_location ? parseFloat(scenario.extra.lng + '') : undefined,
  698. success: function (res) {
  699. uploadLocation(res)
  700. },
  701. fail(res) {
  702. Taro.showToast({
  703. title: '位置修改失败!\n请重新选择就近位置',
  704. icon: 'none'
  705. })
  706. },
  707. complete(res) {
  708. }
  709. })
  710. }
  711. function uploadLocation(res) {
  712. var today = new Date()
  713. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  714. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
  715. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  716. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  717. systemLocation({
  718. lat: res.latitude,
  719. lng: res.longitude,
  720. name: res.name,
  721. address: res.address,
  722. date_start: strYesterday,
  723. date_end: strTomorrow,
  724. coordinate_system_standard: process.env.TARO_ENV == 'weapp' ? 'GCJ-02' : 'WGS-84'
  725. }).then(data => {
  726. global.refreshWindow()
  727. })
  728. }
  729. function updateDuration(duration) {
  730. setDurationPicker(false)
  731. const scenario = getScenario(health.windows, health.mode)
  732. updateEventDuration(scenario.timeline[0].event_id, duration).then(res => {
  733. global.refreshWindow()
  734. })
  735. }
  736. function timePointClass() {
  737. if (getWindowStatus(health.windows, health.mode) == WindowStatusType.process) {
  738. return 'time_point time_point_animation'
  739. }
  740. return 'time_point'
  741. }
  742. function fastWithSleepStatus() {
  743. const { status } = health.fast_with_sleep
  744. var str = ''
  745. switch (status) {
  746. case 'OG1':
  747. str = t('health.fast_before_bed')
  748. break;
  749. case 'OG2_NO1':
  750. str = t('health.fast_missing')
  751. break;
  752. case 'OG2':
  753. str = t('health.fast_while_sleep')
  754. break;
  755. case 'OG2_MISALIGNED':
  756. str = t('health.misaligned')
  757. break;
  758. case 'OG3':
  759. str = t('health.fast_after_sleep')
  760. break
  761. }
  762. return <View className="H26" style={{ color: MainColorType.g02 }}>{str}</View>
  763. }
  764. function longFastStatus() {
  765. const { status } = health.long_fast
  766. return <View className="h26" style={{ color: MainColorType.g02 }}>{status == 'OG' ? 'In progress' : ''}</View>
  767. }
  768. function showMoreBtn() {
  769. if (health.mode == 'DAY' || health.mode == 'NIGHT') {
  770. if (!getScenario(health.windows, health.mode).extra.choose_location) {
  771. return false
  772. }
  773. }
  774. return true;
  775. }
  776. function getTitleColor() {
  777. if (getWindowStatus(health.windows, health.mode) == WindowStatusType.upcoming) {
  778. return MainColorType.g01
  779. }
  780. const scenario = getScenario(health.windows, health.mode)
  781. if (scenario.status == 'OG') {
  782. return getThemeColor(health.mode)
  783. }
  784. return '#000'
  785. }
  786. function polarCheck() {
  787. const scenario = getScenario(health.windows, health.mode)
  788. if (health.mode == 'DAY' && scenario.extra && scenario.extra.is_polar_day) {
  789. return <View className="console_tag_bg" style={{ backgroundColor: getThemeColor(health.mode) }}>
  790. <Image src={global.language == 'en' ? require('@assets/_health/tag_polar.png') : require('@assets/_health/tag_polar_day.png')} className="console_tag_img" />
  791. </View>
  792. }
  793. if (health.mode == 'NIGHT' && scenario.extra && scenario.extra.is_polar_night) {
  794. return <View className="console_tag_bg" style={{ backgroundColor: getThemeColor(health.mode) }}>
  795. <Image src={global.language == 'en' ? require('@assets/_health/tag_polar.png') : require('@assets/_health/tag_polar_night.png')} className="console_tag_img" />
  796. </View>
  797. }
  798. }
  799. function ogTime() {
  800. return <View className="time_count h30 bold" style={{
  801. backgroundColor: getThemeColor(health.mode)
  802. }}>
  803. {/* <View className="console_tag_bg" style={{backgroundColor:getThemeColor(health.mode)}}>
  804. <Image src={global.language=='en'?require('@assets/_health/tag_log.png'):require('@assets/_health/tag_record.png')} className="console_tag_img"/>
  805. </View> */}
  806. {
  807. getCountownTime(health.windows, health.mode)
  808. }
  809. </View>
  810. }
  811. function markDoneTip() {
  812. if (health.mode == 'DAY' && health.mode != 'NIGHT') return
  813. var scenario = getScenario(health.windows, health.mode)
  814. if (scenario.status != 'OG') return
  815. if (health.mode == 'EAT' && hideEatArchiveTip) return
  816. if (health.mode == 'ACTIVE' && hideActiveArchiveTip) return
  817. if (health.mode == 'FAST' && hideFastTip) return
  818. if (health.mode == 'SLEEP' && hideSleepTip) return
  819. function tipContent() {
  820. var strTime = ''
  821. var today = new Date().getDate()
  822. var date = new Date(scenario.archive_timestamp).getDate()
  823. if (today == date) {
  824. strTime = t('health.today_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  825. }
  826. else {
  827. strTime = t('health.tomorrow_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  828. }
  829. switch (health.mode) {
  830. case 'FAST':
  831. if (global.language == 'en') {
  832. return <Text className="h28">After you log <Text className="italic">End Fast</Text>,{'\n'}
  833. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  834. }
  835. return <Text className="h28">在您记录完 <Text className="italic">结束断食</Text> 之后,{'\n'}
  836. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  837. case 'SLEEP':
  838. if (global.language == 'en') {
  839. return <Text className="h28">After you log <Text className="italic">Wake Up</Text>,{'\n'}
  840. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  841. }
  842. return <Text className="h28">在您记录完 <Text className="italic">起床</Text> 之后,{'\n'}
  843. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  844. case 'EAT':
  845. if (global.language == 'en') {
  846. return <Text className="h28"><Text style={{ color: MainColorType.eat }}>{strTime}</Text> or after you <Text className="italic">Mark Done</Text>,{'\n'}
  847. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  848. }
  849. return <Text className="h28"><Text style={{ color: MainColorType.eat }}>{strTime}</Text> 或在您 <Text className="italic">标记完成</Text> 之后,{'\n'}
  850. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  851. case 'ACTIVE':
  852. if (global.language == 'en') {
  853. return <Text className="h28"><Text style={{ color: MainColorType.active }}>{strTime}</Text> or after you <Text className="italic">Mark Done</Text>,{'\n'}
  854. Your moments <Text className="bold">today</Text> will appear in <Text className="bold">Recents</Text>.</Text>
  855. }
  856. return <Text className="h28"><Text style={{ color: MainColorType.active }}>{strTime}</Text> 或在您 <Text className="italic">标记完成</Text> 之后,{'\n'}
  857. 您<Text className="bold">今天</Text>的时刻将出现在<Text className="bold">最近</Text>中。</Text>
  858. }
  859. return <Text className="h28">1</Text>
  860. }
  861. return <View className="mark_done_tip" style={{
  862. backgroundColor: getThemeColor(health.mode) + '1A'
  863. }}>
  864. <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
  865. {
  866. tipContent()
  867. }
  868. </View>
  869. <NewButton type={NewButtonType.img} btnStyle={{
  870. height: rpxToPx(32),
  871. width: rpxToPx(32)
  872. }} onClick={() => {
  873. switch (health.mode) {
  874. case 'FAST':
  875. setHideFastTip(true)
  876. break;
  877. case 'EAT':
  878. setHideEatArchiveTip(true)
  879. break;
  880. case 'SLEEP':
  881. setHideSleepTip(true)
  882. break
  883. case 'ACTIVE':
  884. setHideActiveArchiveTip(true)
  885. break
  886. }
  887. }}>
  888. <IconClose color={MainColorType.g01} width={rpxToPx(32)} height={rpxToPx(32)} />
  889. </NewButton>
  890. </View>
  891. // var strTitle = ''
  892. // if (scenario.archive_timestamp) {
  893. // var today = new Date().getDate()
  894. // var date = new Date(scenario.archive_timestamp).getDate()
  895. // if (today == date) {
  896. // strTitle = t('health.tonight_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  897. // }
  898. // else {
  899. // strTitle = t('health.tomorrow_at', { time: dayjs(scenario.archive_timestamp).format('HH:mm') })
  900. // }
  901. // }
  902. // return <View className="mark_done_tip" style={{
  903. // backgroundColor: getThemeColor(health.mode) + '1A'
  904. // }}>
  905. // <View style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
  906. // <Text className="h24 bold" style={{ color: getThemeColor(health.mode) }}>{strTitle}</Text>
  907. // <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>
  908. // </View>
  909. // <NewButton type={NewButtonType.img} btnStyle={{
  910. // height: rpxToPx(32),
  911. // width: rpxToPx(32)
  912. // }} onClick={() => {
  913. // if (health.mode == 'EAT') {
  914. // setHideEatArchiveTip(true)
  915. // }
  916. // else {
  917. // setHideActiveArchiveTip(true)
  918. // }
  919. // }}>
  920. // <IconClose color={MainColorType.g01} width={rpxToPx(32)} height={rpxToPx(32)} />
  921. // </NewButton>
  922. // </View>
  923. }
  924. return <View className="main-console-bg">
  925. <Image className="main_arrow" src={require('@assets/images/center_arrow.png')} />
  926. <View className="main_summary">
  927. <View className="main_summary_time h30 bold" style={{
  928. marginTop: rpxToPx(14),
  929. }} >
  930. {polarCheck()}
  931. {getScenario(health.windows, health.mode).status == 'OG' ? ogTime() : getDuration(health.windows, health.mode)}
  932. </View>
  933. <Text className="main_summary_duration g01"
  934. style={{
  935. marginBottom: rpxToPx(30)
  936. }}>{getScenario(health.windows, health.mode).status == 'OG' ? getDuration(health.windows, health.mode) : getCountownTime(health.windows, health.mode)}
  937. </Text>
  938. <View className="border_footer_line" />
  939. </View>
  940. <View style={{ backgroundColor: '#fff', width: rpxToPx(750) }}>
  941. {
  942. detail()
  943. }
  944. </View>
  945. <View className="main_footer2">
  946. <View style={{ width: rpxToPx(316), height: rpxToPx(128), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  947. <NewButton
  948. type={NewButtonType.link}
  949. title={switchText()}
  950. onClick={tapSwitchBtn}
  951. >
  952. </NewButton>
  953. </View>
  954. {
  955. showMoreBtn() && <NewButton
  956. btnStyle={{
  957. position: 'absolute',
  958. top: rpxToPx(42),
  959. right: rpxToPx(40)
  960. }}
  961. type={NewButtonType.more}
  962. onClick={more}
  963. />
  964. }
  965. </View>
  966. {
  967. user.isLogin && !hideGuideTip && !health.finish_setup && <View className="guide_tip h26" onClick={() => {
  968. tapGuide();
  969. setHideGuideTip(true)
  970. }}>{t('health.console_guide_tip')}
  971. <NewButton type={NewButtonType.img} btnStyle={{
  972. position: 'absolute',
  973. right: 0,
  974. top: 0,
  975. bottom: 0,
  976. width: rpxToPx(92)
  977. }} onClick={() => {
  978. setHideGuideTip(true)
  979. }}>
  980. <IconClose color={MainColorType.g01} width={rpxToPx(32)} height={rpxToPx(32)} />
  981. </NewButton>
  982. </View>
  983. }
  984. {/* {
  985. markDoneTip()
  986. } */}
  987. {/* {
  988. health.mode == 'ACTIVE' && <View>
  989. <View className="main_column_space" /><IconTitleCell
  990. icon={<IconActive width={rpxToPx(32)} color={MainColorType.active} />}
  991. title={t('health.move_more')}
  992. onClick={() => {
  993. jumpPage('/_health/pages/move')
  994. }}
  995. /></View>
  996. } */}
  997. {/* {
  998. (health.mode == 'FAST' || health.mode == 'SLEEP') && <View >
  999. <View className="main_column_space" />
  1000. <IconTitleCell
  1001. onClick={() => {
  1002. if (health.long_fast.status == 'OG') {
  1003. showAlert({
  1004. title: '长断食进行中',
  1005. content: '当前有一个正在进行的长断食记录,要转换为间歇性断食吗?',
  1006. showCancel: true,
  1007. cancelText: '取消',
  1008. confirmText: '确定',
  1009. confirm: () => {
  1010. updateFast({ fast_type: 'IF' }).then(res => {
  1011. global.refreshWindow()
  1012. jumpPage('/_health/pages/fast_sleep')
  1013. })
  1014. }
  1015. })
  1016. return
  1017. }
  1018. setTimeout(() => {
  1019. setHideErrorTip(true)
  1020. }, 1000)
  1021. jumpPage('/_health/pages/fast_sleep')
  1022. }}
  1023. showLine={health.mode == 'FAST'}
  1024. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1025. title={t('health.fast_with_sleep')}
  1026. desc={<View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  1027. {
  1028. fastWithSleepStatus()
  1029. }
  1030. {
  1031. !hideErrorTip && (health.fast_with_sleep.status == 'OG2_MISALIGNED' || health.fast_with_sleep.status == 'OG2_NO1') && <View style={{
  1032. backgroundColor: MainColorType.error,
  1033. width: rpxToPx(12),
  1034. height: rpxToPx(12),
  1035. borderRadius: rpxToPx(6),
  1036. marginLeft: rpxToPx(12),
  1037. marginRight: rpxToPx(0)
  1038. }} />
  1039. }
  1040. </View>}
  1041. />
  1042. </View>
  1043. } */}
  1044. {/* {
  1045. health.mode == 'FAST' && <IconTitleCell
  1046. onClick={() => {
  1047. jumpPage('/_health/pages/long_fast')
  1048. }}
  1049. icon={<Image className="active_icon" src={require('@assets/_health/fast.png')} />}
  1050. title={t('health.long_fast')}
  1051. desc={
  1052. longFastStatus()
  1053. }
  1054. />
  1055. } */}
  1056. <View className="circle" />
  1057. {
  1058. durationPicker && <DurationPicker
  1059. done={(time) => {
  1060. updateDuration(time)
  1061. }}
  1062. dismiss={() => {
  1063. setDurationPicker(false)
  1064. }} time={getScenario(health.windows, health.mode).target.duration} />
  1065. }
  1066. {
  1067. showModal && <AddLabel labels={labels}
  1068. window='ACTIVE'
  1069. disMiss={() => setShowModal(false)}
  1070. op_page='SCHEDULE_ACTIVE_SLEEP'
  1071. // onlyCheck={true}
  1072. // schedules={[]}
  1073. confirm={(res) => {
  1074. setShowModal(false)
  1075. if ((res as any).result) {
  1076. global.refreshWindow()
  1077. // dispatch(setSchedules((res as any).schedules))
  1078. // dispatch(setFooter((res as any).footer))
  1079. // setList((res as any).schedules)
  1080. // setErrors([])
  1081. }
  1082. else {
  1083. jumpPage('/_health/pages/schedules?mode=' + health.mode + '&error=' + JSON.stringify(res))
  1084. // setList((res as any).schedules)
  1085. // dispatch(setFooter((res as any).footer))
  1086. // setErrors((res as any).error_messages ? (res as any).error_messages : [])
  1087. }
  1088. }}
  1089. color={MainColorType.active} />
  1090. }
  1091. </View >
  1092. }