long_card.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { MainColorType } from "@/context/themes/color";
  2. import { View, Text, Image, ScrollView } from "@tarojs/components";
  3. import './long_card.scss'
  4. import { rpxToPx } from "@/utils/tools";
  5. import ShareBtn from "@/components/basic/ShareBtn";
  6. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  7. import { useDispatch, useSelector } from "react-redux";
  8. import { getScenario } from "@/features/health/hooks/health_hooks";
  9. import { setFollow, setJoinData, setJoinTitle } from "@/store/long";
  10. import Taro from "@tarojs/taro";
  11. import { useTranslation } from "react-i18next";
  12. import { IconArrow } from "@/components/basic/Icons";
  13. export default function LongCard(props: { join?: any, user?: any, hideJoin?: boolean, share?: any, title?: string, isFeedItem?: boolean }) {
  14. const { status, key, from, window } = props.join
  15. const health = useSelector((state: any) => state.health);
  16. const user = useSelector((state: any) => state.user);
  17. const long = useSelector((state: any) => state.long);
  18. const dispatch = useDispatch()
  19. const { t } = useTranslation()
  20. let type = 0
  21. function join(e) {
  22. if (process.env.TARO_ENV == 'weapp') {
  23. e.stopPropagation()
  24. }
  25. if (props.user) {
  26. dispatch(setFollow(props.user))
  27. }
  28. if (props.title) {
  29. dispatch(setJoinTitle(props.title))
  30. }
  31. dispatch(setJoinData(props.join))
  32. if (!user.isLogin) {
  33. jumpPage('/_account/pages/ChooseAuth')
  34. return
  35. }
  36. if (window == 'ACTIVE' || window == 'EAT') {
  37. jumpPage(`/_record/pages/log_record?scenario=${window == 'EAT' ? 'MEAL' : 'ACTIVITY'}&join_id=${key}`)
  38. // jumpPage(`/_health/pages/add_moment?join_id=${key}&is_temp=${true}&window=${window}&title=${props.title ?? long.title}`)
  39. }
  40. else {
  41. if (window == 'FAST') {
  42. // if (getScenario(health.windows, 'FAST').status == 'WFS') {
  43. // //jumpPage(`/_health/pages/log_time?index=${health.mode == 'FAST' ? 0 : 1}&single=1&is_start=1&window=${health.mode}&op_page=${health.mode == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
  44. // jumpPage(`/_health/pages/log_time?join_id=${key}&index=0&single=1&is_start=1&window=${window}`)
  45. // }
  46. // else {
  47. // //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}&op_page=${health.mode == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
  48. // jumpPage(`/_health/pages/log_time?join_id=${key}&index=3&single=1&is_start=0&window=${window}`)
  49. // }
  50. jumpPage(`/_record/pages/time_record?scenario=${window}&join_id=${key}`)
  51. }
  52. else if (window == 'SLEEP') {
  53. jumpPage(`/_record/pages/time_record?scenario=${window}&join_id=${key}`)
  54. // if (getScenario(health.windows, 'SLEEP').status == 'WFS') {
  55. // //jumpPage(`/_health/pages/log_time?index=${health.mode == 'FAST' ? 0 : 1}&single=1&is_start=1&window=${health.mode}&op_page=${health.mode == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
  56. // jumpPage(`/_health/pages/log_time?join_id=${key}&index=1&single=1&is_start=1&window=${window}`)
  57. // }
  58. // else {
  59. // //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}&op_page=${health.mode == 'FAST' ? 'HOME_FAST' : 'HOME_SLEEP'}`)
  60. // jumpPage(`/_health/pages/log_time?join_id=${key}&index=2&single=1&is_start=0&window=${window}`)
  61. // }
  62. }
  63. }
  64. }
  65. function goDetail() {
  66. if (!user.isLogin) {
  67. jumpPage('/_account/pages/ChooseAuth')
  68. return
  69. }
  70. if (props.user) {
  71. dispatch(setFollow(props.user))
  72. }
  73. if (props.title) {
  74. dispatch(setJoinTitle(props.title))
  75. }
  76. dispatch(setJoinData(props.join))
  77. jumpPage(`/_moment/pages/long_detail?join_id=${key}&window=${window}&status=${status}`)
  78. }
  79. function share() {
  80. // global.join_id = key
  81. if (props.share) {
  82. props.share()
  83. }
  84. // if (props.isFeedItem){
  85. // Taro.eventCenter.trigger('moment_share',{
  86. // })
  87. // }
  88. }
  89. function users() {
  90. return <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  91. {
  92. props.join.users.map((item, index) => {
  93. // if (index > 4) return
  94. return <Image className="long_avatar" mode="aspectFill" style={{
  95. zIndex: 10 - index,
  96. marginLeft: index == 0 ? 0 : -rpxToPx(20)
  97. }} src={item.avatar} key={index} />
  98. })
  99. }
  100. {/* <View className="long_avatar"></View> */}
  101. {/* <View className="h26" style={{ marginLeft: rpxToPx(6) }}>{props.join.users.length > 5 ? `+${props.join.users.length - 5} more ` : ''}</View> */}
  102. </View>
  103. }
  104. if (status == 'JOIN')
  105. return <View onClick={goDetail} style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(24) }}>
  106. {
  107. (props.join && props.join.user_count == 0) && <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  108. <Image className="long_avatar" mode="aspectFill" style={{
  109. marginRight: rpxToPx(6)
  110. }} src={props.join.user.avatar} />
  111. </View>
  112. }
  113. {
  114. props.join && props.join.user_count > 0 && users()
  115. }
  116. <View className="h24">在跟卡</View>
  117. <IconArrow width={rpxToPx(24)} color={MainColorType.g02}/>
  118. </View>
  119. if (status == 'SHARE') {
  120. return <View />
  121. }
  122. return <View />
  123. }