view.js
2.83 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
98
99
100
/**
* @author sheng
* @description 关于信巴迪
* @date 2020/09/03
*/
import React, { useCallback, useEffect, useState, useRef } from 'react'
import { View, Image, Text, Alert, Linking } from 'react-native'
import { XbdCell, XbdDivider, XbdToast } from 'rn-ui'
import { styles } from './style'
import { getVersion, getVersionCode, setUnit } from '../../libs/utils'
import { getTopVersion } from '../../api/version'
import { APP } from '../../config'
let http
const Page = ({ navigation }) => {
const [version, setVersion] = useState('')
const downUrl = useRef('')
useEffect(() => {
getCurVersion()
return () => http && http.cancel()
}, [])
/** 打开下载链接 */
const openDown = () => {
Linking.openURL(downUrl.current)
.then(() => { })
.catch(err => {
XbdToast.show('打开下载地址失败,请重试')
})
}
const getUpdate = async () => {
const versionCode = await getVersionCode()
http = getTopVersion(APP.APP_CODE, res => {
if (res === null) return
const { version_code, down, version } = res
downUrl.current = down
if (version_code > versionCode) {
Alert.alert('提示', `发现新版本${version}需要更新,是否更新`, [
{ text: '取消' },
{ text: '立即更新', onPress: openDown }
])
} else {
XbdToast.show('已是最新版本')
}
})
}
/**获取当前版本号 */
const getCurVersion = useCallback(async () => {
const version = await getVersion()
setVersion(version)
}, [])
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}>商品交易所</Text>
<Text style={styles.version}>Version {version}</Text>
</View>
<View style={styles.center}>
<XbdDivider style={{ marginHorizontal: setUnit(25) }} />
<XbdCell
title={'功能介绍'}
onClick={() => navigation.navigate('Features')}
padLeft={setUnit(25)}
padRight={setUnit(25)}
/>
<XbdCell
title={'版本更新'}
onClick={getUpdate}
padLeft={setUnit(25)}
padRight={setUnit(25)}
/>
</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