@smart100/spu-web-plugin 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- var version = "1.0.13";
1
+ var version = "1.0.14";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -16162,29 +16162,32 @@ var TenantSetting = /*#__PURE__*/function () {
16162
16162
  // }
16163
16163
  // }
16164
16164
  // }
16165
- // // 高德地图key配置错误
16166
- // // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
16167
- // // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
16168
- // // // 高德地图公司key
16169
- // // tenantsetting.lbssetting.setting.type = 'amap'
16170
- // // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
16171
- // // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
16172
- // // // 高德地图个人key
16173
- // // tenantsetting.lbssetting.setting.type = 'amap'
16174
- // // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
16175
- // // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
16176
- // // tencent地图key配置错误
16177
- // // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
16178
- // // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
16179
- // // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
16180
- // // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
16165
+ // 高德地图key配置错误
16166
+ // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
16167
+ // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
16168
+ // // 高德地图公司key
16169
+ // tenantsetting.lbssetting.setting.type = 'amap'
16170
+ // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
16171
+ // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
16172
+ // // 高德地图个人key
16173
+ // tenantsetting.lbssetting.setting.type = 'amap'
16174
+ // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
16175
+ // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
16176
+ // tencent地图key配置错误
16177
+ // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
16178
+ // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
16179
+ // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
16180
+ // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
16181
16181
  // tenantsetting.lbssetting.setting.type = 'tencent'
16182
16182
  // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
16183
16183
  // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
16184
- // // 百度地图key配置错误alert以下信息
16185
- // // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
16186
- // // tenantsetting.lbssetting.setting.type = 'baidu'
16187
- // // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
16184
+ // 百度地图key配置错误alert以下信息
16185
+ // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
16186
+ // tenantsetting.lbssetting.setting.type = 'baidu'
16187
+ // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
16188
+ // tenantsetting.lbssetting.setting.type = 'tencent'
16189
+ // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT是的是的'
16190
+ // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0对对对'
16188
16191
  // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
16189
16192
  var tenantsettingStr = lsProxy.getItem('tenantsetting');
16190
16193
  if (tenantsettingStr) {
@@ -17199,40 +17202,63 @@ var MapService = /*#__PURE__*/function () {
17199
17202
  key: "_init",
17200
17203
  value: function () {
17201
17204
  var _init3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17202
- var type;
17205
+ var type, key, secretkey;
17203
17206
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17204
17207
  while (1) switch (_context2.prev = _context2.next) {
17205
17208
  case 0:
17206
17209
  type = this.type;
17210
+ key = this.key;
17211
+ secretkey = this.secretkey;
17207
17212
  if (!(type === 'tencent')) {
17208
- _context2.next = 6;
17213
+ _context2.next = 11;
17209
17214
  break;
17210
17215
  }
17211
- _context2.next = 4;
17216
+ if (!(!key || !secretkey)) {
17217
+ _context2.next = 7;
17218
+ break;
17219
+ }
17220
+ console.error('请填写腾讯地图 Web App Key 和 Web Secret Key');
17221
+ return _context2.abrupt("return");
17222
+ case 7:
17223
+ _context2.next = 9;
17212
17224
  return this.initTecent();
17213
- case 4:
17214
- _context2.next = 14;
17225
+ case 9:
17226
+ _context2.next = 25;
17215
17227
  break;
17216
- case 6:
17228
+ case 11:
17217
17229
  if (!(type === 'amap')) {
17218
- _context2.next = 11;
17230
+ _context2.next = 19;
17219
17231
  break;
17220
17232
  }
17221
- _context2.next = 9;
17233
+ if (!(!key || !secretkey)) {
17234
+ _context2.next = 15;
17235
+ break;
17236
+ }
17237
+ console.error('请填写高德地图 Web App Key 和 Web Secret Key');
17238
+ return _context2.abrupt("return");
17239
+ case 15:
17240
+ _context2.next = 17;
17222
17241
  return this.initAmap();
17223
- case 9:
17224
- _context2.next = 14;
17242
+ case 17:
17243
+ _context2.next = 25;
17225
17244
  break;
17226
- case 11:
17245
+ case 19:
17227
17246
  if (!(type === 'baidu')) {
17228
- _context2.next = 14;
17247
+ _context2.next = 25;
17248
+ break;
17249
+ }
17250
+ if (key) {
17251
+ _context2.next = 23;
17229
17252
  break;
17230
17253
  }
17231
- _context2.next = 14;
17254
+ console.error('请填写百度地图 Web App Key');
17255
+ return _context2.abrupt("return");
17256
+ case 23:
17257
+ _context2.next = 25;
17232
17258
  return this.initBaidu();
17233
- case 14:
17259
+ case 25:
17234
17260
  this.isInit = true;
17235
- case 15:
17261
+ case 26:
17236
17262
  case "end":
17237
17263
  return _context2.stop();
17238
17264
  }
@@ -17288,7 +17314,7 @@ var MapService = /*#__PURE__*/function () {
17288
17314
  case 0:
17289
17315
  // 高德地图api初始化失败 没有返回reject 因此用超时机制检测
17290
17316
  time = setTimeout(function () {
17291
- console.error('initAmap fail: 请检查 AMap key 是否正确配置');
17317
+ console.error('initAmap fail: 请检查高德地图 Web App Key 和 Web Secret Key 是否正确配置');
17292
17318
  resolve(null);
17293
17319
  }, 3000);
17294
17320
  if (_this.secretkey) {
@@ -17657,13 +17683,13 @@ var getAddressByAMap = /*#__PURE__*/function () {
17657
17683
  case 0:
17658
17684
  console.log('getAddressByAMap start...');
17659
17685
  return _context8.abrupt("return", new Promise(function (resolve, reject) {
17686
+ var _window3;
17687
+ if (!((_window3 = window) !== null && _window3 !== void 0 && _window3.AMap)) {
17688
+ console.error('getAddressByAMap fail: AMap is undefinded');
17689
+ resolve('');
17690
+ return;
17691
+ }
17660
17692
  if (position) {
17661
- var _window3;
17662
- if (!((_window3 = window) !== null && _window3 !== void 0 && _window3.AMap)) {
17663
- console.error('getAddressByAMap fail: AMap is undefinded');
17664
- resolve('');
17665
- return;
17666
- }
17667
17693
  new window.AMap.Geocoder({
17668
17694
  city: '',
17669
17695
  radius: 500
@@ -17701,6 +17727,12 @@ var getIPLocationByTMap = /*#__PURE__*/function () {
17701
17727
  case 0:
17702
17728
  console.log('getIPLocationByTMap start...');
17703
17729
  return _context9.abrupt("return", new Promise(function (resolve, reject) {
17730
+ var _window4;
17731
+ if (!((_window4 = window) !== null && _window4 !== void 0 && _window4.TMap)) {
17732
+ console.error('getIPLocationByTMap fail: TMap is undefinded');
17733
+ resolve(null);
17734
+ return;
17735
+ }
17704
17736
  var params = ip ? {
17705
17737
  ip: ip
17706
17738
  } : {};
@@ -17737,6 +17769,12 @@ var getAddressByTMap = /*#__PURE__*/function () {
17737
17769
  case 0:
17738
17770
  console.log('getAddressByTMap start...');
17739
17771
  return _context10.abrupt("return", new Promise(function (resolve, reject) {
17772
+ var _window5;
17773
+ if (!((_window5 = window) !== null && _window5 !== void 0 && _window5.TMap)) {
17774
+ console.error('getAddressByTMap fail: TMap is undefinded');
17775
+ resolve('');
17776
+ return;
17777
+ }
17740
17778
  if (position) {
17741
17779
  // debugger
17742
17780
  new window.TMap.service.Geocoder().getAddress({
@@ -17775,6 +17813,12 @@ var getLocationByBMap = /*#__PURE__*/function () {
17775
17813
  case 0:
17776
17814
  console.log('getLocationByBMap start...');
17777
17815
  return _context12.abrupt("return", new Promise(function (resolve, reject) {
17816
+ var _window6;
17817
+ if (!((_window6 = window) !== null && _window6 !== void 0 && _window6.BMap)) {
17818
+ console.error('getLocationByBMap fail: BMap is undefinded');
17819
+ resolve(null);
17820
+ return;
17821
+ }
17778
17822
  new window.BMap.Geolocation().getCurrentPosition( /*#__PURE__*/function () {
17779
17823
  var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(res) {
17780
17824
  var lng, lat, result;
@@ -17859,6 +17903,12 @@ var getCityLocationByBMap = /*#__PURE__*/function () {
17859
17903
  case 0:
17860
17904
  console.log('getCityLocationByBMap start...');
17861
17905
  return _context14.abrupt("return", new Promise(function (resolve, reject) {
17906
+ var _window7;
17907
+ if (!((_window7 = window) !== null && _window7 !== void 0 && _window7.BMap)) {
17908
+ console.error('getCityLocationByBMap fail: BMap is undefinded');
17909
+ resolve(null);
17910
+ return;
17911
+ }
17862
17912
  new window.BMap.LocalCity().get( /*#__PURE__*/function () {
17863
17913
  var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13(res) {
17864
17914
  var lng, lat, point, result;
@@ -17923,18 +17973,27 @@ var getAddressByBmap = /*#__PURE__*/function () {
17923
17973
  console.log('getAddressByBmap start...');
17924
17974
  return _context16.abrupt("return", new Promise( /*#__PURE__*/function () {
17925
17975
  var _ref16 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee15(resolve, reject) {
17976
+ var _window8;
17926
17977
  var point;
17927
17978
  return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
17928
17979
  while (1) switch (_context15.prev = _context15.next) {
17929
17980
  case 0:
17930
- if (position) {
17981
+ if ((_window8 = window) !== null && _window8 !== void 0 && _window8.BMap) {
17931
17982
  _context15.next = 4;
17932
17983
  break;
17933
17984
  }
17934
- console.error('getAddressByBmap fail');
17985
+ console.error('getAddressByBmap fail: BMap is undefinded');
17935
17986
  resolve('');
17936
17987
  return _context15.abrupt("return");
17937
17988
  case 4:
17989
+ if (position) {
17990
+ _context15.next = 8;
17991
+ break;
17992
+ }
17993
+ console.error('getAddressByBmap fail');
17994
+ resolve('');
17995
+ return _context15.abrupt("return");
17996
+ case 8:
17938
17997
  // // 把 GCJ02 转化为百度 BD09 地址
17939
17998
  // const points: any = await transformGCJ02ToBD09Points([{
17940
17999
  // lng: position.longitude,
@@ -17956,7 +18015,7 @@ var getAddressByBmap = /*#__PURE__*/function () {
17956
18015
  resolve('');
17957
18016
  }
17958
18017
  });
17959
- case 6:
18018
+ case 10:
17960
18019
  case "end":
17961
18020
  return _context15.stop();
17962
18021
  }
@@ -17978,7 +18037,7 @@ var getAddressByBmap = /*#__PURE__*/function () {
17978
18037
  }();
17979
18038
  var getLocationPromise = /*#__PURE__*/function () {
17980
18039
  var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
17981
- var _window4;
18040
+ var _window9;
17982
18041
  var isuseiplocarion,
17983
18042
  location,
17984
18043
  _args17 = arguments;
@@ -17987,7 +18046,7 @@ var getLocationPromise = /*#__PURE__*/function () {
17987
18046
  case 0:
17988
18047
  isuseiplocarion = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
17989
18048
  location = null; // 在 SPU 容器里使用 Native-API 的定位
17990
- if (!((_window4 = window) !== null && _window4 !== void 0 && (_window4 = _window4.Native) !== null && _window4 !== void 0 && _window4.getLocation)) {
18049
+ if (!((_window9 = window) !== null && _window9 !== void 0 && (_window9 = _window9.Native) !== null && _window9 !== void 0 && _window9.getLocation)) {
17991
18050
  _context17.next = 6;
17992
18051
  break;
17993
18052
  }
@@ -18005,58 +18064,61 @@ var getLocationPromise = /*#__PURE__*/function () {
18005
18064
  case 9:
18006
18065
  location = _context17.sent;
18007
18066
  case 10:
18067
+ _context17.next = 12;
18068
+ return mapService.init();
18069
+ case 12:
18008
18070
  if (location) {
18009
- _context17.next = 35;
18071
+ _context17.next = 37;
18010
18072
  break;
18011
18073
  }
18012
18074
  if (!(mapService.type === 'amap')) {
18013
- _context17.next = 21;
18075
+ _context17.next = 23;
18014
18076
  break;
18015
18077
  }
18016
- _context17.next = 14;
18078
+ _context17.next = 16;
18017
18079
  return getLocationByAMap();
18018
- case 14:
18080
+ case 16:
18019
18081
  location = _context17.sent;
18020
18082
  if (!(!location && isuseiplocarion)) {
18021
- _context17.next = 19;
18083
+ _context17.next = 21;
18022
18084
  break;
18023
18085
  }
18024
- _context17.next = 18;
18086
+ _context17.next = 20;
18025
18087
  return getCityLocationByAMap();
18026
- case 18:
18088
+ case 20:
18027
18089
  location = _context17.sent;
18028
- case 19:
18029
- _context17.next = 35;
18030
- break;
18031
18090
  case 21:
18091
+ _context17.next = 37;
18092
+ break;
18093
+ case 23:
18032
18094
  if (!(mapService.type === 'tencent' && isuseiplocarion)) {
18033
- _context17.next = 27;
18095
+ _context17.next = 29;
18034
18096
  break;
18035
18097
  }
18036
- _context17.next = 24;
18098
+ _context17.next = 26;
18037
18099
  return getIPLocationByTMap();
18038
- case 24:
18100
+ case 26:
18039
18101
  location = _context17.sent;
18040
- _context17.next = 35;
18102
+ _context17.next = 37;
18041
18103
  break;
18042
- case 27:
18104
+ case 29:
18043
18105
  if (!(mapService.type === 'baidu')) {
18044
- _context17.next = 35;
18106
+ _context17.next = 37;
18045
18107
  break;
18046
18108
  }
18047
- _context17.next = 30;
18109
+ _context17.next = 32;
18048
18110
  return getLocationByBMap();
18049
- case 30:
18111
+ case 32:
18050
18112
  location = _context17.sent;
18051
18113
  if (!(!location && isuseiplocarion)) {
18052
- _context17.next = 35;
18114
+ _context17.next = 37;
18053
18115
  break;
18054
18116
  }
18055
- _context17.next = 34;
18117
+ _context17.next = 36;
18056
18118
  return getCityLocationByBMap();
18057
- case 34:
18119
+ case 36:
18058
18120
  location = _context17.sent;
18059
- case 35:
18121
+ case 37:
18060
18122
  // 开发模式下为了方便测试提供虚拟定位
18061
18123
  if (!location && urlquery.isvirtuallocation) {
18062
18124
  location = {
@@ -18078,23 +18140,23 @@ var getLocationPromise = /*#__PURE__*/function () {
18078
18140
  // }
18079
18141
  // }
18080
18142
  if (!(location && !location.address)) {
18081
- _context17.next = 43;
18143
+ _context17.next = 45;
18082
18144
  break;
18083
18145
  }
18084
- _context17.next = 39;
18146
+ _context17.next = 41;
18085
18147
  return getAddress(location);
18086
- case 39:
18148
+ case 41:
18087
18149
  _context17.t0 = _context17.sent;
18088
18150
  if (_context17.t0) {
18089
- _context17.next = 42;
18151
+ _context17.next = 44;
18090
18152
  break;
18091
18153
  }
18092
18154
  _context17.t0 = '经纬度获取成功,但地址获取失败。';
18093
- case 42:
18155
+ case 44:
18094
18156
  location.address = _context17.t0;
18095
- case 43:
18157
+ case 45:
18096
18158
  return _context17.abrupt("return", location);
18097
- case 44:
18159
+ case 46:
18098
18160
  case "end":
18099
18161
  return _context17.stop();
18100
18162
  }
@@ -18119,27 +18181,24 @@ function _getLocation() {
18119
18181
  while (1) switch (_context20.prev = _context20.next) {
18120
18182
  case 0:
18121
18183
  isuseiplocarion = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18122
- _context20.next = 3;
18123
- return mapService.init();
18124
- case 3:
18125
18184
  if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18126
- _context20.next = 5;
18185
+ _context20.next = 3;
18127
18186
  break;
18128
18187
  }
18129
18188
  return _context20.abrupt("return", cloneDeep$1(lastLocation));
18130
- case 5:
18189
+ case 3:
18131
18190
  if (!(runing && locationPromise)) {
18132
- _context20.next = 7;
18191
+ _context20.next = 5;
18133
18192
  break;
18134
18193
  }
18135
18194
  return _context20.abrupt("return", locationPromise);
18136
- case 7:
18195
+ case 5:
18137
18196
  // console.log('runing')
18138
18197
  runing = true;
18139
18198
  locationPromise = getLocationPromise(isuseiplocarion);
18140
- _context20.next = 11;
18199
+ _context20.next = 9;
18141
18200
  return locationPromise;
18142
- case 11:
18201
+ case 9:
18143
18202
  locationRes = _context20.sent;
18144
18203
  runing = false;
18145
18204
  if (locationRes) {
@@ -18147,7 +18206,7 @@ function _getLocation() {
18147
18206
  lastLocation = locationRes;
18148
18207
  }
18149
18208
  return _context20.abrupt("return", locationRes);
18150
- case 15:
18209
+ case 13:
18151
18210
  case "end":
18152
18211
  return _context20.stop();
18153
18212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
@@ -101,11 +101,25 @@ class MapService {
101
101
 
102
102
  private async _init() {
103
103
  const type = this.type
104
+ const key = this.key
105
+ const secretkey = this.secretkey
104
106
  if (type === 'tencent') {
107
+ if (!key || !secretkey) {
108
+ console.error('请填写腾讯地图 Web App Key 和 Web Secret Key')
109
+ return
110
+ }
105
111
  await this.initTecent()
106
112
  } else if (type === 'amap') {
113
+ if (!key || !secretkey) {
114
+ console.error('请填写高德地图 Web App Key 和 Web Secret Key')
115
+ return
116
+ }
107
117
  await this.initAmap()
108
118
  } else if (type === 'baidu') {
119
+ if (!key) {
120
+ console.error('请填写百度地图 Web App Key')
121
+ return
122
+ }
109
123
  await this.initBaidu()
110
124
  }
111
125
  this.isInit = true
@@ -130,7 +144,7 @@ class MapService {
130
144
  return new Promise(async (resolve, reject) => {
131
145
  // 高德地图api初始化失败 没有返回reject 因此用超时机制检测
132
146
  const time = setTimeout(() => {
133
- console.error('initAmap fail: 请检查 AMap key 是否正确配置')
147
+ console.error('initAmap fail: 请检查高德地图 Web App Key 和 Web Secret Key 是否正确配置')
134
148
  resolve(null)
135
149
  }, 3000)
136
150
 
package/src/map/index.ts CHANGED
@@ -241,12 +241,12 @@ const getCityLocationByAMap = async (): Promise<Location> => {
241
241
  const getAddressByAMap = async (position: Location): Promise<string> => {
242
242
  console.log('getAddressByAMap start...')
243
243
  return new Promise((resolve, reject) => {
244
+ if (!window?.AMap) {
245
+ console.error('getAddressByAMap fail: AMap is undefinded')
246
+ resolve('')
247
+ return
248
+ }
244
249
  if (position) {
245
- if (!window?.AMap) {
246
- console.error('getAddressByAMap fail: AMap is undefinded')
247
- resolve('')
248
- return
249
- }
250
250
  new window.AMap.Geocoder({
251
251
  city: '',
252
252
  radius: 500
@@ -271,6 +271,12 @@ const getAddressByAMap = async (position: Location): Promise<string> => {
271
271
  const getIPLocationByTMap = async (ip?: string): Promise<Location> => {
272
272
  console.log('getIPLocationByTMap start...')
273
273
  return new Promise((resolve, reject) => {
274
+ if (!window?.TMap) {
275
+ console.error('getIPLocationByTMap fail: TMap is undefinded')
276
+ resolve(null)
277
+ return
278
+ }
279
+
274
280
  const params = ip ? { ip } : {}
275
281
  new window.TMap.service.IPLocation()
276
282
  .locate({ ...params, servicesk: mapService.secretkey })
@@ -294,6 +300,12 @@ const getIPLocationByTMap = async (ip?: string): Promise<Location> => {
294
300
  const getAddressByTMap = async (position: Location): Promise<string> => {
295
301
  console.log('getAddressByTMap start...')
296
302
  return new Promise((resolve, reject) => {
303
+ if (!window?.TMap) {
304
+ console.error('getAddressByTMap fail: TMap is undefinded')
305
+ resolve('')
306
+ return
307
+ }
308
+
297
309
  if (position) {
298
310
  // debugger
299
311
  new window.TMap.service.Geocoder()
@@ -322,6 +334,11 @@ const getAddressByTMap = async (position: Location): Promise<string> => {
322
334
  const getLocationByBMap = async (): Promise<Location> => {
323
335
  console.log('getLocationByBMap start...')
324
336
  return new Promise((resolve, reject) => {
337
+ if (!window?.BMap) {
338
+ console.error('getLocationByBMap fail: BMap is undefinded')
339
+ resolve(null)
340
+ return
341
+ }
325
342
  new window.BMap.Geolocation().getCurrentPosition(
326
343
  async (res: any) => {
327
344
  // console.log(res)
@@ -384,6 +401,11 @@ const getLocationByBMap = async (): Promise<Location> => {
384
401
  const getCityLocationByBMap = async (): Promise<Location> => {
385
402
  console.log('getCityLocationByBMap start...')
386
403
  return new Promise((resolve, reject) => {
404
+ if (!window?.BMap) {
405
+ console.error('getCityLocationByBMap fail: BMap is undefinded')
406
+ resolve(null)
407
+ return
408
+ }
387
409
  new window.BMap.LocalCity().get(async (res: any) => {
388
410
  // console.log(res)
389
411
  // debugger
@@ -417,7 +439,12 @@ const getCityLocationByBMap = async (): Promise<Location> => {
417
439
  const getAddressByBmap = async (position: Location): Promise<string> => {
418
440
  console.log('getAddressByBmap start...')
419
441
  return new Promise(async (resolve, reject) => {
420
- // resolve('')
442
+ if (!window?.BMap) {
443
+ console.error('getAddressByBmap fail: BMap is undefinded')
444
+ resolve('')
445
+ return
446
+ }
447
+
421
448
  if (!position) {
422
449
  console.error('getAddressByBmap fail')
423
450
  resolve('')
@@ -462,6 +489,8 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
462
489
  }
463
490
  // location = null
464
491
 
492
+ await mapService.init()
493
+
465
494
  if (!location) {
466
495
  if (mapService.type === 'amap') {
467
496
  location = await getLocationByAMap()
@@ -515,7 +544,6 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
515
544
  // https://www.jianshu.com/p/559029832a67
516
545
  // 不能精确定位的情况下是否启用ip城市定位,ip定位用于不需要精确定位的场景
517
546
  async function getLocation(isuseiplocarion = false) {
518
- await mapService.init()
519
547
  // debugger
520
548
  // 缓存30秒
521
549
  if (datetime && Date.now() - datetime <= cachetime && lastLocation && !runing) {
@@ -60,33 +60,39 @@ class TenantSetting {
60
60
  // }
61
61
  // }
62
62
 
63
- // // 高德地图key配置错误
64
- // // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
65
- // // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
66
-
67
- // // // 高德地图公司key
68
- // // tenantsetting.lbssetting.setting.type = 'amap'
69
- // // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
70
- // // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
71
-
72
- // // // 高德地图个人key
73
- // // tenantsetting.lbssetting.setting.type = 'amap'
74
- // // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
75
- // // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
76
-
77
- // // tencent地图key配置错误
78
- // // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
79
- // // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
80
- // // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
81
- // // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
63
+ // 高德地图key配置错误
64
+ // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
65
+ // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
66
+
67
+ // // 高德地图公司key
68
+ // tenantsetting.lbssetting.setting.type = 'amap'
69
+ // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
70
+ // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
71
+
72
+ // // 高德地图个人key
73
+ // tenantsetting.lbssetting.setting.type = 'amap'
74
+ // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
75
+ // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
76
+
77
+ // tencent地图key配置错误
78
+ // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
79
+ // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
80
+ // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
81
+ // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
82
82
  // tenantsetting.lbssetting.setting.type = 'tencent'
83
83
  // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
84
84
  // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
85
85
 
86
- // // 百度地图key配置错误alert以下信息
87
- // // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
88
- // // tenantsetting.lbssetting.setting.type = 'baidu'
89
- // // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
86
+ // 百度地图key配置错误alert以下信息
87
+ // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
88
+ // tenantsetting.lbssetting.setting.type = 'baidu'
89
+ // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
90
+
91
+
92
+
93
+ // tenantsetting.lbssetting.setting.type = 'tencent'
94
+ // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT是的是的'
95
+ // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0对对对'
90
96
 
91
97
  // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
92
98