CreditCard.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 routeUtil from '../../utils/routeUtil';
  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. //toTopupPage()
  25. routeUtil.bridge2Page(PageList.topupNew);
  26. /*if (data) {
  27. try {
  28. const msg = JSON.parse(data);
  29. if (msg.msg) {
  30. Dialog.showResultDialog(msg.msg, $t('nav.ok'), back => {
  31. startPage(PageList.topup);
  32. });
  33. }
  34. } catch (error) {
  35. }
  36. console.log('WebviewMessage', data)
  37. }*/
  38. }
  39. render() {
  40. return (
  41. <View style={styles.container}>
  42. <Progress.Bar
  43. style={styles.progress}
  44. width={$vw(100)}
  45. height={2}
  46. color={colorPrimaryDark}
  47. borderWidth={0}
  48. borderRadius={0}
  49. progress={this.state.progress}/>
  50. <WebView
  51. style={ui.flex1}
  52. source={{ uri: this.state.url}}
  53. mixedContentMode={'always'}
  54. applicationNameForUserAgent={'juiceplus/1.0'}
  55. onLoadProgress={({nativeEvent}) => this.setState({ progress: nativeEvent.progress }) }
  56. onLoadEnd={(e) => {
  57. //console.log('webview-end', e)
  58. this.setState({ progress: 0 })
  59. }}
  60. onMessage={e => this.onPostMessage(e.nativeEvent.data)}/>
  61. </View>
  62. );
  63. }
  64. }
  65. const styles = StyleSheet.create({
  66. container: {
  67. flex: 1
  68. },
  69. progress: {
  70. top: 0,
  71. left: 0,
  72. position: 'absolute',
  73. }
  74. })