DayNightDetailPopup.tsx 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. import { View, Text } from '@tarojs/components'
  2. import '@/features/trackTimeDuration/components/CircadianDetailPopup.scss'
  3. import { useTranslation } from 'react-i18next'
  4. import { useEffect, useState } from 'react'
  5. import { getTimezone, getTimezoneName, kIsIOS, rpxToPx } from '@/utils/tools'
  6. import { TimeFormatter } from '@/utils/time_format'
  7. import { useSelector } from 'react-redux'
  8. import { ColorType } from '@/context/themes/color'
  9. import Timeline from '@/components/view/Timeline'
  10. import Taro from '@tarojs/taro'
  11. import dayjs, { Dayjs } from 'dayjs'
  12. import showAlert from '@/components/basic/Alert'
  13. import { AtActivityIndicator } from 'taro-ui'
  14. import showActionSheet from '@/components/basic/ActionSheet'
  15. const utc = require('dayjs/plugin/utc')
  16. const timezone = require('dayjs/plugin/timezone')
  17. dayjs.extend(utc)
  18. dayjs.extend(timezone)
  19. let LinearGradient,useActionSheet
  20. if (process.env.TARO_ENV == 'rn') {
  21. LinearGradient = require('react-native-linear-gradient').default
  22. useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
  23. }
  24. export default function DayNightDetailPopup(props: {
  25. isNight: boolean,
  26. authInfo: any,
  27. nightDate: any,
  28. dayDate: any,
  29. onClose: Function,
  30. updateLocation: Function
  31. }) {
  32. const dayNight = useSelector((state: any) => state.night);
  33. const day = useSelector((state: any) => state.day);
  34. const [tabIndex, setTabIndex] = useState(0)
  35. const [isLoading, setIsLoading] = useState(false)
  36. const { t } = useTranslation()
  37. let showActionSheetWithOptions;
  38. if (process.env.TARO_ENV=='rn'){
  39. showActionSheetWithOptions = useActionSheet()
  40. }
  41. useEffect(() => {
  42. if (isCompleted()) {
  43. setTabIndex(1)
  44. }
  45. }, [])
  46. global.updateLocationLoading = (status) => {
  47. setIsLoading(status)
  48. }
  49. function localNow(now: Date) {
  50. if (props.authInfo && props.authInfo.timezone) {
  51. return new Date(TimeFormatter.transferTimestamp(now.getTime(), props.authInfo.timezone.gmt))
  52. }
  53. return now
  54. }
  55. function getTitle() {
  56. return props.isNight ? t('feature.day_night.night_popover') : t('feature.day_night.day_popover')
  57. }
  58. function getCompletedTitle() {
  59. if (props.isNight) {
  60. return TimeFormatter.getDayOfWeek(new Date(props.authInfo.night_completed.sunrise_ts).getDay(), true)
  61. }
  62. return TimeFormatter.getDayOfWeek(new Date(props.authInfo.night_completed.sunset_ts).getDay(), true)
  63. }
  64. function getSubTitle() {
  65. var now = new Date()
  66. if (props.isNight) {
  67. if (localNow(now).getTime() != now.getTime()) {
  68. return TimeFormatter.getMonthAndDayByTimestamp(props.authInfo.night_completed.sunrise_ts, true)
  69. }
  70. return TimeFormatter.dateDescription(props.authInfo.night_completed.sunrise_ts, true)
  71. }
  72. if (localNow(now).getTime() != now.getTime()) {
  73. return TimeFormatter.getMonthAndDayByTimestamp(props.authInfo.night_completed.sunset_ts, true)
  74. }
  75. return TimeFormatter.dateDescription(props.authInfo.night_completed.sunset_ts, true)
  76. }
  77. function isCompleted() {
  78. if (props.isNight) {
  79. if (props.authInfo && props.authInfo.night_completed && new Date().getTime() > props.authInfo.night_completed.sunrise_ts) {
  80. return true
  81. }
  82. }
  83. else {
  84. if (props.authInfo && props.authInfo.day_completed && new Date().getTime() > props.authInfo.day_completed.sunset_ts) {
  85. return true
  86. }
  87. }
  88. return false
  89. }
  90. function nightDuration() {
  91. if (isCompleted()) {
  92. return TimeFormatter.calculateTimeDifference(props.authInfo.night_completed.sunset_ts, props.authInfo.night_completed.sunrise_ts, true);
  93. }
  94. if (global.nightObj) {
  95. return TimeFormatter.calculateTimeDifference(global.nightObj.sunset.timestamp, global.nightObj.sunrise.timestamp, true);
  96. }
  97. return ''
  98. }
  99. function dayDuration() {
  100. debugger
  101. if (isCompleted()) {
  102. return TimeFormatter.calculateTimeDifference(props.authInfo.day_completed.sunrise_ts, props.authInfo.day_completed.sunset_ts, true);
  103. }
  104. if (global.dayObj) {
  105. return TimeFormatter.calculateTimeDifference(global.dayObj.sunrise.timestamp, global.dayObj.sunset.timestamp, true);
  106. }
  107. return ''
  108. }
  109. function showExtraData() {
  110. var now = new Date()
  111. if (props.isNight) {
  112. if (global.nightObj.sunset.timestamp > now.getTime()) {
  113. return false
  114. }
  115. return true
  116. }
  117. if (global.dayObj.sunrise.timestamp < now.getTime() && now.getTime() < global.dayObj.sunset.timestamp) {
  118. return true;
  119. }
  120. return false
  121. }
  122. function timeCount() {
  123. var now = new Date()
  124. if (props.isNight) {
  125. if (now.getTime() < global.nightObj.sunrise.timestamp) {
  126. return TimeFormatter.countdown(global.nightObj.sunset.timestamp, now.getTime(), true)
  127. }
  128. return TimeFormatter.countdown(global.nightObj.sunset.timestamp, now.getTime(), true)
  129. } else {
  130. if (now.getTime() < global.dayObj.sunset.timestamp) {
  131. return TimeFormatter.countdown(global.dayObj.sunrise.timestamp, now.getTime(), true)
  132. }
  133. return TimeFormatter.countdown(global.dayObj.sunrise.timestamp, now.getTime(), true)
  134. }
  135. }
  136. function timeCount2() {
  137. var now = new Date()
  138. if (props.isNight) {
  139. if (now.getTime() < global.nightObj.sunset.timestamp) {
  140. return TimeFormatter.countdown(global.nightObj.sunrise.timestamp, now.getTime(), true)
  141. }
  142. return TimeFormatter.countdown(global.nightObj.sunrise.timestamp, now.getTime(), true)
  143. } else {
  144. return TimeFormatter.countdown(global.dayObj.sunset.timestamp, now.getTime(), true)
  145. }
  146. }
  147. function timeDesc() {
  148. var now = new Date()
  149. if (props.isNight) {
  150. if (global.nightObj.sunset.timestamp < now.getTime()) {
  151. return t('feature.day_night.time_past_sunset')//'Time past Sunset'
  152. }
  153. return t('feature.day_night.time_to_sunset')//'Time to Sunset'
  154. }
  155. else {
  156. if (now.getTime() < global.dayObj.sunrise.timestamp) {
  157. return t('feature.day_night.time_to_sunrise')//'Time to Sunrise'
  158. }
  159. return t('feature.day_night.time_past_sunrise')//'Time past Sunrise'
  160. }
  161. }
  162. function timeDesc2() {
  163. if (props.isNight) {
  164. return t('feature.day_night.time_to_sunrise')//'Time to Sunrise'
  165. }
  166. return t('feature.day_night.time_to_sunset')//'Time to Sunset'
  167. }
  168. function overview() {
  169. return <View className='pop_ring_bg pop_overview_bg'>
  170. <Text className='pop_duration_title'>{props.isNight ? t('feature.day_night.night_duration') : t('feature.day_night.day_duration')}</Text>
  171. <View style={{ flexDirection: 'row', alignItems: 'center', marginTop: rpxToPx(8), display: 'flex', width: '100%' }}>
  172. <Text className='pop_duration_txt'>{props.isNight ? nightDuration() : dayDuration()}</Text>
  173. </View>
  174. {
  175. !isCompleted() && <View style={{ marginTop: rpxToPx(20), display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  176. <View className='countdown_time_bg'>
  177. <Text className='title' style={{ color: '#fff', opacity: 0.4 }}>{timeDesc()}</Text>
  178. <Text className='value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
  179. </View>
  180. {
  181. showExtraData() && <View className='countdown_time_bg'>
  182. <Text className='title' style={{ color: '#fff', opacity: 0.4 }}>{timeDesc2()}</Text>
  183. <Text className='value' style={{ opacity: 0.4, color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount2()}</Text>
  184. </View>
  185. }
  186. </View>
  187. }
  188. </View>
  189. }
  190. function nightDurationDesc() {
  191. if (!props.authInfo || !(props.authInfo as any).lat) {
  192. if (new Date().getHours() >= 6) {
  193. return [t('feature.day_night.tonight'), t('feature.day_night.tomorrow')]
  194. }
  195. return [t('feature.day_night.last_night'), t('feature.day_night.today')]
  196. }
  197. if (diffTimeZone()) {
  198. var sunriseDate = new Date(TimeFormatter.transferTimestamp(global.nightObj.sunrise.timestamp, props.authInfo.timezone.gmt))
  199. var sunsetDate = new Date(TimeFormatter.transferTimestamp(global.nightObj.sunset.timestamp, props.authInfo.timezone.gmt))
  200. return [
  201. (sunsetDate.getMonth() + 1) + '月' + sunsetDate.getDate() + '日',
  202. (sunriseDate.getMonth() + 1) + '月' + sunriseDate.getDate() + '日',
  203. ];
  204. }
  205. var strSunset = ''
  206. var strSunrise = '';
  207. if (global.nightObj) {
  208. if (new Date().getDate() == new Date(global.nightObj.sunset.timestamp).getDate()) {
  209. strSunset = t('feature.day_night.tonight')
  210. }
  211. else if (new Date().getDate() == new Date(global.nightObj.sunset.timestamp + 24 * 3600 * 1000).getDate()) {
  212. strSunset = t('feature.day_night.last_night')
  213. }
  214. else if (new Date().getDate() == new Date(global.nightObj.sunset.timestamp - 24 * 3600 * 1000).getDate()) {
  215. strSunset = t('feature.day_night.tomorrow')
  216. }
  217. else {
  218. strSunset = dayjs(global.nightObj.sunset.timestamp).format(global.language == 'en' ? 'MMM D' : 'M月D日')
  219. }
  220. if (new Date().getDate() == new Date(global.nightObj.sunrise.timestamp).getDate()) {
  221. strSunrise = t('feature.day_night.today')
  222. }
  223. else if (new Date().getDate() == new Date(global.nightObj.sunrise.timestamp + 24 * 3600 * 1000).getDate()) {
  224. strSunrise = t('feature.day_night.yesterday')
  225. }
  226. else if (new Date().getDate() == new Date(global.nightObj.sunrise.timestamp - 24 * 3600 * 1000).getDate()) {
  227. strSunrise = t('feature.day_night.tomorrow')
  228. }
  229. else {
  230. strSunrise = dayjs(global.nightObj.sunrise.timestamp).format(global.language == 'en' ? 'MMM D' : 'M月D日')
  231. }
  232. }
  233. return [strSunset, strSunrise];
  234. }
  235. function dayDurationDesc() {
  236. debugger
  237. if (!props.authInfo || !(props.authInfo as any).lat) {
  238. if (new Date().getHours() >= 18) {
  239. return [t('feature.day_night.tomorrow'), t('feature.day_night.tomorrow')]
  240. }
  241. return [t('feature.day_night.today'), t('feature.day_night.today')]
  242. }
  243. if (diffTimeZone()) {
  244. var sunriseDate = new Date(TimeFormatter.transferTimestamp(global.dayObj.sunrise.timestamp, props.authInfo.timezone.gmt))
  245. var sunsetDate = new Date(TimeFormatter.transferTimestamp(global.dayObj.sunset.timestamp, props.authInfo.timezone.gmt))
  246. return [
  247. (sunriseDate.getMonth() + 1) + '月' + sunriseDate.getDate() + '日',
  248. (sunsetDate.getMonth() + 1) + '月' + sunsetDate.getDate() + '日',
  249. ];
  250. }
  251. var strSunset = ''
  252. var strSunrise = '';
  253. if (global.dayObj) {
  254. if (new Date().getDate() == new Date(global.dayObj.sunset.timestamp).getDate()) {
  255. strSunset = t('feature.day_night.tonight')
  256. }
  257. else if (new Date().getDate() == new Date(global.dayObj.sunset.timestamp + 24 * 3600 * 1000).getDate()) {
  258. strSunset = t('feature.day_night.last_night')
  259. }
  260. else if (new Date().getDate() == new Date(global.dayObj.sunset.timestamp - 24 * 3600 * 1000).getDate()) {
  261. strSunset = t('feature.day_night.tomorrow')
  262. }
  263. else {
  264. strSunset = dayjs(global.dayObj.sunset.timestamp).format(global.language == 'en' ? 'MMM D' : 'M月D日')
  265. }
  266. if (new Date().getDate() == new Date(global.dayObj.sunrise.timestamp).getDate()) {
  267. strSunrise = t('feature.day_night.today')
  268. }
  269. else if (new Date().getDate() == new Date(global.dayObj.sunrise.timestamp + 24 * 3600 * 1000).getDate()) {
  270. strSunrise = t('feature.day_night.yesterday')
  271. }
  272. else if (new Date().getDate() == new Date(global.dayObj.sunrise.timestamp - 24 * 3600 * 1000).getDate()) {
  273. strSunrise = t('feature.day_night.tomorrow')
  274. }
  275. else {
  276. strSunrise = dayjs(global.dayObj.sunrise.timestamp).format(global.language == 'en' ? 'MMM D' : 'M月D日')
  277. }
  278. }
  279. return [strSunrise, strSunset];
  280. // if (props.dayDate.getDate() == new Date().getDate()) {
  281. // return [t('feature.day_night.today'),t('feature.day_night.today')]
  282. // }
  283. // return [t('feature.day_night.tomorrow'),t('feature.day_night.tomorrow')]
  284. }
  285. function diffTimeZone() {
  286. var now = new Date()
  287. if (props.authInfo && props.authInfo.timezone) {
  288. var t1 = TimeFormatter.tzLocalTime(now.getTime(), props.authInfo.timezone.id)//dayjs(now.getTime()).tz(props.authInfo.timezone.id)
  289. if (now.getHours() == t1.hour() && now.getMinutes() == t1.minute()) {
  290. return false
  291. }
  292. else {
  293. return true
  294. }
  295. }
  296. return false
  297. }
  298. function events() {
  299. let timelineItems: any = []
  300. const timeFormat = global.language == 'en' ? 'MMM D HH:mm' : 'M月D日 HH:mm'
  301. const timeFormat2 = global.language == 'en' ? 'MMM D' : 'M月D日'
  302. if (props.isNight) {
  303. if (isCompleted()) {
  304. var newT;
  305. if (props.authInfo.timezone) {
  306. newT = TimeFormatter.tzTimeFormateLocalTime(props.authInfo.night_completed.sunset_ts, props.authInfo.timezone.id, timeFormat)
  307. //dayjs(props.authInfo.night_completed.sunset_ts).tz(props.authInfo.timezone.id).format('M月D日 HH:mm')
  308. }
  309. else {
  310. newT = dayjs(props.authInfo.night_completed.sunset_ts).format(timeFormat)
  311. }
  312. var list = nightDurationDesc()
  313. timelineItems.push(
  314. {
  315. status: 'done',
  316. title: t('feature.day_night.sunset'),//list[0],
  317. // content: newT,
  318. content: diffTimeZone() ? newT : TimeFormatter.dateTimeFormate(props.authInfo.night_completed.sunset_ts, true),
  319. date: '',
  320. color: ColorType.night
  321. }
  322. )
  323. var newT2;
  324. if (props.authInfo.timezone) {
  325. newT2 = TimeFormatter.tzTimeFormateLocalTime(props.authInfo.night_completed.sunrise_ts, props.authInfo.timezone.id, timeFormat)
  326. //dayjs(props.authInfo.night_completed.sunrise_ts).tz(props.authInfo.timezone.id).format('M月D日 HH:mm')
  327. }
  328. else {
  329. newT2 = dayjs(props.authInfo.night_completed.sunrise_ts).format(timeFormat)
  330. }
  331. // var newT2 = dayjs(props.authInfo.night_completed.sunrise_ts).tz('GMT+0800').format('MM-DD HH:mm')//TimeFormatter.transferTimestamp(props.authInfo.night_completed.sunrise_ts, props.authInfo.timezone)
  332. timelineItems.push(
  333. {
  334. status: 'done',
  335. title: t('feature.day_night.sunrise'),//list[1],
  336. // content: newT2,//list[1] + ' ' + global.nightObj.sunrise.time.substring(0, 5),
  337. content: diffTimeZone() ? newT2 : TimeFormatter.dateTimeFormate(props.authInfo.night_completed.sunrise_ts, true),
  338. date: '',
  339. color: ColorType.night
  340. }
  341. )
  342. }
  343. else {
  344. var list = nightDurationDesc()
  345. if (diffTimeZone() && global.nightObj) {
  346. list[0] = TimeFormatter.tzTimeFormateLocalTime(global.nightObj.sunset.timestamp, props.authInfo.timezone.id, timeFormat2)
  347. list[1] = TimeFormatter.tzTimeFormateLocalTime(global.nightObj.sunrise.timestamp, props.authInfo.timezone.id, timeFormat2)
  348. // list[0] = dayjs(global.nightObj.sunset.timestamp).tz(props.authInfo.timezone.id).format('M月D日')
  349. // list[1] = dayjs(global.nightObj.sunrise.timestamp).tz(props.authInfo.timezone.id).format('M月D日')
  350. }
  351. timelineItems.push(
  352. {
  353. status: showExtraData() ? 'done' : 'padding',
  354. title: t('feature.day_night.sunset'),//list[0],
  355. content: list[0] + ' ' + global.nightObj.sunset.time.substring(0, 5),
  356. date: '',
  357. color: ColorType.night
  358. }
  359. )
  360. timelineItems.push(
  361. {
  362. status: 'padding',
  363. title: t('feature.day_night.sunrise'),//list[1],
  364. content: list[1] + ' ' + global.nightObj.sunrise.time.substring(0, 5),
  365. date: '',
  366. color: ColorType.night
  367. }
  368. )
  369. }
  370. }
  371. else {
  372. if (isCompleted()) {
  373. var newT;
  374. if (props.authInfo.timezone) {
  375. newT = TimeFormatter.tzTimeFormateLocalTime(props.authInfo.day_completed.sunrise_ts, props.authInfo.timezone.id, timeFormat)
  376. // newT = dayjs(props.authInfo.day_completed.sunrise_ts).tz(props.authInfo.timezone.id).format('M月D日 HH:mm')
  377. }
  378. else {
  379. newT = dayjs(props.authInfo.day_completed.sunrise_ts).format(timeFormat)
  380. }
  381. timelineItems.push(
  382. {
  383. status: 'done',
  384. title: t('feature.day_night.sunrise'),//list[0],
  385. content: diffTimeZone() ? newT : TimeFormatter.dateTimeFormate(props.authInfo.day_completed.sunrise_ts, true),
  386. date: '',
  387. color: ColorType.day
  388. }
  389. )
  390. var newT2;
  391. if (props.authInfo.timezone) {
  392. newT2 = TimeFormatter.tzTimeFormateLocalTime(props.authInfo.day_completed.sunset_ts, props.authInfo.timezone.id, timeFormat)
  393. // newT2 = dayjs(props.authInfo.day_completed.sunset_ts).tz(props.authInfo.timezone.id).format('M月D日 HH:mm')
  394. }
  395. else {
  396. newT2 = dayjs(props.authInfo.day_completed.sunset_ts).format(timeFormat)
  397. }
  398. timelineItems.push(
  399. {
  400. status: 'done',
  401. title: t('feature.day_night.sunset'),//list[1],
  402. content: diffTimeZone() ? newT2 : TimeFormatter.dateTimeFormate(props.authInfo.day_completed.sunset_ts, true),
  403. date: '',
  404. color: ColorType.day
  405. }
  406. )
  407. }
  408. else {
  409. var list = dayDurationDesc()
  410. if (diffTimeZone() && global.dayObj) {
  411. list[0] = TimeFormatter.tzTimeFormateLocalTime(global.dayObj.sunrise.timestamp, props.authInfo.timezone.id, timeFormat2)
  412. list[1] = TimeFormatter.tzTimeFormateLocalTime(global.dayObj.sunset.timestamp, props.authInfo.timezone.id, timeFormat2)
  413. // list[0] = dayjs(global.dayObj.sunrise.timestamp).tz(props.authInfo.timezone.id).format('M月D日')
  414. // list[1] = dayjs(global.dayObj.sunset.timestamp).tz(props.authInfo.timezone.id).format('M月D日')
  415. }
  416. timelineItems.push(
  417. {
  418. status: showExtraData() ? 'done' : 'padding',
  419. title: t('feature.day_night.sunrise'),//dayDurationDesc(),
  420. content: list[0] + ' ' + global.dayObj.sunrise.time.substring(0, 5),
  421. date: '',
  422. color: ColorType.day
  423. }
  424. )
  425. timelineItems.push(
  426. {
  427. status: 'padding',
  428. title: t('feature.day_night.sunset'),//dayDurationDesc(),
  429. content: list[1] + ' ' + global.dayObj.sunset.time.substring(0, 5),
  430. date: '',
  431. color: ColorType.day
  432. }
  433. )
  434. }
  435. }
  436. return <View><View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }}>
  437. <Timeline items={timelineItems} title='' width={468} />
  438. </View>
  439. {
  440. diffTimeZone() && <Text className="tz_note_desc" style={{ color: '#FA5151', opacity: 0.4, marginBottom: 10 }}>{diffentTZDesc()}</Text>
  441. }
  442. </View>
  443. }
  444. function getTZLocation() {
  445. var name = props.authInfo.timezone.gmt
  446. if (props.authInfo.timezone.name) {
  447. name = `${name} (${props.authInfo.timezone.name})`
  448. }
  449. return name
  450. }
  451. function getDeviceLocation() {
  452. return `${getTimezone()} (${getTimezoneName()})`
  453. }
  454. function getTZOffset() {
  455. var current1 = dayjs()
  456. var current = TimeFormatter.tzLocalTime(new Date().getTime(), props.authInfo.timezone.id)//dayjs().tz(props.authInfo.timezone.id)
  457. var offset = current.date() * 24 * 60 + current.hour() * 60 + current.minute() - current1.date() * 24 * 60 - current1.hour() * 60 - current1.minute()
  458. var hour = Math.floor(Math.abs(offset) / 60)
  459. var minute = Math.abs(offset) % 60
  460. var time = ''
  461. if (global.language == 'en') {
  462. time = `${hour} h`
  463. if (minute > 0) {
  464. time += ` ${minute} m`
  465. }
  466. }
  467. else {
  468. time = `${hour}小时`
  469. if (minute > 0) {
  470. time += `${minute}分钟`
  471. }
  472. }
  473. return offset > 0 ? t('feature.day_night.ahead_desc', { time: time }) : t('feature.day_night.behind_desc', { time: time })
  474. }
  475. function diffentTZDesc() {
  476. var current1 = dayjs()
  477. var current = TimeFormatter.tzLocalTime(new Date().getTime(), props.authInfo.timezone.id)//dayjs().tz(props.authInfo.timezone.id)
  478. var offset = current.date() * 24 * 60 + current.hour() * 60 + current.minute() - current1.date() * 24 * 60 - current1.hour() * 60 - current1.minute()
  479. var hour = Math.floor(Math.abs(offset) / 60)
  480. var minute = Math.abs(offset) % 60
  481. var time = ''
  482. var type = ''
  483. if (global.language == 'en') {
  484. time = `${hour} h`
  485. type = offset > 0 ? t('feature.day_night.ahead_of') : t('feature.day_night.behind')
  486. if (minute > 0) {
  487. time += ` ${minute} m`
  488. }
  489. }
  490. else {
  491. time = `${hour}小时`
  492. type = offset > 0 ? t('feature.day_night.ahead_of') : t('feature.day_night.behind')
  493. if (minute > 0) {
  494. time += `${minute}分钟`
  495. }
  496. }
  497. return t('feature.common.diff_tz_desc', { location: getTZLocation(), device_location: getDeviceLocation(), offset: getTZOffset() })
  498. }
  499. function getLocation() {
  500. var city = ''
  501. if ((props.authInfo as any).address) {
  502. if ((props.authInfo as any).address.city.length > 0) {
  503. city = (props.authInfo as any).address.city
  504. }
  505. else if ((props.authInfo as any).address.province.length > 0) {
  506. city = (props.authInfo as any).address.province
  507. }
  508. else if ((props.authInfo as any).address.country.length > 0) {
  509. city = (props.authInfo as any).address.country
  510. }
  511. else {
  512. city = t('feature.track_time_duration.third_ring.unknown')
  513. }
  514. }
  515. else {
  516. city = t('feature.track_time_duration.third_ring.unknown')
  517. }
  518. // return city +' | '+parseInt(authInfo.lat)+'°'+ ' '+parseInt(authInfo.lng)
  519. return `${city} | ${Math.abs(parseInt(props.authInfo.lat))}°${parseInt(props.authInfo.lat) < 0 ? 'S' : 'N'} ${Math.abs(parseInt(props.authInfo.lng))}°${parseInt(props.authInfo.lng) < 0 ? 'W' : 'E'} | ${props.authInfo.timezone.gmt}`
  520. }
  521. function chooseLocation() {
  522. props.updateLocation()
  523. }
  524. function clickFooterBtn(e) {
  525. if (process.env.TARO_ENV == 'weapp') {
  526. e.stopPropagation()
  527. }
  528. // else {
  529. // props.onClose()
  530. // }
  531. //
  532. showAlert({
  533. title: t('feature.day_night.location_need'),
  534. content: props.isNight ? t('feature.day_night.location_need_content_night') : t('feature.day_night.location_need_content_day'),
  535. showCancel: true,
  536. cancelText: t('feature.day_night.later'),
  537. confirmText: t('feature.day_night.picker_now'),
  538. confirm: () => {
  539. props.updateLocation()
  540. }
  541. })
  542. }
  543. function testTapLocationIndex(index){
  544. switch (index) {
  545. case 0:
  546. {
  547. global.uploadLocation({
  548. latitude: 40.697,
  549. longitude: -74.309
  550. })
  551. }
  552. break;
  553. case 1:
  554. {
  555. global.uploadLocation({
  556. latitude: 59.699,
  557. longitude: -179.463
  558. })
  559. }
  560. break;
  561. case 2:
  562. {
  563. global.uploadLocation({
  564. latitude: 64.4190338,
  565. longitude: 15.3812476
  566. })
  567. }
  568. break;
  569. case 3:
  570. {
  571. global.uploadLocation({
  572. latitude: -40.4221762,
  573. longitude: 164.4216501
  574. })
  575. }
  576. break;
  577. }
  578. }
  579. function testChangeLocation() {
  580. if (process.env.TARO_ENV=='rn' && kIsIOS){
  581. showActionSheet({
  582. showActionSheetWithOptions: showActionSheetWithOptions,
  583. itemList: [
  584. '纽约40.697,-74.309',
  585. '阿拉斯加59.699,-179.463',
  586. '芬兰64.4190338,15.3812476',
  587. '新西兰-40.4221762,164.4216501'
  588. ],
  589. success: (res) => {
  590. testTapLocationIndex(res)
  591. }
  592. });
  593. return
  594. }
  595. Taro.showActionSheet({
  596. itemList: [
  597. '纽约40.697,-74.309',
  598. '阿拉斯加59.699,-179.463',
  599. '芬兰64.4190338,15.3812476',
  600. '新西兰-40.4221762,164.4216501'
  601. ]
  602. })
  603. .then(res => {
  604. console.log(res.tapIndex)
  605. testTapLocationIndex(res.tapIndex)
  606. })
  607. .catch(err => {
  608. console.log(err.errMsg)
  609. })
  610. }
  611. return <View className='detail_container'>
  612. {/* {
  613. isCompleted() ? <Text className='detail_popup_title' >{getCompletedTitle()}<Text className='detail_popup_subttitle'> {getSubTitle()}</Text></Text> :
  614. <Text className='detail_popup_title' >{getTitle()}</Text>
  615. } */}
  616. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'flex-end' }}>
  617. <Text className='detail_popup_title'>{isCompleted() ? getCompletedTitle() : getTitle()}</Text>
  618. {
  619. isCompleted() && <Text className='detail_popup_subttitle'> {getSubTitle()}</Text>
  620. }
  621. </View>
  622. {
  623. <Text style={{ color: '#fff', fontSize: 20, fontWeight: 'bold' }} onClick={testChangeLocation}>位置更改测试</Text>
  624. }
  625. <View className='detail_tabbar'>
  626. <View onClick={() => { setTabIndex(0) }} className={tabIndex == 0 ? 'detail_tabitem_sel' : 'detail_tabitem_nor'}>{t('feature.day_night.overview')}</View>
  627. <View onClick={() => { setTabIndex(1) }} className={tabIndex == 1 ? 'detail_tabitem_sel' : 'detail_tabitem_nor'}>{t('feature.day_night.events')}</View>
  628. </View>
  629. <View className='detail_content'>
  630. {
  631. tabIndex == 0 ? overview() : events()
  632. }
  633. </View>
  634. {
  635. (props.authInfo && props.authInfo.lat) ?
  636. <View style={{ display: 'flex', flexDirection: 'column' }}>
  637. <Text className='day_night_pop_location'>{getLocation()}</Text>
  638. <View style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' }}>
  639. <Text className='day_night_pop_desc'>{t('feature.track_time_duration.third_ring.base_location_desc')}</Text>
  640. <View onClick={chooseLocation}>
  641. <Text className='day_night_pop_choose' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{t('feature.track_time_duration.third_ring.update_my_location')}</Text>
  642. </View>
  643. </View>
  644. </View> :
  645. <View className='detail_bottom'>{
  646. process.env.TARO_ENV == 'weapp' ?
  647. <View className='detail_bottom_btn' style={{ color: '#000' }} onClick={(e) => {
  648. clickFooterBtn(e)
  649. }}>{props.isNight ? t('feature.day_night.get_local_time') : t('feature.day_night.get_local_time_sunrise')}</View> :
  650. <View onClick={(e) => {
  651. clickFooterBtn(e)
  652. }}>
  653. <LinearGradient
  654. style={{
  655. width: 300,
  656. height: 50,
  657. borderRadius: 25,
  658. alignItems: 'center',
  659. justifyContent: 'center',
  660. flexDirection: 'row'
  661. }}
  662. colors={[ColorType.fast, ColorType.sleep]}
  663. start={{ x: 0, y: 0 }}
  664. end={{ x: 1, y: 0 }}
  665. >
  666. {
  667. isLoading && <View style={{ display: 'flex', overflow: 'hidden', height: 20, marginRight: 5 }}><AtActivityIndicator mode="center" color="#000" /></View>
  668. }
  669. <Text style={{ fontWeight: 'bold', fontSize: 18, color: '#000', opacity: isLoading ? 0.6 : 1.0 }}>{props.isNight ? t('feature.day_night.get_local_time') : t('feature.day_night.get_local_time_sunrise')}</Text>
  670. </LinearGradient>
  671. </View>
  672. }
  673. </View>
  674. }
  675. </View>
  676. }