view.tsx
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* eslint-disable @typescript-eslint/camelcase */
/**
* @author sheng
* @description 关于信巴迪
* @date 2020/09/03
*/
import React, { useCallback, useEffect, useState, useRef } from 'react'
import { View, Image, Text, Linking } from 'react-native'
import { Toast, ModalManager, Divider, Cell } from 'react-native-mb-ui'
import { styles } from './style'
import { getVersion, getVersionCode, setUnit } from '../../libs/utils'
import { getTopVersion } from '../../api/version'
import { APP } from '../../config'
import { RouteList } from '../../router/route'
import { NavigationProp } from '@react-navigation/native'
let http
const Page: React.FC<{ navigation: NavigationProp<RouteList, 'About'> }> = ({ navigation }) => {
const [version, setVersion] = useState('')
const downUrl = useRef('')
useEffect(() => {
(async (): Promise<void> => {
const version = await getVersion()
setVersion(version)
})()
return (): void => http && http.cancel()
}, [])
/** 打开下载链接 */
const openDown = (): void => {
Linking.openURL(downUrl.current)
.then(() => { })
.catch(() => Toast.info('打开下载地址失败,请重试'))
}
const getUpdate = async (): Promise<void> => {
const versionCode = await getVersionCode()
http = getTopVersion(res => {
if (res === null) {
Toast.info('已是最新版本')
return
}
const { version_code, down, version } = res
downUrl.current = down
if (version_code > versionCode) {
ModalManager.alert({
title: '提示',
content: `发现新版本${version}需要更新,是否更新`,
button: [
{ text: '取消' },
{ text: '立即更新', onPress: openDown }
]
})
} else
Toast.info('已是最新版本')
}, err => Toast.info(err))
}
const goPage = useCallback(() => {
navigation.navigate('Privacy')
}, [navigation])
return (
<View style={styles.container}>
<View style={{ flex: 1 }}>
<View style={styles.header}>
<Image
source={require('../../assets/images/ic_launcher.png')}
style={styles.logo}
/>
<Text style={styles.name}>{APP.appName}</Text>
<Text style={styles.version}>Version {version}</Text>
</View>
<View style={styles.center}>
<Divider style={{ marginHorizontal: setUnit(25) }} />
<Cell label={'功能介绍'} onClick={(): void => navigation.navigate('Features')} />
<Cell label={'版本更新'} onClick={getUpdate} />
</View>
</View>
<View style={styles.footer}>
<Text style={styles.private} onPress={goPage}>《商城平台隐私权政策》</Text>
<Text style={styles.copyright}>
{`广州信巴迪信息科技有限公司 版权所有\nCopyright© 粤ICP备18005051号-1`}
</Text>
</View>
</View>
)
}
export default Page