IndexConsole.tsx 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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 { isIOS, kIsIOS, 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. import { ColorType } from '@/context/themes/color';
  22. let useNavigation;
  23. let Linking,PushNotification;
  24. let checkNotification;
  25. if (process.env.TARO_ENV == 'rn') {
  26. useNavigation = require("@react-navigation/native").useNavigation
  27. Linking = require('react-native').Linking;
  28. // JPush = require('jpush-react-native').default;
  29. PushNotification = require('react-native-push-notification')
  30. checkNotification = require('@/utils/native_permission_check').checkNotification;
  31. }
  32. let operateType = ''
  33. let min = 0
  34. let max = 0
  35. let defaultTimestamp = 0
  36. let isTimeout = false
  37. let stageIndex = 0
  38. let nativePushListener = null
  39. export default function IndexConsole(props: { record: any, count: number }) {
  40. const user = useSelector((state: any) => state.user);
  41. const { status } = props.record.current_record;
  42. const currentRecord = props.record.current_record;
  43. const { t } = useTranslation()
  44. const [fastDuration, setFastDuration] = useState<number>(0);
  45. const [sleepDuration, setSleepDuration] = useState<number>(0);
  46. const [expand, setExpand] = useState(false);
  47. const permission = useSelector((state: any) => state.permission);
  48. const common = useSelector((state: any) => state.common);
  49. const [firstEnter, setFirstEnter] = useState(true);
  50. const [showTimePicker, setShowTimePicker] = useState(false);
  51. const dayMilliSeconds = 24 * 3600 * 1000;
  52. const [btnDisable, setBtnDisable] = useState(false)
  53. const [showStageModal, setShowStageModal] = useState(false)
  54. const dispatch = useDispatch();
  55. const limitPickerRef = useRef(null)
  56. let navigation;
  57. if (useNavigation) {
  58. navigation = useNavigation()
  59. }
  60. useDidShow(() => {
  61. if (process.env.TARO_ENV == 'weapp') {
  62. wxPubFollow({ force_refresh: true }).then(res => {
  63. dispatch(setWXFollow((res as any).wx_pub_followed));
  64. })
  65. }
  66. })
  67. useEffect(() => {
  68. if (process.env.TARO_ENV == 'rn') {
  69. // console.error('current status',status)
  70. if (kIsIOS) {
  71. var Jto = require('react-native').NativeModules.NativeBridge;
  72. var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter;
  73. Jto.getNotificationAuthStatus()
  74. if (nativePushListener){
  75. (nativePushListener as any).remove()
  76. }
  77. nativePushListener = NativeAppEventEmitter.addListener('notificationReceive', (data) => {
  78. console.log('notification receive action', data)
  79. const { category_id, action_id,id } = data
  80. uploadLocalPushInfo({
  81. messageId:id
  82. })
  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 - 1 * 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. if (status == 'WAIT_FOR_START') {
  270. Taro.showToast({
  271. title: t('feature.track_time_duration.console.lock_fast_tip'),
  272. icon: 'none'
  273. })
  274. vibrate()
  275. return;
  276. }
  277. if (status == 'ONGOING1'){
  278. showAlert({
  279. title:t('feature.heads_up.alert_title'),
  280. content:t('feature.heads_up.ongoing1_content'),
  281. cancelText:t('feature.heads_up.ongoing1_cancel'),
  282. confirmText:t('feature.heads_up.ongoing1_confirm'),
  283. showCancel:true,
  284. cancel:()=>{
  285. },
  286. confirm:()=>{
  287. tapEndFastOperate()
  288. }
  289. })
  290. return
  291. }
  292. else if (status == 'ONGOING2'){
  293. showAlert({
  294. title:t('feature.heads_up.alert_title'),
  295. content:t('feature.heads_up.ongoing2_content'),
  296. cancelText:t('feature.heads_up.ongoing2_cancel'),
  297. confirmText:t('feature.heads_up.ongoing2_confirm'),
  298. showCancel:true,
  299. cancel:()=>{
  300. },
  301. confirm:()=>{
  302. tapEndFastOperate()
  303. }
  304. })
  305. return
  306. }
  307. tapEndFastOperate()
  308. }
  309. function tapEndFastOperate(){
  310. operateType = 'endFast'
  311. global.pauseIndexTimer = true
  312. global.set_time = new Date().getTime()
  313. var real_start_time = props.record.current_record.fast.real_start_time
  314. var last_check_time = props.record.current_record.last_real_check_time
  315. var now = new Date().getTime()
  316. if (now - real_start_time >= dayMilliSeconds) {
  317. //严重超时
  318. isTimeout = true
  319. // defaultTimestamp = Math.min(props.record.current_record.fast.target_end_time, now)
  320. // min = Math.max(last_check_time, defaultTimestamp - 3 * dayMillionSeconds)
  321. // max = Math.min(now, defaultTimestamp + 3 * dayMillionSeconds)
  322. // debugger
  323. defaultTimestamp = now
  324. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  325. max = defaultTimestamp
  326. }
  327. else {
  328. isTimeout = false
  329. defaultTimestamp = now
  330. min = Math.max(last_check_time, defaultTimestamp - 6 * dayMilliSeconds)
  331. max = defaultTimestamp
  332. }
  333. setShowTimePicker(true)
  334. }
  335. function layoutContent() {
  336. var limit = global.set_time - 7 * 3600 * 1000 * 24;
  337. global.limit = limit
  338. if (currentRecord.last_real_check_time) {
  339. limit = currentRecord.last_real_check_time
  340. global.limit = limit
  341. //当set_time秒数<=latest_record_time秒数时,最小限制时间戳需+1分钟
  342. if (new Date(global.set_time).getSeconds() <= new Date(currentRecord.last_real_check_time).getSeconds() && global.set_time - currentRecord.last_real_check_time > 60000) {
  343. limit = limit + 60 * 1000
  344. }
  345. }
  346. var title = getTimePickerTitle(currentRecord, t, operateType == 'endFast')
  347. var color = getColor(currentRecord, operateType == 'endFast')
  348. var duration = 0
  349. if (operateType == 'startFast' && currentRecord.fast) {
  350. duration = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
  351. }
  352. if (operateType == 'startSleep' && currentRecord.sleep) {
  353. duration = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
  354. }
  355. var endTimestamp = 0
  356. if (operateType == 'endFast') {
  357. endTimestamp = currentRecord.fast.target_end_time
  358. }
  359. else if (operateType == 'endSleep') {
  360. endTimestamp = currentRecord.sleep.target_end_time
  361. }
  362. return <View className="modal_content">
  363. <LimitPickers ref={limitPickerRef} limit={limit} limitDay={7}
  364. themeColor={color}
  365. title={title}
  366. showEndTime={true}
  367. isFast={operateType == 'startFast' || operateType == 'endFast'}
  368. isEnd={operateType == 'endFast' || operateType == 'endSleep'}
  369. endTimestamp={endTimestamp}
  370. // showEndTime={operateType == 'startFast' || operateType == 'startSleep'}
  371. duration={duration}
  372. onCancel={hidePicker} onChange={(e) => {
  373. pickerConfirm(e)
  374. global.pauseIndexTimer = false
  375. // hidePicker()
  376. }} />
  377. </View>
  378. }
  379. function timePickerContent() {
  380. var title = getTimePickerTitle(currentRecord, t, operateType == 'endFast')
  381. var color = getColor(currentRecord, operateType == 'endFast')
  382. // var limit = props.record.current_record.last_real_check_time
  383. // var targetTime = props.record.current_record.fast.target_end_time
  384. // if (props.record.current_record.status == 'ONGOING3') {
  385. // limit = 0
  386. // targetTime = props.record.current_record.sleep.real_end_time + 60 * 1000
  387. // }
  388. var endTimestamp = 0
  389. if (operateType == 'endFast') {
  390. endTimestamp = currentRecord.fast.target_end_time
  391. }
  392. else if (operateType == 'endSleep') {
  393. endTimestamp = currentRecord.sleep.target_end_time
  394. }
  395. var duration = 0
  396. if (operateType == 'startFast' && currentRecord.fast) {
  397. duration = currentRecord.fast.target_end_time - currentRecord.fast.target_start_time
  398. }
  399. if (operateType == 'startSleep' && currentRecord.sleep) {
  400. duration = currentRecord.sleep.target_end_time - currentRecord.sleep.target_start_time
  401. }
  402. return <View className="modal_content">
  403. <ConsolePicker ref={limitPickerRef}
  404. themeColor={color}
  405. title={title}
  406. onCancel={hidePicker}
  407. min={min}
  408. max={max}
  409. current={defaultTimestamp}
  410. duration={duration}
  411. endTimestamp={endTimestamp}
  412. isFast={operateType == 'startFast' || operateType == 'endFast'}
  413. isEnd={operateType == 'endFast' || operateType == 'endSleep'}
  414. isTimeout={isTimeout}
  415. isLoading={btnDisable}
  416. onChange={(e) => {
  417. pickerConfirm(e)
  418. global.pauseIndexTimer = false
  419. }}
  420. />
  421. {/* <LimitTimeoutPickers ref={limitPickerRef} limit={limit} limitDay={7}
  422. themeColor={color}
  423. title={title}
  424. isFast={operateType == 'endFast'}
  425. endTimestamp={endTimestamp}
  426. time={operateType == 'endFast' ? new Date(targetTime).getTime() :
  427. new Date(props.record.current_record.sleep.target_end_time).getTime()
  428. }
  429. onCancel={hidePicker} onChange={(e) => {
  430. pickerConfirm(e)
  431. global.pauseIndexTimer = false
  432. }} /> */}
  433. </View>
  434. }
  435. function showPicker() {
  436. // global.scenario = 'FAST_SLEEP'
  437. if (global.testInfotimer) {
  438. return
  439. }
  440. global.pauseIndexTimer = true
  441. global.set_time = new Date().getTime()
  442. updateNodeInfo()
  443. if (!global.isDebug) {
  444. return
  445. }
  446. // global.testInfotimer = setInterval(() => {
  447. // updateNodeInfo()
  448. // }, 1000)
  449. }
  450. function updateNodeInfo() {
  451. var node = layoutContent()
  452. global.showIndexModal(true, node, null);
  453. }
  454. function hidePicker() {
  455. var node = layoutContent()
  456. global.showIndexModal(false, node, null);
  457. setShowTimePicker(false)
  458. setBtnDisable(false)
  459. global.pauseIndexTimer = false
  460. }
  461. function followWxPub() {
  462. const resource = common.resources.filter((item: any) => {
  463. return item.code == 'follow_wx_pub'
  464. })
  465. jumpPage('/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url)
  466. }
  467. function pickerConfirm(t1: number) {
  468. if (btnDisable) {
  469. return
  470. }
  471. setBtnDisable(true)
  472. // hidePicker()
  473. var date = new Date(t1)
  474. var setDate = new Date(global.set_time);
  475. date.setMilliseconds(setDate.getMilliseconds());
  476. date.setSeconds(setDate.getSeconds());
  477. t1 = date.getTime();
  478. // if (process.env.TARO_ENV=='rn'){
  479. // debugger
  480. // JPush.isNotificationEnabled((res)=>{
  481. // console.log(res)
  482. // debugger
  483. // })
  484. // }
  485. switch (operateType) {
  486. case 'startFast':
  487. startFast(t1, fastDuration).then(res => {
  488. global.indexPageRefresh()
  489. setFirstEnter(false)
  490. hidePicker()
  491. setBtnDisable(false)
  492. refreshDayNight()
  493. if (process.env.TARO_ENV == 'weapp') {
  494. debugger
  495. if (permission.wxPubFollow) {
  496. // showAlert({
  497. // title: t('feature.track_time_duration.reminders.fast_end_title'),
  498. // content:
  499. // t('feature.track_time_duration.reminders.enable_post_fast_content',
  500. // { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  501. // ),
  502. // showCancel: false,
  503. // confirmText: t('feature.track_time_duration.reminders.ok')
  504. // })
  505. }
  506. else {
  507. showAlert({
  508. title: t('feature.track_time_duration.reminders.fast_end_title'),
  509. content: t('feature.track_time_duration.reminders.post_fast_content',
  510. { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  511. ),
  512. showCancel: true,
  513. cancelText: t('feature.track_time_duration.reminders.later'),
  514. confirmText: t('feature.track_time_duration.reminders.open'),
  515. confirm: () => { followWxPub() }
  516. })
  517. }
  518. }
  519. else {
  520. PushNotification.checkPermissions((res)=>{
  521. //允许授权
  522. if ((kIsIOS && res.authorizationStatus == 2) || (!kIsIOS && res.alert)){
  523. getLocalPush()
  524. // showAlert({
  525. // title: t('feature.track_time_duration.reminders.fast_end_title'),
  526. // content:
  527. // t('feature.track_time_duration.reminders.enable_post_fast_content',
  528. // { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  529. // ),
  530. // showCancel: false,
  531. // confirmText: t('feature.track_time_duration.reminders.ok')
  532. // })
  533. }
  534. else {
  535. showAlert({
  536. title: t('feature.track_time_duration.reminders.fast_end_title'),
  537. content: t('feature.track_time_duration.reminders.post_fast_content',
  538. { date: TimeFormatter.dateDescription(t1 + fastDuration, true), time: TimeFormatter.timeDescription(t1 + fastDuration) }
  539. ),
  540. showCancel: true,
  541. cancelText: t('feature.track_time_duration.reminders.later'),
  542. confirmText: t('feature.track_time_duration.reminders.open'),
  543. confirm: () => {
  544. // Linking.openURL('app-settings:notifications')
  545. checkNotification()
  546. }
  547. })
  548. }
  549. })
  550. }
  551. }).catch(e => {
  552. setBtnDisable(false)
  553. })
  554. break
  555. case 'startSleep':
  556. startSleep(t1, sleepDuration).then(res => {
  557. global.indexPageRefresh()
  558. setFirstEnter(false)
  559. hidePicker()
  560. setBtnDisable(false)
  561. refreshDayNight()
  562. if (process.env.TARO_ENV == 'weapp') {
  563. if (permission.wxPubFollow) {
  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: () => { followWxPub() }
  582. })
  583. }
  584. }
  585. else {
  586. PushNotification.checkPermissions((res)=>{
  587. //允许授权
  588. if ((kIsIOS && res.authorizationStatus == 2) || (!kIsIOS && res.alert)){
  589. getLocalPush()
  590. // showAlert({
  591. // title: t('feature.track_time_duration.reminders.wake_title'),
  592. // content:
  593. // t('feature.track_time_duration.reminders.enable_post_sleep_content',
  594. // { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  595. // showCancel: false,
  596. // confirmText: t('feature.track_time_duration.reminders.ok')
  597. // })
  598. }
  599. else {
  600. showAlert({
  601. title: t('feature.track_time_duration.reminders.wake_title'),
  602. content: t('feature.track_time_duration.reminders.post_sleep_content',
  603. { date: TimeFormatter.dateDescription(t1 + sleepDuration, true), time: TimeFormatter.timeDescription(t1 + sleepDuration) }),
  604. cancelText: t('feature.track_time_duration.reminders.later'),
  605. confirmText: t('feature.track_time_duration.reminders.open'),
  606. showCancel: true,
  607. confirm: () => {
  608. checkNotification()
  609. // Linking.openURL('app-settings:notifications')
  610. }
  611. })
  612. }
  613. })
  614. }
  615. }).catch((e) => {
  616. setBtnDisable(false)
  617. var picker = limitPickerRef.current;
  618. (picker as any).resetPickerData()
  619. })
  620. break
  621. case 'endSleep':
  622. endSleep(t1).then(res => {
  623. getLocalPush()
  624. setBtnDisable(false)
  625. global.indexPageRefresh()
  626. setFirstEnter(false)
  627. hidePicker()
  628. global.refrehWeekly()
  629. global.refreshStreaks()
  630. refreshDayNight()
  631. if (props.record.current_record.scenario == 'SLEEP') {
  632. global.scrollToLatest()
  633. }
  634. }).catch((e) => {
  635. setBtnDisable(false)
  636. var picker = limitPickerRef.current;
  637. (picker as any).resetPickerData()
  638. })
  639. break
  640. case 'endFast':
  641. endFast(t1).then(res => {
  642. getLocalPush()
  643. setBtnDisable(false)
  644. global.indexPageRefresh()
  645. setFirstEnter(false)
  646. hidePicker()
  647. global.scrollToLatest()
  648. global.refrehWeekly()
  649. global.refreshStreaks()
  650. refreshDayNight()
  651. var obj = global.checkAccess
  652. if (global.checkAccess) {
  653. console.log('applw')
  654. }
  655. else {
  656. console.log('apple')
  657. }
  658. global.checkAccess((res as any).access)
  659. // checkAccessProvisional((res as any).access,showFastAlert)
  660. }).catch((e) => {
  661. setBtnDisable(false)
  662. var picker = limitPickerRef.current;
  663. (picker as any).resetPickerData()
  664. })
  665. break
  666. }
  667. }
  668. function refreshDayNight() {
  669. if (global.refreshNight) {
  670. global.refreshNight()
  671. }
  672. if (global.refreshDay) {
  673. global.refreshDay()
  674. }
  675. }
  676. function expandBtnText() {
  677. if (status == 'WAIT_FOR_START') {
  678. return t('feature.track_time_duration.console.next_steps')
  679. }
  680. else if (firstEnter) {
  681. return t('feature.track_time_duration.console.show_more')
  682. }
  683. return t('feature.track_time_duration.console.next_steps')
  684. }
  685. function modalContent() {
  686. global.set_time = new Date().getTime()
  687. return <Modal
  688. testInfo={null}
  689. dismiss={() => {
  690. hidePicker()
  691. // setShowTimeoutPicker(false)
  692. }}
  693. confirm={() => { }}>
  694. {
  695. timePickerContent()
  696. }
  697. </Modal>
  698. }
  699. function single() {
  700. if (props.record.scenario.name == 'FAST') {
  701. return <View style={{ marginTop: rpxToPx(0) }}>
  702. {
  703. status == 'WAIT_FOR_START' &&
  704. <View onClick={tapStartFast} className='console_btn'>
  705. <Text style={{ fontWeight: 'bold',color:ColorType.black }}>{t('feature.track_time_duration.common.start_fast')}</Text>
  706. </View>
  707. }
  708. {/* {
  709. status != 'WAIT_FOR_START' && <View className='btn_line' />
  710. } */}
  711. {
  712. status == 'ONGOING' && <View onClick={tapEndFast} className={status == 'ONGOING' ? 'console_btn' : 'console_btn btn_disable'}>
  713. <Text style={{ fontWeight: 'bold',color:ColorType.black }}>{t('feature.track_time_duration.common.end_fast')}</Text>
  714. </View>
  715. }
  716. {
  717. showTimePicker && modalContent()
  718. }
  719. </View>
  720. }
  721. else if (props.record.scenario.name == 'SLEEP') {
  722. return <View style={{ marginTop: rpxToPx(0) }}>
  723. {
  724. status == 'WAIT_FOR_START' &&
  725. <View onClick={tapStartSleep} className='console_btn btn_sleep'>
  726. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.start_sleep')}</Text>
  727. </View>
  728. }
  729. {/* {
  730. status != 'WAIT_FOR_START' && <View className='btn_line' />
  731. } */}
  732. {
  733. status == 'ONGOING' && <View onClick={tapEndSleep} className={status == 'ONGOING' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  734. <Text style={{ fontWeight: 'bold' }}>{t('feature.track_time_duration.common.end_sleep')}</Text>
  735. </View>
  736. }
  737. {
  738. showTimePicker && modalContent()
  739. }
  740. </View>
  741. }
  742. }
  743. function mixed() {
  744. return <View style={{ marginTop: rpxToPx(0) }}>
  745. {
  746. status == 'WAIT_FOR_START' ?
  747. <View onClick={tapStartFast} className='console_btn'>
  748. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32),color:ColorType.black }}>{t('feature.track_time_duration.common.start_fast')}</Text>
  749. </View> :
  750. <View onClick={() => { tapStage(0) }} className='stage_btn'>
  751. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.a')}</Text>
  752. {
  753. status == 'ONGOING1' ?
  754. <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.fast.real_start_time)}</Text> :
  755. <Text style={{ color: '#fff' }}>{TimeFormatter.calculateTimeDifference(currentRecord.fast.real_start_time, currentRecord.sleep.real_start_time)}</Text>
  756. }
  757. </View>
  758. }
  759. <View className='btn_line' />
  760. {
  761. (status == 'WAIT_FOR_START' || status == 'ONGOING1') &&
  762. <View onClick={tapStartSleep} className={status == 'ONGOING1' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  763. {
  764. status != 'ONGOING1' && <Image className='lock' src={require('@assets/images/lock.png')} />
  765. }
  766. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32),color:ColorType.black }}>{t('feature.track_time_duration.common.start_sleep')}</Text>
  767. </View>
  768. }
  769. {
  770. (status != 'WAIT_FOR_START' && status != 'ONGOING1') &&
  771. <View onClick={() => { tapStage(1) }} className='stage_btn'>
  772. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.b')}</Text>
  773. {
  774. status == 'ONGOING2' ? <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.sleep.real_start_time)}</Text> :
  775. <Text style={{ color: '#fff' }}>{TimeFormatter.calculateTimeDifference(currentRecord.sleep.real_start_time, currentRecord.sleep.real_end_time)}</Text>
  776. }
  777. </View>
  778. }
  779. {(expand || (status != 'WAIT_FOR_START' && status != 'ONGOING1')) && <View className='btn_line' />}
  780. {
  781. (expand || (status != 'WAIT_FOR_START' && status != 'ONGOING1')) && (status == 'WAIT_FOR_START' || status == 'ONGOING1' || status == 'ONGOING2') &&
  782. <View onClick={tapEndSleep} className={status == 'ONGOING2' ? 'console_btn btn_sleep' : 'console_btn btn_sleep btn_disable'}>
  783. {
  784. status != 'ONGOING2' && <Image className='lock' src={require('@assets/images/lock.png')} />
  785. }
  786. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32),color:ColorType.black }}>{t('feature.track_time_duration.common.end_sleep')}</Text>
  787. </View>
  788. }
  789. {
  790. status == 'ONGOING3' &&
  791. <View onClick={() => { tapStage(2) }} className='stage_btn'>
  792. <Text style={{ flex: 1, color: '#fff' }}>{t('feature.track_time_duration.stage.c')}</Text>
  793. <Text style={{ color: '#fff' }}>{TimeFormatter.countdown(currentRecord.sleep.real_end_time)}</Text>
  794. </View>
  795. }
  796. {(expand || status == 'ONGOING3' || status == 'ONGOING') && <View className='btn_line' />}
  797. {
  798. (expand || status == 'ONGOING3' || status == 'ONGOING') &&
  799. <View onClick={tapEndFast} className={status == 'ONGOING3' ? 'console_btn' : 'console_btn btn_disable'}>
  800. {
  801. status == 'WAIT_FOR_START' && <Image className='lock' src={require('@assets/images/lock.png')} />
  802. }
  803. <Text style={{ fontWeight: 'bold', fontSize: rpxToPx(32),color:ColorType.black }}>{t('feature.track_time_duration.common.end_fast')}</Text>
  804. </View>
  805. }
  806. {
  807. (status == 'WAIT_FOR_START' || status == 'ONGOING1' || status == 'ONGOING2') &&
  808. <View>
  809. {
  810. !expand && <Text className='expand' onClick={() => { setExpand(true) }}>{expandBtnText()}</Text>
  811. }
  812. </View>
  813. }
  814. {
  815. showTimePicker && modalContent()
  816. }
  817. {
  818. showStageModal && stageContent()
  819. }
  820. </View>
  821. }
  822. function stageContent() {
  823. return <Modal
  824. testInfo={null}
  825. dismiss={() => {
  826. global.pauseIndexTimer = false
  827. setShowStageModal(false)
  828. }}
  829. confirm={() => { }}>
  830. {
  831. <CircadianDetailPopup
  832. record={currentRecord}
  833. schedule={props.record.scenario.schedule}
  834. stageIndex={stageIndex}
  835. onlyStage={true}
  836. onClose={() => { setShowStageModal(false); }} />
  837. }
  838. </Modal>
  839. }
  840. function tapStage(index) {
  841. stageIndex = index
  842. setShowStageModal(true)
  843. }
  844. return <View>
  845. {
  846. props.record.scenario.name == 'FAST_SLEEP' ? mixed() : single()
  847. }
  848. <CheckAccess record={props.record} count={props.count} />
  849. </View>
  850. }