clock.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import { Component, PropsWithChildren, useEffect } from 'react'
  2. import { View, Text, Button, Input } from '@tarojs/components'
  3. import './index/index.scss'
  4. import Taro, { useDidShow, useReady, useRouter } from '@tarojs/taro'
  5. // import ComponentA from './component'
  6. import Rings from '@components/Rings';
  7. import SingleSelect from '@components/SingleSelect';
  8. import { useDispatch, useSelector } from 'react-redux';
  9. import { getInfoSuccess } from '@/store/user';
  10. import { wxPubFollow } from '@/services/permission';
  11. import { staticResources } from '@/services/common';
  12. import { use } from 'i18next';
  13. import Clocks from '@/features/trackTimeDuration/components/Clock';
  14. import Console from '@/features/trackTimeDuration/components/Console';
  15. import More from '@/features/trackTimeDuration/components/More';
  16. import { getChecks } from '@/services/trackTimeDuration';
  17. import { setScenario } from '@/store/scenario';
  18. import { setSpecifiedStatus, setSpecifiedState,machine } from '@/store/trackTimeMachine';
  19. import trackTimeService from '@/store/trackTimeMachine';
  20. // import TabBar from '../../components/Tabbar';
  21. export default function IndexPage() {
  22. const dispatch = useDispatch();
  23. const array: any[] = []
  24. const user = useSelector((state: any) => state.user);
  25. const permission = useSelector((state: any) => state.permission);
  26. const common = useSelector((state: any) => state.common);
  27. array.push('ffff');
  28. array.push(<Text>ffff</Text>)
  29. // array.push(<Rings radius={50}/>)
  30. useReady(async () => {
  31. const userData = await getStorage('userData');
  32. if (userData) {
  33. dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
  34. // return JSON.parse(userData as string) as UserState;
  35. setTimeout(() => {
  36. checkWXPubFollow()
  37. getCheckData()
  38. }, 200)
  39. }
  40. })
  41. useDidShow(() => {
  42. if (user.isLogin)
  43. getCheckData();
  44. })
  45. function getCheckData() {
  46. getChecks().then(res => {
  47. if ((res as any).scenario) {
  48. dispatch(setScenario((res as any).scenario));
  49. global.scenario = (res as any).scenario;
  50. // console.log((res as any).scenario.name + ' ' + (res as any).status);
  51. // trackTimeService.send({type:(res as any).scenario.name});
  52. // setSpecifiedStatus('FAST_SLEEP', 'ON_GOING');
  53. // 初始化状态机
  54. // const initialState = machine.initialState;
  55. // 设置指定状态为 C->3
  56. // const nextState = machine.transition(initialState, 'SET_SPECIFIED_STATE');
  57. // const specifiedState = setSpecifiedState(nextState, 'FAST_SLEEP');
  58. // setSpecifiedState();
  59. // console.log('name:'+(res as any).scenario.name)
  60. // machine.reset();
  61. trackTimeService.send({type:'RESET'});
  62. trackTimeService.send({type:(res as any).scenario.name});
  63. const currentState = trackTimeService.getSnapshot();
  64. let json = {};
  65. var key = (res as any).scenario.name
  66. json[key] = (res as any).status
  67. currentState.value = json;
  68. // debugger
  69. machine.context.currentStatus = `${key}.${(res as any).status}`;//'mixed.ON_GOING2'
  70. // debugger
  71. // trackTimeService.send('APPLE');
  72. // machine.transition(`${key}.${(res as any).status}`,'' as any);
  73. // trackTimeService.send({type:'START_FAST'});
  74. // trackTimeService.send({type:'START_SLEEP'});
  75. // trackTimeService.send({type:'END_SLEEP'});
  76. // trackTimeService.send({type:'END_SLEEP'});
  77. // trackTimeService.send({type:'START_FAST'});
  78. // trackTimeService.send({type:'END_FAST'});
  79. // trackTimeService.send({type:'START_SLEEP'});
  80. // console.log(currentState.value);
  81. // debugger
  82. // trackTimeService.send('setCurrentStatus', {status:(res as any).status});
  83. // setCurrentStatus((res as any).status);
  84. // trackTimeService.send({type:'START_FAST'});
  85. }
  86. })
  87. }
  88. function checkWXPubFollow() {
  89. wxPubFollow().then(res => {
  90. console.log(res);
  91. })
  92. }
  93. function followWxPub() {
  94. const resource = common.resources.filter((item: any) => {
  95. return item.code == 'follow_wx_pub'
  96. })
  97. Taro.showModal({
  98. title: '提示',
  99. content: '关注公众号后可接收提醒\n点击确定,前往关注',
  100. showCancel: true,
  101. success(result) {
  102. if (result.confirm) {
  103. Taro.navigateTo({
  104. url: '/pages/H5?title=fast16cc 关注服务号&url=' + resource[0].url,
  105. })
  106. }
  107. },
  108. })
  109. }
  110. async function getStorage(key: string) {
  111. try {
  112. const res = await Taro.getStorage({ key });
  113. return res.data;
  114. } catch {
  115. return '';
  116. }
  117. }
  118. function goDetail() {
  119. Taro.navigateTo({
  120. // url: '/pages/index/detail'
  121. //src/moduleA/pages/third.tsx
  122. url: '../../moduleA/pages/third'
  123. })
  124. }
  125. function login() {
  126. if (user.isLogin) {
  127. Taro.navigateTo({
  128. url: '/pages/ChooseScenario'
  129. })
  130. }
  131. else {
  132. Taro.navigateTo({
  133. url: '/pages/ChooseAuth'
  134. })
  135. }
  136. }
  137. return (
  138. <View style={{ backgroundColor: '#fff', flex: 1, flexDirection: 'column', display: 'flex' }}>
  139. {
  140. permission.wxPubFollow == false ? <Text onClick={() => followWxPub()}>去关注公众号</Text>:<Text>已关注</Text>
  141. }
  142. {/* <ComponentA value="ABBBB" /> */}
  143. <Button onClick={() => goDetail()}>go detail</Button>
  144. {/* <SingleSelect items={array}></SingleSelect> */}
  145. {/* <Input placeholder="请输入用户名1" style={{ textAlign: 'left', backgroundColor: 'pink' }} /> */}
  146. <Text className='login' onClick={() => login()}>sss</Text>
  147. {/* <TabBar /> */}
  148. <Clocks />
  149. <Console />
  150. <More />
  151. </View>
  152. )
  153. }