@smart100/spu-web-plugin 1.0.11 → 1.0.12

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.11";
1
+ var version = "1.0.12";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -16142,34 +16142,37 @@ var TenantSetting = /*#__PURE__*/function () {
16142
16142
  }, {
16143
16143
  key: "get",
16144
16144
  value: function get(key) {
16145
+ // const tenantsetting = {
16146
+ // lbssetting: {
16147
+ // enable: '1',
16148
+ // setting: {
16149
+ // type: '',
16150
+ // key: {
16151
+ // web: '',
16152
+ // android: '',
16153
+ // ios: '',
16154
+ // harmony: ''
16155
+ // },
16156
+ // secretkey: {
16157
+ // web: '',
16158
+ // android: '',
16159
+ // ios: '',
16160
+ // harmony: ''
16161
+ // }
16162
+ // }
16163
+ // }
16164
+ // }
16165
+ // tenantsetting.lbssetting.setting.type = 'amap'
16166
+ // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
16167
+ // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
16168
+ // // tenantsetting.lbssetting.setting.type = 'tencent'
16169
+ // // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
16170
+ // // tenantsetting.lbssetting.setting.type = 'baidu'
16171
+ // // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
16172
+ // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
16145
16173
  var tenantsettingStr = lsProxy.getItem('tenantsetting');
16146
16174
  if (tenantsettingStr) {
16147
16175
  var tenantsetting = JSON.parse(tenantsettingStr);
16148
- // tenantsetting.lbssetting = {
16149
- // enable: '1',
16150
- // setting: {
16151
- // type: '',
16152
- // key: {
16153
- // web: '',
16154
- // android: '',
16155
- // ios: '',
16156
- // harmony: ''
16157
- // },
16158
- // secretkey: {
16159
- // web: '',
16160
- // android: '',
16161
- // ios: '',
16162
- // harmony: ''
16163
- // }
16164
- // }
16165
- // }
16166
- // tenantsetting.lbssetting.setting.type = 'amap'
16167
- // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
16168
- // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
16169
- // tenantsetting.lbssetting.setting.type = 'tencent'
16170
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
16171
- // tenantsetting.lbssetting.setting.type = 'baidu'
16172
- // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
16173
16176
  if (key) {
16174
16177
  return tenantsetting[key];
16175
16178
  }
@@ -17261,13 +17264,13 @@ var MapService = /*#__PURE__*/function () {
17261
17264
  return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17262
17265
  while (1) switch (_context4.prev = _context4.next) {
17263
17266
  case 0:
17264
- // if (this.secretkey) {
17265
- // window._AMapSecurityConfig = {
17266
- // securityJsCode: this.secretkey
17267
- // }
17268
- // }
17269
- plugin = ['AMap.Geolocation']; // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
17270
- _context4.next = 3;
17267
+ if (this.secretkey) {
17268
+ window._AMapSecurityConfig = {
17269
+ securityJsCode: this.secretkey
17270
+ };
17271
+ }
17272
+ plugin = ['AMap.Geolocation', 'AMap.Geocoder'];
17273
+ _context4.next = 4;
17271
17274
  return AMapLoader$1.load({
17272
17275
  key: this.key,
17273
17276
  version: '2.0',
@@ -17277,7 +17280,7 @@ var MapService = /*#__PURE__*/function () {
17277
17280
  plugins: []
17278
17281
  }
17279
17282
  });
17280
- case 3:
17283
+ case 4:
17281
17284
  AMap = _context4.sent;
17282
17285
  window.AMap = AMap;
17283
17286
  this.AMap = AMap;
@@ -17287,7 +17290,7 @@ var MapService = /*#__PURE__*/function () {
17287
17290
  // console.log(window.AMapUI)
17288
17291
  // console.log(window.AMapLoader)
17289
17292
  // console.log(window.AMap === aaaa)
17290
- case 7:
17293
+ case 8:
17291
17294
  case "end":
17292
17295
  return _context4.stop();
17293
17296
  }
@@ -17717,34 +17720,32 @@ var getCityLocationByAmap = /*#__PURE__*/function () {
17717
17720
  // 高德逆地址解析
17718
17721
  var getAddressByAmap = /*#__PURE__*/function () {
17719
17722
  var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(position) {
17720
- var address;
17721
17723
  return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
17722
17724
  while (1) switch (_context8.prev = _context8.next) {
17723
17725
  case 0:
17724
17726
  console.log('getAddressByAmap start...');
17725
- console.log('getAddressByAmap changeto getAddressByIpaas');
17726
- // return new Promise((resolve, reject) => {
17727
- // if (position) {
17728
- // new window.AMap.Geocoder({
17729
- // city: '',
17730
- // radius: 500
17731
- // }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
17732
- // if (status === 'complete' && result.info === 'OK' && result.regeocode) {
17733
- // resolve(result?.regeocode?.formattedAddress || '')
17734
- // } else {
17735
- // console.error('getAddressByAmap fail')
17736
- // resolve('')
17737
- // }
17738
- // })
17739
- // }
17740
- // })
17741
- // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
17742
- _context8.next = 4;
17743
- return getAddressByIpaas(position);
17744
- case 4:
17745
- address = _context8.sent;
17746
- return _context8.abrupt("return", address);
17747
- case 6:
17727
+ return _context8.abrupt("return", new Promise(function (resolve, reject) {
17728
+ if (position) {
17729
+ new window.AMap.Geocoder({
17730
+ city: '',
17731
+ radius: 500
17732
+ }).getAddress([position.longitude, position.latitude], function (status, result) {
17733
+ var _result$regeocode;
17734
+ // console.log(status)
17735
+ // console.log(result)
17736
+ // debugger
17737
+ if (status === 'complete' && result.info === 'OK' && result !== null && result !== void 0 && (_result$regeocode = result.regeocode) !== null && _result$regeocode !== void 0 && _result$regeocode.formattedAddress) {
17738
+ var address = result.regeocode.formattedAddress || '';
17739
+ console.log("getAddressByAmap success: ".concat(address));
17740
+ resolve(address);
17741
+ } else {
17742
+ console.error("getAddressByAmap fail: status = ".concat(status, ", result = ").concat(result));
17743
+ resolve('');
17744
+ }
17745
+ });
17746
+ }
17747
+ }));
17748
+ case 2:
17748
17749
  case "end":
17749
17750
  return _context8.stop();
17750
17751
  }
@@ -18037,94 +18038,96 @@ var getAddressByBmap = /*#__PURE__*/function () {
18037
18038
  return _ref15.apply(this, arguments);
18038
18039
  };
18039
18040
  }();
18040
- // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 地图商高精度定位 > 地图商城市ip定位
18041
18041
  var getLocationPromise = /*#__PURE__*/function () {
18042
18042
  var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
18043
18043
  var _window;
18044
- var location;
18044
+ var isuseiplocarion,
18045
+ location,
18046
+ _args17 = arguments;
18045
18047
  return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18046
18048
  while (1) switch (_context17.prev = _context17.next) {
18047
18049
  case 0:
18050
+ isuseiplocarion = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18048
18051
  location = null; // 在 SPU 容器里使用 Native-API 的定位
18049
18052
  if (!((_window = window) !== null && _window !== void 0 && (_window = _window.Native) !== null && _window !== void 0 && _window.getLocation)) {
18050
- _context17.next = 5;
18053
+ _context17.next = 6;
18051
18054
  break;
18052
18055
  }
18053
- _context17.next = 4;
18056
+ _context17.next = 5;
18054
18057
  return getLocationByNative();
18055
- case 4:
18056
- location = _context17.sent;
18057
18058
  case 5:
18059
+ location = _context17.sent;
18060
+ case 6:
18058
18061
  if (location) {
18059
- _context17.next = 9;
18062
+ _context17.next = 10;
18060
18063
  break;
18061
18064
  }
18062
- _context17.next = 8;
18065
+ _context17.next = 9;
18063
18066
  return getLocationByNavigator();
18064
- case 8:
18065
- location = _context17.sent;
18066
18067
  case 9:
18068
+ location = _context17.sent;
18069
+ case 10:
18067
18070
  if (location) {
18068
- _context17.next = 34;
18071
+ _context17.next = 39;
18069
18072
  break;
18070
18073
  }
18071
18074
  if (!(mapService.type === 'amap')) {
18072
- _context17.next = 20;
18075
+ _context17.next = 25;
18073
18076
  break;
18074
18077
  }
18075
- _context17.next = 13;
18078
+ _context17.next = 14;
18076
18079
  return getLocationByAmap();
18077
- case 13:
18080
+ case 14:
18078
18081
  location = _context17.sent;
18079
- if (location) {
18080
- _context17.next = 18;
18082
+ if (!(!location && isuseiplocarion)) {
18083
+ _context17.next = 19;
18081
18084
  break;
18082
18085
  }
18083
- _context17.next = 17;
18086
+ _context17.next = 18;
18084
18087
  return getCityLocationByAmap();
18085
- case 17:
18086
- location = _context17.sent;
18087
18088
  case 18:
18088
- _context17.next = 34;
18089
+ location = _context17.sent;
18090
+ case 19:
18091
+ if (!(!location && isuseiplocarion)) {
18092
+ _context17.next = 23;
18093
+ break;
18094
+ }
18095
+ _context17.next = 22;
18096
+ return getIPLocationByIpaas();
18097
+ case 22:
18098
+ location = _context17.sent;
18099
+ case 23:
18100
+ _context17.next = 39;
18089
18101
  break;
18090
- case 20:
18091
- if (!(mapService.type === 'tencent')) {
18092
- _context17.next = 26;
18102
+ case 25:
18103
+ if (!(mapService.type === 'tencent' && isuseiplocarion)) {
18104
+ _context17.next = 31;
18093
18105
  break;
18094
18106
  }
18095
- _context17.next = 23;
18107
+ _context17.next = 28;
18096
18108
  return getIPLocationByTMap();
18097
- case 23:
18109
+ case 28:
18098
18110
  location = _context17.sent;
18099
- _context17.next = 34;
18111
+ _context17.next = 39;
18100
18112
  break;
18101
- case 26:
18113
+ case 31:
18102
18114
  if (!(mapService.type === 'baidu')) {
18103
- _context17.next = 34;
18115
+ _context17.next = 39;
18104
18116
  break;
18105
18117
  }
18106
- _context17.next = 29;
18118
+ _context17.next = 34;
18107
18119
  return getLocationByBMap();
18108
- case 29:
18120
+ case 34:
18109
18121
  location = _context17.sent;
18110
- if (location) {
18111
- _context17.next = 34;
18122
+ if (!(!location && isuseiplocarion)) {
18123
+ _context17.next = 39;
18112
18124
  break;
18113
18125
  }
18114
- _context17.next = 33;
18126
+ _context17.next = 38;
18115
18127
  return getCityLocationByBMap();
18116
- case 33:
18117
- location = _context17.sent;
18118
- case 34:
18119
- if (location) {
18120
- _context17.next = 38;
18121
- break;
18122
- }
18123
- _context17.next = 37;
18124
- return getIPLocationByIpaas();
18125
- case 37:
18126
- location = _context17.sent;
18127
18128
  case 38:
18129
+ location = _context17.sent;
18130
+ case 39:
18128
18131
  // 开发模式下为了方便测试提供虚拟定位
18129
18132
  if (!location && urlquery.isvirtuallocation) {
18130
18133
  location = {
@@ -18133,23 +18136,23 @@ var getLocationPromise = /*#__PURE__*/function () {
18133
18136
  };
18134
18137
  }
18135
18138
  if (!(location && !location.address)) {
18136
- _context17.next = 46;
18139
+ _context17.next = 47;
18137
18140
  break;
18138
18141
  }
18139
- _context17.next = 42;
18142
+ _context17.next = 43;
18140
18143
  return getAddress(location);
18141
- case 42:
18144
+ case 43:
18142
18145
  _context17.t0 = _context17.sent;
18143
18146
  if (_context17.t0) {
18144
- _context17.next = 45;
18147
+ _context17.next = 46;
18145
18148
  break;
18146
18149
  }
18147
18150
  _context17.t0 = '经纬度获取成功,但地址获取失败。';
18148
- case 45:
18149
- location.address = _context17.t0;
18150
18151
  case 46:
18151
- return _context17.abrupt("return", location);
18152
+ location.address = _context17.t0;
18152
18153
  case 47:
18154
+ return _context17.abrupt("return", location);
18155
+ case 48:
18153
18156
  case "end":
18154
18157
  return _context17.stop();
18155
18158
  }
@@ -18161,36 +18164,40 @@ var getLocationPromise = /*#__PURE__*/function () {
18161
18164
  }();
18162
18165
  // WGS84 GCJ-02 BD-09 坐标系
18163
18166
  // https://www.jianshu.com/p/559029832a67
18167
+ // 不能精确定位的情况下是否启用ip城市定位,ip定位用于不需要精确定位的场景
18164
18168
  function getLocation() {
18165
18169
  return _getLocation.apply(this, arguments);
18166
18170
  } // 逆地址解析
18167
18171
  function _getLocation() {
18168
18172
  _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
18169
- var locationRes;
18173
+ var isuseiplocarion,
18174
+ locationRes,
18175
+ _args20 = arguments;
18170
18176
  return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18171
18177
  while (1) switch (_context20.prev = _context20.next) {
18172
18178
  case 0:
18173
- _context20.next = 2;
18179
+ isuseiplocarion = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18180
+ _context20.next = 3;
18174
18181
  return mapService.init();
18175
- case 2:
18182
+ case 3:
18176
18183
  if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18177
- _context20.next = 4;
18184
+ _context20.next = 5;
18178
18185
  break;
18179
18186
  }
18180
18187
  return _context20.abrupt("return", cloneDeep$1(lastLocation));
18181
- case 4:
18188
+ case 5:
18182
18189
  if (!(runing && locationPromise)) {
18183
- _context20.next = 6;
18190
+ _context20.next = 7;
18184
18191
  break;
18185
18192
  }
18186
18193
  return _context20.abrupt("return", locationPromise);
18187
- case 6:
18194
+ case 7:
18188
18195
  // console.log('runing')
18189
18196
  runing = true;
18190
- locationPromise = getLocationPromise();
18191
- _context20.next = 10;
18197
+ locationPromise = getLocationPromise(isuseiplocarion);
18198
+ _context20.next = 11;
18192
18199
  return locationPromise;
18193
- case 10:
18200
+ case 11:
18194
18201
  locationRes = _context20.sent;
18195
18202
  runing = false;
18196
18203
  if (locationRes) {
@@ -18198,7 +18205,7 @@ function _getLocation() {
18198
18205
  lastLocation = locationRes;
18199
18206
  }
18200
18207
  return _context20.abrupt("return", locationRes);
18201
- case 14:
18208
+ case 15:
18202
18209
  case "end":
18203
18210
  return _context20.stop();
18204
18211
  }
@@ -18215,49 +18222,53 @@ var getAddress = /*#__PURE__*/function () {
18215
18222
  _context18.next = 2;
18216
18223
  return mapService.init();
18217
18224
  case 2:
18218
- address = ''; // 先统一用ipaas解析 因为需要储存一致的地址格式(各地图商逆地址查询的地址格式不统一)
18219
- // 如果不行再按照各地图商解析
18220
- _context18.next = 5;
18221
- return getAddressByIpaas(position);
18222
- case 5:
18223
- address = _context18.sent;
18225
+ address = '';
18224
18226
  if (address) {
18225
- _context18.next = 23;
18227
+ _context18.next = 24;
18226
18228
  break;
18227
18229
  }
18228
18230
  if (!(mapService.type === 'amap')) {
18229
- _context18.next = 13;
18231
+ _context18.next = 14;
18230
18232
  break;
18231
18233
  }
18232
- _context18.next = 10;
18234
+ _context18.next = 7;
18233
18235
  return getAddressByAmap(position);
18234
- case 10:
18236
+ case 7:
18235
18237
  address = _context18.sent;
18236
- _context18.next = 23;
18238
+ if (address) {
18239
+ _context18.next = 12;
18240
+ break;
18241
+ }
18242
+ _context18.next = 11;
18243
+ return getAddressByIpaas(position);
18244
+ case 11:
18245
+ address = _context18.sent;
18246
+ case 12:
18247
+ _context18.next = 24;
18237
18248
  break;
18238
- case 13:
18249
+ case 14:
18239
18250
  if (!(mapService.type === 'tencent')) {
18240
- _context18.next = 19;
18251
+ _context18.next = 20;
18241
18252
  break;
18242
18253
  }
18243
- _context18.next = 16;
18254
+ _context18.next = 17;
18244
18255
  return getAddressByTMap(position);
18245
- case 16:
18256
+ case 17:
18246
18257
  address = _context18.sent;
18247
- _context18.next = 23;
18258
+ _context18.next = 24;
18248
18259
  break;
18249
- case 19:
18260
+ case 20:
18250
18261
  if (!(mapService.type === 'baidu')) {
18251
- _context18.next = 23;
18262
+ _context18.next = 24;
18252
18263
  break;
18253
18264
  }
18254
- _context18.next = 22;
18265
+ _context18.next = 23;
18255
18266
  return getAddressByBmap(position);
18256
- case 22:
18257
- address = _context18.sent;
18258
18267
  case 23:
18259
- return _context18.abrupt("return", address);
18268
+ address = _context18.sent;
18260
18269
  case 24:
18270
+ return _context18.abrupt("return", address);
18271
+ case 25:
18261
18272
  case "end":
18262
18273
  return _context18.stop();
18263
18274
  }
@@ -52888,9 +52899,7 @@ var load = function load(options) {
52888
52899
  };
52889
52900
  }
52890
52901
  }
52891
- // 不开放地址查询 改用ipaas
52892
- var plugin = ['AMap.Geolocation'];
52893
- // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
52902
+ var plugin = ['AMap.Geolocation', 'AMap.Geocoder'];
52894
52903
  return AMapLoader$1.load({
52895
52904
  key: AMapKey.key,
52896
52905
  version: '2.0',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
@@ -22,9 +22,7 @@ const load = (options?: {
22
22
  }
23
23
  }
24
24
 
25
- // 不开放地址查询 改用ipaas
26
- const plugin = ['AMap.Geolocation']
27
- // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
25
+ const plugin = ['AMap.Geolocation', 'AMap.Geocoder']
28
26
 
29
27
  return AMapLoader.load({
30
28
  key: AMapKey.key,
@@ -127,14 +127,13 @@ class MapService {
127
127
  }
128
128
 
129
129
  private async initAmap() {
130
- // if (this.secretkey) {
131
- // window._AMapSecurityConfig = {
132
- // securityJsCode: this.secretkey
133
- // }
134
- // }
130
+ if (this.secretkey) {
131
+ window._AMapSecurityConfig = {
132
+ securityJsCode: this.secretkey
133
+ }
134
+ }
135
135
 
136
- const plugin = ['AMap.Geolocation']
137
- // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
136
+ const plugin = ['AMap.Geolocation', 'AMap.Geocoder']
138
137
 
139
138
  const AMap = await AMapLoader.load({
140
139
  key: this.key,
package/src/map/index.ts CHANGED
@@ -232,25 +232,26 @@ const getCityLocationByAmap = async (): Promise<Location> => {
232
232
  // 高德逆地址解析
233
233
  const getAddressByAmap = async (position: Location): Promise<string> => {
234
234
  console.log('getAddressByAmap start...')
235
- console.log('getAddressByAmap changeto getAddressByIpaas')
236
- // return new Promise((resolve, reject) => {
237
- // if (position) {
238
- // new window.AMap.Geocoder({
239
- // city: '',
240
- // radius: 500
241
- // }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
242
- // if (status === 'complete' && result.info === 'OK' && result.regeocode) {
243
- // resolve(result?.regeocode?.formattedAddress || '')
244
- // } else {
245
- // console.error('getAddressByAmap fail')
246
- // resolve('')
247
- // }
248
- // })
249
- // }
250
- // })
251
- // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
252
- const address = await getAddressByIpaas(position)
253
- return address
235
+ return new Promise((resolve, reject) => {
236
+ if (position) {
237
+ new window.AMap.Geocoder({
238
+ city: '',
239
+ radius: 500
240
+ }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
241
+ // console.log(status)
242
+ // console.log(result)
243
+ // debugger
244
+ if (status === 'complete' && result.info === 'OK' && result?.regeocode?.formattedAddress) {
245
+ const address = result.regeocode.formattedAddress || ''
246
+ console.log(`getAddressByAmap success: ${address}`)
247
+ resolve(address)
248
+ } else {
249
+ console.error(`getAddressByAmap fail: status = ${status}, result = ${result}`)
250
+ resolve('')
251
+ }
252
+ })
253
+ }
254
+ })
254
255
  }
255
256
 
256
257
  // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
@@ -437,8 +438,7 @@ const getAddressByBmap = async (position: Location): Promise<string> => {
437
438
  })
438
439
  }
439
440
 
440
- // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 地图商高精度定位 > 地图商城市ip定位
441
- const getLocationPromise = async (): Promise<Location> => {
441
+ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> => {
442
442
  let location: Location = null
443
443
 
444
444
  // 在 SPU 容器里使用 Native-API 的定位
@@ -449,29 +449,27 @@ const getLocationPromise = async (): Promise<Location> => {
449
449
  if (!location) {
450
450
  location = await getLocationByNavigator()
451
451
  }
452
+ // location = null
452
453
 
453
454
  if (!location) {
454
455
  if (mapService.type === 'amap') {
455
456
  location = await getLocationByAmap()
456
- // ip城市定位结果不精确 但总比定不到位好
457
- if (!location) {
457
+ if (!location && isuseiplocarion) {
458
458
  location = await getCityLocationByAmap()
459
459
  }
460
- } else if (mapService.type === 'tencent') {
460
+ if (!location && isuseiplocarion) {
461
+ location = await getIPLocationByIpaas()
462
+ }
463
+ } else if (mapService.type === 'tencent' && isuseiplocarion) {
461
464
  location = await getIPLocationByTMap()
462
465
  } else if (mapService.type === 'baidu') {
463
466
  location = await getLocationByBMap()
464
- // ip城市定位结果不精确 但总比定不到位好
465
- if (!location) {
467
+ if (!location && isuseiplocarion) {
466
468
  location = await getCityLocationByBMap()
467
469
  }
468
470
  }
469
471
  }
470
472
 
471
- if (!location) {
472
- location = await getIPLocationByIpaas()
473
- }
474
-
475
473
  // 开发模式下为了方便测试提供虚拟定位
476
474
  if (!location && urlquery.isvirtuallocation) {
477
475
  location = {
@@ -489,7 +487,8 @@ const getLocationPromise = async (): Promise<Location> => {
489
487
 
490
488
  // WGS84 GCJ-02 BD-09 坐标系
491
489
  // https://www.jianshu.com/p/559029832a67
492
- async function getLocation() {
490
+ // 不能精确定位的情况下是否启用ip城市定位,ip定位用于不需要精确定位的场景
491
+ async function getLocation(isuseiplocarion = false) {
493
492
  await mapService.init()
494
493
  // debugger
495
494
  // 缓存30秒
@@ -502,7 +501,7 @@ async function getLocation() {
502
501
  }
503
502
  // console.log('runing')
504
503
  runing = true
505
- locationPromise = getLocationPromise()
504
+ locationPromise = getLocationPromise(isuseiplocarion)
506
505
  const locationRes = await locationPromise
507
506
  runing = false
508
507
  if (locationRes) {
@@ -518,13 +517,14 @@ const getAddress = async (position: Location): Promise<string> => {
518
517
 
519
518
  let address = ''
520
519
 
521
- // 先统一用ipaas解析 因为需要储存一致的地址格式(各地图商逆地址查询的地址格式不统一)
522
- // 如果不行再按照各地图商解析
523
- address = await getAddressByIpaas(position)
524
-
525
520
  if (!address) {
526
521
  if (mapService.type === 'amap') {
527
522
  address = await getAddressByAmap(position)
523
+
524
+ if (!address) {
525
+ // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
526
+ address = await getAddressByIpaas(position)
527
+ }
528
528
  } else if (mapService.type === 'tencent') {
529
529
  address = await getAddressByTMap(position)
530
530
  } else if (mapService.type === 'baidu') {
@@ -39,38 +39,43 @@ class TenantSetting {
39
39
  }
40
40
 
41
41
  get(key: string) {
42
- const tenantsettingStr = lsProxy.getItem('tenantsetting')
43
- if (tenantsettingStr) {
44
- const tenantsetting = JSON.parse(tenantsettingStr)
42
+ // const tenantsetting = {
43
+ // lbssetting: {
44
+ // enable: '1',
45
+ // setting: {
46
+ // type: '',
47
+ // key: {
48
+ // web: '',
49
+ // android: '',
50
+ // ios: '',
51
+ // harmony: ''
52
+ // },
53
+ // secretkey: {
54
+ // web: '',
55
+ // android: '',
56
+ // ios: '',
57
+ // harmony: ''
58
+ // }
59
+ // }
60
+ // }
61
+ // }
62
+
63
+ // tenantsetting.lbssetting.setting.type = 'amap'
64
+ // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
65
+ // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
45
66
 
46
- // tenantsetting.lbssetting = {
47
- // enable: '1',
48
- // setting: {
49
- // type: '',
50
- // key: {
51
- // web: '',
52
- // android: '',
53
- // ios: '',
54
- // harmony: ''
55
- // },
56
- // secretkey: {
57
- // web: '',
58
- // android: '',
59
- // ios: '',
60
- // harmony: ''
61
- // }
62
- // }
63
- // }
64
- // tenantsetting.lbssetting.setting.type = 'amap'
65
- // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
66
- // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
67
+ // // tenantsetting.lbssetting.setting.type = 'tencent'
68
+ // // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
67
69
 
68
- // tenantsetting.lbssetting.setting.type = 'tencent'
69
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
70
+ // // tenantsetting.lbssetting.setting.type = 'baidu'
71
+ // // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
70
72
 
71
- // tenantsetting.lbssetting.setting.type = 'baidu'
72
- // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
73
+ // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
73
74
 
75
+
76
+ let tenantsettingStr = lsProxy.getItem('tenantsetting')
77
+ if (tenantsettingStr) {
78
+ const tenantsetting = JSON.parse(tenantsettingStr)
74
79
  if (key) {
75
80
  return tenantsetting[key]
76
81
  }