recents.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { ScrollView, View, Text } from "@tarojs/components";
  2. import './recents.scss'
  3. import Layout from "@/components/layout/layout";
  4. import { useTranslation } from "react-i18next";
  5. import NewHeader, { NewHeaderType } from "../components/new_header";
  6. import { rpxToPx } from "@/utils/tools";
  7. import NewButton, { NewButtonType } from "../base/new_button";
  8. import { getThemeColor } from "@/features/health/hooks/health_hooks";
  9. import { MainColorType } from "@/context/themes/color";
  10. import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
  11. import { useEffect, useRef, useState } from "react";
  12. import MainHistory from "@/features/health/MainHistory";
  13. import Taro from "@tarojs/taro";
  14. import { checkSummaries } from "@/services/health";
  15. import StickyDateList from "../components/sticky_date_list";
  16. export default function Recents() {
  17. const [mode, setMode] = useState('EAT')
  18. const { t } = useTranslation()
  19. const historyRef = useRef()
  20. const [list, setList] = useState<any>([])
  21. const [isPulling,setIsPulling] = useState(false)
  22. useEffect(() => {
  23. getData()
  24. }, [])
  25. function getData() {
  26. checkSummaries().then(res => {
  27. setList((res as any).windows)
  28. setMode((res as any).windows[0].window)
  29. })
  30. }
  31. if (list.length == 0) {
  32. return <View />
  33. }
  34. function detail() {
  35. return <StickyDateList
  36. isPulling={isPulling}
  37. showDate={false}
  38. date={''}
  39. onRefresherRefresh={() => {
  40. global.refreshWindow()
  41. setIsPulling(true)
  42. if (global.refreshHistory) {
  43. global.refreshHistory()
  44. }
  45. }}
  46. loadMore={() => {
  47. if (historyRef) {
  48. (historyRef.current as any).more()
  49. }
  50. }}
  51. onScroll={e => {
  52. // props.onScroll(e)
  53. // if (showDate && e.detail.scrollTop > 100) {
  54. // dispatch(setTitle(t('health.recents')))
  55. // }
  56. // else if (e.detail.scrollTop > 100) {
  57. // dispatch(setTitle(t('health.today')))
  58. // }
  59. // else {
  60. // dispatch(setTitle(''))
  61. // }
  62. // if (historyRef2) {
  63. // (historyRef2.current as any).onScroll(e)
  64. // }
  65. if (e.detail.scrollTop > 100){
  66. Taro.setNavigationBarTitle({
  67. title:t('health.check_ins')
  68. })
  69. }
  70. else {
  71. Taro.setNavigationBarTitle({
  72. title:''
  73. })
  74. }
  75. }}
  76. ><View style={{ display: 'flex', flexDirection: 'column', height: '100vh' }}>
  77. <NewHeader type={NewHeaderType.left} title={t('health.check_ins')} />
  78. <ScrollView style={{ width: rpxToPx(750), flexDirection: 'row', display: 'flex', height: rpxToPx(72) }} scrollX enableFlex showScrollbar={false}>
  79. <View style={{ display: 'flex', flexDirection: 'row', flexShrink: 0 }}>
  80. <View style={{ width: rpxToPx(40), flexShrink: 0 }} />
  81. {
  82. list.map((item, index) => {
  83. return <NewButton key={index} type={NewButtonType.img} onClick={() => setMode(item.window)}>
  84. <View className="streak_toolbar_btn"
  85. style={{ backgroundColor: mode == item.window ? getThemeColor(item.window) + '1A' : 'transparent' }}
  86. >
  87. <Text className={mode == item.window ? 'bold h30' : 'h30'}
  88. style={{ color: mode == item.window ? getThemeColor(item.window) : MainColorType.g01, marginRight: 5 }}>{item.title}</Text>
  89. <Text className={mode == item.window ? 'bold h20' : 'h20'}
  90. style={{ color: mode == item.window ? getThemeColor(item.window) : MainColorType.g01 }}>{item.log_count}</Text>
  91. </View>
  92. </NewButton>
  93. })
  94. }
  95. <View style={{ width: rpxToPx(40), flexShrink: 0 }} />
  96. </View>
  97. </ScrollView>
  98. <View style={{ height: rpxToPx(36), flexShrink: 0 }} />
  99. <MainHistory ref={historyRef} type={mode} updateDate={(e) => {
  100. // setShowDate(e.show)
  101. // setDate(e.date)
  102. }} />
  103. </View>
  104. </StickyDateList>
  105. }
  106. return detail()
  107. // return <Layout children={detail()}
  108. // title={t('health.check_ins')}
  109. // type={TemplateType.customHeader}
  110. // titleShowStyle={NaviBarTitleShowType.scrollToShow}
  111. // />
  112. }