DayNightCard.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. import { PageContainer, Switch, Text, View } 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, setNightRingData, updateMember } from '@/store/day_night'
  13. import Modal from '@/components/layout/Modal.weapp'
  14. import { rpxToPx } from '@/utils/tools'
  15. import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
  16. let useNavigation;
  17. if (process.env.TARO_ENV == 'rn') {
  18. useNavigation = require("@react-navigation/native").useNavigation
  19. }
  20. let locationDetail;
  21. let sunriseA = new Date()
  22. sunriseA.setHours(6)
  23. sunriseA.setMinutes(0)
  24. sunriseA.setSeconds(0)
  25. sunriseA.setMilliseconds(0)
  26. const sunsetA = new Date()
  27. sunsetA.setHours(18)
  28. sunsetA.setMinutes(0)
  29. sunsetA.setSeconds(0)
  30. sunsetA.setMilliseconds(0)
  31. const sunriseB = new Date()
  32. sunriseB.setHours(6)
  33. sunriseB.setMinutes(0)
  34. sunriseB.setSeconds(0)
  35. sunriseB.setMilliseconds(0)
  36. export default function DayNightCard(props: { isNight: boolean, switchChanged: Function }) {
  37. const [expand, setExpand] = useState(false)
  38. const user = useSelector((state: any) => state.user);
  39. const [authInfo, setAuthInfo] = useState(null)
  40. const [count, setCount] = useState(0)
  41. const [sunriseTime, setSunriseTime] = useState('06:00')
  42. const [sunriseTmrTime, setSunriseTmrTime] = useState('06:00')
  43. const [sunsetTime, setSunsetTime] = useState('18:00')
  44. const [sunriseDate, setSunriseDate] = useState<any>(sunriseA)
  45. const [sunriseTmrDate, setSunriseTmrDate] = useState<any>(new Date(sunriseB.getTime() + 24 * 3600 * 1000))
  46. const [sunsetDate, setSunsetDate] = useState<any>(sunsetA)
  47. const [showDetailModal, setShowDetailModal] = useState(false)
  48. // const [locationDetail, setLocationDetail] = useState(null)
  49. const [nightDate, setNightDate] = useState(new Date())
  50. const [dayDate, setDayDate] = useState(new Date())
  51. const dispatch = useDispatch();
  52. const { t } = useTranslation()
  53. let navigation;
  54. if (useNavigation) {
  55. navigation = useNavigation()
  56. }
  57. useEffect(() => {
  58. if (user.isLogin) {
  59. getPerm({}).then(res => {
  60. setExpand(props.isNight ? (res as any).show_night_ring : (res as any).show_day_ring)
  61. })
  62. var today = new Date()
  63. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  64. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
  65. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  66. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  67. latestLocation({
  68. date_start: strYesterday, date_end: strTomorrow
  69. }).then(data => {
  70. debugger
  71. setAuthInfo(data as any)
  72. updateDate(data)
  73. locationDetail = data
  74. console.log(data)
  75. // setLocationDetail(data as any)
  76. })
  77. }
  78. getContent()
  79. }, [user.isLogin])
  80. useEffect(() => {
  81. if (props.isNight) {
  82. global.clearNightLocation = () => {
  83. clearCacheData()
  84. }
  85. }
  86. else {
  87. global.clearDayLocation = () => {
  88. clearCacheData()
  89. }
  90. }
  91. setInterval(() => {
  92. setCount((prevCounter) => prevCounter + 1)
  93. if (locationDetail) {
  94. var detail: any = locationDetail
  95. var now = new Date()
  96. if (now.getHours() == 0 && now.getMinutes() == 0 && now.getSeconds() == 0) {
  97. detail.daylights.splice(0, 1)
  98. }
  99. locationDetail = detail
  100. // setLocationDetail(detail)
  101. updateDate(detail)
  102. }
  103. else {
  104. }
  105. }, 1000)
  106. }, [])
  107. // useDidShow(() => {
  108. // getContent()
  109. // })
  110. function updateDate(data) {
  111. var today = new Date()
  112. // var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  113. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000)
  114. // var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  115. // var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  116. if (data && data.daylights && data.daylights.length > 0) {
  117. var yesterdayDate = new Date(data.daylights[0].date + 'T' + data.daylights[0].sunset)
  118. var todaySunriseDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunrise)
  119. var todaySunsetDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunset)
  120. var tomorrowSunriseDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunrise)
  121. var tomorrowSunsetDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunset)
  122. // var tomorrowSunsetDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunset)
  123. //今天凌晨日出前
  124. if (yesterdayDate.getTime() < today.getTime() && today.getTime() < todaySunriseDate.getTime()) {
  125. setNightDate(yesterdayDate)
  126. setDayDate(today)
  127. if (props.isNight) {
  128. setSunsetTime(data.daylights[0].sunset)
  129. setSunriseTmrTime(data.daylights[1].sunrise)
  130. setSunsetDate(yesterdayDate)
  131. setSunriseTmrDate(todaySunriseDate)
  132. }
  133. else {
  134. setSunriseTime(data.daylights[1].sunrise)
  135. setSunsetTime(data.daylights[1].sunset)
  136. setSunriseDate(todaySunriseDate)
  137. setSunsetDate(todaySunsetDate)
  138. }
  139. dispatch(setNightRingData({
  140. date: yesterdayDate.getTime(),
  141. sunrise: data.daylights[1].sunrise,
  142. sunset: data.daylights[0].sunset
  143. }))
  144. dispatch(setDayRingData({
  145. date: today.getTime(),
  146. sunrise: data.daylights[1].sunrise,
  147. sunset: data.daylights[1].sunset
  148. }))
  149. }
  150. //今天白天(今天出日后-日落前)
  151. else if (todaySunriseDate.getTime() < today.getTime() && today.getTime() < todaySunsetDate.getTime()) {
  152. setNightDate(todaySunsetDate)
  153. setDayDate(todaySunriseDate)
  154. if (props.isNight) {
  155. setSunsetTime(data.daylights[1].sunset)
  156. setSunriseTmrTime(data.daylights[2].sunrise)
  157. setSunsetDate(todaySunsetDate)
  158. setSunriseTmrDate(tomorrowSunriseDate)
  159. }
  160. else {
  161. setSunriseTime(data.daylights[1].sunrise)
  162. setSunsetTime(data.daylights[1].sunset)
  163. setSunsetDate(todaySunsetDate)
  164. setSunriseDate(todaySunriseDate)
  165. }
  166. dispatch(setNightRingData({
  167. date: today.getTime(),
  168. sunrise: data.daylights[2].sunrise,
  169. sunset: data.daylights[1].sunset
  170. }))
  171. dispatch(setDayRingData({
  172. date: today.getTime(),
  173. sunrise: data.daylights[1].sunrise,
  174. sunset: data.daylights[1].sunset
  175. }))
  176. }
  177. //今天夜晚
  178. else if (today.getTime() > todaySunsetDate.getTime() && today.getTime() < tomorrowSunriseDate.getTime()) {
  179. setNightDate(todaySunsetDate)
  180. setDayDate(tomorrowSunriseDate)
  181. if (props.isNight) {
  182. setSunsetTime(data.daylights[1].sunset)
  183. setSunriseTmrTime(data.daylights[2].sunrise)
  184. setSunsetDate(todaySunsetDate)
  185. setSunriseTmrDate(tomorrowSunriseDate)
  186. }
  187. else {
  188. setSunriseTime(data.daylights[2].sunrise)
  189. setSunsetTime(data.daylights[2].sunset)
  190. setSunriseDate(tomorrowSunriseDate)
  191. setSunsetDate(tomorrowSunsetDate)
  192. }
  193. dispatch(setNightRingData({
  194. date: today.getTime(),
  195. sunrise: data.daylights[2].sunrise,
  196. sunset: data.daylights[1].sunset
  197. }))
  198. dispatch(setDayRingData({
  199. date: tomorrowSunriseDate.getTime(),
  200. sunrise: data.daylights[2].sunrise,
  201. sunset: data.daylights[2].sunset
  202. }))
  203. }
  204. }
  205. else {
  206. }
  207. }
  208. async function getContent() {
  209. const isShow = await getStorage(props.isNight ? 'showNightRing' : 'showDayRing') || false
  210. setExpand(isShow)
  211. const gpsInfo = await getStorage('gps') || null
  212. if (gpsInfo) {
  213. var data = JSON.parse(gpsInfo)
  214. setAuthInfo(data)
  215. setSunriseTime((data as any).daylights[0].sunrise)
  216. setSunriseTmrTime((data as any).daylights[1].sunrise)
  217. setSunsetTime((data as any).daylights[0].sunset)
  218. dispatch(updateMember({ isMember: user.test_user, gpsInfo: data }))
  219. }
  220. else {
  221. setSunriseTime('06:00')
  222. setSunriseTmrTime('06:00')
  223. setSunsetTime('18:00')
  224. setAuthInfo(null)
  225. }
  226. if (props.isNight) {
  227. global.showNightRing = isShow
  228. global.refreshIndex()
  229. }
  230. else {
  231. props.switchChanged(isShow)
  232. }
  233. }
  234. async function getStorage(key: string) {
  235. try {
  236. const res = await Taro.getStorage({ key });
  237. return res.data;
  238. } catch {
  239. return '';
  240. }
  241. }
  242. function footer() {
  243. return <View className='day_night_card_footer'>
  244. <Text style={{ color: '#9E9E9E', fontSize: rpxToPx(20) }}>{
  245. // !isMember ? t('feature.track_time_duration.third_ring.member_desc') :
  246. authInfo && (authInfo as any).lat ? t('feature.track_time_duration.third_ring.base_location_desc') :
  247. t('feature.track_time_duration.third_ring.enter_location_desc')
  248. }</Text>
  249. {
  250. authInfo && (authInfo as any).lat && <Text style={{ color: '#9E9E9E', fontSize: rpxToPx(20) }} onClick={(e) => {
  251. e.stopPropagation()
  252. auth()
  253. }}>Edit Location</Text>
  254. }
  255. </View>
  256. }
  257. function tapCard(e) {
  258. if (!user.isLogin) {
  259. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  260. return
  261. }
  262. if (!expand) {
  263. return
  264. }
  265. var list = ['Current location Info',
  266. 'Choose a new location']
  267. if (user.test_user) {
  268. list.push('clear location data')
  269. }
  270. Taro.showActionSheet({
  271. itemList: list
  272. }).then(res => {
  273. switch (res.tapIndex) {
  274. case 0:
  275. setShowDetailModal(true)
  276. break
  277. case 1:
  278. auth()
  279. break;
  280. case 2:
  281. clearData()
  282. break;
  283. }
  284. })
  285. }
  286. function auth() {
  287. Taro.chooseLocation({
  288. success: function (res) {
  289. console.log(res)
  290. var today = new Date()
  291. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  292. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
  293. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  294. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  295. systemLocation({ lat: res.latitude, lng: res.longitude, date_start: strYesterday, date_end: strTomorrow }).then(data => {
  296. console.log(data);
  297. updateDate(data);
  298. locationDetail = data;
  299. // setLocationDetail(data as any);
  300. // (data as any).latitude = res.latitude;
  301. // (data as any).longitude = res.longitude;
  302. setAuthInfo(data as any)
  303. setSunriseTime((data as any).daylights[0].sunrise)
  304. setSunriseTmrTime((data as any).daylights[1].sunrise)
  305. setSunsetTime((data as any).daylights[0].sunset)
  306. Taro.setStorage({
  307. key: 'gps',
  308. data: JSON.stringify(data as any)
  309. })
  310. dispatch(updateMember({ isMember: user.test_user, gpsInfo: (data as any) }))
  311. })
  312. },
  313. fail(res) {
  314. Taro.showToast({
  315. title: '位置修改失败!\n请重新选择就近位置',
  316. icon: 'none'
  317. })
  318. },
  319. })
  320. }
  321. function getLocation() {
  322. if ((authInfo as any).address.city.length > 0) {
  323. return (authInfo as any).address.city
  324. }
  325. if ((authInfo as any).address.province.length > 0) {
  326. return (authInfo as any).address.province
  327. }
  328. if ((authInfo as any).address.country.length > 0) {
  329. return (authInfo as any).address.country
  330. }
  331. return t('feature.track_time_duration.third_ring.unknown')
  332. }
  333. function timeCount() {
  334. var now = new Date()
  335. if (props.isNight) {
  336. if (now.getTime() < sunriseTmrDate.getTime()) {
  337. return TimeFormatter.countdown(sunsetDate.getTime())
  338. }
  339. return TimeFormatter.countdown(sunsetDate.getTime())
  340. } else {
  341. if (now.getTime() < sunsetDate.getTime()) {
  342. return TimeFormatter.countdown(sunriseDate.getTime())
  343. }
  344. return TimeFormatter.countdown(sunriseTmrDate.getTime())
  345. }
  346. }
  347. function timeCount2() {
  348. var now = new Date()
  349. if (props.isNight) {
  350. if (now.getTime() < sunsetDate.getTime()) {
  351. return TimeFormatter.countdown(sunriseTmrDate.getTime())
  352. }
  353. return TimeFormatter.countdown(sunriseTmrDate.getTime())
  354. } else {
  355. return TimeFormatter.countdown(sunsetDate.getTime())
  356. }
  357. }
  358. function showExtraData() {
  359. var now = new Date()
  360. if (props.isNight) {
  361. if (sunsetDate.getTime() > now.getTime()) {
  362. return false
  363. }
  364. return true
  365. }
  366. if (sunriseDate.getTime() < now.getTime() && now.getTime() < sunsetDate.getTime()) {
  367. return true;
  368. }
  369. return false
  370. }
  371. function timeDesc() {
  372. var now = new Date()
  373. if (props.isNight) {
  374. var list = sunsetTime.split(':')
  375. var hour = parseInt(list[0])
  376. var min = parseInt(list[1])
  377. var second = list.length == 3 ? parseInt(list[2]) : 0
  378. now.setHours(hour)
  379. now.setMinutes(min)
  380. now.setSeconds(second)
  381. var sunriseDate = new Date()
  382. var list2 = sunriseTmrTime.split(':')
  383. var hour2 = parseInt(list2[0])
  384. var min2 = parseInt(list2[1])
  385. var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
  386. sunriseDate.setHours(hour2)
  387. sunriseDate.setMinutes(min2)
  388. sunriseDate.setSeconds(second2)
  389. if (sunriseDate.getTime() > new Date().getTime()) {
  390. return 'Time past Sunset'
  391. }
  392. if (now.getTime() < new Date().getTime()) {
  393. return 'Time past Sunset'
  394. }
  395. return 'Time to Sunset'
  396. }
  397. else {
  398. var list = sunriseTime.split(':')
  399. var hour = parseInt(list[0])
  400. var min = parseInt(list[1])
  401. var second = list.length == 3 ? parseInt(list[2]) : 0
  402. now.setHours(hour)
  403. now.setMinutes(min)
  404. now.setSeconds(second)
  405. var sunsetDate = new Date()
  406. var list2 = sunsetTime.split(':')
  407. var hour2 = parseInt(list2[0])
  408. var min2 = parseInt(list2[1])
  409. var second2 = list2.length == 3 ? parseInt(list2[2]) : 0
  410. sunsetDate.setHours(hour2)
  411. sunsetDate.setMinutes(min2)
  412. sunsetDate.setSeconds(second2)
  413. if (new Date().getTime() > sunsetDate.getTime()) {
  414. return 'Time to Sunrise'
  415. }
  416. if (now.getTime() < new Date().getTime()) {
  417. return 'Time past Sunrise'
  418. }
  419. return 'Time to Sunrise'
  420. }
  421. }
  422. function timeDesc2() {
  423. if (props.isNight) {
  424. return 'Time to Sunrise'
  425. }
  426. return 'Time to Sunset'
  427. }
  428. function clearData() {
  429. Taro.showModal({
  430. title: '提示',
  431. content: '确认清除位置数据?',
  432. success: function (res) {
  433. if (res.confirm) {
  434. clearLocation().then(res => {
  435. if (global.clearNightLocation) {
  436. global.clearNightLocation()
  437. }
  438. if (global.clearDayLocation) {
  439. global.clearDayLocation()
  440. }
  441. })
  442. } else if (res.cancel) {
  443. console.log('用户点击取消')
  444. }
  445. }
  446. })
  447. }
  448. function clearCacheData() {
  449. locationDetail = null
  450. Taro.removeStorage({ key: 'gps' })
  451. setAuthInfo(null)
  452. setSunriseTime('06:00')
  453. setSunriseTmrTime('06:00')
  454. setSunsetTime('18:00')
  455. dispatch(updateMember({ isMember: user.test_user, gpsInfo: null }))
  456. dispatch(setDayRingData({
  457. date: new Date().getTime(),
  458. sunrise: '06:00',
  459. sunset: '18:00'
  460. }))
  461. dispatch(setNightRingData({
  462. date: new Date().getTime(),
  463. sunrise: '06:00',
  464. sunset: '18:00'
  465. }))
  466. }
  467. function detailModalContent() {
  468. var split = new Date().toString().split(' ');
  469. var timezone = split[split.length - 2];
  470. if (!authInfo || !(authInfo as any).lat) {
  471. return <View style={{ height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', width: rpxToPx(750) }}>
  472. <Text>暂无位置信息</Text>
  473. </View>
  474. }
  475. return <View>
  476. {
  477. <View className="cell_bg">
  478. {
  479. <View className="cell_full">
  480. <Text className="cell_title">{t('feature.track_time_duration.third_ring.location')}</Text>
  481. <Text className="cell_value">{authInfo ? getLocation() : t('feature.track_time_duration.third_ring.enter')}</Text>
  482. </View>
  483. }
  484. <View className="cell_line" style={{ height: 1 }} />
  485. {
  486. <View className="cell_full" >
  487. <Text className="cell_title">{t('feature.track_time_duration.third_ring.latitude')}</Text>
  488. <Text className="cell_value">{(authInfo as any).lat}</Text>
  489. </View>
  490. }
  491. <View className="cell_line" style={{ height: 1 }} />
  492. <View className="cell_full">
  493. <Text className="cell_title" >{t('feature.track_time_duration.third_ring.longitude')}</Text>
  494. <Text className="cell_value">{(authInfo as any).lng}</Text>
  495. </View>
  496. <View className="cell_line" style={{ height: 1 }} />
  497. <View className="cell_full">
  498. <Text className="cell_title">{t('feature.track_time_duration.third_ring.timezone')}</Text>
  499. <Text className="cell_value">{timezone}</Text>
  500. </View>
  501. </View>
  502. }
  503. </View>
  504. }
  505. function modalContent() {
  506. if (process.env.TARO_ENV == 'weapp') {
  507. return <Modal
  508. testInfo={null}
  509. dismiss={() => {
  510. setShowDetailModal(false)
  511. }}
  512. confirm={() => { }}>
  513. {
  514. detailModalContent()
  515. }
  516. </Modal>
  517. }
  518. else if (process.env.TARO_ENV == 'rn') {
  519. return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
  520. // overlayStyle='background-color:rgba(0,0,0,0.9)'
  521. // custom-style='background-color:#1c1c1c'
  522. overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
  523. customStyle={{ backgroundColor: '#1c1c1c' }}
  524. closeOnSlideDown={false}
  525. onBeforeEnter={() => {
  526. }}
  527. onBeforeLeave={() => {
  528. }}
  529. onClick={() => { alert('b') }}
  530. onClickOverlay={() => { alert('a') }}
  531. onAfterLeave={() => { setShowDetailModal(false) }}
  532. show={showDetailModal} round={true} overlay={true} position='bottom'
  533. >
  534. {
  535. detailModalContent()
  536. }
  537. </PageContainer>
  538. }
  539. }
  540. function nightDurationDesc() {
  541. if (!authInfo || !(authInfo as any).lat) {
  542. if (new Date().getHours() >= 6) {
  543. return `Today ${sunsetTime} - Tomorrow ${sunriseTmrTime}`
  544. }
  545. return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  546. }
  547. if (nightDate.getDate() == new Date().getDate()) {
  548. return `Today ${sunsetTime} - Tomorrow ${sunriseTmrTime}`
  549. }
  550. return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  551. }
  552. function dayDurationDesc() {
  553. if (!authInfo || !(authInfo as any).lat) {
  554. if (new Date().getHours() >= 18) {
  555. return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  556. }
  557. return `Today ${sunriseTime} - ${sunsetTime}`
  558. }
  559. if (dayDate.getDate() == new Date().getDate()) {
  560. return `Today ${sunriseTime} - ${sunsetTime}`
  561. }
  562. return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  563. }
  564. return <View style={{ color: '#fff' }}>
  565. <Box onClick={tapCard}>
  566. <View>
  567. <View className='day_night_top'>
  568. <Text className='day_night_title'>{props.isNight ? 'Overnight' : 'Day'}</Text>
  569. <View className='free' style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day, color: props.isNight ? '#fff' : '#1C1C1C' }}>限时免费</View>
  570. <View style={{ flex: 1 }} />
  571. <Switch checked={expand}
  572. color={props.isNight ? ColorType.night : ColorType.day}
  573. onClick={(e) => { e.stopPropagation() }}
  574. onChange={(e) => {
  575. props.switchChanged(e.detail.value)
  576. e.stopPropagation()
  577. setExpand(e.detail.value)
  578. if (props.isNight) {
  579. global.showNightRing = e.detail.value
  580. global.refreshIndex()
  581. }
  582. Taro.setStorage({
  583. key: props.isNight ? 'showNightRing' : 'showDayRing',
  584. data: e.detail.value
  585. })
  586. if (user.isLogin) {
  587. if (props.isNight) {
  588. uploadPerm({ show_night_ring: e.detail.value })
  589. }
  590. else {
  591. uploadPerm({ show_day_ring: e.detail.value })
  592. }
  593. }
  594. }}
  595. />
  596. </View>
  597. {
  598. expand && <View>
  599. <View style={{ display: 'flex', flexDirection: 'column' }}>
  600. <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? nightDurationDesc() : dayDurationDesc()}</Text>
  601. <Text className='day_night_desc'>{props.isNight ? 'Sunset to Sunrise' : 'Sunrise to Sunset'}</Text>
  602. <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(32) }}>
  603. <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
  604. <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{timeCount()}</Text>
  605. <Text className='day_night_desc'>{timeDesc()}</Text>
  606. </View>
  607. {
  608. showExtraData() && <View style={{ display: 'flex', flexDirection: 'column', width: rpxToPx(300) }}>
  609. <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day, opacity: 0.6 }}>{timeCount2()}</Text>
  610. <Text className='day_night_desc'>{timeDesc2()}</Text>
  611. </View>
  612. }
  613. </View>
  614. </View>
  615. {
  616. footer()
  617. }
  618. </View>
  619. }
  620. </View>
  621. </Box>
  622. {
  623. showDetailModal && modalContent()
  624. }
  625. </View>
  626. }