index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import { Tabs, Tab, Calendar, Icon } from 'vant'
  4. import { defineComponent, reactive, ref } from 'vue'
  5. import { useRouter } from 'vue-router'
  6. // import linkBg from './images/ranking-bg.png'
  7. import TimerBang from './components/timer-bang'
  8. import DayBang from './components/day-bang'
  9. import styles from './index.module.less'
  10. import dayjs from 'dayjs'
  11. import isBetween from 'dayjs/plugin/isBetween'
  12. dayjs.extend(isBetween)
  13. const activeName = ref('day')
  14. const timers = ref('')
  15. export default defineComponent({
  16. name: 'ranking-list',
  17. setup() {
  18. const router = useRouter()
  19. const state = reactive({
  20. heightV: 0,
  21. showPopoverTime: false,
  22. startTime: dayjs().day(1).format('YYYY-MM-DD'),
  23. endTime: dayjs().day(7).format('YYYY-MM-DD')
  24. })
  25. const setTime = (val: string) => {
  26. timers.value = val
  27. }
  28. const getHeight = (dataHeight: number) => {
  29. state.heightV = dataHeight
  30. console.log(state.heightV, '获取高度')
  31. }
  32. return () => (
  33. <>
  34. <OSticky position="top" background="#F8F8F8" onGetHeight={getHeight}>
  35. <div class={styles.topWrap}>
  36. <OHeader
  37. color={'#ffffff'}
  38. backIconColor="white"
  39. background={'transparent'}
  40. border={false}
  41. ></OHeader>
  42. <span class={styles.topTime} onClick={() => (state.showPopoverTime = true)}>
  43. {state.startTime}~{state.endTime}
  44. {/* <i></i> */}
  45. <Icon
  46. name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'}
  47. class={styles.imgIcon}
  48. />
  49. </span>
  50. </div>
  51. <Tabs
  52. v-model:active={activeName.value}
  53. class={styles.rankTabs}
  54. background={'rgba(224, 69, 21,.71)'}
  55. title-active-color={'#fff'}
  56. title-inactive-color={'#fff'}
  57. color={'#fff'}
  58. >
  59. <Tab name="day" title="天数榜"></Tab>
  60. <Tab name="timer" title="时长榜"></Tab>
  61. </Tabs>
  62. </OSticky>
  63. {activeName.value == 'timer' ? (
  64. <TimerBang
  65. startTime={state.startTime}
  66. endTime={state.endTime}
  67. toHeight={state.heightV}
  68. ></TimerBang>
  69. ) : (
  70. <DayBang
  71. startTime={state.startTime}
  72. endTime={state.endTime}
  73. toHeight={state.heightV}
  74. ></DayBang>
  75. )}
  76. <Calendar
  77. v-model:show={state.showPopoverTime}
  78. firstDayOfWeek={1}
  79. showConfirm={false}
  80. type="range"
  81. maxRange={7}
  82. minDate={new Date('2023-02-27')}
  83. defaultDate={[dayjs(state.startTime).toDate(), dayjs(state.endTime).toDate()]}
  84. style={{
  85. height: '70%'
  86. }}
  87. onSelect={(item: any) => {
  88. state.startTime = ''
  89. state.endTime = ''
  90. if (!dayjs(item[0]).isBetween(dayjs(state.startTime), dayjs(state.endTime))) {
  91. state.startTime = dayjs(item[0]).day(1).format('YYYY-MM-DD')
  92. state.endTime = dayjs(item[0]).day(7).format('YYYY-MM-DD')
  93. }
  94. state.showPopoverTime = false
  95. }}
  96. />
  97. </>
  98. )
  99. }
  100. })