CreditCard.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { Component } from 'react';
  2. import { View, Text, StyleSheet } from 'react-native';
  3. import * as Progress from 'react-native-progress';
  4. import WebView from 'react-native-webview';
  5. import Dialog from '../../components/Dialog';
  6. import { PageList } from '../Router';
  7. export default class CreditCard extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. url: 'http://161.117.183.142/juiceplus/cardCancelPage.html',
  12. url2: 'http://baidu.com',
  13. progress: 0
  14. };
  15. }
  16. componentDidMount() {
  17. if (this.props.route.params.url) {
  18. this.setState({
  19. url: this.props.route.params.url
  20. });
  21. }
  22. }
  23. onPostMessage(data) {
  24. startPage(PageList.topup);
  25. /*if (data) {
  26. try {
  27. const msg = JSON.parse(data);
  28. if (msg.msg) {
  29. Dialog.showResultDialog(msg.msg, 'OK', back => {
  30. startPage(PageList.topup);
  31. });
  32. }
  33. } catch (error) {
  34. }
  35. console.log('WebviewMessage', data)
  36. }*/
  37. }
  38. render() {
  39. return (
  40. <View style={styles.container}>
  41. <Progress.Bar
  42. style={styles.progress}
  43. width={$vw(100)}
  44. height={2}
  45. color={colorPrimaryDark}
  46. borderWidth={0}
  47. borderRadius={0}
  48. progress={this.state.progress}/>
  49. <WebView
  50. style={ui.flex1}
  51. source={{ uri: this.state.url}}
  52. mixedContentMode={'always'}
  53. applicationNameForUserAgent={'juiceplus/1.0'}
  54. onLoadProgress={({nativeEvent}) => this.setState({ progress: nativeEvent.progress }) }
  55. onLoadEnd={(e) => {
  56. //console.log('webview-end', e)
  57. this.setState({ progress: 0 })
  58. }}
  59. onMessage={e => this.onPostMessage(e.nativeEvent.data)}/>
  60. </View>
  61. );
  62. }
  63. }
  64. const styles = StyleSheet.create({
  65. container: {
  66. flex: 1
  67. },
  68. progress: {
  69. top: 0,
  70. left: 0,
  71. position: 'absolute',
  72. }
  73. })