SearchMapScreen.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* eslint-disable react/style-prop-object */
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { WebView } from "react-native-webview";
  5. import { Toast, Portal } from "@ant-design/react-native";
  6. import { useMount } from "ahooks";
  7. import { useModel } from "flooks";
  8. import { getLocation } from "../Utils/MapUtils";
  9. export default function SearchMapScreen({ navigation }) {
  10. const { saveLocation, setchooseLocal } = useModel("userModel", true);
  11. const webRef = React.useRef();
  12. const { showDialog } = useModel("dialogModel", true);
  13. useMount(() => {
  14. const key = Toast.loading("Loading...", 0);
  15. getLocation().then(res => {
  16. let location = "";
  17. // saveLocation(
  18. // "江苏省南京市建邺区白龙江东街9号新城科技园科技创新综合体",
  19. // 31.981402,
  20. // 118.737781
  21. // ).then(() => {
  22. // navigation.goBack();
  23. // });
  24. if (res.addressName !== "定位失败") {
  25. location = `${res.location.lat},${res.location.lng}`;
  26. }
  27. webRef.current.injectJavaScript(`window.setLocation('${location}')`);
  28. Portal.remove(key);
  29. });
  30. });
  31. function showChange(val, title, max, type) {
  32. showDialog({
  33. pla: "",
  34. maxLength: max || 50,
  35. defaultValue: val,
  36. InputType: type,
  37. isEdit: true,
  38. title,
  39. cancelable: true,
  40. confirmCallback: info => {
  41. console.log("当前已经选择");
  42. saveLocation(info).then(() => {
  43. navigation.goBack();
  44. });
  45. },
  46. });
  47. }
  48. return (
  49. <WebView
  50. ref={webRef}
  51. source={{
  52. uri: "http://dingdong.izouma.com/map/chooseLocation",
  53. }}
  54. style={{ flexGrow: 1, width: "100%" }}
  55. onMessage={({ nativeEvent }) => {
  56. const info = JSON.parse(nativeEvent.data);
  57. setchooseLocal(info.latlng);
  58. showChange(info.poiaddress + info.poiname, "请录入详细地址", 100);
  59. }}
  60. />
  61. );
  62. }