DayNightCard.tsx 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  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 { rpxToPx } from '@/utils/tools'
  16. import { jumpPage } from '@/features/trackTimeDuration/hooks/Common'
  17. import DayNightDetailPopup from './DayNightDetailPopup'
  18. import { IconDay, IconInfo, IconNight } from '@/components/basic/Icons'
  19. import { getClocks } from '@/services/trackTimeDuration'
  20. import { request } from '@/services/http/request'
  21. import { API_USER_LOCATION } from '@/services/http/api'
  22. let useNavigation;
  23. if (process.env.TARO_ENV == 'rn') {
  24. useNavigation = require("@react-navigation/native").useNavigation
  25. }
  26. let locationDetail;
  27. let sunriseA = new Date()
  28. sunriseA.setHours(6)
  29. sunriseA.setMinutes(0)
  30. sunriseA.setSeconds(0)
  31. sunriseA.setMilliseconds(0)
  32. const sunsetA = new Date()
  33. sunsetA.setHours(18)
  34. sunsetA.setMinutes(0)
  35. sunsetA.setSeconds(0)
  36. sunsetA.setMilliseconds(0)
  37. const sunriseB = new Date()
  38. sunriseB.setHours(6)
  39. sunriseB.setMinutes(0)
  40. sunriseB.setSeconds(0)
  41. sunriseB.setMilliseconds(0)
  42. let lastDayInfo: any = null;
  43. let lastNightInfo: any = null;
  44. let joingMember = false
  45. export default function DayNightCard(props: { isNight: boolean, count: number }) {
  46. const user = useSelector((state: any) => state.user);
  47. const dayStore = useSelector((state: any) => state.day);
  48. const nightStore = useSelector((state: any) => state.night);
  49. const [authInfo, setAuthInfo] = useState(global.locationDetail ? global.locationDetail : null)
  50. const [sunriseTime, setSunriseTime] = useState('06:00')
  51. const [sunriseTmrTime, setSunriseTmrTime] = useState('06:00')
  52. const [sunsetTime, setSunsetTime] = useState('18:00')
  53. const [sunriseDate, setSunriseDate] = useState<any>(sunriseA)
  54. const [sunriseTmrDate, setSunriseTmrDate] = useState<any>(new Date(sunriseB.getTime() + 24 * 3600 * 1000))
  55. const [sunsetDate, setSunsetDate] = useState<any>(sunsetA)
  56. const [showDetailModal, setShowDetailModal] = useState(false)
  57. const [showDetailPopup, setShowDetailPopup] = useState(false)
  58. // const [locationDetail, setLocationDetail] = useState(null)
  59. const [nightDate, setNightDate] = useState(new Date())
  60. const [dayDate, setDayDate] = useState(new Date())
  61. const dispatch = useDispatch();
  62. const { t } = useTranslation()
  63. const isMember = true;
  64. let navigation;
  65. if (useNavigation) {
  66. navigation = useNavigation()
  67. }
  68. useEffect(() => {
  69. if (user.isLogin) {
  70. if (global.locationDetail) {
  71. locationDetail = global.locationDetail
  72. setAuthInfo(locationDetail)
  73. }
  74. var today = new Date()
  75. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  76. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
  77. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  78. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  79. latestLocation({
  80. date_start: strYesterday, date_end: strTomorrow
  81. }).then(data => {
  82. setAuthInfo(data as any)
  83. updateDate(data)
  84. locationDetail = data
  85. global.locationDetail = locationDetail
  86. Taro.setStorage({
  87. key: 'gps',
  88. data: JSON.stringify(data as any)
  89. })
  90. })
  91. } else {
  92. setSunriseTime('06:00');
  93. setSunriseTmrTime('06:00')
  94. setSunsetTime('18:00')
  95. setSunriseDate(sunriseA)
  96. setSunriseTmrDate(new Date(sunriseB.getTime() + 24 * 3600 * 1000))
  97. setSunsetDate(sunsetA)
  98. }
  99. }, [user.isLogin])
  100. useEffect(() => {
  101. locationDetail = global.locationDetail
  102. setAuthInfo(locationDetail)
  103. }, [global.locationDetail])
  104. useEffect(() => {
  105. if (locationDetail)
  106. updateDate(locationDetail)
  107. if (props.isNight) {
  108. global.clearNightLocation = () => {
  109. clearCacheData()
  110. }
  111. }
  112. else {
  113. global.clearDayLocation = () => {
  114. clearCacheData()
  115. }
  116. }
  117. }, [])
  118. useEffect(() => {
  119. if (locationDetail) {
  120. var detail: any = locationDetail
  121. var now = new Date()
  122. if (now.getHours() == 0 && now.getMinutes() == 0 && now.getSeconds() == 0) {
  123. detail.daylights.splice(0, 1)
  124. }
  125. locationDetail = detail
  126. // setLocationDetail(detail)
  127. updateDate(detail)
  128. }
  129. }, [props.count])
  130. useEffect(() => {
  131. // if (user.test_user && joingMember) {
  132. // auth()
  133. // }
  134. if (!isMember) {
  135. lastNightInfo = null
  136. lastDayInfo = null
  137. locationDetail = null
  138. setAuthInfo(null)
  139. setSunriseTime('06:00')
  140. setSunriseTmrTime('06:00')
  141. setSunsetTime('18:00')
  142. dispatch(updateMember({ isMember: isMember, gpsInfo: null }))
  143. dispatch(setDayRingData({
  144. date: new Date().getTime(),
  145. sunrise: '06:00',
  146. sunset: '18:00'
  147. }))
  148. dispatch(setNightRingData({
  149. date: new Date().getTime(),
  150. sunrise: '06:00',
  151. sunset: '18:00'
  152. }))
  153. }
  154. else {
  155. getGPSCache()
  156. }
  157. }, [user.test_user])
  158. useDidShow(() => {
  159. if (!user.isLogin) {
  160. dispatch(showNight(false))
  161. dispatch(showDay(false))
  162. Taro.setStorage({
  163. key: 'showNightRing',
  164. data: false
  165. })
  166. Taro.setStorage({
  167. key: 'showDayRing',
  168. data: false
  169. })
  170. }
  171. })
  172. async function getGPSCache() {
  173. var gps = await getStorage('gps')
  174. if (gps && gps.length > 0) {
  175. locationDetail = JSON.parse(gps)
  176. global.locationDetail = JSON.parse(gps)
  177. }
  178. }
  179. async function getStorage(key: string) {
  180. try {
  181. const res = await Taro.getStorage({ key });
  182. return res.data;
  183. } catch {
  184. return '';
  185. }
  186. }
  187. function updateDate(data) {
  188. var today = new Date()
  189. // var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  190. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000)
  191. // var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  192. // var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  193. if (isMember && data && data.daylights && data.daylights.length > 0) {
  194. var yesterdayDate = new Date(data.daylights[0].date + 'T' + data.daylights[0].sunset)
  195. var todaySunriseDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunrise)
  196. var todaySunsetDate = new Date(data.daylights[1].date + 'T' + data.daylights[1].sunset)
  197. var tomorrowSunriseDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunrise)
  198. var tomorrowSunsetDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunset)
  199. // var tomorrowSunsetDate = new Date(data.daylights[2].date + 'T' + data.daylights[2].sunset)
  200. //今天凌晨日出前
  201. if (yesterdayDate.getTime() < today.getTime() && today.getTime() < todaySunriseDate.getTime()) {
  202. setNightDate(yesterdayDate)
  203. setDayDate(today)
  204. if (props.isNight) {
  205. setSunsetTime(data.daylights[0].sunset)
  206. setSunriseTmrTime(data.daylights[1].sunrise)
  207. setSunsetDate(yesterdayDate)
  208. setSunriseTmrDate(todaySunriseDate)
  209. }
  210. else {
  211. setSunriseTime(data.daylights[1].sunrise)
  212. setSunsetTime(data.daylights[1].sunset)
  213. setSunriseDate(todaySunriseDate)
  214. setSunsetDate(todaySunsetDate)
  215. }
  216. updateNightStore(yesterdayDate, data.daylights[1].sunrise, data.daylights[0].sunset)
  217. updateDayStore(today, data.daylights[1].sunrise, data.daylights[1].sunset)
  218. }
  219. //今天白天(今天出日后-日落前)
  220. else if (todaySunriseDate.getTime() < today.getTime() && today.getTime() < todaySunsetDate.getTime()) {
  221. setNightDate(todaySunsetDate)
  222. setDayDate(todaySunriseDate)
  223. if (props.isNight) {
  224. setSunsetTime(data.daylights[1].sunset)
  225. setSunriseTmrTime(data.daylights[2].sunrise)
  226. setSunsetDate(todaySunsetDate)
  227. setSunriseTmrDate(tomorrowSunriseDate)
  228. }
  229. else {
  230. setSunriseTime(data.daylights[1].sunrise)
  231. setSunsetTime(data.daylights[1].sunset)
  232. setSunsetDate(todaySunsetDate)
  233. setSunriseDate(todaySunriseDate)
  234. }
  235. updateNightStore(today, data.daylights[2].sunrise, data.daylights[1].sunset)
  236. updateDayStore(today, data.daylights[1].sunrise, data.daylights[1].sunset)
  237. }
  238. //今天夜晚
  239. else if (today.getTime() > todaySunsetDate.getTime() && today.getTime() < tomorrowSunriseDate.getTime()) {
  240. setNightDate(todaySunsetDate)
  241. setDayDate(tomorrowSunriseDate)
  242. if (props.isNight) {
  243. setSunsetTime(data.daylights[1].sunset)
  244. setSunriseTmrTime(data.daylights[2].sunrise)
  245. setSunsetDate(todaySunsetDate)
  246. setSunriseTmrDate(tomorrowSunriseDate)
  247. }
  248. else {
  249. setSunriseTime(data.daylights[2].sunrise)
  250. setSunsetTime(data.daylights[2].sunset)
  251. setSunriseDate(tomorrowSunriseDate)
  252. setSunsetDate(tomorrowSunsetDate)
  253. }
  254. updateNightStore(today, data.daylights[2].sunrise, data.daylights[1].sunset)
  255. updateDayStore(tomorrowSunriseDate, data.daylights[2].sunrise, data.daylights[2].sunset)
  256. }
  257. }
  258. else {
  259. locationDetail = null
  260. setAuthInfo(null)
  261. setSunriseTime('06:00')
  262. setSunriseTmrTime('06:00')
  263. setSunsetTime('18:00')
  264. dispatch(updateMember({ isMember: isMember, gpsInfo: null }))
  265. dispatch(setDayRingData({
  266. date: new Date().getTime(),
  267. sunrise: '06:00',
  268. sunset: '18:00'
  269. }))
  270. dispatch(setNightRingData({
  271. date: new Date().getTime(),
  272. sunrise: '06:00',
  273. sunset: '18:00'
  274. }))
  275. }
  276. }
  277. function updateNightStore(date, sunrise, sunset) {
  278. if (lastNightInfo && lastNightInfo.date.getDate() == new Date(date).getDate() &&
  279. lastNightInfo.sunrise == sunrise &&
  280. lastNightInfo.sunset == sunset
  281. ) {
  282. return
  283. }
  284. lastNightInfo = {
  285. date,
  286. sunrise,
  287. sunset
  288. }
  289. dispatch(setNightRingData({
  290. date: date.getTime(),
  291. sunrise: sunrise,
  292. sunset: sunset
  293. }))
  294. }
  295. function updateDayStore(date, sunrise, sunset) {
  296. if (lastDayInfo && lastDayInfo.date.getDate() == new Date(date).getDate() &&
  297. lastDayInfo.sunrise == sunrise &&
  298. lastDayInfo.sunset == sunset
  299. ) {
  300. return
  301. }
  302. lastDayInfo = {
  303. date,
  304. sunrise,
  305. sunset
  306. }
  307. dispatch(setDayRingData({
  308. date: date.getTime(),
  309. sunrise: sunrise,
  310. sunset: sunset
  311. }))
  312. }
  313. function tapCard(e) {
  314. // if (process.env.TARO_ENV == 'weapp') {
  315. // e.stopPropagation()
  316. // }
  317. if (!user.isLogin) {
  318. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  319. return
  320. }
  321. if (!dayStore.showDayRing) {
  322. return
  323. }
  324. setShowDetailPopup(true)
  325. }
  326. function auth(e?: any) {
  327. if (e && process.env.TARO_ENV == 'weapp') {
  328. e.stopPropagation()
  329. }
  330. var today = new Date()
  331. var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
  332. var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 3)
  333. var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
  334. var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
  335. // systemLocation({
  336. // lat: 77,
  337. // lng: 20,
  338. // date_start: strYesterday,
  339. // date_end: strTomorrow,
  340. // coordinate_system_standard: 'GCJ-02'
  341. // }).then(data => {
  342. // })
  343. // return
  344. if (process.env.TARO_ENV == 'rn') {
  345. Taro.getLocation({
  346. success(res) {
  347. systemLocation({
  348. lat: res.latitude,
  349. lng: res.longitude,
  350. // name: 'app test',
  351. // address: 'app test',
  352. date_start: strYesterday,
  353. date_end: strTomorrow,
  354. // coordinate_system_standard: 'GCJ-02'
  355. }).then(data => {
  356. console.log('get Location',data)
  357. updateDate(data);
  358. locationDetail = data;
  359. global.locationDetail = locationDetail
  360. setAuthInfo(data as any)
  361. setSunriseTime((data as any).daylights[0].sunrise)
  362. setSunriseTmrTime((data as any).daylights[1].sunrise)
  363. setSunsetTime((data as any).daylights[0].sunset)
  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. })
  371. },
  372. fail(res) {
  373. if (res.errMsg == 'Permissions denied!') {
  374. alert('aaa')
  375. }
  376. console.log(res)
  377. showRing()
  378. },
  379. complete(res) {
  380. }
  381. })
  382. return
  383. }
  384. joingMember = false;
  385. Taro.chooseLocation({
  386. latitude: authInfo && authInfo.lat ? authInfo.lat : undefined,
  387. longitude: authInfo && authInfo.lat ? authInfo.lng : undefined,
  388. success: function (res) {
  389. systemLocation({
  390. lat: res.latitude,
  391. lng: res.longitude,
  392. name: res.name,
  393. address: res.address,
  394. date_start: strYesterday,
  395. date_end: strTomorrow,
  396. coordinate_system_standard: 'GCJ-02'
  397. }).then(data => {
  398. updateDate(data);
  399. locationDetail = data;
  400. global.locationDetail = locationDetail
  401. setAuthInfo(data as any)
  402. setSunriseTime((data as any).daylights[0].sunrise)
  403. setSunriseTmrTime((data as any).daylights[1].sunrise)
  404. setSunsetTime((data as any).daylights[0].sunset)
  405. Taro.setStorage({
  406. key: 'gps',
  407. data: JSON.stringify(data as any)
  408. })
  409. showRing()
  410. dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
  411. })
  412. },
  413. fail(res) {
  414. Taro.showToast({
  415. title: '位置修改失败!\n请重新选择就近位置',
  416. icon: 'none'
  417. })
  418. showRing()
  419. },
  420. complete(res) {
  421. }
  422. })
  423. }
  424. function showRing() {
  425. dispatch(showNight(true))
  426. dispatch(showDay(true))
  427. Taro.setStorage({
  428. key: 'showNightRing',
  429. data: true
  430. })
  431. Taro.setStorage({
  432. key: 'showDayRing',
  433. data: true
  434. })
  435. }
  436. function getLocation() {
  437. var city = ''
  438. if ((authInfo as any).address){
  439. if ((authInfo as any).address.city.length > 0) {
  440. city = (authInfo as any).address.city
  441. }
  442. else if ((authInfo as any).address.province.length > 0) {
  443. city = (authInfo as any).address.province
  444. }
  445. else if ((authInfo as any).address.country.length > 0) {
  446. city = (authInfo as any).address.country
  447. }
  448. else {
  449. city = t('feature.track_time_duration.third_ring.unknown')
  450. }
  451. }
  452. else {
  453. city = t('feature.track_time_duration.third_ring.unknown')
  454. }
  455. // return city +' | '+parseInt(authInfo.lat)+'°'+ ' '+parseInt(authInfo.lng)
  456. return `${city} | ${Math.abs(parseInt(authInfo.lat))}°${parseInt(authInfo.lat) < 0 ? 'S' : 'N'} ${Math.abs(parseInt(authInfo.lng))}°${parseInt(authInfo.lng) < 0 ? 'W' : 'E'}`
  457. }
  458. function clearData() {
  459. Taro.showModal({
  460. title: '提示',
  461. content: '确认清除位置数据?',
  462. success: function (res) {
  463. if (res.confirm) {
  464. clearLocation().then(res => {
  465. if (global.clearNightLocation) {
  466. global.clearNightLocation()
  467. }
  468. if (global.clearDayLocation) {
  469. global.clearDayLocation()
  470. }
  471. lastNightInfo = null
  472. lastDayInfo = null
  473. })
  474. } else if (res.cancel) {
  475. console.log('用户点击取消')
  476. }
  477. }
  478. })
  479. }
  480. function clearCacheData() {
  481. locationDetail = null
  482. Taro.removeStorage({ key: 'gps' })
  483. setAuthInfo(null)
  484. setSunriseTime('06:00')
  485. setSunriseTmrTime('06:00')
  486. setSunsetTime('18:00')
  487. dispatch(updateMember({ isMember: isMember, gpsInfo: null }))
  488. dispatch(setDayRingData({
  489. date: new Date().getTime(),
  490. sunrise: '06:00',
  491. sunset: '18:00'
  492. }))
  493. dispatch(setNightRingData({
  494. date: new Date().getTime(),
  495. sunrise: '06:00',
  496. sunset: '18:00'
  497. }))
  498. }
  499. function detailModalContent() {
  500. var split = new Date().toString().split(' ');
  501. var timezone = split[split.length - 2];
  502. if (!authInfo || !(authInfo as any).lat) {
  503. return <View style={{ height: 100, display: 'flex', alignItems: 'center', justifyContent: 'center', width: rpxToPx(750) }}>
  504. <Text>暂无位置信息</Text>
  505. </View>
  506. }
  507. return <View style={{ display: 'flex', flexDirection: 'column' }}>
  508. {
  509. <View className="cell_bg">
  510. {
  511. <View className="cell_full">
  512. <Text className="cell_title">{t('feature.track_time_duration.third_ring.location')}</Text>
  513. <Text className="cell_value">{authInfo ? getLocation() : t('feature.track_time_duration.third_ring.enter')}</Text>
  514. </View>
  515. }
  516. <View className="cell_line" style={{ height: 1 }} />
  517. {
  518. <View className="cell_full" >
  519. <Text className="cell_title">{t('feature.track_time_duration.third_ring.latitude')}</Text>
  520. <Text className="cell_value">{(authInfo as any).lat}</Text>
  521. </View>
  522. }
  523. <View className="cell_line" style={{ height: 1 }} />
  524. <View className="cell_full">
  525. <Text className="cell_title" >{t('feature.track_time_duration.third_ring.longitude')}</Text>
  526. <Text className="cell_value">{(authInfo as any).lng}</Text>
  527. </View>
  528. <View className="cell_line" style={{ height: 1 }} />
  529. <View className="cell_full">
  530. <Text className="cell_title">{t('feature.track_time_duration.third_ring.timezone')}</Text>
  531. <Text className="cell_value">{timezone}</Text>
  532. </View>
  533. </View>
  534. }
  535. <Text onClick={() => {
  536. clearData()
  537. setShowDetailModal(false)
  538. }} style={{ width: '100%', textAlign: 'center', marginBottom: 50, color: '#fff', marginTop: 20 }}>清除位置</Text>
  539. </View>
  540. }
  541. function modalContent2() {
  542. if (process.env.TARO_ENV == 'weapp') {
  543. return <Modal
  544. testInfo={null}
  545. dismiss={() => {
  546. setShowDetailModal(false)
  547. }}
  548. confirm={() => { }}>
  549. {
  550. detailModalContent()
  551. }
  552. </Modal>
  553. }
  554. else if (process.env.TARO_ENV == 'rn') {
  555. return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
  556. // overlayStyle='background-color:rgba(0,0,0,0.9)'
  557. // custom-style='background-color:#1c1c1c'
  558. overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
  559. customStyle={{ backgroundColor: '#1c1c1c' }}
  560. closeOnSlideDown={false}
  561. onBeforeEnter={() => {
  562. }}
  563. onBeforeLeave={() => {
  564. }}
  565. onClick={() => { alert('b') }}
  566. onClickOverlay={() => { alert('a') }}
  567. onAfterLeave={() => { setShowDetailModal(false) }}
  568. show={showDetailModal} round={true} overlay={true} position='bottom'
  569. >
  570. {
  571. detailModalContent()
  572. }
  573. </PageContainer>
  574. }
  575. }
  576. function modalContent() {
  577. if (process.env.TARO_ENV == 'weapp') {
  578. return <Modal
  579. testInfo={null}
  580. dismiss={() => {
  581. setShowDetailPopup(false)
  582. }}
  583. confirm={() => { }}>
  584. <DayNightDetailPopup
  585. sunsetDate={sunsetDate}
  586. sunriseDate={sunriseDate}
  587. sunriseTmrDate={sunriseTmrDate}
  588. sunsetTime={sunsetTime}
  589. sunriseTime={sunriseTime}
  590. sunriseTmrTime={sunriseTmrTime}
  591. isNight={props.isNight}
  592. authInfo={authInfo}
  593. nightDate={nightDate}
  594. dayDate={dayDate}
  595. onClose={() => { setShowDetailPopup(false) }}
  596. />
  597. </Modal>
  598. }
  599. else if (process.env.TARO_ENV == 'rn') {
  600. return <PageContainer style={{ backgroundColor: '#1c1c1c' }}
  601. // overlayStyle='background-color:rgba(0,0,0,0.9)'
  602. // custom-style='background-color:#1c1c1c'
  603. overlayStyle={{ backgroundColor: 'rgba(0,0,0,0.9)' }}
  604. customStyle={{ backgroundColor: '#1c1c1c' }}
  605. closeOnSlideDown={false}
  606. onBeforeEnter={() => {
  607. }}
  608. onBeforeLeave={() => {
  609. }}
  610. onClick={() => { alert('b') }}
  611. onClickOverlay={() => { alert('a') }}
  612. onAfterLeave={() => { setShowDetailPopup(false) }}
  613. show={showDetailModal} round={true} overlay={true} position='bottom'
  614. >
  615. <DayNightDetailPopup
  616. sunsetDate={sunsetDate}
  617. sunriseDate={sunriseDate}
  618. sunriseTmrDate={sunriseTmrDate}
  619. sunsetTime={sunsetTime}
  620. sunriseTime={sunriseTime}
  621. sunriseTmrTime={sunriseTmrTime}
  622. isNight={props.isNight}
  623. authInfo={authInfo}
  624. nightDate={nightDate}
  625. dayDate={dayDate}
  626. onClose={() => { setShowDetailPopup(false) }}
  627. />
  628. </PageContainer>
  629. }
  630. }
  631. function nightDuration() {
  632. if (!authInfo || !(authInfo as any).lat) {
  633. if (new Date().getHours() >= 6) {
  634. return `${t('feature.day_night.tonight')} ${sunsetTime} - ${t('feature.day_night.tomorrow_morning')} ${sunriseTmrTime}`
  635. }
  636. return `${t('feature.day_night.last_night')} ${sunsetTime} - ${t('feature.day_night.this_morning')} ${sunriseTmrTime}`
  637. // return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  638. }
  639. if (nightDate.getDate() == new Date().getDate()) {
  640. return `${t('feature.day_night.tonight')} ${sunsetTime.substring(0, 5)} - ${t('feature.day_night.tomorrow_morning')} ${sunriseTmrTime.substring(0, 5)}`
  641. }
  642. return `${t('feature.day_night.last_night')} ${sunsetTime.substring(0, 5)} - ${t('feature.day_night.this_morning')} ${sunriseTmrTime.substring(0, 5)}`
  643. //`Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  644. }
  645. function getSunsetTime() {
  646. if (props.isNight) {
  647. if (!authInfo || !(authInfo as any).lat) {
  648. if (new Date().getHours() >= 6) {
  649. return `${t('feature.day_night.tonight')} ${sunsetTime}`
  650. }
  651. return `${t('feature.day_night.last_night')} ${sunsetTime}`
  652. // return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  653. }
  654. if (nightDate.getDate() == new Date().getDate()) {
  655. return `${t('feature.day_night.tonight')} ${sunsetTime.substring(0, 5)}`
  656. }
  657. return `${t('feature.day_night.last_night')} ${sunsetTime.substring(0, 5)}`
  658. }
  659. if (!authInfo || !(authInfo as any).lat) {
  660. if (new Date().getHours() >= 18) {
  661. return `${t('feature.day_night.tomorrow')} ${sunriseTime}`
  662. // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  663. }
  664. return `${t('feature.day_night.today')} ${sunriseTime}`
  665. // return `Today ${sunriseTime} - ${sunsetTime}`
  666. }
  667. if (dayDate.getDate() == new Date().getDate()) {
  668. return `${t('feature.day_night.today')} ${sunriseTime.substring(0, 5)}`
  669. // return `Today ${sunriseTime} - ${sunsetTime}`
  670. }
  671. return `${t('feature.day_night.tomorrow')} ${sunriseTime.substring(0, 5)}`
  672. }
  673. function getSunriseTime() {
  674. if (props.isNight) {
  675. if (!authInfo || !(authInfo as any).lat) {
  676. if (new Date().getHours() >= 6) {
  677. return `${t('feature.day_night.tomorrow_morning')} ${sunriseTmrTime}`
  678. }
  679. return `${t('feature.day_night.this_morning')} ${sunriseTmrTime}`
  680. // return `Yesterday ${sunsetTime} - Today ${sunriseTmrTime}`
  681. }
  682. if (nightDate.getDate() == new Date().getDate()) {
  683. return `${t('feature.day_night.tomorrow_morning')} ${sunriseTmrTime.substring(0, 5)}`
  684. }
  685. return `${t('feature.day_night.this_morning')} ${sunriseTmrTime.substring(0, 5)}`
  686. }
  687. if (!authInfo || !(authInfo as any).lat) {
  688. if (new Date().getHours() >= 18) {
  689. return `${t('feature.day_night.tomorrow')} ${sunsetTime}`
  690. // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  691. }
  692. return `${t('feature.day_night.today')} ${sunsetTime}`
  693. // return `Today ${sunriseTime} - ${sunsetTime}`
  694. }
  695. if (dayDate.getDate() == new Date().getDate()) {
  696. return `${t('feature.day_night.today')} ${sunsetTime.substring(0, 5)}`
  697. // return `Today ${sunriseTime} - ${sunsetTime}`
  698. }
  699. return `${t('feature.day_night.tomorrow')} ${sunsetTime.substring(0, 5)}`
  700. }
  701. function dayDuration() {
  702. if (!authInfo || !(authInfo as any).lat) {
  703. if (new Date().getHours() >= 18) {
  704. return `${t('feature.day_night.tomorrow')} ${sunriseTime} - ${sunsetTime}`
  705. // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  706. }
  707. return `${t('feature.day_night.today')} ${sunriseTime} - ${sunsetTime}`
  708. // return `Today ${sunriseTime} - ${sunsetTime}`
  709. }
  710. if (dayDate.getDate() == new Date().getDate()) {
  711. return `${t('feature.day_night.today')} ${sunriseTime.substring(0, 5)} - ${sunsetTime.substring(0, 5)}`
  712. // return `Today ${sunriseTime} - ${sunsetTime}`
  713. }
  714. return `${t('feature.day_night.tomorrow')} ${sunriseTime.substring(0, 5)} - ${sunsetTime.substring(0, 5)}`
  715. // return `Tomorrow ${sunriseTime} - ${sunsetTime}`
  716. }
  717. function nightDurationDesc1() {
  718. if (authInfo && authInfo.lat) {
  719. return t('feature.day_night.sunset_to_sunrise')
  720. }
  721. return t('feature.day_night.night_tip')
  722. }
  723. function dayDurationDesc1() {
  724. if (authInfo && authInfo.lat) {
  725. return t('feature.day_night.sunrise_to_sunset')
  726. }
  727. return t('feature.day_night.day_tip')
  728. }
  729. function longClick() {
  730. if (user.isLogin && user.test_user && authInfo)
  731. setShowDetailModal(true)
  732. }
  733. function showLocationAlert(e) {
  734. if (process.env.TARO_ENV == 'weapp') {
  735. e.stopPropagation()
  736. }
  737. if (isMember && authInfo && authInfo.lat) {
  738. tapCard(e)
  739. return
  740. }
  741. Taro.showModal({
  742. title: props.isNight ? t('feature.day_night.alert_required_night') : t('feature.day_night.alert_required_day'),
  743. content: props.isNight ? t('feature.day_night.alert_night_content') : t('feature.day_night.alert_day_content'),
  744. confirmText: t('feature.day_night.choose_location'),
  745. cancelText: t('feature.day_night.view_more'),
  746. success: function (res) {
  747. if (res.confirm) {
  748. auth()
  749. // console.log('用户点击确定')
  750. } else if (res.cancel) {
  751. setShowDetailPopup(true)
  752. }
  753. }
  754. })
  755. }
  756. function tapShow() {
  757. dispatch(showNight(true))
  758. dispatch(showDay(true))
  759. Taro.showModal({
  760. title: 'Login Required',
  761. content: props.isNight ? 'Log in to see your daily local nighttime from sunset to sunrise.' : 'Log in to see your daily local daytime from sunrise to sunset.',
  762. cancelText: 'Later',
  763. confirmText: 'Login',
  764. success: function (res) {
  765. if (res.confirm) {
  766. Taro.setStorage({
  767. key: 'showNightRing',
  768. data: true
  769. })
  770. Taro.setStorage({
  771. key: 'showDayRing',
  772. data: true
  773. })
  774. if (!user.isLogin) {
  775. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  776. return
  777. }
  778. } else if (res.cancel) {
  779. dispatch(showNight(false))
  780. dispatch(showDay(false))
  781. Taro.setStorage({
  782. key: 'showNightRing',
  783. data: false
  784. })
  785. Taro.setStorage({
  786. key: 'showDayRing',
  787. data: false
  788. })
  789. }
  790. }
  791. })
  792. }
  793. function operate(e) {
  794. if (process.env.TARO_ENV == 'weapp') {
  795. e.stopPropagation()
  796. }
  797. Taro.showActionSheet({
  798. itemList: ['选择位置', '重置'],
  799. success: function (res) {
  800. switch (res.tapIndex) {
  801. case 0:
  802. auth()
  803. break;
  804. case 1:
  805. reset()
  806. break;
  807. }
  808. },
  809. fail: function (res) {
  810. console.log(res.errMsg)
  811. }
  812. })
  813. }
  814. function reset() {
  815. var content = ''
  816. if (props.isNight) {
  817. if (authInfo && authInfo.lat) {
  818. content = 'Local times for sunset and sunrise, together with the nighttime ring will turn off, and your location data will be cleared. '
  819. }
  820. else {
  821. content = 'Sunset and sunrise times, together with the nighttime ring will turn off.'
  822. }
  823. }
  824. else {
  825. if (authInfo && authInfo.lat) {
  826. content = 'Local times for sunrise and sunset, together with the daytime ring will turn off, and your location data will be cleared. '
  827. }
  828. else {
  829. content = 'Sunrise and sunset times, together with the daytime ring will turn off.'
  830. }
  831. }
  832. Taro.showModal({
  833. title: 'Reset Alert',
  834. content: content,
  835. success: function (res) {
  836. if (res.confirm) {
  837. if (user.isLogin) {
  838. uploadPerm({ show_ring: false })
  839. }
  840. clearLocation().then(res => {
  841. if (global.clearNightLocation) {
  842. global.clearNightLocation()
  843. }
  844. if (global.clearDayLocation) {
  845. global.clearDayLocation()
  846. }
  847. lastNightInfo = null
  848. lastDayInfo = null
  849. dispatch(showNight(false))
  850. dispatch(showDay(false))
  851. Taro.setStorage({
  852. key: 'showNightRing',
  853. data: false
  854. })
  855. Taro.setStorage({
  856. key: 'showDayRing',
  857. data: false
  858. })
  859. })
  860. } else if (res.cancel) {
  861. console.log('用户点击取消')
  862. }
  863. }
  864. })
  865. }
  866. // return <View>
  867. // {
  868. // !user.isLogin && <View style={{ color: '#fff' }} onClick={tapShow}>{props.isNight ? '显示当地夜晚时间' : '显示当地白天时间'}</View>
  869. // }
  870. // {
  871. // user.isLogin && !dayStore.showDayRing && <View style={{ color: '#fff' }} onClick={auth}>{props.isNight ? '显示当地夜晚时间' : '显示当地白天时间'}</View>
  872. // }
  873. // {
  874. // user.isLogin && dayStore.showDayRing && <View style={{ display: 'flex', flexDirection: 'column' }} onClick={showLocationAlert} onLongPress={longClick}>
  875. // <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? nightDuration() : dayDuration()}</Text>
  876. // <Text className='day_night_desc'>{props.isNight ? nightDurationDesc1() : dayDurationDesc1()}</Text>
  877. // <View className='daynightsummary'>
  878. // <View style={{ display: 'flex', flexDirection: 'column' }}>
  879. // <Image className='sunicon' src={props.isNight ? require('@assets/images/sunset.png') :
  880. // require('@assets/images/sunrise.png')} />
  881. // <Image className='sunicon' src={props.isNight ? require('@assets/images/sunrise.png') :
  882. // require('@assets/images/sunset.png')} />
  883. // </View>
  884. // <View style={{ display: 'flex', flexDirection: 'column' }}>
  885. // <Text className='duration_title2'>{props.isNight ? '日落' : '日出'}</Text>
  886. // <Text style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? getSunsetTime() : getSunriseTime()}</Text>
  887. // <Text className='duration_title2'>{!props.isNight ? '日落' : '日出'}</Text>
  888. // <Text style={{ color: !props.isNight ? ColorType.night : ColorType.day }}>{!props.isNight ? getSunsetTime() : getSunriseTime()}</Text>
  889. // </View>
  890. // </View>
  891. // {
  892. // authInfo && authInfo.lat ?
  893. // <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(18) }} onClick={operate}>
  894. // <View className={props.isNight ? 'night_location_btn' : 'day_location_btn'}>{getLocation()}</View>
  895. // </View>
  896. // :
  897. // <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(18) }} onClick={operate}>
  898. // <View className={props.isNight ? 'night_location_btn' : 'day_location_btn'} >
  899. // {props.isNight ? t('feature.day_night.get_local_time') : t('feature.day_night.get_local_time_sunrise')}
  900. // </View>
  901. // </View>
  902. // }
  903. // </View>
  904. // }
  905. // {
  906. // showDetailPopup && modalContent()
  907. // }
  908. // {
  909. // showDetailModal && modalContent2()
  910. // }
  911. // </View>
  912. return <View style={{ color: '#fff' }} onLongPress={longClick}>
  913. <Box onClick={tapCard}>
  914. <View style={{ marginTop: -rpxToPx(14), marginBottom: -rpxToPx(14) }}>
  915. <View className='day_night_top'>
  916. {
  917. user.isLogin ? <Text className='day_night_title'>{props.isNight ? t('feature.day_night.night_ring_login') : t('feature.day_night.day_ring_login')}</Text> :
  918. <Text className='day_night_title'>{props.isNight ? t('feature.day_night.night_ring') : t('feature.day_night.day_ring')}</Text>
  919. }
  920. {
  921. user.isLogin && <View className='free' style={{ backgroundColor: props.isNight ? ColorType.night : ColorType.day, color: props.isNight ? '#fff' : '#1C1C1C' }}>{t('feature.day_night.limited_free')}</View>
  922. }
  923. <View style={{ flex: 1 }} />
  924. <View style={{ height: rpxToPx(50), display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
  925. <Switch checked={props.isNight ? dayStore.showDayRing : dayStore.showDayRing}
  926. className='switch'
  927. color={props.isNight ? ColorType.night : ColorType.day}
  928. onClick={(e) => { e.stopPropagation() }}
  929. onChange={(e) => {
  930. if (process.env.TARO_ENV == 'weapp') {
  931. e.stopPropagation()
  932. }
  933. dispatch(showNight(e.detail.value))
  934. dispatch(showDay(e.detail.value))
  935. Taro.setStorage({
  936. key: 'showNightRing',
  937. data: e.detail.value
  938. })
  939. Taro.setStorage({
  940. key: 'showDayRing',
  941. data: e.detail.value
  942. })
  943. if (user.isLogin) {
  944. uploadPerm({ show_ring: e.detail.value })
  945. }
  946. else {
  947. if (e.detail.value) {
  948. setTimeout(() => {
  949. Taro.showModal({
  950. title: props.isNight ?
  951. t('feature.day_night.night_alert_title') :
  952. t('feature.day_night.day_alert_title'),
  953. content: props.isNight ?
  954. t('feature.day_night.night_alert_content') :
  955. t('feature.day_night.day_alert_content'),
  956. showCancel: false,
  957. confirmText: t('feature.day_night.got_it')
  958. })
  959. }, 500)
  960. }
  961. }
  962. }}
  963. />
  964. </View>
  965. </View>
  966. {
  967. user.isLogin && dayStore.showDayRing && <View className='day_night_detail' onClick={showLocationAlert}>
  968. <View className='day_night_detail_icon'>
  969. {
  970. props.isNight ? <IconNight width={rpxToPx(48)} color={ColorType.night} /> : <IconDay width={rpxToPx(48)} color={ColorType.day} />
  971. }
  972. </View>
  973. <View style={{ display: 'flex', flexDirection: 'column', paddingTop: rpxToPx(8) }}>
  974. <Text className='day_night_value' style={{ color: props.isNight ? ColorType.night : ColorType.day }}>{props.isNight ? nightDuration() : dayDuration()}</Text>
  975. <Text className='day_night_desc'>{props.isNight ? nightDurationDesc1() : dayDurationDesc1()}</Text>
  976. {
  977. authInfo && authInfo.lat ?
  978. <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(18) }} onClick={auth}>
  979. <View className={props.isNight ? 'night_location_btn' : 'day_location_btn'} onClick={auth}>{getLocation()}</View>
  980. </View>
  981. :
  982. <View style={{ display: 'flex', flexDirection: 'row', marginTop: rpxToPx(18) }} onClick={auth}>
  983. <View className={props.isNight ? 'night_location_btn' : 'day_location_btn'} onClick={auth}>
  984. {props.isNight ? t('feature.day_night.get_local_time') : t('feature.day_night.get_local_time_sunrise')}
  985. </View>
  986. </View>
  987. }
  988. </View>
  989. </View>
  990. }
  991. </View>
  992. </Box >
  993. {
  994. showDetailPopup && modalContent()
  995. }
  996. {
  997. showDetailModal && modalContent2()
  998. }
  999. </View >
  1000. }