| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { View, Text } from "@tarojs/components";
- import Taro from "@tarojs/taro";
- import { useEffect } from "react";
- import { useTranslation } from "react-i18next";
- import { useSelector } from "react-redux";
- import trackTimeService, { machine } from "@/store/trackTimeMachine"
- import { recordCheck } from "@/services/trackTimeDuration";
- export default function Component() {
- const { t } = useTranslation()
- const scenario = useSelector((state: any) => state.scenario);
- useEffect(() => {
- var value = trackTimeService.getSnapshot().value
- }, [machine.context.currentStatus])
- useEffect(() => {
- trackTimeService.onTransition(state => {
- var value = trackTimeService.getSnapshot().value
- });
- }, []);
- function waitActionSheet() {
- Taro.showActionSheet({
- itemList: [t('feature.track_time_duration.action_sheet.change_schedule'), t('feature.track_time_duration.action_sheet.switch_scenario')]
- })
- .then(res => {
- console.log(res.tapIndex)
- switch (res.tapIndex) {
- case 0:
- Taro.navigateTo({
- url: '/pages/SetSchedule'
- })
- break;
- case 1:
- Taro.navigateTo({
- url: '/pages/ChooseScenario'
- })
- break;
- }
- })
- .catch(err => {
- console.log(err.errMsg)
- })
- }
- function endFastActionSheet() {
- Taro.showActionSheet({
- itemList: [t('feature.track_time_duration.action_sheet.end_fast')]
- })
- .then(res => {
- console.log(res.tapIndex)
- switch (res.tapIndex) {
- case 0:
- {
- const start_time = new Date().getTime();
- // const duration = 8 * 3600 * 1000;
- const extra = {
- set_time: start_time - 20 * 1000,
- confirm_time: start_time + 50 * 1000,
- }
- recordCheck({
- action: 'FAST_END',
- real_check_time: start_time,
- extra: extra
- }).then(res => {
- trackTimeService.send({ type: 'END_FAST' });
- console.log(res);
- trackTimeService.send({ type: 'RESET' });
- trackTimeService.send({ type: global.scenario.name });
- });
- }
- break;
- }
- })
- .catch(err => {
- console.log(err.errMsg)
- })
- }
- function ongoingActionSheet() {
- Taro.showActionSheet({
- itemList: [t('feature.track_time_duration.action_sheet.give_up'), t('feature.track_time_duration.action_sheet.switch_scenario')]
- })
- .then(res => {
- console.log(res.tapIndex)
- })
- .catch(err => {
- console.log(err.errMsg)
- })
- }
- function checkActionSheetData() {
- var state = trackTimeService.getSnapshot().value
- debugger
- if ((state as any).FAST_SLEEP === 'WAIT_FOR_START' ||
- (state as any).FAST === 'WAIT_FOR_START' ||
- (state as any).SLEEP === 'WAIT_FOR_START') {
- waitActionSheet()
- }
- else if ((state as any).FAST_SLEEP === 'ONGOING1' ||
- (state as any).FAST_SLEEP === 'ONGOING2') {
- endFastActionSheet()
- }
- else if ((state as any).FAST_SLEEP === 'ONGOING3') {
- Taro.showToast({
- title: '暂无更多操作',
- icon: 'none',
- duration: 2000
- })
- }
- }
- return (
- <View>
- <Text onClick={checkActionSheetData}>More Component</Text>
- </View>
- )
- }
|