@smart100/spu-web-plugin 1.0.10 → 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.10";
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
  }
@@ -17071,6 +17074,7 @@ var MapService = /*#__PURE__*/function () {
17071
17074
  function MapService() {
17072
17075
  _classCallCheck$1(this, MapService);
17073
17076
  _defineProperty$1(this, "isInit", false);
17077
+ _defineProperty$1(this, "initPromise", null);
17074
17078
  _defineProperty$1(this, "AMap", null);
17075
17079
  _defineProperty$1(this, "TMap", null);
17076
17080
  _defineProperty$1(this, "BMap", null);
@@ -17145,8 +17149,7 @@ var MapService = /*#__PURE__*/function () {
17145
17149
  // return window.BMap
17146
17150
  // }
17147
17151
  function () {
17148
- var _init = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17149
- var type;
17152
+ var _init2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17150
17153
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
17151
17154
  while (1) switch (_context.prev = _context.next) {
17152
17155
  case 0:
@@ -17156,70 +17159,97 @@ var MapService = /*#__PURE__*/function () {
17156
17159
  }
17157
17160
  return _context.abrupt("return");
17158
17161
  case 2:
17159
- this.isInit = true;
17160
- type = this.type; // if (process.env.NODE_ENV === 'development') {
17161
- // type = 'baidu'
17162
- // }
17163
- if (!(type === 'tencent')) {
17164
- _context.next = 9;
17162
+ if (!this.initPromise) {
17163
+ _context.next = 4;
17165
17164
  break;
17166
17165
  }
17166
+ return _context.abrupt("return", this.initPromise);
17167
+ case 4:
17168
+ this.initPromise = this._init();
17167
17169
  _context.next = 7;
17168
- return this.initTecent();
17170
+ return this.initPromise;
17169
17171
  case 7:
17170
- _context.next = 17;
17172
+ case "end":
17173
+ return _context.stop();
17174
+ }
17175
+ }, _callee, this);
17176
+ }));
17177
+ function init() {
17178
+ return _init2.apply(this, arguments);
17179
+ }
17180
+ return init;
17181
+ }()
17182
+ }, {
17183
+ key: "_init",
17184
+ value: function () {
17185
+ var _init3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17186
+ var type;
17187
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17188
+ while (1) switch (_context2.prev = _context2.next) {
17189
+ case 0:
17190
+ type = this.type;
17191
+ if (!(type === 'tencent')) {
17192
+ _context2.next = 6;
17193
+ break;
17194
+ }
17195
+ _context2.next = 4;
17196
+ return this.initTecent();
17197
+ case 4:
17198
+ _context2.next = 14;
17171
17199
  break;
17172
- case 9:
17200
+ case 6:
17173
17201
  if (!(type === 'amap')) {
17174
- _context.next = 14;
17202
+ _context2.next = 11;
17175
17203
  break;
17176
17204
  }
17177
- _context.next = 12;
17205
+ _context2.next = 9;
17178
17206
  return this.initAmap();
17179
- case 12:
17180
- _context.next = 17;
17207
+ case 9:
17208
+ _context2.next = 14;
17181
17209
  break;
17182
- case 14:
17210
+ case 11:
17183
17211
  if (!(type === 'baidu')) {
17184
- _context.next = 17;
17212
+ _context2.next = 14;
17185
17213
  break;
17186
17214
  }
17187
- _context.next = 17;
17215
+ _context2.next = 14;
17188
17216
  return this.initBaidu();
17189
- case 17:
17217
+ case 14:
17218
+ this.isInit = true;
17219
+ case 15:
17190
17220
  case "end":
17191
- return _context.stop();
17221
+ return _context2.stop();
17192
17222
  }
17193
- }, _callee, this);
17223
+ }, _callee2, this);
17194
17224
  }));
17195
- function init() {
17196
- return _init.apply(this, arguments);
17225
+ function _init() {
17226
+ return _init3.apply(this, arguments);
17197
17227
  }
17198
- return init;
17228
+ return _init;
17199
17229
  }() // reset() {
17200
17230
  // this.isInit = false
17201
17231
  // }
17202
17232
  }, {
17203
17233
  key: "initTecent",
17204
17234
  value: function () {
17205
- var _initTecent = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17206
- return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17207
- while (1) switch (_context2.prev = _context2.next) {
17235
+ var _initTecent = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17236
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17237
+ while (1) switch (_context3.prev = _context3.next) {
17208
17238
  case 0:
17209
- _context2.next = 2;
17239
+ _context3.next = 2;
17210
17240
  return importJS("https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=".concat(this.key),
17211
17241
  // `https://map.qq.com/api/gljs?v=1.exp&key=${this.key}`,
17212
17242
  'TMap');
17213
17243
  case 2:
17214
17244
  this.TMap = window.TMap;
17215
17245
  this.MapCore = window.TMap;
17216
- _context2.next = 6;
17246
+ _context3.next = 6;
17217
17247
  return delay(300);
17218
17248
  case 6:
17219
17249
  case "end":
17220
- return _context2.stop();
17250
+ return _context3.stop();
17221
17251
  }
17222
- }, _callee2, this);
17252
+ }, _callee3, this);
17223
17253
  }));
17224
17254
  function initTecent() {
17225
17255
  return _initTecent.apply(this, arguments);
@@ -17229,18 +17259,18 @@ var MapService = /*#__PURE__*/function () {
17229
17259
  }, {
17230
17260
  key: "initAmap",
17231
17261
  value: function () {
17232
- var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17262
+ var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17233
17263
  var plugin, AMap;
17234
- return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17235
- while (1) switch (_context3.prev = _context3.next) {
17264
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17265
+ while (1) switch (_context4.prev = _context4.next) {
17236
17266
  case 0:
17237
- // if (this.secretkey) {
17238
- // window._AMapSecurityConfig = {
17239
- // securityJsCode: this.secretkey
17240
- // }
17241
- // }
17242
- plugin = ['AMap.Geolocation']; // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
17243
- _context3.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;
17244
17274
  return AMapLoader$1.load({
17245
17275
  key: this.key,
17246
17276
  version: '2.0',
@@ -17250,8 +17280,8 @@ var MapService = /*#__PURE__*/function () {
17250
17280
  plugins: []
17251
17281
  }
17252
17282
  });
17253
- case 3:
17254
- AMap = _context3.sent;
17283
+ case 4:
17284
+ AMap = _context4.sent;
17255
17285
  window.AMap = AMap;
17256
17286
  this.AMap = AMap;
17257
17287
  this.MapCore = window.AMap;
@@ -17260,11 +17290,11 @@ var MapService = /*#__PURE__*/function () {
17260
17290
  // console.log(window.AMapUI)
17261
17291
  // console.log(window.AMapLoader)
17262
17292
  // console.log(window.AMap === aaaa)
17263
- case 7:
17293
+ case 8:
17264
17294
  case "end":
17265
- return _context3.stop();
17295
+ return _context4.stop();
17266
17296
  }
17267
- }, _callee3, this);
17297
+ }, _callee4, this);
17268
17298
  }));
17269
17299
  function initAmap() {
17270
17300
  return _initAmap.apply(this, arguments);
@@ -17274,12 +17304,12 @@ var MapService = /*#__PURE__*/function () {
17274
17304
  }, {
17275
17305
  key: "initBaidu",
17276
17306
  value: function () {
17277
- var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17307
+ var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5() {
17278
17308
  var _this = this;
17279
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17280
- while (1) switch (_context4.prev = _context4.next) {
17309
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
17310
+ while (1) switch (_context5.prev = _context5.next) {
17281
17311
  case 0:
17282
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
17312
+ return _context5.abrupt("return", new Promise(function (resolve, reject) {
17283
17313
  window.BMAP_INITIAL_CALLBACK = function () {
17284
17314
  _this.BMap = window.BMap;
17285
17315
  _this.MapCore = window.BMap;
@@ -17300,9 +17330,9 @@ var MapService = /*#__PURE__*/function () {
17300
17330
  }));
17301
17331
  case 1:
17302
17332
  case "end":
17303
- return _context4.stop();
17333
+ return _context5.stop();
17304
17334
  }
17305
- }, _callee4);
17335
+ }, _callee5);
17306
17336
  }));
17307
17337
  function initBaidu() {
17308
17338
  return _initBaidu.apply(this, arguments);
@@ -17690,34 +17720,32 @@ var getCityLocationByAmap = /*#__PURE__*/function () {
17690
17720
  // 高德逆地址解析
17691
17721
  var getAddressByAmap = /*#__PURE__*/function () {
17692
17722
  var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(position) {
17693
- var address;
17694
17723
  return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
17695
17724
  while (1) switch (_context8.prev = _context8.next) {
17696
17725
  case 0:
17697
17726
  console.log('getAddressByAmap start...');
17698
- console.log('getAddressByAmap changeto getAddressByIpaas');
17699
- // return new Promise((resolve, reject) => {
17700
- // if (position) {
17701
- // new window.AMap.Geocoder({
17702
- // city: '',
17703
- // radius: 500
17704
- // }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
17705
- // if (status === 'complete' && result.info === 'OK' && result.regeocode) {
17706
- // resolve(result?.regeocode?.formattedAddress || '')
17707
- // } else {
17708
- // console.error('getAddressByAmap fail')
17709
- // resolve('')
17710
- // }
17711
- // })
17712
- // }
17713
- // })
17714
- // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
17715
- _context8.next = 4;
17716
- return getAddressByIpaas(position);
17717
- case 4:
17718
- address = _context8.sent;
17719
- return _context8.abrupt("return", address);
17720
- 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:
17721
17749
  case "end":
17722
17750
  return _context8.stop();
17723
17751
  }
@@ -18010,94 +18038,96 @@ var getAddressByBmap = /*#__PURE__*/function () {
18010
18038
  return _ref15.apply(this, arguments);
18011
18039
  };
18012
18040
  }();
18013
- // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 地图商高精度定位 > 地图商城市ip定位
18014
18041
  var getLocationPromise = /*#__PURE__*/function () {
18015
18042
  var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
18016
18043
  var _window;
18017
- var location;
18044
+ var isuseiplocarion,
18045
+ location,
18046
+ _args17 = arguments;
18018
18047
  return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18019
18048
  while (1) switch (_context17.prev = _context17.next) {
18020
18049
  case 0:
18050
+ isuseiplocarion = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18021
18051
  location = null; // 在 SPU 容器里使用 Native-API 的定位
18022
18052
  if (!((_window = window) !== null && _window !== void 0 && (_window = _window.Native) !== null && _window !== void 0 && _window.getLocation)) {
18023
- _context17.next = 5;
18053
+ _context17.next = 6;
18024
18054
  break;
18025
18055
  }
18026
- _context17.next = 4;
18056
+ _context17.next = 5;
18027
18057
  return getLocationByNative();
18028
- case 4:
18029
- location = _context17.sent;
18030
18058
  case 5:
18059
+ location = _context17.sent;
18060
+ case 6:
18031
18061
  if (location) {
18032
- _context17.next = 9;
18062
+ _context17.next = 10;
18033
18063
  break;
18034
18064
  }
18035
- _context17.next = 8;
18065
+ _context17.next = 9;
18036
18066
  return getLocationByNavigator();
18037
- case 8:
18038
- location = _context17.sent;
18039
18067
  case 9:
18068
+ location = _context17.sent;
18069
+ case 10:
18040
18070
  if (location) {
18041
- _context17.next = 34;
18071
+ _context17.next = 39;
18042
18072
  break;
18043
18073
  }
18044
18074
  if (!(mapService.type === 'amap')) {
18045
- _context17.next = 20;
18075
+ _context17.next = 25;
18046
18076
  break;
18047
18077
  }
18048
- _context17.next = 13;
18078
+ _context17.next = 14;
18049
18079
  return getLocationByAmap();
18050
- case 13:
18080
+ case 14:
18051
18081
  location = _context17.sent;
18052
- if (location) {
18053
- _context17.next = 18;
18082
+ if (!(!location && isuseiplocarion)) {
18083
+ _context17.next = 19;
18054
18084
  break;
18055
18085
  }
18056
- _context17.next = 17;
18086
+ _context17.next = 18;
18057
18087
  return getCityLocationByAmap();
18058
- case 17:
18059
- location = _context17.sent;
18060
18088
  case 18:
18061
- _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;
18062
18101
  break;
18063
- case 20:
18064
- if (!(mapService.type === 'tencent')) {
18065
- _context17.next = 26;
18102
+ case 25:
18103
+ if (!(mapService.type === 'tencent' && isuseiplocarion)) {
18104
+ _context17.next = 31;
18066
18105
  break;
18067
18106
  }
18068
- _context17.next = 23;
18107
+ _context17.next = 28;
18069
18108
  return getIPLocationByTMap();
18070
- case 23:
18109
+ case 28:
18071
18110
  location = _context17.sent;
18072
- _context17.next = 34;
18111
+ _context17.next = 39;
18073
18112
  break;
18074
- case 26:
18113
+ case 31:
18075
18114
  if (!(mapService.type === 'baidu')) {
18076
- _context17.next = 34;
18115
+ _context17.next = 39;
18077
18116
  break;
18078
18117
  }
18079
- _context17.next = 29;
18118
+ _context17.next = 34;
18080
18119
  return getLocationByBMap();
18081
- case 29:
18120
+ case 34:
18082
18121
  location = _context17.sent;
18083
- if (location) {
18084
- _context17.next = 34;
18122
+ if (!(!location && isuseiplocarion)) {
18123
+ _context17.next = 39;
18085
18124
  break;
18086
18125
  }
18087
- _context17.next = 33;
18126
+ _context17.next = 38;
18088
18127
  return getCityLocationByBMap();
18089
- case 33:
18090
- location = _context17.sent;
18091
- case 34:
18092
- if (location) {
18093
- _context17.next = 38;
18094
- break;
18095
- }
18096
- _context17.next = 37;
18097
- return getIPLocationByIpaas();
18098
- case 37:
18099
- location = _context17.sent;
18100
18128
  case 38:
18129
+ location = _context17.sent;
18130
+ case 39:
18101
18131
  // 开发模式下为了方便测试提供虚拟定位
18102
18132
  if (!location && urlquery.isvirtuallocation) {
18103
18133
  location = {
@@ -18106,23 +18136,23 @@ var getLocationPromise = /*#__PURE__*/function () {
18106
18136
  };
18107
18137
  }
18108
18138
  if (!(location && !location.address)) {
18109
- _context17.next = 46;
18139
+ _context17.next = 47;
18110
18140
  break;
18111
18141
  }
18112
- _context17.next = 42;
18142
+ _context17.next = 43;
18113
18143
  return getAddress(location);
18114
- case 42:
18144
+ case 43:
18115
18145
  _context17.t0 = _context17.sent;
18116
18146
  if (_context17.t0) {
18117
- _context17.next = 45;
18147
+ _context17.next = 46;
18118
18148
  break;
18119
18149
  }
18120
18150
  _context17.t0 = '经纬度获取成功,但地址获取失败。';
18121
- case 45:
18122
- location.address = _context17.t0;
18123
18151
  case 46:
18124
- return _context17.abrupt("return", location);
18152
+ location.address = _context17.t0;
18125
18153
  case 47:
18154
+ return _context17.abrupt("return", location);
18155
+ case 48:
18126
18156
  case "end":
18127
18157
  return _context17.stop();
18128
18158
  }
@@ -18134,36 +18164,40 @@ var getLocationPromise = /*#__PURE__*/function () {
18134
18164
  }();
18135
18165
  // WGS84 GCJ-02 BD-09 坐标系
18136
18166
  // https://www.jianshu.com/p/559029832a67
18167
+ // 不能精确定位的情况下是否启用ip城市定位,ip定位用于不需要精确定位的场景
18137
18168
  function getLocation() {
18138
18169
  return _getLocation.apply(this, arguments);
18139
18170
  } // 逆地址解析
18140
18171
  function _getLocation() {
18141
18172
  _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
18142
- var locationRes;
18173
+ var isuseiplocarion,
18174
+ locationRes,
18175
+ _args20 = arguments;
18143
18176
  return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18144
18177
  while (1) switch (_context20.prev = _context20.next) {
18145
18178
  case 0:
18146
- _context20.next = 2;
18179
+ isuseiplocarion = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18180
+ _context20.next = 3;
18147
18181
  return mapService.init();
18148
- case 2:
18182
+ case 3:
18149
18183
  if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18150
- _context20.next = 4;
18184
+ _context20.next = 5;
18151
18185
  break;
18152
18186
  }
18153
18187
  return _context20.abrupt("return", cloneDeep$1(lastLocation));
18154
- case 4:
18188
+ case 5:
18155
18189
  if (!(runing && locationPromise)) {
18156
- _context20.next = 6;
18190
+ _context20.next = 7;
18157
18191
  break;
18158
18192
  }
18159
18193
  return _context20.abrupt("return", locationPromise);
18160
- case 6:
18194
+ case 7:
18161
18195
  // console.log('runing')
18162
18196
  runing = true;
18163
- locationPromise = getLocationPromise();
18164
- _context20.next = 10;
18197
+ locationPromise = getLocationPromise(isuseiplocarion);
18198
+ _context20.next = 11;
18165
18199
  return locationPromise;
18166
- case 10:
18200
+ case 11:
18167
18201
  locationRes = _context20.sent;
18168
18202
  runing = false;
18169
18203
  if (locationRes) {
@@ -18171,7 +18205,7 @@ function _getLocation() {
18171
18205
  lastLocation = locationRes;
18172
18206
  }
18173
18207
  return _context20.abrupt("return", locationRes);
18174
- case 14:
18208
+ case 15:
18175
18209
  case "end":
18176
18210
  return _context20.stop();
18177
18211
  }
@@ -18188,49 +18222,53 @@ var getAddress = /*#__PURE__*/function () {
18188
18222
  _context18.next = 2;
18189
18223
  return mapService.init();
18190
18224
  case 2:
18191
- address = ''; // 先统一用ipaas解析 因为需要储存一致的地址格式(各地图商逆地址查询的地址格式不统一)
18192
- // 如果不行再按照各地图商解析
18193
- _context18.next = 5;
18194
- return getAddressByIpaas(position);
18195
- case 5:
18196
- address = _context18.sent;
18225
+ address = '';
18197
18226
  if (address) {
18198
- _context18.next = 23;
18227
+ _context18.next = 24;
18199
18228
  break;
18200
18229
  }
18201
18230
  if (!(mapService.type === 'amap')) {
18202
- _context18.next = 13;
18231
+ _context18.next = 14;
18203
18232
  break;
18204
18233
  }
18205
- _context18.next = 10;
18234
+ _context18.next = 7;
18206
18235
  return getAddressByAmap(position);
18207
- case 10:
18236
+ case 7:
18208
18237
  address = _context18.sent;
18209
- _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;
18210
18248
  break;
18211
- case 13:
18249
+ case 14:
18212
18250
  if (!(mapService.type === 'tencent')) {
18213
- _context18.next = 19;
18251
+ _context18.next = 20;
18214
18252
  break;
18215
18253
  }
18216
- _context18.next = 16;
18254
+ _context18.next = 17;
18217
18255
  return getAddressByTMap(position);
18218
- case 16:
18256
+ case 17:
18219
18257
  address = _context18.sent;
18220
- _context18.next = 23;
18258
+ _context18.next = 24;
18221
18259
  break;
18222
- case 19:
18260
+ case 20:
18223
18261
  if (!(mapService.type === 'baidu')) {
18224
- _context18.next = 23;
18262
+ _context18.next = 24;
18225
18263
  break;
18226
18264
  }
18227
- _context18.next = 22;
18265
+ _context18.next = 23;
18228
18266
  return getAddressByBmap(position);
18229
- case 22:
18230
- address = _context18.sent;
18231
18267
  case 23:
18232
- return _context18.abrupt("return", address);
18268
+ address = _context18.sent;
18233
18269
  case 24:
18270
+ return _context18.abrupt("return", address);
18271
+ case 25:
18234
18272
  case "end":
18235
18273
  return _context18.stop();
18236
18274
  }
@@ -52861,9 +52899,7 @@ var load = function load(options) {
52861
52899
  };
52862
52900
  }
52863
52901
  }
52864
- // 不开放地址查询 改用ipaas
52865
- var plugin = ['AMap.Geolocation'];
52866
- // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
52902
+ var plugin = ['AMap.Geolocation', 'AMap.Geocoder'];
52867
52903
  return AMapLoader$1.load({
52868
52904
  key: AMapKey.key,
52869
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.10",
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,
@@ -20,6 +20,7 @@ interface ILbsSettingData {
20
20
 
21
21
  class MapService {
22
22
  private isInit = false
23
+ private initPromise: any = null
23
24
 
24
25
  get isLbssettingEnable() {
25
26
  return tenantSetting.get('lbssetting')?.enable === '1'
@@ -89,13 +90,17 @@ class MapService {
89
90
  async init() {
90
91
  if (this.isInit) return
91
92
 
92
- this.isInit = true
93
+ // 兼容同时间发起多个
94
+ if (this.initPromise) {
95
+ return this.initPromise
96
+ }
93
97
 
94
- const type = this.type
98
+ this.initPromise = this._init()
99
+ await this.initPromise
100
+ }
95
101
 
96
- // if (process.env.NODE_ENV === 'development') {
97
- // type = 'baidu'
98
- // }
102
+ private async _init() {
103
+ const type = this.type
99
104
  if (type === 'tencent') {
100
105
  await this.initTecent()
101
106
  } else if (type === 'amap') {
@@ -103,6 +108,7 @@ class MapService {
103
108
  } else if (type === 'baidu') {
104
109
  await this.initBaidu()
105
110
  }
111
+ this.isInit = true
106
112
  }
107
113
 
108
114
  // reset() {
@@ -121,14 +127,13 @@ class MapService {
121
127
  }
122
128
 
123
129
  private async initAmap() {
124
- // if (this.secretkey) {
125
- // window._AMapSecurityConfig = {
126
- // securityJsCode: this.secretkey
127
- // }
128
- // }
130
+ if (this.secretkey) {
131
+ window._AMapSecurityConfig = {
132
+ securityJsCode: this.secretkey
133
+ }
134
+ }
129
135
 
130
- const plugin = ['AMap.Geolocation']
131
- // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
136
+ const plugin = ['AMap.Geolocation', 'AMap.Geocoder']
132
137
 
133
138
  const AMap = await AMapLoader.load({
134
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
  }