|
|
@@ -9,7 +9,7 @@ import dayjs from "dayjs";
|
|
|
import moment from 'moment-timezone'
|
|
|
import Modal from "@/components/layout/Modal.weapp";
|
|
|
import { loginAnonymous, place } from "./services/net";
|
|
|
-import Taro from "@tarojs/taro";
|
|
|
+import Taro, { useDidShow } from "@tarojs/taro";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import 'dayjs/locale/zh-cn';
|
|
|
import 'dayjs/locale/en';
|
|
|
@@ -17,13 +17,15 @@ import momentT from 'moment';
|
|
|
|
|
|
import { getTimezone, getTimezoneName, kIsAndroid } from "@/utils/tools";
|
|
|
|
|
|
-import { AppState, SafeAreaView } from "react-native";
|
|
|
+import { AppState, Linking, SafeAreaView } from "react-native";
|
|
|
import { method } from "lodash";
|
|
|
import { AtActivityIndicator } from "taro-ui";
|
|
|
+import { systemVersion } from "@/services/common";
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
// import 'moment/locale/en';
|
|
|
|
|
|
|
|
|
-
|
|
|
+let showUpdate = false;
|
|
|
let LinearGradient, useActionSheet, useNavigation
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
LinearGradient = require('react-native-linear-gradient').default
|
|
|
@@ -48,6 +50,7 @@ export default function IndexTimePage() {
|
|
|
|
|
|
useEffect(() => {
|
|
|
getLanguage();
|
|
|
+
|
|
|
AppState.addEventListener('change', handleAppStateChange);
|
|
|
login()
|
|
|
setInterval(() => {
|
|
|
@@ -68,6 +71,23 @@ export default function IndexTimePage() {
|
|
|
}, 1000)
|
|
|
}, [])
|
|
|
|
|
|
+ function login() {
|
|
|
+ loginAnonymous(kIsAndroid ? DeviceInfo.getAndroidIdSync() : DeviceInfo.getDeviceId()).then(res => {
|
|
|
+ global.token = (res as any).token
|
|
|
+ Taro.setStorage({
|
|
|
+ key: 'token',
|
|
|
+ data: (res as any).token
|
|
|
+ })
|
|
|
+ checkVersionUpdate()
|
|
|
+ }).catch(e => {
|
|
|
+ console.log('login error', e)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ useDidShow(()=>{
|
|
|
+ checkVersionUpdate()
|
|
|
+ })
|
|
|
+
|
|
|
const handleAppStateChange = (nextAppState) => {
|
|
|
console.log(nextAppState)
|
|
|
if (nextAppState != 'active') {
|
|
|
@@ -80,6 +100,36 @@ export default function IndexTimePage() {
|
|
|
|
|
|
};
|
|
|
|
|
|
+ async function checkVersionUpdate() {
|
|
|
+ systemVersion('time').then(res => {
|
|
|
+ if ((res as any).result == 'UPDATE' && !showUpdate) {
|
|
|
+ showUpdate = true
|
|
|
+ showAlert({
|
|
|
+ title: (res as any).title,
|
|
|
+ content: (res as any).description,
|
|
|
+ showCancel: true,
|
|
|
+ confirmText: 'Update',
|
|
|
+ confirm: () => {
|
|
|
+ Linking.openURL((res as any).download_url)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else if ((res as any).result == 'FORCE_UPDATE') {
|
|
|
+ showAlert({
|
|
|
+ title: (res as any).title,
|
|
|
+ content: (res as any).description,
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: 'Update',
|
|
|
+ confirm: () => {
|
|
|
+ Linking.openURL((res as any).download_url)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
function refresh() {
|
|
|
if (current) {
|
|
|
chooseLocation({
|
|
|
@@ -146,18 +196,7 @@ export default function IndexTimePage() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function login() {
|
|
|
- loginAnonymous(kIsAndroid ? DeviceInfo.getAndroidIdSync() : DeviceInfo.getDeviceId()).then(res => {
|
|
|
- global.token = (res as any).token
|
|
|
- Taro.setStorage({
|
|
|
- key: 'token',
|
|
|
- data: (res as any).token
|
|
|
- })
|
|
|
- console.log('login success', res)
|
|
|
- }).catch(e => {
|
|
|
- console.log('login error', e)
|
|
|
- })
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
async function goMap() {
|
|
|
if (loading) {
|
|
|
@@ -426,7 +465,7 @@ export default function IndexTimePage() {
|
|
|
|
|
|
<View className="location">
|
|
|
{
|
|
|
- loading && <View style={{ display: 'flex', overflow: 'hidden', height: 20, marginRight: 5 }}><AtActivityIndicator color="#CACACA"/></View>
|
|
|
+ loading && <View style={{ display: 'flex', overflow: 'hidden', height: 20, marginRight: 5 }}><AtActivityIndicator color="#CACACA" /></View>
|
|
|
}
|
|
|
{
|
|
|
loading && <Text className="location_text">{t('time_of_day.index.updating')}</Text>
|