More.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { View, Text } from "@tarojs/components";
  2. import Taro from "@tarojs/taro";
  3. import { useEffect } from "react";
  4. import { useTranslation } from "react-i18next";
  5. import { useSelector } from "react-redux";
  6. import trackTimeService, { machine } from "@/store/trackTimeMachine"
  7. import { recordCheck } from "@/services/trackTimeDuration";
  8. export default function Component() {
  9. const { t } = useTranslation()
  10. const scenario = useSelector((state: any) => state.scenario);
  11. useEffect(() => {
  12. var value = trackTimeService.getSnapshot().value
  13. }, [machine.context.currentStatus])
  14. useEffect(() => {
  15. trackTimeService.onTransition(state => {
  16. var value = trackTimeService.getSnapshot().value
  17. });
  18. }, []);
  19. function waitActionSheet() {
  20. Taro.showActionSheet({
  21. itemList: [t('feature.track_time_duration.action_sheet.change_schedule'), t('feature.track_time_duration.action_sheet.switch_scenario')]
  22. })
  23. .then(res => {
  24. console.log(res.tapIndex)
  25. switch (res.tapIndex) {
  26. case 0:
  27. Taro.navigateTo({
  28. url: '/pages/SetSchedule'
  29. })
  30. break;
  31. case 1:
  32. Taro.navigateTo({
  33. url: '/pages/ChooseScenario'
  34. })
  35. break;
  36. }
  37. })
  38. .catch(err => {
  39. console.log(err.errMsg)
  40. })
  41. }
  42. function endFastActionSheet() {
  43. Taro.showActionSheet({
  44. itemList: [t('feature.track_time_duration.action_sheet.end_fast')]
  45. })
  46. .then(res => {
  47. console.log(res.tapIndex)
  48. switch (res.tapIndex) {
  49. case 0:
  50. {
  51. const start_time = new Date().getTime();
  52. // const duration = 8 * 3600 * 1000;
  53. const extra = {
  54. set_time: start_time - 20 * 1000,
  55. confirm_time: start_time + 50 * 1000,
  56. }
  57. recordCheck({
  58. action: 'FAST_END',
  59. real_check_time: start_time,
  60. extra: extra
  61. }).then(res => {
  62. trackTimeService.send({ type: 'END_FAST' });
  63. console.log(res);
  64. trackTimeService.send({ type: 'RESET' });
  65. trackTimeService.send({ type: global.scenario.name });
  66. });
  67. }
  68. break;
  69. }
  70. })
  71. .catch(err => {
  72. console.log(err.errMsg)
  73. })
  74. }
  75. function ongoingActionSheet() {
  76. Taro.showActionSheet({
  77. itemList: [t('feature.track_time_duration.action_sheet.give_up'), t('feature.track_time_duration.action_sheet.switch_scenario')]
  78. })
  79. .then(res => {
  80. console.log(res.tapIndex)
  81. })
  82. .catch(err => {
  83. console.log(err.errMsg)
  84. })
  85. }
  86. function checkActionSheetData() {
  87. var state = trackTimeService.getSnapshot().value
  88. debugger
  89. if ((state as any).FAST_SLEEP === 'WAIT_FOR_START' ||
  90. (state as any).FAST === 'WAIT_FOR_START' ||
  91. (state as any).SLEEP === 'WAIT_FOR_START') {
  92. waitActionSheet()
  93. }
  94. else if ((state as any).FAST_SLEEP === 'ONGOING1' ||
  95. (state as any).FAST_SLEEP === 'ONGOING2') {
  96. endFastActionSheet()
  97. }
  98. else if ((state as any).FAST_SLEEP === 'ONGOING3') {
  99. Taro.showToast({
  100. title: '暂无更多操作',
  101. icon: 'none',
  102. duration: 2000
  103. })
  104. }
  105. }
  106. return (
  107. <View>
  108. <Text onClick={checkActionSheetData}>More Component</Text>
  109. </View>
  110. )
  111. }