Просмотр исходного кода

UAS移动版取消百度地图加载

zhouy 3 месяцев назад
Родитель
Сommit
4633606b9f

+ 2 - 0
uas-office-web/uas-mobile/public/index.html

@@ -29,7 +29,9 @@
 
 <body>
 <noscript>You need to enable JavaScript to run this app.</noscript>
+<!--
 <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=T1GtvYvfay3OYbSauKyRSYZCGE31mnXv"></script>
+-->
 
 <div id="root" style="width: 100%;height: 100%;"></div>
 

+ 1 - 1
uas-office-web/uas-mobile/src/components/common/formNew/FormInput.jsx

@@ -31,7 +31,7 @@ import BillModel, {
   billReadOnly,
 } from '../../../model/common/BillModel'
 
-import MapSearch from '../map/MapSearch'
+/*import MapSearch from '../map/MapSearch'*/
 
 /**
  * Created by RaoMeng on 2020/2/19

+ 8 - 2
uas-office-web/uas-mobile/src/components/common/map/MapSearch.jsx

@@ -29,6 +29,11 @@ export default class MapSearch extends Component {
   componentDidMount () {
     document.title = '地图搜索'
     this.searchBar.focus()
+    // 检查 BMap 是否存在
+    if (!window.BMap) {
+      console.warn('百度地图未加载,搜索功能将不可用')
+      return
+    }
     const { BMap } = window
     let that = this
     this.localSearch = new BMap.LocalSearch(this.map,
@@ -62,9 +67,10 @@ export default class MapSearch extends Component {
       center,
       searchList,
     } = this.state
-
+    // 只有在 BMap 可用时才渲染搜索结果
+    const showSearchResults = !!window.BMap;
     const searchItems = []
-    if (searchList) {
+    if (showSearchResults && searchList) {
       searchList.forEach((item, index) => {
         searchItems.push(
           <div