TitleView.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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, titleColor?: string,
  12. secondPage?: boolean,
  13. showAddBtn?: boolean
  14. }) {
  15. const time = useSelector((state: any) => state.time);
  16. const user = useSelector((state: any) => state.user);
  17. const { t } = useTranslation()
  18. const dispatch = useDispatch();
  19. const isFastFirst = true
  20. function more() {
  21. Taro.showActionSheet({
  22. itemList: [
  23. t('feature.track_time_duration.action_sheet.switch_scenario'),
  24. t('feature.track_time_duration.action_sheet.change_schedule')
  25. ]
  26. }).then(res => {
  27. switch (res.tapIndex) {
  28. case 1:
  29. if (time.status != 'WAIT_FOR_START') {
  30. Taro.showToast({
  31. title: t('feature.common.toast.ongoing'),
  32. icon: 'none'
  33. })
  34. return;
  35. }
  36. if (time.scenario == 'FAST_SLEEP') {
  37. dispatch(setStep(isFastFirst ? 'fast' : 'sleep'))
  38. }
  39. else if (time.scenario == 'SLEEP') {
  40. dispatch(setStep('sleep'))
  41. }
  42. else {
  43. dispatch(setStep('fast'))
  44. }
  45. jumpPage('/pages/clock/SetSchedule')
  46. break;
  47. case 0:
  48. if (time.status != 'WAIT_FOR_START') {
  49. Taro.showToast({
  50. title: t('feature.common.toast.ongoing'),
  51. icon: 'none'
  52. })
  53. return;
  54. }
  55. jumpPage('/pages/clock/ChooseScenario')
  56. break;
  57. }
  58. })
  59. .catch(err => {
  60. console.log(err.errMsg)
  61. })
  62. }
  63. return <View className='title_view'>
  64. <View className='title_bg'>
  65. <Text className='title' style={{
  66. color: props.titleColor ? props.titleColor : '#fff',
  67. fontSize: props.secondPage ? 28 : 36
  68. }}>{props.title}</Text>
  69. {
  70. user.isLogin && props.showAddBtn && <View className='iconAddBg' onClick={more}><Image src={require('@/assets/images/add.png')} className='iconAdd' /></View>
  71. }
  72. </View>
  73. {
  74. props.children ? props.children : <View />
  75. }
  76. {
  77. props.subTitle && <Text className='subTitle'>{props.subTitle}</Text>
  78. }
  79. </View>
  80. }