TitleView.tsx 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { View, Text, Image } from '@tarojs/components'
  2. import './TitleView.scss'
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import Taro from '@tarojs/taro';
  5. import { setStep } from '@/store/scenario';
  6. import { useTranslation } from 'react-i18next';
  7. import { jumpPage } from '../hooks/Common';
  8. export default function Component(props: {
  9. children?: any,
  10. subTitle?: string,
  11. title: string,
  12. titleColor?: string,
  13. secondPage?: boolean,
  14. showAddBtn?: boolean,
  15. onClick?: Function
  16. }) {
  17. const time = useSelector((state: any) => state.time);
  18. const user = useSelector((state: any) => state.user);
  19. const { t } = useTranslation()
  20. const dispatch = useDispatch();
  21. const isFastFirst = true
  22. function more() {
  23. if (props.onClick) {
  24. props.onClick()
  25. return
  26. }
  27. Taro.showActionSheet({
  28. itemList: [
  29. t('feature.track_time_duration.action_sheet.switch_scenario'),
  30. t('feature.track_time_duration.action_sheet.change_schedule')
  31. ]
  32. }).then(res => {
  33. switch (res.tapIndex) {
  34. case 1:
  35. if (time.status != 'WAIT_FOR_START') {
  36. Taro.showToast({
  37. title: t('feature.common.toast.ongoing'),
  38. icon: 'none'
  39. })
  40. return;
  41. }
  42. if (time.scenario == 'FAST_SLEEP') {
  43. dispatch(setStep(isFastFirst ? 'fast' : 'sleep'))
  44. }
  45. else if (time.scenario == 'SLEEP') {
  46. dispatch(setStep('sleep'))
  47. }
  48. else {
  49. dispatch(setStep('fast'))
  50. }
  51. jumpPage('/pages/clock/SetSchedule')
  52. break;
  53. case 0:
  54. if (time.status != 'WAIT_FOR_START') {
  55. Taro.showToast({
  56. title: t('feature.common.toast.ongoing'),
  57. icon: 'none'
  58. })
  59. return;
  60. }
  61. jumpPage('/pages/clock/ChooseScenario')
  62. break;
  63. }
  64. })
  65. .catch(err => {
  66. console.log(err.errMsg)
  67. })
  68. }
  69. var showAddIcon = user.isLogin && props.showAddBtn
  70. return <View className={props.children ? 'title_view' : 'title_view no_sub_element'} >
  71. <View className='title_bg'>
  72. <Text className='title' style={{
  73. color: props.titleColor ? props.titleColor : '#fff',
  74. fontSize: props.secondPage ? 28 : 36
  75. }}>{props.title}</Text>
  76. {
  77. showAddIcon ? <View className='iconAddBg' onClick={more}>
  78. <Image src={require('@/assets/images/add.png')} className='iconAdd' />
  79. </View> : <View className='iconAddBg' style={{ opacity: 0 }}>
  80. <Image src={require('@/assets/images/add.png')} className='iconAdd' />
  81. </View>
  82. }
  83. </View>
  84. {
  85. props.children ? props.children : <View />
  86. }
  87. {
  88. props.subTitle && <Text className='subTitle'>{props.subTitle}</Text>
  89. }
  90. </View>
  91. }