IndexConsole.tsx 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. import { View, Text, Image, PageContainer } from '@tarojs/components'
  2. import './IndexConsole.scss'
  3. import { useTranslation } from 'react-i18next'
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { endFast, endSleep, getLocalPush, startFast, startSleep, uploadLocalPushInfo } from "../actions/TrackTimeActions";
  6. import { jumpPage } from '../hooks/Common';
  7. import { useContext, useEffect, useRef, useState } from 'react';
  8. import ConsolePicker from './ConsolePicker';
  9. import LimitPickers from '@/components/input/LimitPickers';
  10. import LimitTimeoutPickers from '@/components/input/LimitTimeoutPickers';
  11. import { getColor, getTimePickerTitle } from '../hooks/Console';
  12. import { rpxToPx, vibrate } from '@/utils/tools';
  13. import { TimeFormatter } from '@/utils/time_format';
  14. import Modal from '@/components/layout/Modal.weapp';
  15. import Taro, { useDidShow } from '@tarojs/taro';
  16. import { wxPubFollow } from '@/services/permission';
  17. import { setWXFollow } from '@/store/permission';
  18. import CircadianDetailPopup from './CircadianDetailPopup';
  19. import showAlert from '@/components/basic/Alert';
  20. import CheckAccess from './CheckAccess';
  21. let useNavigation;
  22. let Linking,PushNotification;
  23. let checkNotification;
  24. if (process.env.TARO_ENV == 'rn') {
  25. useNavigation = require("@react-navigation/native").useNavigation
  26. Linking = require('react-native').Linking;
  27. // JPush = require('jpush-react-native').default;
  28. PushNotification = require('react-native-push-notification')
  29. checkNotification = require('@/utils/native_permission_check').checkNotification;
  30. }
  31. let operateType = ''
  32. let min = 0
  33. let max = 0
  34. let defaultTimestamp = 0
  35. let isTimeout = false
  36. let stageIndex = 0
  37. let nativePushListener = null
  38. export default function IndexConsole(props: { record: any, count: number }) {
  39. const user = useSelector((state: any) => state.user);
  40. const { status } = props.record.current_record;
  41. const currentRecord = props.record.current_record;
  42. const { t } = useTranslation()
  43. const [fastDuration, setFastDuration] = useState<number>(0);
  44. const [sleepDuration, setSleepDuration] = useState<number>(0);
  45. const [expand, setExpand] = useState(false);
  46. const permission = useSelector((state: any) => state.permission);
  47. const common = useSelector((state: any) => state.common);
  48. const [firstEnter, setFirstEnter] = useState(true);
  49. const [showTimePicker, setShowTimePicker] = useState(false);
  50. const dayMilliSeconds = 24 * 3600 * 1000;
  51. const [btnDisable, setBtnDisable] = useState(false)
  52. const [showStageModal, setShowStageModal] = useState(false)
  53. const dispatch = useDispatch();
  54. const limitPickerRef = useRef(null)
  55. let navigation;
  56. if (useNavigation) {
  57. navigation = useNavigation()
  58. }
  59. useDidShow(() => {
  60. if (process.env.TARO_ENV == 'weapp') {
  61. wxPubFollow({ force_refresh: true }).then(res => {
  62. dispatch(setWXFollow((res as any).wx_pub_followed));
  63. })
  64. }
  65. })
  66. useEffect(() => {
  67. if (process.env.TARO_ENV == 'rn') {
  68. // console.error('current status',status)
  69. if (Taro.getSystemInfoSync().platform == 'ios') {
  70. var Jto = require('react-native').NativeModules.NativeBridge;
  71. var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter;
  72. Jto.getNotificationAuthStatus()
  73. if (nativePushListener){
  74. (nativePushListener as any).remove()
  75. }
  76. nativePushListener = NativeAppEventEmitter.addListener('notificationReceive', (data) => {
  77. console.log('notification receive action', data)
  78. const { category_id, action_id,id } = data
  79. uploadLocalPushInfo({
  80. messageId:id
  81. })
  82. console.log(props.record)
  83. switch (action_id) {
  84. case 'START_TIMER_NOW':
  85. {
  86. if (category_id == 'REMINDER_FS_START_FAST'){
  87. operateType = 'startFast'
  88. }
  89. else {
  90. operateType = 'startSleep'
  91. }
  92. global.set_time = new Date().getTime()
  93. pickerConfirm(new Date().getTime())
  94. }
  95. break;
  96. case 'PICK_EARLIER_START':
  97. {
  98. if (category_id == 'REMINDER_FS_START_FAST'){
  99. tapStartFast(null)
  100. }
  101. else {
  102. tapStartSleep(null)
  103. }
  104. }
  105. break;
  106. case 'END_TIMER_NOW':
  107. {
  108. if (category_id == 'REMINDER_FS_END_FAST'){
  109. operateType = 'endFast'
  110. }
  111. else {
  112. operateType = 'endSleep'
  113. }
  114. global.set_time = new Date().getTime()
  115. pickerConfirm(new Date().getTime())
  116. }
  117. break;
  118. case 'PICK_EARLIER_END':
  119. {
  120. if (category_id == 'REMINDER_FS_END_FAST'){
  121. tapEndFast(null)
  122. }
  123. else {
  124. tapEndSleep(null)
  125. }
  126. }
  127. break;
  128. case 'SKIP':
  129. break;
  130. }
  131. })
  132. }
  133. }
  134. }, [props.record])
  135. useEffect(() => {
  136. if (currentRecord.fast) {
  137. var fastCount = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
  138. setFastDuration(fastCount)
  139. }
  140. if (currentRecord.sleep) {
  141. var sleepCount = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
  142. setSleepDuration(sleepCount)
  143. }
  144. if (props.record.current_record.status == 'WAIT_FOR_START') {
  145. setExpand(false)
  146. }
  147. }, [props.record])
  148. function tapStartFast(e) {
  149. if (process.env.TARO_ENV == 'weapp') {
  150. e.stopPropagation()
  151. }
  152. if (!user.isLogin) {
  153. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  154. return
  155. }
  156. operateType = 'startFast'
  157. global.pauseIndexTimer = true
  158. global.set_time = new Date().getTime()
  159. defaultTimestamp = new Date().getTime()
  160. min = defaultTimestamp - 6 * 24 * 3600 * 1000
  161. max = defaultTimestamp
  162. isTimeout = false
  163. setShowTimePicker(true)
  164. // showPicker()
  165. }
  166. function tapStartSleep(e) {
  167. if (process.env.TARO_ENV == 'weapp') {
  168. e.stopPropagation()
  169. }
  170. if (!user.isLogin) {
  171. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
  172. return
  173. }
  174. if (status != 'ONGOING1' && props.record.scenario.name == 'FAST_SLEEP') {
  175. if (status == 'WAIT_FOR_START') {
  176. Taro.showToast({
  177. title: t('feature.track_time_duration.console.lock_fast_tip'),
  178. icon: 'none'
  179. })
  180. }
  181. vibrate()
  182. return;
  183. }
  184. operateType = 'startSleep'
  185. global.pauseIndexTimer = true
  186. global.set_time = new Date().getTime()
  187. isTimeout = false
  188. if (props.record.scenario.name == 'SLEEP') {
  189. defaultTimestamp = new Date().getTime()
  190. min = defaultTimestamp - 6 * dayMilliSeconds
  191. max = defaultTimestamp
  192. }
  193. else {
  194. //todolist
  195. var now = new Date().getTime()
  196. var last_check_time = props.record.current_record.last_real_check_time
  197. if (now - last_check_time >= dayMilliSeconds) {
  198. //ongoing1 严重超时单独处理
  199. // var schedule_start_time = props.record.current_record.sleep.target_start_time
  200. // defaultTimestamp = Math.min(now, schedule_start_time)
  201. // min = Math.max(last_check_time, schedule_start_time - 3 * dayMillionSeconds)
  202. // max = Math.min(now, schedule_start_time + 3 * dayMillionSeconds)
  203. defaultTimestamp = now
  204. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  205. max = defaultTimestamp
  206. }
  207. else {
  208. defaultTimestamp = now
  209. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  210. max = defaultTimestamp
  211. }
  212. }
  213. setShowTimePicker(true)
  214. // showPicker()
  215. }
  216. function tapEndSleep(e) {
  217. if (process.env.TARO_ENV == 'weapp') {
  218. e.stopPropagation()
  219. }
  220. if (!user.isLogin) {
  221. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
  222. return
  223. }
  224. if (status != 'ONGOING2' && status != 'ONGOING') {
  225. Taro.showToast({
  226. title: t('feature.track_time_duration.console.lock_sleep_tip'),
  227. icon: 'none'
  228. })
  229. vibrate()
  230. return;
  231. }
  232. operateType = 'endSleep'
  233. global.pauseIndexTimer = true
  234. global.set_time = new Date().getTime()
  235. var real_start_time = props.record.current_record.sleep.real_start_time
  236. var last_check_time = props.record.current_record.last_real_check_time
  237. var now = new Date().getTime()
  238. if (now - real_start_time >= dayMilliSeconds) {
  239. //严重超时
  240. isTimeout = true
  241. // defaultTimestamp = Math.min(props.record.current_record.sleep.target_end_time, now)
  242. // min = Math.max(last_check_time, defaultTimestamp - 3 * dayMillionSeconds)
  243. // max = Math.min(now, defaultTimestamp + 3 * dayMillionSeconds)
  244. defaultTimestamp = now
  245. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  246. max = defaultTimestamp
  247. }
  248. else {
  249. isTimeout = false
  250. defaultTimestamp = now
  251. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  252. max = defaultTimestamp
  253. }
  254. setShowTimePicker(true)
  255. // if (last_check_time + 24 * 3600 * 1000 <= new Date().getTime()) {
  256. // setShowTimePicker(true)
  257. // return
  258. // }
  259. // showPicker()
  260. }
  261. function tapEndFast(e) {
  262. if (process.env.TARO_ENV == 'weapp') {
  263. e.stopPropagation()
  264. }
  265. if (!user.isLogin) {
  266. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth')
  267. return
  268. }
  269. debugger
  270. if (status == 'WAIT_FOR_START') {
  271. Taro.showToast({
  272. title: t('feature.track_time_duration.console.lock_fast_tip'),
  273. icon: 'none'
  274. })
  275. vibrate()
  276. return;
  277. }
  278. operateType = 'endFast'
  279. global.pauseIndexTimer = true
  280. global.set_time = new Date().getTime()
  281. var real_start_time = props.record.current_record.fast.real_start_time
  282. var last_check_time = props.record.current_record.last_real_check_time
  283. var now = new Date().getTime()
  284. if (now - real_start_time >= dayMilliSeconds) {
  285. //严重超时
  286. isTimeout = true
  287. // defaultTimestamp = Math.min(props.record.current_record.fast.target_end_time, now)
  288. // min = Math.max(last_check_time, defaultTimestamp - 3 * dayMillionSeconds)
  289. // max = Math.min(now, defaultTimestamp + 3 * dayMillionSeconds)
  290. // debugger
  291. defaultTimestamp = now
  292. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  293. max = defaultTimestamp
  294. }
  295. else {
  296. isTimeout = false
  297. defaultTimestamp = now
  298. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  299. max = defaultTimestamp
  300. }
  301. setShowTimePicker(true)
  302. // if (last_check_time + 24 * 3600 * 1000 <= new Date().getTime() ||
  303. // props.record.current_record.fast.real_check_time + 24 * 3600 * 1000 <= new Date().getTime()) {
  304. // setShowTimePicker(true)
  305. // return
  306. // }
  307. // showPicker()
  308. }
  309. function layoutContent() {
  310. var limit = global.set_time - 7 * 3600 * 1000 * 24;
  311. global.limit = limit
  312. if (currentRecord.last_real_check_time) {
  313. limit = currentRecord.last_real_check_time
  314. global.limit = limit
  315. //当set_time秒数<=latest_record_time秒数时,最小限制时间戳需+1分钟
  316. if (new Date(global.set_time).getSeconds() <= new Date(currentRecord.last_real_check_time).getSeconds() && global.set_time - currentRecord.last_real_check_time > 60000) {
  317. limit = limit + 60 * 1000
  318. }
  319. }
  320. var title = getTimePickerTitle(currentRecord, t, operateType == 'endFast')
  321. var color = getColor(currentRecord, operateType == 'endFast')
  322. var duration = 0
  323. if (operateType == 'startFast' && currentRecord.fast) {
  324. duration = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
  325. }
  326. if (operateType == 'startSleep' && currentRecord.sleep) {
  327. duration = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
  328. }
  329. var endTimestamp = 0
  330. if (operateType == 'endFast') {
  331. endTimestamp = currentRecord.fast.target_end_time
  332. }
  333. else if (operateType == 'endSleep') {
  334. endTimestamp = currentRecord.sleep.target_end_time
  335. }
  336. return <View className="modal_content">
  337. <LimitPickers ref={limitPickerRef} limit={limit} limitDay={7}
  338. themeColor={color}
  339. title={title}
  340. showEndTime={true}
  341. isFast={operateType == 'startFast' || operateType == 'endFast'}
  342. isEnd={operateType == 'endFast' || operateType == 'endSleep'}
  343. endTimestamp={endTimestamp}
  344. // showEndTime={operateType == 'startFast' || operateType == 'startSleep'}
  345. duration={duration}
  346. onCancel={hidePicker} onChange={(e) => {
  347. pickerConfirm(e)
  348. global.pauseIndexTimer = false
  349. // hidePicker()
  350. }} />
  351. </View>
  352. }
  353. function timePickerContent() {
  354. var title = getTimePickerTitle(currentRecord, t, operateType == 'endFast')
  355. var color = getColor(currentRecord, operateType == 'endFast')
  356. // var limit = props.record.current_record.last_real_check_time
  357. // var targetTime = props.record.current_record.fast.target_end_time
  358. // if (props.record.current_record.status == 'ONGOING3') {
  359. // limit = 0
  360. // targetTime = props.record.current_record.sleep.real_end_time + 60 * 1000
  361. // }
  362. var endTimestamp = 0
  363. if (operateType == 'endFast') {
  364. endTimestamp = currentRecord.fast.target_end_time
  365. }
  366. else if (operateType == 'endSleep') {
  367. endTimestamp = currentRecord.sleep.target_end_time
  368. }
  369. var duration = 0
  370. if (operateType == 'startFast' && currentRecord.fast) {
  371. duration = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
  372. }
  373. if (operateType == 'startSleep' && currentRecord.sleep) {
  374. duration = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
  375. }
  376. return <View className="modal_content">
  377. <ConsolePicker ref={limitPickerRef}
  378. themeColor={color}
  379. title={title}
  380. onCancel={hidePicker}
  381. min={min}
  382. max={max}
  383. current={defaultTimestamp}
  384. duration={duration}
  385. endTimestamp={endTimestamp}
  386. isFast={operateType == 'startFast' || operateType == 'endFast'}
  387. isEnd={operateType == 'endFast' || operateType == 'endSleep'}
  388. isTimeout={isTimeout}
  389. onChange={(e) => {
  390. pickerConfirm(e)
  391. global.pauseIndexTimer = false
  392. }}
  393. />
  394. {/* <LimitTimeoutPickers ref={limitPickerRef} limit={limit} limitDay={7}
  395. themeColor={color}
  396. title={title}
  397. isFast={operateType == 'endFast'}
  398. endTimestamp={endTimestamp}
  399. time={operateType == 'endFast' ? new Date(targetTime).getTime() :
  400. new Date(props.record.current_record.sleep.target_end_time).getTime()
  401. }
  402. onCancel={hidePicker} onChange={(e) => {
  403. pickerConfirm(e)
  404. global.pauseIndexTimer = false
  405. }} /> */}
  406. </View>
  407. }
  408. function showPicker() {
  409. // global.scenario = 'FAST_SLEEP'
  410. if (global.testInfotimer) {
  411. return
  412. }
  413. global.pauseIndexTimer = true
  414. global.set_time = new Date().getTime()
  415. updateNodeInfo()
  416. if (!global.isDebug) {
  417. return
  418. }
  419. // global.testInfotimer = setInterval(() => {
  420. // updateNodeInfo()
  421. // }, 1000)
  422. }
  423. function updateNodeInfo() {
  424. var node = layoutContent()
  425. global.showIndexModal(true, node, null);
  426. }
  427. function hidePicker() {
  428. var node = layoutContent()
  429. global.showIndexModal(false, node, null);
  430. setShowTimePicker(false)
  431. setBtnDisable(false)
  432. global.pauseIndexTimer = false
  433. }
  434. function followWxPub() {
  435. const resource = common.resources.filter((item: any) => {
  436. return item.code == 'follow_wx_pub'
  437. })
  438. jumpPage('/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url)
  439. }
  440. function pickerConfirm(t1: number) {
  441. debugger
  442. if (btnDisable) {
  443. return
  444. }
  445. setBtnDisable(true)
  446. // hidePicker()
  447. var date = new Date(t1)
  448. var setDate = new Date(global.set_time);
  449. date.setMilliseconds(setDate.getMilliseconds());
  450. date.setSeconds(setDate.getSeconds());
  451. t1 = date.getTime();
  452. // if (process.env.TARO_ENV=='rn'){
  453. // debugger
  454. // JPush.isNotificationEnabled((res)=>{
  455. // console.log(res)
  456. // debugger
  457. // })
  458. // }
  459. switch (operateType) {
  460. case 'startFast':
  461. startFast(t1, fastDuration).then(res => {
  462. global.indexPageRefresh()
  463. setFirstEnter(false)
  464. hidePicker()
  465. setBtnDisable(false)
  466. refreshDayNight()
  467. if (process.env.TARO_ENV == 'weapp') {
  468. debugger
  469. if (permission.wxPubFollow) {
  470. // showAlert({
  471. // title: t('feature.track_time_duration.reminders.fast_end_title'),
  472. // content:
  473. // t('feature.track_time_duration.reminders.enable_post_fast_content',
  474. // { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  475. // ),
  476. // showCancel: false,
  477. // confirmText: t('feature.track_time_duration.reminders.ok')
  478. // })
  479. }
  480. else {
  481. showAlert({
  482. title: t('feature.track_time_duration.reminders.fast_end_title'),
  483. content: t('feature.track_time_duration.reminders.post_fast_content',
  484. { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  485. ),
  486. showCancel: true,
  487. cancelText: t('feature.track_time_duration.reminders.later'),
  488. confirmText: t('feature.track_time_duration.reminders.open'),
  489. confirm: () => { followWxPub() }
  490. })
  491. }
  492. }
  493. else {
  494. PushNotification.checkPermissions((res)=>{
  495. //允许授权
  496. if (res.authorizationStatus == 2){
  497. getLocalPush()
  498. // showAlert({
  499. // title: t('feature.track_time_duration.reminders.fast_end_title'),
  500. // content:
  501. // t('feature.track_time_duration.reminders.enable_post_fast_content',
  502. // { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  503. // ),
  504. // showCancel: false,
  505. // confirmText: t('feature.track_time_duration.reminders.ok')
  506. // })
  507. }
  508. else {
  509. showAlert({
  510. title: t('feature.track_time_duration.reminders.fast_end_title'),
  511. content: t('feature.track_time_duration.reminders.post_fast_content',
  512. { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  513. ),
  514. showCancel: true,
  515. cancelText: t('feature.track_time_duration.reminders.later'),
  516. confirmText: t('feature.track_time_duration.reminders.open'),
  517. confirm: () => {
  518. // Linking.openURL('app-settings:notifications')
  519. checkNotification()
  520. }
  521. })
  522. }
  523. })
  524. }
  525. }).catch(e => {
  526. setBtnDisable(false)
  527. })
  528. break
  529. case 'startSleep':
  530. startSleep(t1, sleepDuration).then(res => {
  531. global.indexPageRefresh()
  532. setFirstEnter(false)
  533. hidePicker()
  534. setBtnDisable(false)
  535. refreshDayNight()
  536. if (process.env.TARO_ENV == 'weapp') {
  537. if (permission.wxPubFollow) {
  538. // showAlert({
  539. // title: t('feature.track_time_duration.reminders.wake_title'),
  540. // content:
  541. // t('feature.track_time_duration.reminders.enable_post_sleep_content',
  542. // { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  543. // showCancel: false,
  544. // confirmText: t('feature.track_time_duration.reminders.ok')
  545. // })
  546. }
  547. else {
  548. showAlert({
  549. title: t('feature.track_time_duration.reminders.wake_title'),
  550. content: t('feature.track_time_duration.reminders.post_sleep_content',
  551. { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  552. cancelText: t('feature.track_time_duration.reminders.later'),
  553. confirmText: t('feature.track_time_duration.reminders.open'),
  554. showCancel: true,
  555. confirm: () => { followWxPub() }
  556. })
  557. }
  558. }
  559. else {
  560. PushNotification.checkPermissions((res)=>{
  561. //允许授权
  562. if (res.authorizationStatus == 2){
  563. getLocalPush()
  564. // showAlert({
  565. // title: t('feature.track_time_duration.reminders.wake_title'),
  566. // content:
  567. // t('feature.track_time_duration.reminders.enable_post_sleep_content',
  568. // { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  569. // showCancel: false,
  570. // confirmText: t('feature.track_time_duration.reminders.ok')
  571. // })
  572. }
  573. else {
  574. showAlert({
  575. title: t('feature.track_time_duration.reminders.wake_title'),
  576. content: t('feature.track_time_duration.reminders.post_sleep_content',
  577. { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  578. cancelText: t('feature.track_time_duration.reminders.later'),
  579. confirmText: t('feature.track_time_duration.reminders.open'),
  580. showCancel: true,
  581. confirm: () => {
  582. checkNotification()
  583. // Linking.openURL('app-settings:notifications')
  584. }
  585. })
  586. }
  587. })
  588. }
  589. }).catch((e) => {
  590. setBtnDisable(false)
  591. var picker = limitPickerRef.current;
  592. (picker as any).resetPickerData()
  593. })
  594. break
  595. case 'endSleep':
  596. endSleep(t1).then(res => {
  597. getLocalPush()
  598. setBtnDisable(false)
  599. global.indexPageRefresh()
  600. setFirstEnter(false)
  601. hidePicker()
  602. global.refrehWeekly()
  603. global.refreshStreaks()
  604. refreshDayNight()
  605. if (props.record.current_record.scenario == 'SLEEP') {
  606. global.scrollToLatest()
  607. }
  608. }).catch((e) => {
  609. setBtnDisable(false)
  610. var picker = limitPickerRef.current;
  611. (picker as any).resetPickerData()
  612. })
  613. break
  614. case 'endFast':
  615. endFast(t1).then(res => {
  616. getLocalPush()
  617. setBtnDisable(false)
  618. global.indexPageRefresh()
  619. setFirstEnter(false)
  620. hidePicker()
  621. global.scrollToLatest()
  622. global.refrehWeekly()
  623. global.refreshStreaks()
  624. refreshDayNight()
  625. var obj = global.checkAccess
  626. if (obj) {
  627. console.log('applw')
  628. }
  629. else {
  630. console.log('apple')
  631. }
  632. global.checkAccess((res as any).access)
  633. // checkAccessProvisional((res as any).access,showFastAlert)
  634. }).catch((e) => {
  635. setBtnDisable(false)
  636. var picker = limitPickerRef.current;
  637. (picker as any).resetPickerData()
  638. })
  639. break
  640. }
  641. }
  642. function refreshDayNight() {
  643. if (global.refreshNight) {
  644. global.refreshNight()
  645. }
  646. if (global.refreshDay) {
  647. global.refreshDay()
  648. }
  649. }
  650. function expandBtnText() {
  651. if (status == 'WAIT_FOR_START') {
  652. return t('feature.track_time_duration.console.next_steps')
  653. }
  654. else if (firstEnter) {
  655. return t('feature.track_time_duration.console.show_more')
  656. }
  657. return t('feature.track_time_duration.console.next_steps')
  658. }
  659. function modalContent() {
  660. global.set_time = new Date().getTime()
  661. return <Modal
  662. testInfo={null}
  663. dismiss={() => {
  664. hidePicker()
  665. // setShowTimeoutPicker(false)
  666. }}
  667. confirm={() => { }}>
  668. {
  669. timePickerContent()
  670. }
  671. </Modal>
  672. }
  673. function single() {
  674. if (props.record.scenario.name == 'FAST') {
  675. return <View style={{ marginTop: rpxToPx(0) }}>
  676. {
  677. status == 'WAIT_FOR_START' &&
  678. <View onClick={tapStartFast} className='console_btn'>
  679. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.start_fast')}</Text>
  680. </View>
  681. }
  682. {/* {
  683. status != 'WAIT_FOR_START' && <View className='btn_line' />
  684. } */}
  685. {
  686. status == 'ONGOING' && <View onClick={tapEndFast} className={status == 'ONGOING' ? 'console_btn' : 'console_btn btn_disable'}>
  687. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.end_fast')}</Text>
  688. </View>
  689. }
  690. {
  691. showTimePicker && modalContent()
  692. }
  693. </View>
  694. }
  695. else if (props.record.scenario.name == 'SLEEP') {
  696. return <View style={{ marginTop: rpxToPx(0) }}>
  697. {
  698. status == 'WAIT_FOR_START' &&
  699. <View onClick={tapStartSleep} className='console_btn btn_sleep'>
  700. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.start_sleep')}</Text>
  701. </View>
  702. }
  703. {/* {
  704. status != 'WAIT_FOR_START' && <View className='btn_line' />
  705. } */}
  706. {
  707. status == 'ONGOING' && <View onClick={tapEndSleep} className={status == 'ONGOING' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  708. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.end_sleep')}</Text>
  709. </View>
  710. }
  711. {
  712. showTimePicker && modalContent()
  713. }
  714. </View>
  715. }
  716. }
  717. function mixed() {
  718. return <View style={{ marginTop: rpxToPx(0) }}>
  719. {
  720. status == 'WAIT_FOR_START' ?
  721. <View onClick={tapStartFast} className='console_btn'>
  722. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32) }}>{t('feature.track_time_duration.common.start_fast')}</Text>
  723. </View> :
  724. <View onClick={() => { tapStage(0) }} className='stage_btn'>
  725. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.a')}</Text>
  726. {
  727. status == 'ONGOING1' ?
  728. <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.fast.real_start_time)}</Text> :
  729. <Text style={{ color: '#fff' }}>{TimeFormatter.calculateTimeDifference(currentRecord.fast.real_start_time, currentRecord.sleep.real_start_time)}</Text>
  730. }
  731. </View>
  732. }
  733. <View className='btn_line' />
  734. {
  735. (status == 'WAIT_FOR_START' || status == 'ONGOING1') &&
  736. <View onClick={tapStartSleep} className={status == 'ONGOING1' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  737. {
  738. status != 'ONGOING1' && <Image className='lock' src={require('@assets/images/lock.png')} />
  739. }
  740. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32) }}>{t('feature.track_time_duration.common.start_sleep')}</Text>
  741. </View>
  742. }
  743. {
  744. (status != 'WAIT_FOR_START' && status != 'ONGOING1') &&
  745. <View onClick={() => { tapStage(1) }} className='stage_btn'>
  746. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.b')}</Text>
  747. {
  748. status == 'ONGOING2' ? <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.sleep.real_start_time)}</Text> :
  749. <Text style={{ color: '#fff' }}>{TimeFormatter.calculateTimeDifference(currentRecord.sleep.real_start_time, currentRecord.sleep.real_end_time)}</Text>
  750. }
  751. </View>
  752. }
  753. {(expand || (status != 'WAIT_FOR_START' && status != 'ONGOING1')) && <View className='btn_line' />}
  754. {
  755. (expand || (status != 'WAIT_FOR_START' && status != 'ONGOING1')) && (status == 'WAIT_FOR_START' || status == 'ONGOING1' || status == 'ONGOING2') &&
  756. <View onClick={tapEndSleep} className={status == 'ONGOING2' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  757. {
  758. status != 'ONGOING2' && <Image className='lock' src={require('@assets/images/lock.png')} />
  759. }
  760. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32) }}>{t('feature.track_time_duration.common.end_sleep')}</Text>
  761. </View>
  762. }
  763. {
  764. status == 'ONGOING3' &&
  765. <View onClick={() => { tapStage(2) }} className='stage_btn'>
  766. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.c')}</Text>
  767. <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.sleep.real_end_time)}</Text>
  768. </View>
  769. }
  770. {(expand || status == 'ONGOING3' || status == 'ONGOING') && <View className='btn_line' />}
  771. {
  772. (expand || status == 'ONGOING3' || status == 'ONGOING') &&
  773. <View onClick={tapEndFast} className={status == 'ONGOING3' ? 'console_btn' : 'console_btn btn_disable'}>
  774. {
  775. status == 'WAIT_FOR_START' && <Image className='lock' src={require('@assets/images/lock.png')} />
  776. }
  777. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32) }}>{t('feature.track_time_duration.common.end_fast')}</Text>
  778. </View>
  779. }
  780. {
  781. (status == 'WAIT_FOR_START' || status == 'ONGOING1' || status == 'ONGOING2') &&
  782. <View>
  783. {
  784. !expand && <Text className='expand' onClick={() => { setExpand(true) }}>{expandBtnText()}</Text>
  785. }
  786. </View>
  787. }
  788. {
  789. showTimePicker && modalContent()
  790. }
  791. {
  792. showStageModal && stageContent()
  793. }
  794. </View>
  795. }
  796. function stageContent() {
  797. return <Modal
  798. testInfo={null}
  799. dismiss={() => {
  800. global.pauseIndexTimer = false
  801. setShowStageModal(false)
  802. }}
  803. confirm={() => { }}>
  804. {
  805. <CircadianDetailPopup
  806. record={currentRecord}
  807. schedule={props.record.scenario.schedule}
  808. stageIndex={stageIndex}
  809. onlyStage={true}
  810. onClose={() => { setShowStageModal(false); }} />
  811. }
  812. </Modal>
  813. }
  814. function tapStage(index) {
  815. stageIndex = index
  816. setShowStageModal(true)
  817. }
  818. return <View>
  819. {
  820. props.record.scenario.name == 'FAST_SLEEP' ? mixed() : single()
  821. }
  822. <CheckAccess record={props.record} count={props.count} />
  823. </View>
  824. }