DayNightCard.tsx 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. import { PageContainer, Switch, Text, View, Image } from '@tarojs/components'
  2. import './DayNightCard.scss'
  3. import { ColorType } from '@/context/themes/color'
  4. import { useEffect, useState } from 'react'
  5. import Box from '@/components/layout/Box'
  6. import Taro, { useDidShow } from '@tarojs/taro'
  7. import { clearLocation, getPerm, latestLocation, uploadPerm } from '@/services/user'
  8. import { useDispatch, useSelector } from 'react-redux'
  9. import { useTranslation } from 'react-i18next'
  10. import { TimeFormatter } from '@/utils/time_format'
  11. import { systemLocation } from '@/services/common'
  12. import { setDayRingData, showDay } from '@/store/day'
  13. import { setNightRingData, showNight, updateMember } from '@/store/night'
  14. import Modal from '@/components/layout/Modal.weapp'
  15. import { getTimezone, rpxToPx } from '@/utils/tools'
  16. import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
  17. import DayNightDetailPopup from './DayNightDetailPopup'
  18. import '@/utils/ring_card.scss';
  19. import { IconNight, IconSunrise, IconSunset } from '@/components/basic/Icons'
  20. import DayNightRing from './DayNightRing'
  21. import dayjs from 'dayjs'
  22. import DayNightStatus from './DayNightStatus'
  23. import showAlert from '@/components/basic/Alert'
  24. // import checkLocation from '@/utils/native_permission_check'
  25. let useNavigation;
  26. let Linking;
  27. if (process.env.TARO_ENV == 'rn') {
  28. useNavigation = require("@react-navigation/native").useNavigation
  29. Linking = require('react-native').Linking;
  30. }
  31. let locationDetail;
  32. let sunriseA = new Date()
  33. sunriseA.setHours(6)
  34. sunriseA.setMinutes(0)
  35. sunriseA.setSeconds(0)
  36. sunriseA.setMilliseconds(0)
  37. const sunsetA = new Date()
  38. sunsetA.setHours(18)
  39. sunsetA.setMinutes(0)
  40. sunsetA.setSeconds(0)
  41. sunsetA.setMilliseconds(0)
  42. const utc = require('dayjs/plugin/utc')
  43. const timezone = require('dayjs/plugin/timezone')
  44. var advanced = require("dayjs/plugin/advancedFormat")
  45. dayjs.extend(utc)
  46. dayjs.extend(timezone)
  47. dayjs.extend(advanced)
  48. let noTimestampData = false;
  49. export default function DayNightCard(props: { isNight: boolean, count: number, detailPop?: Function }) {
  50. const user = useSelector((state: any) => state.user);
  51. const dayStore = useSelector((state: any) => state.day);
  52. const nightStore = useSelector((state: any) => state.night);
  53. const [authInfo, setAuthInfo] = useState(global.locationDetail ? global.locationDetail : null)
  54. const [sunriseDate, setSunriseDate] = useState<any>(sunriseA)
  55. const [sunsetDate, setSunsetDate] = useState<any>(sunsetA)
  56. const [showDetailModal, setShowDetailModal] = useState(false)
  57. const [showDetailPopup, setShowDetailPopup] = useState(false)
  58. const [nightDate, setNightDate] = useState(new Date())
  59. const [dayDate, setDayDate] = useState(new Date())
  60. const dispatch = useDispatch();
  61. const { t } = useTranslation()
  62. const isMember = true;
  63. let navigation;
  64. if (useNavigation) {
  65. navigation = useNavigation()
  66. }
  67. useEffect(() => {
  68. if (user.isLogin) {
  69. if (global.locationDetail) {
  70. locationDetail = global.locationDetail
  71. setAuthInfo(locationDetail)
  72. }
  73. getLatestLocation()
  74. if (props.isNight) {
  75. global.refreshNight = () => {
  76. getLatestLocation()
  77. }
  78. }
  79. else {
  80. global.refreshDay = () => {
  81. getLatestLocation()
  82. }
  83. }
  84. } else {
  85. setSunriseDate(sunriseA)
  86. setSunsetDate(sunsetA)
  87. dispatch(setDayRingData({
  88. date: new Date().getTime(),
  89. sunrise: '06:00',
  90. sunset: '18:00'
  91. }))
  92. dispatch(setNightRingData({
  93. date: new Date().getTime(),
  94. sunrise: '06:00',
  95. sunset: '18:00'
  96. }))
  97. setAuthInfo(null)
  98. global.locationDetail = null
  99. updateUnloginData()
  100. }
  101. }, [user.isLogin])
  102. useEffect(() => {
  103. locationDetail = global.locationDetail
  104. setAuthInfo(locationDetail)
  105. }, [global.locationDetail])
  106. useEffect(() => {
  107. if (locationDetail)
  108. updateDate(locationDetail)
  109. }, [])
  110. useEffect(() => {
  111. if (!locationDetail && global.locationDetail){
  112. locationDetail = global.locationDetail
  113. }
  114. if (locationDetail) {
  115. var detail: any = locationDetail
  116. var now = new Date()
  117. if (now.getHours() == 0 && now.getMinutes() == 0 && now.getSeconds() == 0) {
  118. detail.daylights.splice(0, 1)
  119. }
  120. locationDetail = detail
  121. if (detail && (detail as any).daylights) {
  122. (detail as any).daylights.map(item => {
  123. if (noTimestampData) {
  124. item.sunrise_ts = new Date(item.date + 'T' + item.sunrise + ':00').getTime()
  125. item.sunset_ts = new Date(item.date + 'T' + item.sunset + ':00').getTime()
  126. }
  127. })
  128. }
  129. // setLocationDetail(detail)
  130. updateDate(detail)
  131. }
  132. }, [props.count])
  133. useDidShow(() => {
  134. if (!user.isLogin) {
  135. dispatch(showNight(false))
  136. dispatch(showDay(false))
  137. Taro.setStorage({
  138. key: 'showNightRing',
  139. data: false
  140. })
  141. Taro.setStorage({
  142. key: 'showDayRing',
  143. data: false
  144. })
  145. }
  146. })
  147. function getLatestLocation() {
  148. var today = new Date()
  149. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  150. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 50)
  151. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  152. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  153. latestLocation({
  154. date_start: strYesterday, date_end: strTomorrow
  155. }).then(data => {
  156. // (data as any).timezone = 'GMT-1000'
  157. if (data && (data as any).daylights) {
  158. (data as any).daylights.map(item => {
  159. if (!item.sunrise_ts) {
  160. noTimestampData = true
  161. item.sunrise_ts = new Date(item.date + 'T' + item.sunrise + ':00').getTime()
  162. item.sunset_ts = new Date(item.date + 'T' + item.sunset + ':00').getTime()
  163. }
  164. else {
  165. noTimestampData = false
  166. }
  167. })
  168. }
  169. setAuthInfo(data as any)
  170. updateDate(data)
  171. locationDetail = data
  172. global.locationDetail = locationDetail
  173. Taro.setStorage({
  174. key: 'gps',
  175. data: JSON.stringify(data as any)
  176. })
  177. })
  178. }
  179. function updateDate(data) {
  180. var today = new Date()
  181. if (user.isLogin && isMember && data && data.daylights && data.daylights.length > 0) {
  182. // var sunriseObj,sunsetObj;
  183. var list = data.daylights
  184. for (var i = 0; i < (list.length - 1); i++) {
  185. //夜间
  186. if (list[i].sunset_ts < today.getTime() && list[i + 1].sunrise_ts > today.getTime()) {
  187. if (props.isNight) {
  188. global.nightObj = {
  189. is_polar_night: list[i].is_polar_night,
  190. sunrise: {
  191. timestamp: list[i + 1].sunrise_ts,
  192. time: list[i + 1].sunrise
  193. },
  194. sunset: {
  195. timestamp: list[i].sunset_ts,
  196. time: list[i].sunset
  197. }
  198. }
  199. }
  200. else {
  201. global.dayObj = {
  202. is_polar_day: list[i + 1].is_polar_day,
  203. sunrise: {
  204. timestamp: list[i + 1].sunrise_ts,
  205. time: list[i + 1].sunrise
  206. },
  207. sunset: {
  208. timestamp: list[i + 1].sunset_ts,
  209. time: list[i + 1].sunset
  210. }
  211. }
  212. }
  213. }
  214. //白天
  215. else if (list[i].sunrise_ts < today.getTime() && list[i].sunset_ts > today.getTime()) {
  216. if (props.isNight) {
  217. global.nightObj = {
  218. is_polar_night: list[i].is_polar_night,
  219. sunrise: {
  220. timestamp: list[i + 1].sunrise_ts,
  221. time: list[i + 1].sunrise
  222. },
  223. sunset: {
  224. timestamp: list[i].sunset_ts,
  225. time: list[i].sunset
  226. }
  227. }
  228. }
  229. else {
  230. global.dayObj = {
  231. is_polar_day: list[i].is_polar_day,
  232. sunrise: {
  233. timestamp: list[i].sunrise_ts,
  234. time: list[i].sunrise
  235. },
  236. sunset: {
  237. timestamp: list[i].sunset_ts,
  238. time: list[i].sunset
  239. }
  240. }
  241. }
  242. }
  243. }
  244. }
  245. else {
  246. locationDetail = null
  247. setAuthInfo(null)
  248. dispatch(updateMember({ isMember: isMember, gpsInfo: null }))
  249. dispatch(setDayRingData({
  250. date: sunriseDate.getTime(),
  251. sunrise: '06:00',
  252. sunset: '18:00'
  253. }))
  254. dispatch(setNightRingData({
  255. date: sunsetDate.getTime(),
  256. sunrise: '06:00',
  257. sunset: '18:00'
  258. }))
  259. debugger
  260. updateUnloginData()
  261. }
  262. }
  263. function updateUnloginData() {
  264. var now = new Date()
  265. var sunriseT = 0
  266. var sunsetT = 0
  267. var sunriseTDay = 0
  268. var sunsetTDay = 0
  269. if (now.getHours() < 6) {
  270. var temp1 = new Date(now.getTime() - 24 * 3600 * 1000)
  271. temp1.setHours(18)
  272. temp1.setMinutes(0)
  273. temp1.setSeconds(0)
  274. temp1.setMilliseconds(0)
  275. sunsetT = temp1.getTime()
  276. sunriseT = sunsetT + 12 * 3600 * 1000
  277. sunriseTDay = sunriseT
  278. sunsetTDay = sunriseTDay + 12 * 3600 * 1000
  279. }
  280. else if (now.getHours() < 18) {
  281. var temp1 = new Date()
  282. temp1.setHours(6)
  283. temp1.setMinutes(0)
  284. temp1.setSeconds(0)
  285. temp1.setMilliseconds(0)
  286. sunriseTDay = temp1.getTime()
  287. sunsetTDay = sunriseTDay + 12 * 3600 * 1000
  288. sunsetT = sunsetTDay
  289. sunriseT = sunsetT + 12 * 3600 * 1000
  290. }
  291. else {
  292. var temp1 = new Date()
  293. temp1.setHours(18)
  294. temp1.setMinutes(0)
  295. temp1.setSeconds(0)
  296. temp1.setMilliseconds(0)
  297. sunsetT = temp1.getTime()
  298. sunriseT = sunsetT + 12 * 3600 * 1000
  299. sunriseTDay = sunriseT
  300. sunsetTDay = sunriseTDay + 12 * 3600 * 1000
  301. }
  302. global.nightObj = {
  303. sunrise: {
  304. timestamp: sunriseT,
  305. time: '06:00'
  306. },
  307. sunset: {
  308. timestamp: sunsetT,
  309. time: '18:00'
  310. }
  311. }
  312. global.dayObj = {
  313. sunrise: {
  314. timestamp: sunriseTDay,
  315. time: '06:00'
  316. },
  317. sunset: {
  318. timestamp: sunsetTDay,
  319. time: '18:00'
  320. }
  321. }
  322. }
  323. function tapCard(e) {
  324. // if (process.env.TARO_ENV == 'weapp') {
  325. // e.stopPropagation()
  326. // }
  327. if (!user.isLogin) {
  328. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  329. return
  330. }
  331. global.showDayNightSwiperPop(props.isNight, nightDate, dayDate)
  332. // if (!dayStore.showDayRing) {
  333. // return
  334. // }
  335. // setShowDetailPopup(true)
  336. // if (props.detailPop)
  337. // props.detailPop(props.isNight, nightDate, dayDate)
  338. }
  339. function auth(e?: any) {
  340. if (e && process.env.TARO_ENV == 'weapp') {
  341. e.stopPropagation()
  342. }
  343. var today = new Date()
  344. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  345. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
  346. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  347. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  348. if (process.env.TARO_ENV == 'rn') {
  349. Taro.getLocation({
  350. success(res) {
  351. systemLocation({
  352. lat: res.latitude,
  353. lng: res.longitude,
  354. date_start: strYesterday,
  355. date_end: strTomorrow,
  356. coordinate_system_standard: 'WGS-84'
  357. }).then(data => {
  358. noTimestampData = false
  359. console.log('get Location', data)
  360. updateDate(data);
  361. locationDetail = data;
  362. global.locationDetail = locationDetail
  363. setAuthInfo(data as any)
  364. Taro.setStorage({
  365. key: 'gps',
  366. data: JSON.stringify(data as any)
  367. })
  368. dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
  369. showRing()
  370. if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
  371. var ToastAndroid = require('react-native').ToastAndroid;
  372. ToastAndroid.show(t('feature.day_night.location_updated'), ToastAndroid.LONG);
  373. }
  374. else {
  375. Taro.showToast({
  376. title: t('feature.day_night.location_updated'),
  377. icon: 'none'
  378. })
  379. }
  380. })
  381. },
  382. fail(res) {
  383. if (res.errMsg == 'Permissions denied!') {
  384. showAlert({
  385. title: t('feature.auth_sys.location_title'),
  386. content: t('feature.auth_sys.location_desc'),
  387. showCancel: true,
  388. cancelText: t('feature.auth_sys.location_cancel'),
  389. confirmText: t('feature.auth_sys.location_confirm'),
  390. confirm: () => {
  391. Linking.openURL('app-settings:')
  392. }
  393. })
  394. }
  395. else {
  396. if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
  397. var ToastAndroid = require('react-native').ToastAndroid;
  398. ToastAndroid.show(t('feature.day_night.location_failed'), ToastAndroid.LONG);
  399. }
  400. else {
  401. Taro.showToast({
  402. title: t('feature.day_night.location_failed'),
  403. icon: 'none'
  404. })
  405. }
  406. }
  407. console.log(res)
  408. showRing()
  409. },
  410. complete(res) {
  411. }
  412. })
  413. return
  414. }
  415. Taro.chooseLocation({
  416. latitude: authInfo && authInfo.lat ? authInfo.lat : undefined,
  417. longitude: authInfo && authInfo.lat ? authInfo.lng : undefined,
  418. success: function (res) {
  419. systemLocation({
  420. lat: res.latitude,
  421. lng: res.longitude,
  422. name: res.name,
  423. address: res.address,
  424. date_start: strYesterday,
  425. date_end: strTomorrow,
  426. coordinate_system_standard: 'GCJ-02'
  427. }).then(data => {
  428. noTimestampData = false;
  429. updateDate(data);
  430. locationDetail = data;
  431. global.locationDetail = locationDetail
  432. setAuthInfo(data as any)
  433. Taro.setStorage({
  434. key: 'gps',
  435. data: JSON.stringify(data as any)
  436. })
  437. showRing()
  438. dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
  439. if (global.swiperDayNightRefresh) {
  440. global.swiperDayNightRefresh()
  441. }
  442. })
  443. },
  444. fail(res) {
  445. Taro.showToast({
  446. title: '位置修改失败!\n请重新选择就近位置',
  447. icon: 'none'
  448. })
  449. showRing()
  450. },
  451. complete(res) {
  452. }
  453. })
  454. }
  455. function showRing() {
  456. dispatch(showNight(true))
  457. dispatch(showDay(true))
  458. Taro.setStorage({
  459. key: 'showNightRing',
  460. data: true
  461. })
  462. Taro.setStorage({
  463. key: 'showDayRing',
  464. data: true
  465. })
  466. }
  467. function getLocation() {
  468. if (!authInfo) {
  469. return ''
  470. }
  471. return `${getCity()} | ${Math.abs(parseInt(authInfo.lat))}°${parseInt(authInfo.lat) < 0 ? 'S' : 'N'} ${Math.abs(parseInt(authInfo.lng))}°${parseInt(authInfo.lng) < 0 ? 'W' : 'E'}`
  472. }
  473. function getCity() {
  474. var city = ''
  475. if (!authInfo) {
  476. return ''
  477. }
  478. if ((authInfo as any).address) {
  479. if ((authInfo as any).address.city.length > 0) {
  480. city = (authInfo as any).address.city
  481. }
  482. else if ((authInfo as any).address.province.length > 0) {
  483. city = (authInfo as any).address.province
  484. }
  485. else if ((authInfo as any).address.country.length > 0) {
  486. city = (authInfo as any).address.country
  487. }
  488. else {
  489. city = t('feature.track_time_duration.third_ring.unknown')
  490. }
  491. }
  492. else {
  493. city = t('feature.track_time_duration.third_ring.unknown')
  494. }
  495. return city
  496. }
  497. function clearData() {
  498. Taro.showModal({
  499. title: '提示',
  500. content: '确认清除位置数据?',
  501. success: function (res) {
  502. if (res.confirm) {
  503. clearLocation().then(res => {
  504. getLatestLocation()
  505. })
  506. } else if (res.cancel) {
  507. console.log('用户点击取消')
  508. }
  509. }
  510. })
  511. }
  512. function detailModalContent() {
  513. var timezone = getTimezone()
  514. if (!authInfo || !(authInfo as any).lat) {
  515. return <View style={{ height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', width: rpxToPx(750) }}>
  516. <Text>暂无位置信息</Text>
  517. </View>
  518. }
  519. return <View style={{ display: 'flex', flexDirection: 'column' }}>
  520. {
  521. <View className="cell_bg">
  522. {
  523. <View className="cell_full">
  524. <Text className="cell_title">{t('feature.track_time_duration.third_ring.location')}</Text>
  525. <Text className="cell_value">{authInfo ? getLocation() : t('feature.track_time_duration.third_ring.enter')}</Text>
  526. </View>
  527. }
  528. <View className="cell_line" style={{ height: 1 }} />
  529. {
  530. <View className="cell_full" >
  531. <Text className="cell_title">{t('feature.track_time_duration.third_ring.latitude')}</Text>
  532. <Text className="cell_value">{(authInfo as any).lat}</Text>
  533. </View>
  534. }
  535. <View className="cell_line" style={{ height: 1 }} />
  536. <View className="cell_full">
  537. <Text className="cell_title" >{t('feature.track_time_duration.third_ring.longitude')}</Text>
  538. <Text className="cell_value">{(authInfo as any).lng}</Text>
  539. </View>
  540. <View className="cell_line" style={{ height: 1 }} />
  541. <View className="cell_full">
  542. <Text className="cell_title">{t('feature.track_time_duration.third_ring.timezone')}</Text>
  543. <Text className="cell_value">{timezone}</Text>
  544. </View>
  545. </View>
  546. }
  547. <Text onClick={() => {
  548. clearData()
  549. setShowDetailModal(false)
  550. }} style={{ width: '100%', textAlign: 'center', marginBottom: 50, color: '#fff', marginTop: 20 }}>清除位置</Text>
  551. </View>
  552. }
  553. function modalContent2() {
  554. return <Modal
  555. testInfo={null}
  556. dismiss={() => {
  557. setShowDetailModal(false)
  558. }}
  559. confirm={() => { }}>
  560. {
  561. detailModalContent()
  562. }
  563. </Modal>
  564. }
  565. function modalContent() {
  566. return <Modal
  567. testInfo={null}
  568. dismiss={() => {
  569. setShowDetailPopup(false)
  570. }}
  571. confirm={() => { }}>
  572. <DayNightDetailPopup
  573. isNight={props.isNight}
  574. authInfo={authInfo}
  575. nightDate={nightDate}
  576. dayDate={dayDate}
  577. updateLocation={auth}
  578. onClose={() => { setShowDetailPopup(false) }}
  579. />
  580. </Modal>
  581. }
  582. function longClick() {
  583. if (user.isLogin && user.test_user && authInfo)
  584. global.showDayNightSwiperModal()
  585. // setShowDetailModal(true)
  586. }
  587. function showLocationAlert(e) {
  588. if (process.env.TARO_ENV == 'weapp') {
  589. e.stopPropagation()
  590. }
  591. tapCard(e)
  592. }
  593. function nightRing() {
  594. return <DayNightRing
  595. isNight={true}
  596. isThirdRing={false}
  597. canvasId={'day_night_card_night_ring'}
  598. authInfo={authInfo}
  599. />
  600. }
  601. function localNow(now: Date) {
  602. if (authInfo && authInfo.timezone) {
  603. return new Date(TimeFormatter.transferTimestamp(now.getTime(), authInfo.timezone.gmt))
  604. }
  605. return now
  606. }
  607. function dayRing() {
  608. return <DayNightRing
  609. isNight={false}
  610. isThirdRing={false}
  611. canvasId={'day_night_card_big_day'}
  612. authInfo={authInfo}
  613. />
  614. }
  615. function getSunsetDuration() {
  616. if (authInfo && authInfo.night_completed && new Date().getTime() > authInfo.night_completed.sunrise_ts) {
  617. global.sunsetDuration = TimeFormatter.durationFormate(authInfo.night_completed.sunrise_ts, authInfo.night_completed.sunset_ts, true)
  618. return TimeFormatter.durationFormate(authInfo.night_completed.sunrise_ts, authInfo.night_completed.sunset_ts, true)
  619. }
  620. var now = new Date()
  621. if (authInfo && global.nightObj) {
  622. var nightObj = global.nightObj
  623. if (nightObj.sunset.timestamp < now.getTime() && nightObj.sunrise.timestamp > now.getTime()) {
  624. global.sunsetDuration = TimeFormatter.countdown(nightObj.sunset.timestamp, now.getTime(), true)
  625. return TimeFormatter.countdown(nightObj.sunset.timestamp, now.getTime(), true)
  626. }
  627. global.sunsetDuration = TimeFormatter.calculateTimeDifference(nightObj.sunset.timestamp, nightObj.sunrise.timestamp);
  628. return TimeFormatter.calculateTimeDifference(nightObj.sunset.timestamp, nightObj.sunrise.timestamp);
  629. }
  630. now = localNow(now)
  631. if (props.isNight && sunsetDate) {
  632. if (now.getTime() > sunsetDate.getTime()) {
  633. global.sunsetDuration = TimeFormatter.countdown(sunsetDate.getTime(), now.getTime(), true)
  634. return TimeFormatter.countdown(sunsetDate.getTime(), now.getTime(), true)
  635. }
  636. // return TimeFormatter.countdown(sunsetDate.getTime())
  637. }
  638. var sunRiseObj = nightStore.nightRingSunrise
  639. var sunSetObj = nightStore.nightRingSunset
  640. var sunRise = 24 * 60 + parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
  641. var sunSet = parseInt(sunSetObj.split(':')[0]) * 60 + parseInt(sunSetObj.split(':')[1])
  642. if (sunSetObj.indexOf('PM') != -1) {
  643. sunSet += 12 * 60
  644. }
  645. var duration = (sunRise - sunSet) * 60 * 1000
  646. global.sunsetDuration = TimeFormatter.calculateTimeDifference(now.getTime(), now.getTime() + duration);
  647. return TimeFormatter.calculateTimeDifference(now.getTime(), now.getTime() + duration);
  648. }
  649. function getSunriseDuration() {
  650. if (authInfo && authInfo.day_completed && new Date().getTime() > authInfo.day_completed.sunset_ts) {
  651. global.sunriseDuration = TimeFormatter.durationFormate(authInfo.day_completed.sunrise_ts, authInfo.day_completed.sunset_ts, true)
  652. return TimeFormatter.durationFormate(authInfo.day_completed.sunrise_ts, authInfo.day_completed.sunset_ts, true)
  653. }
  654. var now = new Date()
  655. var now = new Date()
  656. if (global.dayObj) {
  657. var dayObj = global.dayObj
  658. if (dayObj.sunrise.timestamp < now.getTime() && dayObj.sunset.timestamp > now.getTime()) {
  659. global.sunriseDuration = TimeFormatter.countdown(dayObj.sunrise.timestamp, now.getTime(), true)
  660. return TimeFormatter.countdown(dayObj.sunrise.timestamp, now.getTime(), true)
  661. }
  662. global.sunriseDuration = TimeFormatter.calculateTimeDifference(dayObj.sunrise.timestamp, dayObj.sunset.timestamp, true);
  663. return TimeFormatter.calculateTimeDifference(dayObj.sunrise.timestamp, dayObj.sunset.timestamp, true);
  664. }
  665. return ''
  666. // now = localNow(now)
  667. // if (!props.isNight && sunriseDate) {
  668. // if (now.getTime() > sunriseDate.getTime()) {
  669. // global.sunriseDuration = TimeFormatter.countdown(sunriseDate.getTime())
  670. // return TimeFormatter.countdown(sunriseDate.getTime(), now.getTime())
  671. // }
  672. // }
  673. // var sunRiseObj = dayStore.dayRingSunrise
  674. // var sunSetObj = dayStore.dayRingSunset
  675. // var sunRise = parseInt(sunRiseObj.split(':')[0]) * 60 + parseInt(sunRiseObj.split(':')[1])
  676. // var sunSet = parseInt(sunSetObj.split(':')[0]) * 60 + parseInt(sunSetObj.split(':')[1])
  677. // if (sunSetObj.indexOf('PM') != -1) {
  678. // sunSet += 12 * 60
  679. // }
  680. // var duration = (sunSet - sunRise) * 60 * 1000
  681. // global.sunriseDuration = TimeFormatter.calculateTimeDifference(now.getTime(), now.getTime() + duration);
  682. // return TimeFormatter.calculateTimeDifference(now.getTime(), now.getTime() + duration);
  683. }
  684. function completedDate() {
  685. if (props.isNight) {
  686. if (authInfo && authInfo.night_completed && new Date().getTime() > authInfo.night_completed.sunrise_ts) {
  687. if (localNow(new Date()).getTime() != new Date().getTime()) {
  688. return TimeFormatter.getMonthAndDayByTimestamp(authInfo.night_completed.sunrise_ts, true)
  689. }
  690. return TimeFormatter.dateDescription(authInfo.night_completed.sunrise_ts, true)
  691. }
  692. return ''
  693. }
  694. if (authInfo && authInfo.day_completed && new Date().getTime() > authInfo.day_completed.sunset_ts) {
  695. if (localNow(new Date()).getTime() != new Date().getTime()) {
  696. return TimeFormatter.getMonthAndDayByTimestamp(authInfo.day_completed.sunset_ts, true)
  697. }
  698. return TimeFormatter.dateDescription(authInfo.day_completed.sunset_ts, true)
  699. }
  700. return ''
  701. }
  702. function showArrow() {
  703. if (props.isNight) {
  704. if (authInfo && authInfo.night_completed && new Date().getTime() > authInfo.night_completed.sunrise_ts) {
  705. return true
  706. }
  707. return false
  708. }
  709. if (authInfo && authInfo.day_completed && new Date().getTime() > authInfo.day_completed.sunset_ts) {
  710. return true
  711. }
  712. return false
  713. }
  714. function currentStatus() {
  715. if (showArrow()) {
  716. if (props.isNight) {
  717. if (authInfo.day_completed && new Date().getTime() > authInfo.day_completed.sunset_ts) {
  718. return t('feature.day_night.last_updated')
  719. }
  720. return t('feature.day_night.ended')
  721. }
  722. return t('feature.day_night.last_updated')
  723. }
  724. var strTime = props.isNight ? getSunsetDuration() : getSunriseDuration()
  725. return (strTime.indexOf('小时') != -1 || strTime.indexOf('分钟') != -1) ? t('feature.day_night.upcoming') : t('feature.day_night.in_real_time')
  726. }
  727. function footerDesc() {
  728. var now = new Date()
  729. if (props.isNight) {
  730. if (global.nightObj) {
  731. if (now.getTime() < global.nightObj.sunset.timestamp) {
  732. return TimeFormatter.countdown(global.nightObj.sunset.timestamp, now.getTime(), true)
  733. }
  734. return TimeFormatter.countdown(global.nightObj.sunrise.timestamp, now.getTime(), true)
  735. }
  736. }
  737. else {
  738. if (global.dayObj) {
  739. if (now.getTime() < global.dayObj.sunrise.timestamp) {
  740. return TimeFormatter.countdown(global.dayObj.sunrise.timestamp, now.getTime(), true)
  741. }
  742. return TimeFormatter.countdown(global.dayObj.sunset.timestamp, now.getTime(), true)
  743. }
  744. }
  745. return ''
  746. }
  747. function footerIcon() {
  748. var now = new Date()
  749. if (props.isNight) {
  750. if (now.getTime() < sunsetDate.getTime()) {
  751. return <IconSunset color={ColorType.white + '66'} width={rpxToPx(28)} />
  752. }
  753. return <IconSunrise color={ColorType.white + '66'} width={rpxToPx(28)} />
  754. }
  755. if (now.getTime() > sunriseDate.getTime() && now.getTime() < sunsetDate.getTime()) {
  756. return <IconSunset color={ColorType.white + '66'} width={rpxToPx(28)} />
  757. }
  758. return <IconSunrise color={ColorType.white + '66'} width={rpxToPx(28)} />
  759. }
  760. function currentTime() {
  761. var now = new Date()
  762. if (authInfo && authInfo.timezone) {
  763. var t1 = TimeFormatter.tzLocalTime(now.getTime(), authInfo.timezone.id)////dayjs(now.getTime()).tz(authInfo.timezone.id)
  764. if (now.getHours() == t1.hour() && now.getMinutes() == t1.minute()) {
  765. return <View />
  766. }
  767. }
  768. var now2 = localNow(now)
  769. if (now.getTime() == now2.getTime()) {
  770. return ''
  771. }
  772. let offset = 0;
  773. if (authInfo && authInfo.timezone) {
  774. var current1 = dayjs()
  775. var current = TimeFormatter.tzLocalTime(now.getTime(), authInfo.timezone.id)//dayjs().tz(authInfo.timezone.id)
  776. offset = current.date() * 24 * 60 + current.hour() * 60 + current.minute() - current1.date() * 24 * 60 - current1.hour() * 60 - current1.minute()
  777. }
  778. var hour = Math.floor(Math.abs(offset) / 60)
  779. var minute = Math.abs(offset) % 60
  780. var time = ''
  781. if (global.language == 'en') {
  782. time = `${hour} h`
  783. if (minute > 0) {
  784. time += ` ${minute} m`
  785. }
  786. }
  787. else {
  788. time = `${hour}小时`
  789. if (minute > 0) {
  790. time += `${minute}分钟`
  791. }
  792. }
  793. // const ccc = dayjs().tz('Arctic/Longyearbyen').format('YYYY-MM-DD HH:mm:ss')
  794. // const current = dayjs().utcOffset(offset).format('YYYY-MM-DD HH:mm:ss')
  795. var current;
  796. if (authInfo && authInfo.timezone) {
  797. current = TimeFormatter.tzTimeFormateLocalTime(new Date().getTime(), authInfo.timezone.id, 'HH:mm')//dayjs().tz(authInfo.timezone.id).format('HH:mm')
  798. }
  799. else {
  800. current = dayjs().format('HH:mm')
  801. }
  802. return <View style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
  803. <Text className='ring_city' numberOfLines={1}>{getCity()}</Text>
  804. <Text className='ring_clock' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{current}</Text>
  805. <Text className='ring_timezone'>{
  806. offset > 0 ? t('feature.day_night.ahead_desc', { time: time }) : t('feature.day_night.behind_desc', { time: time })
  807. }</Text>
  808. </View>
  809. }
  810. function cardContent() {
  811. return <View style={{ position: 'relative' }}>
  812. <View style={{ display: 'flex', flexDirection: 'column', zIndex: 1 }} onClick={showLocationAlert} onLongPress={longClick}>
  813. <View className="ring_full_container" style={{ paddingBottom: 0 }}>
  814. <View style={{
  815. display: 'flex',
  816. flexDirection: 'row',
  817. marginTop: 0,
  818. marginBottom: 0,
  819. padding: 0,
  820. alignItems: 'center'
  821. }}>
  822. <View style={{ display: 'flex', position: 'relative' }}>
  823. {
  824. props.isNight ? nightRing() : dayRing()
  825. }
  826. <View style={{ color: '#fff', position: 'absolute', left: 0, right: 0, top: 0, bottom: 0, alignItems: 'center', justifyContent: 'center', display: 'flex' }}>{currentTime()}</View>
  827. </View>
  828. <View style={{ display: 'flex', flexDirection: 'column', flexShrink: 0, flex: 1, marginLeft: rpxToPx(52) }}>
  829. <View style={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}>
  830. <Text className='ring_card_duration_title'>{props.isNight ? t('feature.common.overnight') : t('feature.common.day')}</Text>
  831. {
  832. !props.isNight && global.dayObj && global.dayObj.is_polar_day && <View className='polar_tag'>{t('feature.day_night.polar_day')}</View>
  833. }
  834. {
  835. props.isNight && global.nightObj && global.nightObj.is_polar_night && <View className='polar_tag'>{t('feature.day_night.polar_night')}</View>
  836. }
  837. </View>
  838. <Text className='ring_card_duration_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? getSunsetDuration() : getSunriseDuration()}</Text>
  839. </View>
  840. {/* {
  841. !showArrow() && <Image className="card_arrow2" src={require('@/assets/images/arrow3.png')} />
  842. } */}
  843. <View className='day_card_header'>
  844. {
  845. props.isNight && global.nightObj && <DayNightStatus
  846. authInfo={authInfo}
  847. isNight={props.isNight}
  848. sunrise_ts={global.nightObj.sunrise.timestamp}
  849. sunset_ts={global.nightObj.sunset.timestamp}
  850. />
  851. }
  852. {
  853. !props.isNight && global.dayObj && <DayNightStatus
  854. authInfo={authInfo}
  855. isNight={props.isNight}
  856. sunrise_ts={global.dayObj.sunrise.timestamp}
  857. sunset_ts={global.dayObj.sunset.timestamp}
  858. />
  859. }
  860. </View>
  861. <Image className="card_arrowaaa"
  862. style={{ backgroundColor: global.isDebug ? 'blue' : 'transparent' }}
  863. src={require('@/assets/images/arrow3.png')} />
  864. {/* <View className='day_night_card_footer1' style={{ backgroundColor: global.isDebug ? 'red' : 'transparent' }}>
  865. {
  866. !showArrow() && <View className='footer_sun_icon_bg' style={{ backgroundColor: global.isDebug ? 'pink' : 'transparent' }}>
  867. {
  868. footerIcon()
  869. }
  870. </View>
  871. }
  872. <Text className='footer_desc_text' style={{ backgroundColor: global.isDebug ? 'black' : 'transparent' }}>{showArrow() ? completedDate() : footerDesc()}</Text>
  873. <Image className="card_arrowaaa"
  874. style={{ backgroundColor: global.isDebug ? 'blue' : 'transparent' }}
  875. src={require('@/assets/images/arrow3.png')} />
  876. </View> */}
  877. </View>
  878. </View>
  879. </View>
  880. {
  881. showDetailPopup && modalContent()
  882. }
  883. {
  884. showDetailModal && modalContent2()
  885. }
  886. </View>
  887. }
  888. function detail() {
  889. return <View>
  890. {cardContent()}
  891. <View className='day_night_card_footer_btn'
  892. onClick={(e) => {
  893. if (process.env.TARO_ENV == 'weapp') {
  894. e.stopPropagation()
  895. }
  896. if (props.isNight) {
  897. global.tapShowNight()
  898. }
  899. else {
  900. global.tapShowDay()
  901. }
  902. }}
  903. style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day }}>
  904. <Text style={{ color: props.isNight ? ColorType.white : ColorType.black, fontWeight: 'bold' }}>白天/夜晚</Text>
  905. </View>
  906. </View>
  907. }
  908. return process.env.TARO_ENV == 'weapp' ? <Box style={{marginBottom:0}}>{detail()}</Box> :
  909. <View className='rn_card_bg'>{detail()}</View>
  910. }