Clock.tsx 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. import { View, Text, Image, ScrollView, PageContainer, Swiper, SwiperItem, Switch } from "@tarojs/components";
  2. import Tabbar from "@/components/navigation/TabBar";
  3. import IndexItem from '@/features/trackTimeDuration/components/IndexItem';
  4. import Rings from "@/features/trackTimeDuration/components/Rings";
  5. import './Clock.scss'
  6. import { useDispatch, useSelector } from "react-redux";
  7. import { useDidHide, useDidShow, usePageScroll, useReady, useShareAppMessage } from "@tarojs/taro";
  8. import Taro from "@tarojs/taro";
  9. import { getInfoSuccess } from "@/store/user";
  10. import { clockHome, clockSummaryRecords, clockSummaryStats, getClockRecords, getClocks, getPlans } from "@/services/trackTimeDuration";
  11. import { updateScenario } from "@/store/time";
  12. import { setConfigs } from "@/store/common";
  13. import { setScenario, setStep } from "@/store/scenario";
  14. import { useEffect, useRef, useState } from "react";
  15. import { IconPlus, IconRadioCheck, IconRadioCross } from "@/components/basic/Icons";
  16. import { ColorType } from "@/context/themes/color";
  17. import { bigRingRadius, getBgRing, getCommon, getDot, getSchedule, ringWidth, smallRingRadius } from "@/features/trackTimeDuration/hooks/RingData";
  18. import { RealRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  19. import IndexConsole from "@/features/trackTimeDuration/components/IndexConsole";
  20. import Modal from '@/components/layout/Modal'
  21. import { compareVersion, rpxToPx } from "@/utils/tools";
  22. import RecordFastSleep from "@/features/trackTimeDuration/components/RecordFastSleep";
  23. import DayLight from "@/features/trackTimeDuration/components/DayLight";
  24. import { getInfo, latestLocation } from "@/services/user";
  25. import { TimeFormatter } from "@/utils/time_format";
  26. import WeekCalendar from "@/features/trackTimeDuration/components/WeekCalendar";
  27. import { useTranslation } from "react-i18next";
  28. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  29. import Layout from "@/components/layout/layout";
  30. import { ModalType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
  31. import TitleView from "@/features/trackTimeDuration/components/TitleView";
  32. import ClockHeader from "@/features/trackTimeDuration/components/ClockHeader";
  33. import DurationPicker from "@/features/trackTimeDuration/components/DurationPicker";
  34. import SegmentPop from "@/features/trackTimeDuration/components/SegmentPop";
  35. import Box from "@/components/layout/Box";
  36. import DayNightCard from "@/features/daynight/DayNightCard";
  37. import StageSelector from "@/features/trackTimeDuration/components/StageSelector";
  38. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  39. import { clearNightStore, showNight } from "@/store/night";
  40. import { showDay } from "@/store/day";
  41. import { clientInfo, staticResources, systemVersion } from "@/services/common";
  42. import { changeFastDuration, changeSleepDuration, setCurrentRecord, setSchedule } from "@/store/ring";
  43. import { checkAuthorized } from "@/utils/check_authorized";
  44. import NoData from "@/components/view/NoData";
  45. import { AtActivityIndicator } from "taro-ui";
  46. import Tooltip from "@/components/view/Tooltip";
  47. import AllRings from "@/features/daynight/AllRings";
  48. import Streaks from "@/features/trackTimeDuration/components/Streaks";
  49. import dayjs from 'dayjs'
  50. import DayNightSwiper from "@/features/daynight/DayNightSwiper";
  51. import showAlert from "@/components/basic/Alert";
  52. import { APP_VERSION, WX_VERSION } from "@/services/http/api";
  53. const utc = require('dayjs/plugin/utc')
  54. const timezone = require('dayjs/plugin/timezone')
  55. dayjs.extend(utc)
  56. dayjs.extend(timezone)
  57. let GradientText
  58. let useNavigation;
  59. let timer
  60. let pauseTimer = false;
  61. let AppState;
  62. let needScroll = false;
  63. let showUpdate = false;
  64. let Linking;
  65. let JPush;
  66. let checkNotification, uploadPermissions;
  67. if (process.env.TARO_ENV == 'rn') {
  68. JPush = require('jpush-react-native').default;
  69. Linking = require('react-native').Linking;
  70. AppState = require("react-native").AppState
  71. GradientText = require('@/components/basic/GradientText').default
  72. useNavigation = require("@react-navigation/native").useNavigation
  73. checkNotification = require('@/utils/native_permission_check').checkNotification;
  74. uploadPermissions = require('@/utils/native_permission_check').uploadPermissions;
  75. }
  76. const defaultValue = `[{"scenario":{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}},"current_record":{"scenario":"FAST_SLEEP","status":"WAIT_FOR_START","fast":{"status":"WAIT_FOR_START","target_start_time":1710514800000,"target_end_time":1710576000000},"sleep":{"status":"WAIT_FOR_START","target_start_time":1710540000000,"target_end_time":1710572400000}},"wx_pub_followed":false,"time_input_schema":{"min":60,"max":1380,"step":5},"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}},{"scenarios":[{"name":"FAST","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"}}},{"name":"SLEEP","count":0,"schedule":{"sleep":{"start_time":"22:00","end_time":"07:00"}}},{"name":"FAST_SLEEP","count":0,"schedule":{"fast":{"start_time":"15:00","end_time":"08:00"},"sleep":{"start_time":"22:00","end_time":"07:00"}}}],"select_count":0,"theme_color":{"fast":"#00FFFF","sleep":"#8183FF"}}]`
  77. export default function Page() {
  78. const dispatch = useDispatch();
  79. global.dispatch = dispatch;
  80. let navigation;
  81. if (useNavigation) {
  82. navigation = useNavigation()
  83. }
  84. const { t } = useTranslation()
  85. const user = useSelector((state: any) => state.user);
  86. const time = useSelector((state: any) => state.time);
  87. const [count, setCount] = useState(0)
  88. const [homeData, setHomeData] = useState(null)
  89. const [loaded, setLoaded] = useState(false)
  90. const [showErrorPage, setErrorPage] = useState(false)
  91. const [showModal, setShowModal] = useState(false)
  92. const [modalDetail, setModalDetail] = useState<any>(null)
  93. const [showModal2, setShowModal2] = useState(false)
  94. const [modalDetail2, setModalDetail2] = useState<any>(null)
  95. const [debugInfo, setDebugInfo] = useState(null)
  96. const [needShowAddTip, setNeedShowAddTip] = useState(false)
  97. const [showTip, setShowTip] = useState(false)
  98. const [records, setRecords] = useState([])
  99. const permission = useSelector((state: any) => state.permission);
  100. const common = useSelector((state: any) => state.common);
  101. const scrollRef = useRef(null);
  102. const nightStore = useSelector((state: any) => state.night);
  103. if (process.env.TARO_ENV == 'weapp') {
  104. useShareAppMessage((e) => {
  105. return {
  106. title: t('feature.track_time_duration.common.share_title'),
  107. path: 'pages/clock/Clock'
  108. }
  109. })
  110. }
  111. useEffect(() => {
  112. dispatch(staticResources() as any);
  113. timer = setInterval(() => {
  114. var now = new Date()
  115. if (now.getDay() == 0 && now.getHours() == 12 && now.getMinutes() == 0 && now.getSeconds() == 0) {
  116. if (global.refrehWeekly) {
  117. global.refrehWeekly()
  118. }
  119. }
  120. if (global.pauseIndexTimer || pauseTimer) {
  121. return
  122. }
  123. setCount((prevCounter) => prevCounter + 1)
  124. }, 1000)
  125. }, [])
  126. useEffect(() => {
  127. if (process.env.TARO_ENV == 'weapp') {
  128. loadWXCache()
  129. }
  130. else {
  131. loadRNCache()
  132. // const test = require('@/utils/push').default
  133. // test()
  134. }
  135. if (process.env.TARO_ENV == 'rn') {
  136. JPush.setBadge({
  137. badge: 0,
  138. appBadge: 0
  139. })
  140. JPush.isNotificationEnabled((res) => {
  141. if (res) {
  142. const test = require('@/utils/push').default
  143. test()
  144. }
  145. })
  146. AppState.addEventListener('change', handleAppStateChange);
  147. }
  148. }, [])
  149. useEffect(() => {
  150. getCheckData()
  151. // global.pauseIndexTimer = !user.isLogin
  152. if (user.isLogin) {
  153. uploadUserClient();
  154. checkAuthorized();
  155. //检查用户是否添加过小程序
  156. checkAddToMini();
  157. if (process.env.TARO_ENV == 'rn') {
  158. uploadPermissions()
  159. JPush.isNotificationEnabled((res) => {
  160. if (res) {
  161. const test = require('@/utils/push').default
  162. test()
  163. }
  164. })
  165. checkVersionUpdate()
  166. }
  167. }
  168. else {
  169. dispatch(clearNightStore());
  170. }
  171. }, [user.isLogin])
  172. useReady(async () => {
  173. const userData = await getStorage('userData');
  174. if (userData) {
  175. dispatch(getInfoSuccess(JSON.parse(userData as string)) as any);
  176. getHistory()
  177. }
  178. })
  179. async function checkVersionUpdate() {
  180. if (!user.isLogin) {
  181. return
  182. }
  183. if (process.env.TARO_ENV == 'rn') {
  184. systemVersion().then(res => {
  185. if ((res as any).result == 'UPDATE' && !showUpdate) {
  186. showUpdate = true
  187. showAlert({
  188. title: (res as any).title,
  189. content: (res as any).description,
  190. showCancel: true,
  191. confirmText: '更新',
  192. confirm: () => {
  193. Linking.openURL((res as any).download_url)
  194. }
  195. })
  196. }
  197. else if ((res as any).result == 'FORCE_UPDATE') {
  198. showAlert({
  199. title: (res as any).title,
  200. content: (res as any).description,
  201. showCancel: false,
  202. confirmText: '更新',
  203. confirm: () => {
  204. Linking.openURL((res as any).download_url)
  205. }
  206. })
  207. }
  208. })
  209. return;
  210. }
  211. const showAlert1 = await getStorage('120alert') || false;
  212. if (!showAlert1) {
  213. showAlert({
  214. title: '版本更新提示',
  215. content: '「连续纪录」新增归零倒计时提示⏳\n别让连续记录终止, 将它们一直保持下去!',
  216. showCancel: false,
  217. confirmText: '我知道了'
  218. })
  219. }
  220. Taro.setStorage({ key: '120alert', data: true })
  221. }
  222. function checkAddToMini() {
  223. if (process.env.TARO_ENV == 'weapp') {
  224. const version = Taro.getAppBaseInfo().SDKVersion
  225. if (compareVersion(version, '2.30.3') >= 0) {
  226. wx.checkIsAddedToMyMiniProgram({
  227. success: (res) => {
  228. if (!res.added) {
  229. setNeedShowAddTip(true)
  230. }
  231. },
  232. fail: (e) => {
  233. }
  234. });
  235. }
  236. }
  237. }
  238. useDidShow(() => {
  239. checkTimeZone()
  240. setCount(pre => pre + 1)
  241. //resume timer
  242. pauseTimer = false
  243. if (user.isLogin) {
  244. if (global.refreshRecent) {
  245. global.refreshRecent()
  246. }
  247. }
  248. setTimeout(() => {
  249. checkVersionUpdate();
  250. if (process.env.TARO_ENV == 'rn' && user.isLogin)
  251. uploadPermissions()
  252. }, 1000)
  253. })
  254. usePageScroll((e) => {
  255. if (e.scrollTop > 70) {
  256. setShowTip(true)
  257. }
  258. else {
  259. setShowTip(false)
  260. }
  261. })
  262. useDidHide(() => {
  263. //pause timer
  264. pauseTimer = true
  265. })
  266. global.refreshIndex = () => {
  267. setCount((prevCounter) => prevCounter + 1)
  268. }
  269. const handleAppStateChange = (nextAppState) => {
  270. console.log(nextAppState)
  271. if (nextAppState != 'active') {
  272. return
  273. }
  274. checkTimeZone()
  275. if (user.isLogin) {
  276. uploadPermissions()
  277. }
  278. if (process.env.TARO_ENV == 'rn') {
  279. JPush.setBadge({
  280. badge: 0,
  281. appBadge: 0
  282. })
  283. }
  284. };
  285. function checkTimeZone() {
  286. setCount((prevCounter) => prevCounter + 1)
  287. var split = new Date().toString().split(' ');
  288. var timeZoneFormatted = split[split.length - 2];
  289. Taro.getStorage({
  290. key: 'last_tz',
  291. success: function (res) {
  292. if (res.data && res.data != timeZoneFormatted) {
  293. if (global.refrehWeekly) {
  294. global.refrehWeekly()
  295. }
  296. // if (global.refreshNight){
  297. // global.refreshNight()
  298. // }
  299. // if (global.refreshDay){
  300. // global.refreshDay()
  301. // }
  302. if (global.currentStatus != 'WAIT_FOR_START') {
  303. showAlert({
  304. title: t('feature.track_time_duration.change_tz_alert.title'),
  305. content: t('feature.track_time_duration.change_tz_alert.content', { tz: timeZoneFormatted }),
  306. showCancel: false,
  307. confirmText: t('feature.track_time_duration.change_tz_alert.confirm'),
  308. })
  309. }
  310. }
  311. },
  312. complete: function () {
  313. Taro.setStorage({ key: 'last_tz', data: timeZoneFormatted })
  314. }
  315. })
  316. }
  317. function uploadUserClient() {
  318. var systemInfo = Taro.getSystemInfoSync();
  319. console.log(systemInfo)
  320. var language: any = systemInfo.language
  321. if (process.env.TARO_ENV == 'rn') {
  322. var NativeModules = require('react-native').NativeModules;
  323. if (Taro.getSystemInfoSync().platform == 'ios') {
  324. // language = NativeModules.SettingsManager.settings.AppleLocale
  325. // languageList = NativeModules.SettingsManager.settings.AppleLanguages
  326. language = {
  327. AppleLocale: NativeModules.SettingsManager.settings.AppleLocale,
  328. AppleLanguages: NativeModules.SettingsManager.settings.AppleLanguages,
  329. NSLanguages: NativeModules.SettingsManager.settings.NSLanguages
  330. }
  331. }
  332. else {
  333. language = NativeModules.I18nManager.localeIdentifier
  334. }
  335. // iOS:
  336. // var locale = NativeModules.SettingsManager.settings.AppleLocale ||
  337. // NativeModules.SettingsManager.settings.AppleLanguages[0] // "fr_FR"
  338. showAlert({
  339. title: 'locale',
  340. content: JSON.stringify(NativeModules.SettingsManager.settings)
  341. })
  342. // Android:
  343. // locale = NativeModules.I18nManager.localeIdentifier // "fr_FR"
  344. }
  345. var split = new Date().toString().split(' ');
  346. var timeZoneFormatted = split[split.length - 2];
  347. var timeZoneId = ''
  348. if (Taro.getSystemInfoSync().platform == 'ios') {
  349. timeZoneId = dayjs.tz.guess()
  350. }
  351. clientInfo({
  352. client: {
  353. client_type: process.env.TARO_ENV == 'weapp' ? 'MP' : 'APP',
  354. client_version: process.env.TARO_ENV == 'weapp' ? WX_VERSION : APP_VERSION,//Taro.getAccountInfoSync().miniProgram.version : '1.0',//'1.0'
  355. wx_version: process.env.TARO_ENV == 'weapp' ? systemInfo.version : '_'
  356. },
  357. meta: {
  358. language: language,
  359. time_zone: {
  360. // id: Intl.DateTimeFormat().resolvedOptions().timeZone,
  361. name: timeZoneFormatted,
  362. id: timeZoneId
  363. },
  364. },
  365. device: {
  366. brand: systemInfo.brand,
  367. model: systemInfo.model,
  368. platform: systemInfo.platform,
  369. system: systemInfo.system
  370. },
  371. perm: {
  372. wifi_enabled: systemInfo.wifiEnabled,
  373. location_authorized: systemInfo.locationAuthorized,
  374. location_enabled: systemInfo.locationEnabled
  375. }
  376. })
  377. }
  378. function loadWXCache() {
  379. var showDayRing = Taro.getStorageSync('showDayRing') || false;
  380. var showNightRing = Taro.getStorageSync('showNightRing') || false;
  381. dispatch(showDay(showDayRing))
  382. dispatch(showNight(showNightRing))
  383. var gps = Taro.getStorageSync('gps')
  384. if (gps) {
  385. global.locationDetail = JSON.parse(gps)
  386. }
  387. var userData = Taro.getStorageSync('userData')
  388. if (userData) {
  389. dispatch(getInfoSuccess(JSON.parse(userData)));
  390. }
  391. }
  392. async function loadRNCache() {
  393. var showDayRing = await getStorage('showDayRing') || false;
  394. var showNightRing = await getStorage('showNightRing') || false;
  395. dispatch(showDay(showDayRing))
  396. dispatch(showNight(showNightRing))
  397. var gps = await getStorage('gps')
  398. if (gps) {
  399. global.locationDetail = JSON.parse(gps)
  400. }
  401. var userData = await getStorage('userData')
  402. if (userData) {
  403. dispatch(getInfoSuccess(JSON.parse(userData)));
  404. }
  405. }
  406. function getCheckData() {
  407. Promise.all([getClocks(), getPlans()]).then((list) => {
  408. setErrorPage(false)
  409. setCheckData(list)
  410. if (needScroll) {
  411. needScroll = false
  412. if (process.env.TARO_ENV == 'weapp') {
  413. setTimeout(() => {
  414. Taro.createSelectorQuery().select('#latest').boundingClientRect((rect) => {
  415. Taro.pageScrollTo({
  416. scrollTop: (rect as any).top,
  417. duration: 150
  418. })
  419. }).exec()
  420. }, 100)
  421. }
  422. else {
  423. // debugger
  424. // (scrollRef.current as any).scrollTo({ y: rpxToPx(400), animated: true })
  425. }
  426. }
  427. setLoaded(true)
  428. }).catch((e) => {
  429. setErrorPage(true)
  430. var list = JSON.parse(defaultValue)
  431. setCheckData(list)
  432. needScroll = false
  433. setLoaded(true)
  434. })
  435. getHistory()
  436. }
  437. function setCheckData(list: any) {
  438. setHomeData(list[0])
  439. global.homeData = list[0]
  440. global.currentStatus = list[0].current_record.status;
  441. var array = list[1].scenarios
  442. var schedule = null
  443. array.map(item => {
  444. if (item.name == 'FAST_SLEEP') {
  445. schedule = item.schedule;
  446. }
  447. })
  448. if (user.isLogin) {
  449. dispatch(updateScenario(list[0].current_record))
  450. dispatch(setConfigs(list[0].time_input_schema));
  451. dispatch(setScenario(list[0].scenario));
  452. global.scenario = list[0].scenario.name;
  453. }
  454. dispatch(setCurrentRecord(list[0].current_record))
  455. dispatch(setSchedule(schedule))
  456. // setLoaded(true)
  457. }
  458. function getHistory() {
  459. if (user.isLogin)
  460. getClockRecords({
  461. page: 1,
  462. limit: 1,
  463. // part_completed: true
  464. completed: true
  465. }).then(res => {
  466. setRecords((res as any).data)
  467. })
  468. }
  469. global.indexPageRefresh = () => {
  470. getCheckData()
  471. if (global.swiperDayNightRefresh) {
  472. global.swiperDayNightRefresh()
  473. }
  474. }
  475. global.showIndexModal = (isShow: boolean, detail: any, debugNode?: any) => {
  476. global.showModal = isShow
  477. setDebugInfo(debugNode)
  478. setShowModal(isShow)
  479. setModalDetail(detail)
  480. }
  481. global.showIndexModal2 = (isShow: boolean, detail: any) => {
  482. setDebugInfo(null)
  483. global.showModal = isShow
  484. setShowModal2(isShow)
  485. setModalDetail2(detail)
  486. }
  487. global.changeTargetDuration = (duration: number, isFast: boolean) => {
  488. var obj = JSON.parse(JSON.stringify(homeData))
  489. var record = obj.current_record
  490. if (isFast) {
  491. record.fast.target_end_time = record.fast.target_start_time + duration * 60 * 1000
  492. }
  493. else {
  494. record.sleep.target_end_time = record.sleep.target_start_time + duration * 60 * 1000
  495. }
  496. setHomeData(obj)
  497. }
  498. global.updateFastSleepData = (data: any, schedule?: any) => {
  499. if (data.id == (homeData as any).current_record.id) {
  500. var obj = JSON.parse(JSON.stringify(homeData))
  501. obj.current_record = data
  502. if (schedule) {
  503. obj.scenario.schedule = schedule
  504. }
  505. setHomeData(obj)
  506. }
  507. switch (data.scenario) {
  508. case 'FAST':
  509. if (data.status == 'WAIT_FOR_START') {
  510. dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
  511. }
  512. break;
  513. case 'SLEEP':
  514. if (data.status == 'WAIT_FOR_START') {
  515. dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
  516. }
  517. break;
  518. case 'FAST_SLEEP':
  519. if (data.status == 'WAIT_FOR_START') {
  520. dispatch(changeFastDuration(data.fast.target_end_time - data.fast.target_start_time))
  521. }
  522. else if (data.status == 'ONGOING1') {
  523. dispatch(changeSleepDuration(data.sleep.target_end_time - data.sleep.target_start_time))
  524. }
  525. break;
  526. }
  527. }
  528. global.popScheduleAlert = (scenario, startTime) => {
  529. if (process.env.TARO_ENV == 'weapp') {
  530. if (permission.wxPubFollow) {
  531. showAlert({
  532. title: t('feature.track_time_duration.reminders.schedule_title'),
  533. content: scenario.name == 'FAST' ?
  534. t('feature.track_time_duration.reminders.enable_schedule_fast_content', { time: startTime }) :
  535. t('feature.track_time_duration.reminders.enable_schedule_sleep_content', { time: startTime }),
  536. showCancel: false,
  537. confirmText: t('feature.track_time_duration.reminders.ok')
  538. })
  539. }
  540. else {
  541. showAlert({
  542. title: t('feature.track_time_duration.reminders.schedule_title'),
  543. content: scenario.name == 'FAST' ?
  544. t('feature.track_time_duration.reminders.schedule_fast_content', { time: startTime }) :
  545. t('feature.track_time_duration.reminders.schedule_sleep_content', { time: startTime }),
  546. cancelText: t('feature.track_time_duration.reminders.later'),
  547. confirmText: t('feature.track_time_duration.reminders.open'),
  548. showCancel: true,
  549. confirm: () => {
  550. followWxPub()
  551. }
  552. })
  553. }
  554. }
  555. else {
  556. JPush.isNotificationEnabled((res) => {
  557. if (res) {
  558. showAlert({
  559. title: t('feature.track_time_duration.reminders.schedule_title'),
  560. content: scenario.name == 'FAST' ?
  561. t('feature.track_time_duration.reminders.enable_schedule_fast_content', { time: startTime }) :
  562. t('feature.track_time_duration.reminders.enable_schedule_sleep_content', { time: startTime }),
  563. showCancel: false,
  564. confirmText: t('feature.track_time_duration.reminders.ok')
  565. })
  566. }
  567. else {
  568. showAlert({
  569. title: t('feature.track_time_duration.reminders.schedule_title'),
  570. content: scenario.name == 'FAST' ?
  571. t('feature.track_time_duration.reminders.schedule_fast_content', { time: startTime }) :
  572. t('feature.track_time_duration.reminders.schedule_sleep_content', { time: startTime }),
  573. cancelText: t('feature.track_time_duration.reminders.later'),
  574. confirmText: t('feature.track_time_duration.reminders.open'),
  575. showCancel: true,
  576. confirm: () => {
  577. checkNotification()
  578. // Linking.openURL('app-settings:notifications')
  579. }
  580. })
  581. }
  582. })
  583. }
  584. }
  585. global.popMixScheduleAlert = (time1, time2) => {
  586. if (process.env.TARO_ENV == 'weapp') {
  587. if (permission.wxPubFollow) {
  588. showAlert({
  589. title: t('feature.track_time_duration.reminders.schedule_title'),
  590. content: t('feature.track_time_duration.reminders.enable_schedule_mix_content', { time1: time1, time2: time2 }),
  591. showCancel: false,
  592. confirmText: t('feature.track_time_duration.reminders.ok')
  593. })
  594. }
  595. else {
  596. showAlert({
  597. title: t('feature.track_time_duration.reminders.schedule_title'),
  598. content:
  599. t('feature.track_time_duration.reminders.schedule_mix_content'),
  600. cancelText: t('feature.track_time_duration.reminders.later'),
  601. confirmText: t('feature.track_time_duration.reminders.open'),
  602. showCancel: true,
  603. confirm: () => {
  604. followWxPub()
  605. }
  606. })
  607. }
  608. }
  609. else {
  610. JPush.isNotificationEnabled((res) => {
  611. if (res) {
  612. showAlert({
  613. title: t('feature.track_time_duration.reminders.schedule_title'),
  614. content: t('feature.track_time_duration.reminders.enable_schedule_mix_content', { time1: time1, time2: time2 }),
  615. showCancel: false,
  616. confirmText: t('feature.track_time_duration.reminders.ok')
  617. })
  618. }
  619. else {
  620. showAlert({
  621. title: t('feature.track_time_duration.reminders.schedule_title'),
  622. content:
  623. t('feature.track_time_duration.reminders.schedule_mix_content'),
  624. cancelText: t('feature.track_time_duration.reminders.later'),
  625. confirmText: t('feature.track_time_duration.reminders.open'),
  626. showCancel: true,
  627. confirm: () => {
  628. checkNotification()
  629. // Linking.openURL('app-settings:notifications')
  630. }
  631. })
  632. }
  633. })
  634. }
  635. }
  636. function followWxPub() {
  637. const resource = common.resources.filter((item: any) => {
  638. return item.code == 'follow_wx_pub'
  639. })
  640. jumpPage('/pages/common/H5?title=fast16cc 关注服务号&url=' + resource[0].url)
  641. }
  642. function modalContent() {
  643. if (showModal || showModal2) {
  644. return <Modal
  645. testInfo={debugInfo}
  646. dismiss={() => {
  647. setDebugInfo(null)
  648. setShowModal(false);
  649. setShowModal2(false);
  650. global.pauseIndexTimer = false
  651. }}
  652. confirm={() => { }}>
  653. {
  654. showModal ? modalDetail : modalDetail2
  655. }
  656. </Modal>
  657. }
  658. return <View />
  659. }
  660. async function getStorage(key: string) {
  661. try {
  662. const res = await Taro.getStorage({ key });
  663. return res.data;
  664. } catch {
  665. return '';
  666. }
  667. }
  668. function more() {
  669. jumpPage('/pages/common/RecordsHistory?type=time&title=time', 'RecordsHistory', navigation, {
  670. type: 'time',
  671. title: 'time'
  672. })
  673. }
  674. function tapLogin() {
  675. // if (process.env.TARO_ENV=='rn'){
  676. // Taro.getLocation({
  677. // success(result) {
  678. // console.log(result)
  679. // },
  680. // fail(res) {
  681. // console.log(res)
  682. // },
  683. // })
  684. // return
  685. // }
  686. if (!user.isLogin) {
  687. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  688. return
  689. }
  690. }
  691. function headerView() {
  692. return <ClockHeader homeData={homeData} />
  693. }
  694. global.scrollToLatest = () => {
  695. needScroll = true;
  696. }
  697. var timestamp = new Date().getTime()
  698. function render() {
  699. if (!loaded) {
  700. return <Layout type={TemplateType.customHeader} header={headerView()} title={t('page.clock.title')} titleShowStyle={NaviBarTitleShowType.scrollToShow}>
  701. <View style={{ width: rpxToPx(750), height: rpxToPx(900), display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
  702. <AtActivityIndicator size={40} color="#fff" />
  703. {
  704. process.env.TARO_ENV == 'weapp' && <Tabbar index={0} />
  705. }
  706. </View>
  707. </Layout>
  708. }
  709. return <Layout type={TemplateType.customHeader} header={headerView()} title={t('page.clock.title')} titleShowStyle={NaviBarTitleShowType.scrollToShow}>
  710. <View className="index_container">
  711. {
  712. needShowAddTip && showTip && <Tooltip title="添加到我的小程序" closeTip={() => { setNeedShowAddTip(false) }} />
  713. }
  714. <Text className="count">{count}</Text>
  715. <Box>
  716. <View>
  717. <IndexItem type="FAST_SLEEP" data={homeData} time={timestamp} showStage={false} />
  718. {
  719. user.isLogin ? <IndexConsole record={homeData} /> : <StageSelector />
  720. }
  721. </View>
  722. </Box>
  723. {
  724. process.env.TARO_ENV == 'weapp' && <DayNightCard isNight={true} count={count} />
  725. }
  726. {
  727. process.env.TARO_ENV == 'rn' && <DayNightSwiper count={count} />
  728. // <Swiper
  729. // className="rn_swiper"
  730. // indicatorDots indicatorColor='#333'
  731. // indicatorActiveColor='#999'>
  732. // <SwiperItem>
  733. // <DayNightCard isNight={true} count={count} />
  734. // </SwiperItem>
  735. // <SwiperItem>
  736. // <DayNightCard isNight={false} count={count} />
  737. // </SwiperItem>
  738. // </Swiper>
  739. }
  740. {
  741. process.env.TARO_ENV == 'rn' && <View style={{ height: rpxToPx(20) }} />
  742. }
  743. {user.isLogin && <AllRings data={homeData} time={timestamp} />}
  744. {
  745. user.isLogin && records.length > 0 && <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', marginTop: rpxToPx(40), }}>
  746. {
  747. <Text className="discovery1" style={{ marginBottom: 0 }}>{t('feature.track_time_duration.record_fast_sleep.header.latest_record')}</Text>
  748. }
  749. {
  750. process.env.TARO_ENV == 'weapp' && <Text className="fast_sleep_more index_more" onClick={more}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</Text>
  751. }
  752. {
  753. process.env.TARO_ENV == 'rn' && <View onClick={more}>
  754. <GradientText style={{ fontSize: rpxToPx(32), fontWeight: 'bold', marginRight: rpxToPx(46) }}>{t('feature.track_time_duration.record_fast_sleep.header.btn_show_all')}</GradientText>
  755. </View>
  756. }
  757. </View>
  758. }
  759. {
  760. user.isLogin && records.length > 0 && <View id="latest" className="fast_sleep_item_bg">
  761. <RecordFastSleep data={records[0]} type='record' index={-20000} />
  762. </View>
  763. }
  764. {
  765. loaded && !user.isLogin && <View style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', marginTop: rpxToPx(36) }}>
  766. <ChooseScenarioBtn title={t('feature.auth.login.login_now')} background={ColorType.fast} onClick={tapLogin} />
  767. </View>
  768. }
  769. {
  770. showErrorPage && <NoData refresh={() => { getCheckData() }} />
  771. }
  772. {
  773. user.isLogin && !showErrorPage && <View style={{ marginTop: rpxToPx(60), display: 'flex', flexDirection: 'column' }}>
  774. <Text className="discovery1" >{t('feature.track_time_duration.weekly.title')}</Text>
  775. <WeekCalendar />
  776. </View>
  777. }
  778. {
  779. user.isLogin && <Streaks count={count} />
  780. }
  781. {
  782. process.env.TARO_ENV == 'weapp' && <View style={{ height: 100 }} />
  783. }
  784. {
  785. modalContent()
  786. }
  787. {
  788. homeData && <SegmentPop data={homeData} />
  789. }
  790. {
  791. homeData && <DurationPicker record={(homeData as any).current_record} />
  792. }
  793. <Tabbar index={0} />
  794. </View>
  795. </Layout>
  796. }
  797. // if (process.env.TARO_ENV == 'rn') {
  798. // return <ScrollView>
  799. // {
  800. // render()
  801. // }
  802. // </ScrollView>
  803. // }
  804. return render()
  805. }