UNPKG

@wufengteam/wform

Version:

@wufengteam/wform

99 lines 5.16 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useMemo, useState } from 'react'; import { Input, Layout, List } from 'antd'; import AMapContainer from './AMapContainer'; import { prefix } from '../utils'; import useLocation from './useLocation'; import BMapContainer from './BMapContainer'; var LocationPC = function LocationPC(_a) { var poi = _a.poi, onChange = _a.onChange, locationRange = _a.locationRange, radius = _a.radius, isAMap = _a.isAMap, restProps = __rest(_a, ["poi", "onChange", "locationRange", "radius", "isAMap"]); var _useLocation = useLocation({ currentPoi: poi, setCurrentPoi: onChange, locationRange: locationRange, radius: radius, platform: 'pc' }), onSearch = _useLocation.onSearch, poiList = _useLocation.poiList, mapRef = _useLocation.mapRef; var height = useMemo(function () { // 调整高度,防止超过屏幕可视范围 var defaultHeight = 548; var docHeight = document.documentElement.clientHeight; var maxHeight = docHeight * 0.7; return defaultHeight > maxHeight ? maxHeight : defaultHeight; }, []); var _useState = useState(''), _useState2 = _slicedToArray(_useState, 2), searchValue = _useState2[0], setSearchValue = _useState2[1]; var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), BPoiList = _useState4[0], setPoiList = _useState4[1]; return /*#__PURE__*/React.createElement(Layout, { className: "".concat(prefix, "-location-layout"), hasSider: true, style: { height: height } }, /*#__PURE__*/React.createElement(Layout.Sider, { className: "location-sider", width: 320 }, /*#__PURE__*/React.createElement(Input.Search, { className: "location-search-pc", onSearch: isAMap ? onSearch : function (val) { return setSearchValue(val); } }), /*#__PURE__*/React.createElement(List, { className: "location-list-pc", dataSource: isAMap ? poiList : BPoiList, renderItem: function renderItem(item) { return /*#__PURE__*/React.createElement(List.Item, { onClick: function onClick() { var _a, _b; if (item.point) { var BItem = item; BItem.location = item.point; BItem.name = (_a = item.title) !== null && _a !== void 0 ? _a : ''; BItem.id = (_b = item.uid) !== null && _b !== void 0 ? _b : ''; onChange === null || onChange === void 0 ? void 0 : onChange(BItem); } else { onChange === null || onChange === void 0 ? void 0 : onChange(item); } } }, /*#__PURE__*/React.createElement(List.Item.Meta, { title: item.name || item.title, description: item.address })); } })), /*#__PURE__*/React.createElement(Layout.Content, null, isAMap ? ( /*#__PURE__*/React.createElement(AMapContainer, Object.assign({ ref: mapRef, className: "map-container-pc" }, restProps))) : ( /*#__PURE__*/React.createElement(BMapContainer, Object.assign({ className: "map-container-pc", searchValue: searchValue, setPoiList: setPoiList, currentPoi: poi }, restProps))))); }; export default LocationPC;