|
@@ -1,7 +1,114 @@
|
|
|
-import { View } from "@tarojs/components";
|
|
|
|
|
|
|
+import { ScrollView, View, Text, Image } from "@tarojs/components";
|
|
|
|
|
+import Taro from "@tarojs/taro";
|
|
|
|
|
+import { useEffect, useState } from "react";
|
|
|
|
|
+import { useTranslation } from "react-i18next";
|
|
|
|
|
+import './index_time.scss'
|
|
|
|
|
+import { useNavigation, useRoute } from "@react-navigation/native";
|
|
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
|
|
|
|
|
-export default function MyPlacesPage(){
|
|
|
|
|
- return <View>
|
|
|
|
|
|
|
+export default function MyPlacesPage() {
|
|
|
|
|
+ const [list, setList] = useState<any>([])
|
|
|
|
|
+ const { t } = useTranslation()
|
|
|
|
|
+ const navigation = useNavigation()
|
|
|
|
|
+ const router = useRoute()
|
|
|
|
|
+ const [current, setCurrent] = useState<any>(null)
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ navigation.setOptions({
|
|
|
|
|
+ headerTitle: 'My Places',
|
|
|
|
|
+ });
|
|
|
|
|
+ getDatas()
|
|
|
|
|
+ }, [])
|
|
|
|
|
+
|
|
|
|
|
+ async function getDatas() {
|
|
|
|
|
+ var strLocation = await getStorage('lastLocation')
|
|
|
|
|
+ if (strLocation) {
|
|
|
|
|
+ setCurrent(JSON.parse(strLocation))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var locations = await getStorage('locations')
|
|
|
|
|
+ if (locations) {
|
|
|
|
|
+ setList(JSON.parse(locations))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async function getStorage(key: string) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await Taro.getStorage({ key });
|
|
|
|
|
+ return res.data;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function getLocation(current: any) {
|
|
|
|
|
+ if (current.geo) {
|
|
|
|
|
+ if (current.geo.city) {
|
|
|
|
|
+ return current.geo.city
|
|
|
|
|
+ }
|
|
|
|
|
+ if (current.geo.country) {
|
|
|
|
|
+ return current.geo.country
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return t('time_of_day.index.unknown')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function clearAll() {
|
|
|
|
|
+ showAlert({
|
|
|
|
|
+ title: 'clear',
|
|
|
|
|
+ content: 'clear all',
|
|
|
|
|
+ showCancel: true,
|
|
|
|
|
+ confirm: () => {
|
|
|
|
|
+ if ((router.params! as any).clearLocation) {
|
|
|
|
|
+ (router.params! as any).clearLocation()
|
|
|
|
|
+ }
|
|
|
|
|
+ navigation.goBack()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function isChecked(item) {
|
|
|
|
|
+ if (current && item.geo.lat == current.geo.lat && item.geo.lng == current.geo.lng){
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return <View style={{ flex: 1, backgroundColor: '#fff' }}>
|
|
|
|
|
+ <ScrollView style={{ flex: 1 }}>
|
|
|
|
|
+ <View>
|
|
|
|
|
+ {
|
|
|
|
|
+ list.map((item, index) => {
|
|
|
|
|
+ return <View className="history_item" key={index} onClick={() => {
|
|
|
|
|
+ if ((router.params! as any).changeLocation) {
|
|
|
|
|
+ (router.params! as any).changeLocation(item)
|
|
|
|
|
+ }
|
|
|
|
|
+ navigation.goBack()
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <Text style={{ color: '#262626', fontSize: 14 }}>{getLocation(item)}</Text>
|
|
|
|
|
+ {
|
|
|
|
|
+ isChecked(item) && <Image className="check" src={require('@assets/index_time/check.png')} />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ </View>
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ <View
|
|
|
|
|
+ onClick={clearAll}
|
|
|
|
|
+ style={{
|
|
|
|
|
+ alignItems: 'center',
|
|
|
|
|
+ justifyContent: 'center',
|
|
|
|
|
+ marginTop: 15,
|
|
|
|
|
+ marginBottom: 15,
|
|
|
|
|
+ paddingTop: 15,
|
|
|
|
|
+ paddingBottom: 15,
|
|
|
|
|
+ paddingLeft: 50,
|
|
|
|
|
+ paddingRight: 50
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <Text style={{ color: '#FA5151', fontWeight: 'bold' }}>Clear All</Text>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </View>
|
|
|
|
|
+ </ScrollView>
|
|
|
</View>
|
|
</View>
|
|
|
}
|
|
}
|