MapScreen.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StatusBar } from 'expo-status-bar';
  4. import {
  5. Div,
  6. Button,
  7. Image,
  8. Text,
  9. Avatar,
  10. Icon,
  11. Input,
  12. } from 'react-native-magnus';
  13. import { Appbar } from 'react-native-paper';
  14. import { ScrollView } from 'react-native-gesture-handler';
  15. import { WebView } from 'react-native-webview';
  16. import useModel from 'flooks';
  17. import User from '../../flooks/User'; // detail模块通用方法
  18. import Header from '../../components/Header';
  19. import { alert } from '../../Utils/TotastUtils';
  20. export default function MapScreen({ navigation }) {
  21. const key = 'c4faf80125b298f93bbc1477db10e69c';
  22. const html = `
  23. <head lang="zh-CN">
  24. <meta charset="UTF-8">
  25. <meta name="viewport"
  26. content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  27. <meta name="mobile-web-app-capable" content="yes">
  28. <meta name="apple-mobile-web-app-capable" content="yes">
  29. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  30. <meta name="format-detection" content="address=no">
  31. <script type="text/javascript"
  32. src="https://3gimg.qq.com/lightmap/components/locationPicker2/js/main-62c2e3b971.js"></script>
  33. <title>locationPicker Components Demo - iframe</title>
  34. <style>
  35. * {
  36. margin: 0;
  37. padding: 0;
  38. }
  39. body,
  40. html {
  41. overflow: hidden;
  42. }
  43. </style>
  44. </head>
  45. <body>
  46. <!-- 通过 iframe 嵌入地图选点组件 -->
  47. <iframe id="iframe" style="width:100vw;height:100vh" frameborder=0 scrolling="no"
  48. src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K&referer=Dingdong">
  49. </iframe>
  50. <script>
  51. window.addEventListener('message', function (event) {
  52. var loc = event.data;
  53. window.ReactNativeWebView.postMessage(JSON.stringify(loc))
  54. }, false);
  55. </script>
  56. </body>
  57. `;
  58. return (
  59. <>
  60. <StatusBar backgroundColor="#fff" style="dark" translucent />
  61. <Appbar.Header
  62. theme={{ colors: { primary: '#fff' } }}
  63. style={{
  64. elevation: 0,
  65. shadowOffset: {
  66. width: 0,
  67. height: 0,
  68. },
  69. shadowOpacity: 0,
  70. zIndex: 2,
  71. }}
  72. >
  73. <Appbar.BackAction onPress={navigation.goBack} />
  74. <Appbar.Content
  75. title="选择收货地址"
  76. titleStyle={{ textAlign: 'center', fontSize: 16 }}
  77. />
  78. <Div w={56} h={56} />
  79. </Appbar.Header>
  80. <WebView
  81. source={{
  82. html,
  83. }}
  84. style={{ flexGrow: 1, width: '100%' }}
  85. onMessage={({ nativeEvent }) => {
  86. const info = JSON.parse(nativeEvent.data);
  87. console.log(info);
  88. alert('', `您当前选择的是:${info.poiaddress}`, () => {
  89. navigation.goBack();
  90. });
  91. }}
  92. />
  93. </>
  94. );
  95. }