Clock.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. import { View, Text, Image, ScrollView, PageContainer, Swiper, SwiperItem, Switch } from "@tarojs/components";
  2. import Tabbar from "@/components/navigation/TabBar";
  3. import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
  4. import Rings from "@/features/trackTimeDuration/components/Rings";
  5. import './Clock.scss'
  6. import { useDispatch, useSelector } from "react-redux";
  7. import { useDidHide, useDidShow, usePageScroll, useReady, useShareAppMessage } from "@tarojs/taro";
  8. import Taro from "@tarojs/taro";
  9. import { getInfoSuccess } from "@/store/user";
  10. import { clockHome, clockSummaryRecords, clockSummaryStats, getClockRecords, getClocks, getPlans } from "@/services/trackTimeDuration";
  11. import { updateScenario } from "@/store/time";
  12. import { setConfigs } from "@/store/common";
  13. import { setScenario, setStep } from "@/store/scenario";
  14. import { useEffect, useState } from "react";
  15. import { IconPlus, IconRadioCheck, IconRadioCross } from "@/components/basic/Icons";
  16. import { ColorType } from "@/context/themes/color";
  17. import { bigRingRadius, getBgRing, getCommon, getDot, getSchedule, ringWidth, smallRingRadius } from "@/features/trackTimeDuration/hooks/RingData";
  18. import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  19. import IndexConsole from "@/features/trackTimeDuration/components/IndexConsole";
  20. import Modal from '@/components/layout/Modal'
  21. import { rpxToPx } from "@/utils/tools";
  22. import RecordFastSleep from "@/features/trackTimeDuration/components/RecordFastSleep";
  23. import DayLight from "@/features/trackTimeDuration/components/DayLight";
  24. import { getInfo, latestLocation } from "@/services/user";
  25. import { TimeFormatter } from "@/utils/time_format";
  26. import WeekCalendar from "@/features/trackTimeDuration/components/WeekCalendar";
  27. import { useTranslation } from "react-i18next";
  28. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  29. import Layout from "@/components/layout/layout";
  30. import { ModalType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
  31. import TitleView from "@/features/trackTimeDuration/components/TitleView";
  32. import ClockHeader from "@/features/trackTimeDuration/components/ClockHeader";
  33. import DurationPicker from "@/features/trackTimeDuration/components/DurationPicker";
  34. import SegmentPop from "@/features/trackTimeDuration/components/SegmentPop";
  35. import Box from "@/components/layout/Box";
  36. import DayNightCard from "@/features/trackTimeDuration/components/DayNightCard";
  37. import StageSelector from "@/features/trackTimeDuration/components/StageSelector";
  38. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  39. import { clearNightStore, showNight } from "@/store/night";
  40. import { showDay } from "@/store/day";
  41. import { clientInfo, staticResources } from "@/services/common";
  42. import { changeFastDuration, changeSleepDuration, setCurrentRecord, setSchedule } from "@/store/ring";
  43. import { checkAuthorized } from "@/utils/check_authorized";
  44. import NoData from "@/components/view/NoData";
  45. import { AtActivityIndicator } from "taro-ui";
  46. import Tooltip from "@/components/view/Tooltip";
  47. let GradientText
  48. let useNavigation;
  49. let timer
  50. let pauseTimer = false;
  51. let AppState;
  52. let needScroll = false;
  53. if (process.env.TARO_ENV == 'rn') {
  54. AppState = require("react-native").AppState
  55. GradientText = require('@/components/basic/GradientText').default
  56. useNavigation = require("@react-navigation/native").useNavigation
  57. }
  58. const defaultValue = `[{"scenario":{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}},"current_record":{"scenario":"FAST_SLEEP","status":"WAIT_FOR_START","fast":{"status":"WAIT_FOR_START","target_start_time":1710514800000,"target_end_time":1710576000000},"sleep":{"status":"WAIT_FOR_START","target_start_time":1710540000000,"target_end_time":1710572400000}},"wx_pub_followed":false,"time_input_schema":{"min":60,"max":1380,"step":5},"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}},{"scenarios":[{"name":"FAST","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"}}},{"name":"SLEEP","count":0,"schedule":{"sleep":{"start_time":"22:00","end_time":"07:00"}}},{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}}],"select_count":0,"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}}]`
  59. export default function Page() {
  60. const dispatch = useDispatch();
  61. global.dispatch = dispatch;
  62. let navigation;
  63. if (useNavigation) {
  64. navigation = useNavigation()
  65. }
  66. const { t } = useTranslation()
  67. const user = useSelector((state: any) => state.user);
  68. const time = useSelector((state: any) => state.time);
  69. const [count, setCount] = useState(0)
  70. const [homeData, setHomeData] = useState(null)
  71. const [loaded, setLoaded] = useState(false)
  72. const [showErrorPage, setErrorPage] = useState(false)
  73. const [showModal, setShowModal] = useState(false)
  74. const [modalDetail, setModalDetail] = useState<any>(null)
  75. const [showModal2, setShowModal2] = useState(false)
  76. const [modalDetail2, setModalDetail2] = useState<any>(null)
  77. const [debugInfo, setDebugInfo] = useState(null)
  78. const [needShowAddTip, setNeedShowAddTip] = useState(false)
  79. const [showTip, setShowTip] = useState(false)
  80. const [records, setRecords] = useState([])
  81. const permission = useSelector((state: any) => state.permission);
  82. const common = useSelector((state: any) => state.common);
  83. const nightStore = useSelector((state: any) => state.night);
  84. if (process.env.TARO_ENV == 'weapp') {
  85. useShareAppMessage((e) => {
  86. return {
  87. title: t('feature.track_time_duration.common.share_title'),
  88. path: 'pages/clock/Clock'
  89. }
  90. })
  91. }
  92. useEffect(() => {
  93. dispatch(staticResources() as any);
  94. timer = setInterval(() => {
  95. var now = new Date()
  96. if (now.getDay() == 0 && now.getHours() == 12 && now.getMinutes() == 0 && now.getSeconds() == 0) {
  97. if (global.refrehWeekly) {
  98. global.refrehWeekly()
  99. }
  100. }
  101. if (global.pauseIndexTimer || pauseTimer) {
  102. return
  103. }
  104. setCount((prevCounter) => prevCounter + 1)
  105. }, 1000)
  106. }, [])
  107. useEffect(() => {
  108. if (process.env.TARO_ENV == 'weapp') {
  109. loadWXCache()
  110. }
  111. else {
  112. loadRNCache()
  113. }
  114. if (process.env.TARO_ENV == 'rn') {
  115. AppState.addEventListener('change', handleAppStateChange);
  116. }
  117. }, [])
  118. useEffect(() => {
  119. getCheckData()
  120. global.pauseIndexTimer = !user.isLogin
  121. if (user.isLogin) {
  122. uploadUserClient();
  123. checkAuthorized();
  124. //检查用户是否添加过小程序
  125. checkAddToMini();
  126. }
  127. else {
  128. dispatch(clearNightStore());
  129. }
  130. }, [user.isLogin])
  131. useReady(async () => {
  132. const userData = await getStorage('userData');
  133. if (userData) {
  134. dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
  135. getHistory()
  136. }
  137. })
  138. async function checkVersionUpdate() {
  139. if (!user.isLogin) {
  140. return
  141. }
  142. const showAlert = await getStorage('117alert') || false;
  143. if (!showAlert) {
  144. Taro.showModal({
  145. title: '版本更新提示',
  146. content: '【昼夜环】追踪每天日出日落时间;\n【周统计】查看每周断食和睡眠平均时长;\n【记录筛选】根据场景, 浏览历史记录',
  147. showCancel: false,
  148. confirmText: '我知道了'
  149. })
  150. }
  151. Taro.setStorage({ key: '117alert', data: true })
  152. }
  153. function checkAddToMini() {
  154. process.env.TARO_ENV == 'weapp' &&
  155. wx.checkIsAddedToMyMiniProgram({
  156. success: (res) => {
  157. if (!res.added) {
  158. setNeedShowAddTip(true)
  159. }
  160. },
  161. fail: (e) => {
  162. }
  163. });
  164. }
  165. useDidShow(() => {
  166. checkTimeZone()
  167. setCount(pre => pre + 1)
  168. //resume timer
  169. pauseTimer = false
  170. if (user.isLogin) {
  171. // getInfo().then(res => {
  172. // dispatch(getInfoSuccess(res))
  173. // }).catch(e => {
  174. // Taro.stopPullDownRefresh()
  175. // })
  176. if (global.refreshRecent) {
  177. global.refreshRecent()
  178. }
  179. }
  180. setTimeout(() => {
  181. checkVersionUpdate();
  182. }, 1000)
  183. })
  184. usePageScroll((e) => {
  185. if (e.scrollTop > 70) {
  186. setShowTip(true)
  187. }
  188. else {
  189. setShowTip(false)
  190. }
  191. })
  192. useDidHide(() => {
  193. //pause timer
  194. pauseTimer = true
  195. })
  196. global.refreshIndex = () => {
  197. setCount((prevCounter) => prevCounter + 1)
  198. }
  199. const handleAppStateChange = (nextAppState) => {
  200. checkTimeZone()
  201. };
  202. function checkTimeZone() {
  203. var split = new Date().toString().split(' ');
  204. var timeZoneFormatted = split[split.length - 2];
  205. Taro.getStorage({
  206. key: 'last_tz',
  207. success: function (res) {
  208. if (res.data && res.data != timeZoneFormatted) {
  209. if (global.refrehWeekly) {
  210. global.refrehWeekly()
  211. }
  212. if (global.currentStatus != 'WAIT_FOR_START') {
  213. Taro.showModal({
  214. title: t('feature.track_time_duration.change_tz_alert.title'),
  215. content: t('feature.track_time_duration.change_tz_alert.content', { tz: timeZoneFormatted }),
  216. showCancel: false,
  217. confirmText: t('feature.track_time_duration.change_tz_alert.confirm'),
  218. })
  219. }
  220. }
  221. },
  222. complete: function () {
  223. Taro.setStorage({ key: 'last_tz', data: timeZoneFormatted })
  224. }
  225. })
  226. }
  227. function uploadUserClient() {
  228. var systemInfo = Taro.getSystemInfoSync();
  229. console.log(systemInfo)
  230. var split = new Date().toString().split(' ');
  231. var timeZoneFormatted = split[split.length - 2];
  232. clientInfo({
  233. client: {
  234. client_type: process.env.TARO_ENV == 'weapp' ? 'MP' : 'APP',
  235. client_version: process.env.TARO_ENV == 'weapp' ? '1.3.6':'1.0',//Taro.getAccountInfoSync().miniProgram.version : '1.0',//'1.0'
  236. wx_version: process.env.TARO_ENV == 'weapp' ? systemInfo.version : '_'
  237. },
  238. meta: {
  239. language: systemInfo.language,
  240. time_zone: {
  241. // id: Intl.DateTimeFormat().resolvedOptions().timeZone,
  242. name: timeZoneFormatted
  243. },
  244. },
  245. device: {
  246. brand: systemInfo.brand,
  247. model: systemInfo.model,
  248. platform: systemInfo.platform,
  249. system: systemInfo.system
  250. },
  251. perm: {
  252. wifi_enabled: systemInfo.wifiEnabled,
  253. location_authorized: systemInfo.locationAuthorized,
  254. location_enabled: systemInfo.locationEnabled
  255. }
  256. })
  257. }
  258. function loadWXCache() {
  259. var showDayRing = Taro.getStorageSync('showDayRing') || false;
  260. var showNightRing = Taro.getStorageSync('showNightRing') || false;
  261. dispatch(showDay(showDayRing))
  262. dispatch(showNight(showNightRing))
  263. var gps = Taro.getStorageSync('gps')
  264. if (gps) {
  265. global.locationDetail = JSON.parse(gps)
  266. }
  267. var userData = Taro.getStorageSync('userData')
  268. if (userData) {
  269. dispatch(getInfoSuccess(JSON.parse(userData)));
  270. }
  271. }
  272. async function loadRNCache() {
  273. var showDayRing = await getStorage('showDayRing') || false;
  274. var showNightRing = await getStorage('showNightRing') || false;
  275. dispatch(showDay(showDayRing))
  276. dispatch(showNight(showNightRing))
  277. var gps = await getStorage('gps')
  278. if (gps) {
  279. global.locationDetail = JSON.parse(gps)
  280. }
  281. var userData = await getStorage('userData')
  282. if (userData) {
  283. dispatch(getInfoSuccess(JSON.parse(userData)));
  284. }
  285. }
  286. function getCheckData() {
  287. Promise.all([getClocks(), getPlans()]).then((list) => {
  288. setErrorPage(false)
  289. setCheckData(list)
  290. if (needScroll) {
  291. needScroll = false
  292. setTimeout(() => {
  293. Taro.createSelectorQuery().select('#latest').boundingClientRect((rect) => {
  294. Taro.pageScrollTo({
  295. scrollTop: (rect as any).top,
  296. duration: 150
  297. })
  298. }).exec()
  299. }, 100)
  300. }
  301. }).catch((e) => {
  302. setErrorPage(true)
  303. var list = JSON.parse(defaultValue)
  304. setCheckData(list)
  305. needScroll = false
  306. })
  307. getHistory()
  308. }
  309. function setCheckData(list: any) {
  310. setHomeData(list[0])
  311. global.homeData = list[0]
  312. global.currentStatus = list[0].current_record.status;
  313. var array = list[1].scenarios
  314. var schedule = null
  315. array.map(item => {
  316. if (item.name == 'FAST_SLEEP') {
  317. schedule = item.schedule;
  318. }
  319. })
  320. if (user.isLogin) {
  321. dispatch(updateScenario(list[0].current_record))
  322. dispatch(setConfigs(list[0].time_input_schema));
  323. dispatch(setScenario(list[0].scenario));
  324. global.scenario = list[0].scenario.name;
  325. }
  326. dispatch(setCurrentRecord(list[0].current_record))
  327. dispatch(setSchedule(schedule))
  328. setLoaded(true)
  329. }
  330. function getHistory() {
  331. if (user.isLogin)
  332. getClockRecords({
  333. page: 1,
  334. limit: 1,
  335. // part_completed: true
  336. completed: true
  337. }).then(res => {
  338. setRecords((res as any).data)
  339. })
  340. }
  341. global.indexPageRefresh = () => {
  342. getCheckData()
  343. }
  344. global.showIndexModal = (isShow: boolean, detail: any, debugNode?: any) => {
  345. global.showModal = isShow
  346. setDebugInfo(debugNode)
  347. setShowModal(isShow)
  348. setModalDetail(detail)
  349. }
  350. global.showIndexModal2 = (isShow: boolean, detail: any) => {
  351. setDebugInfo(null)
  352. global.showModal = isShow
  353. setShowModal2(isShow)
  354. setModalDetail2(detail)
  355. }
  356. global.changeTargetDuration = (duration: number, isFast: boolean) => {
  357. var obj = JSON.parse(JSON.stringify(homeData))
  358. var record = obj.current_record
  359. if (isFast) {
  360. record.fast.target_end_time = record.fast.target_start_time + duration * 60 * 1000
  361. }
  362. else {
  363. record.sleep.target_end_time = record.sleep.target_start_time + duration * 60 * 1000
  364. }
  365. setHomeData(obj)
  366. }
  367. global.updateFastSleepData = (data: any) => {
  368. if (data.id == (homeData as any).current_record.id) {
  369. var obj = JSON.parse(JSON.stringify(homeData))
  370. obj.current_record = data
  371. setHomeData(obj)
  372. }
  373. switch (data.scenario) {
  374. case 'FAST':
  375. if (data.status == 'WAIT_FOR_START') {
  376. dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
  377. }
  378. break;
  379. case 'SLEEP':
  380. if (data.status == 'WAIT_FOR_START') {
  381. dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
  382. }
  383. break;
  384. case 'FAST_SLEEP':
  385. if (data.status == 'WAIT_FOR_START') {
  386. dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
  387. }
  388. else if (data.status == 'ONGOING1') {
  389. debugger
  390. dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
  391. }
  392. break;
  393. }
  394. }
  395. global.popScheduleAlert = (scenario, startTime) => {
  396. if (permission.wxPubFollow) {
  397. debugger
  398. Taro.showModal({
  399. title: t('feature.track_time_duration.reminders.schedule_title'),
  400. content: scenario.name == 'FAST' ?
  401. t('feature.track_time_duration.reminders.enable_schedule_fast_content', { time: startTime }) :
  402. t('feature.track_time_duration.reminders.enable_schedule_sleep_content', { time: startTime }),
  403. showCancel: false,
  404. confirmText: t('feature.track_time_duration.reminders.ok')
  405. })
  406. }
  407. else {
  408. Taro.showModal({
  409. title: t('feature.track_time_duration.reminders.schedule_title'),
  410. content: scenario.name == 'FAST' ?
  411. t('feature.track_time_duration.reminders.schedule_fast_content', { time: startTime }) :
  412. t('feature.track_time_duration.reminders.schedule_sleep_content', { time: startTime }),
  413. cancelText: t('feature.track_time_duration.reminders.later'),
  414. confirmText: t('feature.track_time_duration.reminders.open'),
  415. success: function (res) {
  416. if (res.confirm) {
  417. followWxPub()
  418. } else if (res.cancel) {
  419. }
  420. }
  421. })
  422. }
  423. }
  424. global.popMixScheduleAlert = (time1, time2) => {
  425. if (permission.wxPubFollow) {
  426. Taro.showModal({
  427. title: t('feature.track_time_duration.reminders.schedule_title'),
  428. content: t('feature.track_time_duration.reminders.enable_schedule_mix_content', { time1: time1, time2: time2 }),
  429. showCancel: false,
  430. confirmText: t('feature.track_time_duration.reminders.ok')
  431. })
  432. }
  433. else {
  434. Taro.showModal({
  435. title: t('feature.track_time_duration.reminders.schedule_title'),
  436. content:
  437. t('feature.track_time_duration.reminders.schedule_mix_content'),
  438. cancelText: t('feature.track_time_duration.reminders.later'),
  439. confirmText: t('feature.track_time_duration.reminders.open'),
  440. success: function (res) {
  441. if (res.confirm) {
  442. followWxPub()
  443. } else if (res.cancel) {
  444. }
  445. }
  446. })
  447. }
  448. }
  449. function followWxPub() {
  450. const resource = common.resources.filter((item: any) => {
  451. return item.code == 'follow_wx_pub'
  452. })
  453. jumpPage('/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url)
  454. }
  455. function modalContent() {
  456. if (showModal || showModal2) {
  457. if (process.env.TARO_ENV == 'weapp') {
  458. return <Modal
  459. testInfo={debugInfo}
  460. dismiss={() => {
  461. setDebugInfo(null)
  462. setShowModal(false);
  463. setShowModal2(false);
  464. global.pauseIndexTimer = false
  465. }}
  466. confirm={() => { }}>
  467. {
  468. showModal ? modalDetail : modalDetail2
  469. }
  470. </Modal>
  471. }
  472. else if (process.env.TARO_ENV == 'rn') {
  473. return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
  474. // overlayStyle='background-color:rgba(0,0,0,0.9)'
  475. // custom-style='background-color:#1c1c1c'
  476. overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
  477. customStyle={{ backgroundColor: '#1c1c1c' }}
  478. closeOnSlideDown={false}
  479. onBeforeEnter={() => {
  480. Taro.hideTabBar();
  481. }}
  482. onBeforeLeave={() => {
  483. Taro.showTabBar();
  484. }}
  485. onClick={() => { alert('b') }}
  486. onClickOverlay={() => { alert('a') }}
  487. onAfterLeave={() => { setShowModal(false); setShowModal2(false); global.pauseIndexTimer = false }}
  488. show={showModal || showModal2} round={true} overlay={true} position='bottom'
  489. >
  490. {
  491. showModal ? modalDetail : modalDetail2
  492. }
  493. </PageContainer>
  494. }
  495. }
  496. return <View />
  497. }
  498. async function getStorage(key: string) {
  499. try {
  500. const res = await Taro.getStorage({ key });
  501. return res.data;
  502. } catch {
  503. return '';
  504. }
  505. }
  506. function more() {
  507. jumpPage('/pages/common/RecordsHistory?type=time&title=time', 'RecordsHistory', navigation, {
  508. type: 'time',
  509. title: 'time'
  510. })
  511. }
  512. function tapLogin() {
  513. if (process.env.TARO_ENV=='rn'){
  514. Taro.getLocation({
  515. success(result) {
  516. console.log(result)
  517. },
  518. fail(res) {
  519. console.log(res)
  520. },
  521. })
  522. return
  523. }
  524. if (!user.isLogin) {
  525. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
  526. return
  527. }
  528. }
  529. function headerView() {
  530. return <ClockHeader homeData={homeData} />
  531. }
  532. global.scrollToLatest = () => {
  533. needScroll = true;
  534. }
  535. var timestamp = new Date().getTime()
  536. function render() {
  537. if (!loaded) {
  538. return <Layout type={TemplateType.customHeader} header={headerView()} title={t('page.clock.title')} titleShowStyle={NaviBarTitleShowType.scrollToShow}>
  539. <View style={{ width: rpxToPx(750), height: rpxToPx(900), display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
  540. <AtActivityIndicator size={40} color="#fff" />
  541. <Tabbar index={0} />
  542. </View>
  543. </Layout>
  544. }
  545. return <Layout type={TemplateType.customHeader} header={headerView()} title={t('page.clock.title')} titleShowStyle={NaviBarTitleShowType.scrollToShow}>
  546. <View className="index_container">
  547. {
  548. needShowAddTip && showTip && <Tooltip title="添加到我的小程序" closeTip={() => { setNeedShowAddTip(false) }} />
  549. }
  550. <Text className="count">{count}</Text>
  551. <Box>
  552. <View>
  553. <IndexItem type="FAST_SLEEP" data={homeData} time={timestamp} showStage={false} />
  554. {
  555. user.isLogin ? <IndexConsole record={homeData} /> : <StageSelector />
  556. }
  557. </View>
  558. </Box>
  559. <DayNightCard isNight={true} count={count} />
  560. {
  561. user.isLogin && records.length > 0 && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginTop: rpxToPx(40), }}>
  562. {
  563. <Text className="discovery1" style={{ marginBottom: 0 }}>{t('feature.track_time_duration.record_fast_sleep.header.latest_record')}</Text>
  564. }
  565. {
  566. process.env.TARO_ENV == 'weapp' && <Text className="fast_sleep_more index_more" onClick={more}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
  567. }
  568. {
  569. process.env.TARO_ENV == 'rn' && <GradientText onClick={more} style={{ fontSize: rpxToPx(32), fontWeight: 'bold' }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</GradientText>
  570. }
  571. </View>
  572. }
  573. {
  574. user.isLogin && records.length > 0 && <View id="latest" className="fast_sleep_item_bg">
  575. <RecordFastSleep data={records[0]} type='record' index={-20000} />
  576. </View>
  577. }
  578. {
  579. loaded && !user.isLogin && <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginTop: rpxToPx(36) }}>
  580. <ChooseScenarioBtn title={t('feature.auth.login.login_now')} background={ColorType.fast} onClick={tapLogin} />
  581. </View>
  582. }
  583. {
  584. showErrorPage && <NoData refresh={() => { getCheckData() }} />
  585. }
  586. {
  587. user.isLogin && !showErrorPage && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
  588. <Text className="discovery1" >周统计</Text>
  589. <WeekCalendar />
  590. </View>
  591. }
  592. <View style={{ height: 100 }} />
  593. {
  594. modalContent()
  595. }
  596. {
  597. homeData && <SegmentPop data={homeData} />
  598. }
  599. {
  600. homeData && <DurationPicker record={(homeData as any).current_record} />
  601. }
  602. <Tabbar index={0} />
  603. </View>
  604. </Layout>
  605. }
  606. // if (process.env.TARO_ENV == 'rn') {
  607. // return <ScrollView>
  608. // {
  609. // render()
  610. // }
  611. // </ScrollView>
  612. // }
  613. return render()
  614. }