@smart100/spu-web-plugin 1.0.10 → 1.0.11

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.11";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -17071,6 +17071,7 @@ var MapService = /*#__PURE__*/function () {
17071
17071
  function MapService() {
17072
17072
  _classCallCheck$1(this, MapService);
17073
17073
  _defineProperty$1(this, "isInit", false);
17074
+ _defineProperty$1(this, "initPromise", null);
17074
17075
  _defineProperty$1(this, "AMap", null);
17075
17076
  _defineProperty$1(this, "TMap", null);
17076
17077
  _defineProperty$1(this, "BMap", null);
@@ -17145,8 +17146,7 @@ var MapService = /*#__PURE__*/function () {
17145
17146
  // return window.BMap
17146
17147
  // }
17147
17148
  function () {
17148
- var _init = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17149
- var type;
17149
+ var _init2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17150
17150
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
17151
17151
  while (1) switch (_context.prev = _context.next) {
17152
17152
  case 0:
@@ -17156,70 +17156,97 @@ var MapService = /*#__PURE__*/function () {
17156
17156
  }
17157
17157
  return _context.abrupt("return");
17158
17158
  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;
17159
+ if (!this.initPromise) {
17160
+ _context.next = 4;
17165
17161
  break;
17166
17162
  }
17163
+ return _context.abrupt("return", this.initPromise);
17164
+ case 4:
17165
+ this.initPromise = this._init();
17167
17166
  _context.next = 7;
17168
- return this.initTecent();
17167
+ return this.initPromise;
17169
17168
  case 7:
17170
- _context.next = 17;
17169
+ case "end":
17170
+ return _context.stop();
17171
+ }
17172
+ }, _callee, this);
17173
+ }));
17174
+ function init() {
17175
+ return _init2.apply(this, arguments);
17176
+ }
17177
+ return init;
17178
+ }()
17179
+ }, {
17180
+ key: "_init",
17181
+ value: function () {
17182
+ var _init3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17183
+ var type;
17184
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17185
+ while (1) switch (_context2.prev = _context2.next) {
17186
+ case 0:
17187
+ type = this.type;
17188
+ if (!(type === 'tencent')) {
17189
+ _context2.next = 6;
17190
+ break;
17191
+ }
17192
+ _context2.next = 4;
17193
+ return this.initTecent();
17194
+ case 4:
17195
+ _context2.next = 14;
17171
17196
  break;
17172
- case 9:
17197
+ case 6:
17173
17198
  if (!(type === 'amap')) {
17174
- _context.next = 14;
17199
+ _context2.next = 11;
17175
17200
  break;
17176
17201
  }
17177
- _context.next = 12;
17202
+ _context2.next = 9;
17178
17203
  return this.initAmap();
17179
- case 12:
17180
- _context.next = 17;
17204
+ case 9:
17205
+ _context2.next = 14;
17181
17206
  break;
17182
- case 14:
17207
+ case 11:
17183
17208
  if (!(type === 'baidu')) {
17184
- _context.next = 17;
17209
+ _context2.next = 14;
17185
17210
  break;
17186
17211
  }
17187
- _context.next = 17;
17212
+ _context2.next = 14;
17188
17213
  return this.initBaidu();
17189
- case 17:
17214
+ case 14:
17215
+ this.isInit = true;
17216
+ case 15:
17190
17217
  case "end":
17191
- return _context.stop();
17218
+ return _context2.stop();
17192
17219
  }
17193
- }, _callee, this);
17220
+ }, _callee2, this);
17194
17221
  }));
17195
- function init() {
17196
- return _init.apply(this, arguments);
17222
+ function _init() {
17223
+ return _init3.apply(this, arguments);
17197
17224
  }
17198
- return init;
17225
+ return _init;
17199
17226
  }() // reset() {
17200
17227
  // this.isInit = false
17201
17228
  // }
17202
17229
  }, {
17203
17230
  key: "initTecent",
17204
17231
  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) {
17232
+ var _initTecent = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17233
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17234
+ while (1) switch (_context3.prev = _context3.next) {
17208
17235
  case 0:
17209
- _context2.next = 2;
17236
+ _context3.next = 2;
17210
17237
  return importJS("https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=".concat(this.key),
17211
17238
  // `https://map.qq.com/api/gljs?v=1.exp&key=${this.key}`,
17212
17239
  'TMap');
17213
17240
  case 2:
17214
17241
  this.TMap = window.TMap;
17215
17242
  this.MapCore = window.TMap;
17216
- _context2.next = 6;
17243
+ _context3.next = 6;
17217
17244
  return delay(300);
17218
17245
  case 6:
17219
17246
  case "end":
17220
- return _context2.stop();
17247
+ return _context3.stop();
17221
17248
  }
17222
- }, _callee2, this);
17249
+ }, _callee3, this);
17223
17250
  }));
17224
17251
  function initTecent() {
17225
17252
  return _initTecent.apply(this, arguments);
@@ -17229,10 +17256,10 @@ var MapService = /*#__PURE__*/function () {
17229
17256
  }, {
17230
17257
  key: "initAmap",
17231
17258
  value: function () {
17232
- var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17259
+ var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17233
17260
  var plugin, AMap;
17234
- return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17235
- while (1) switch (_context3.prev = _context3.next) {
17261
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17262
+ while (1) switch (_context4.prev = _context4.next) {
17236
17263
  case 0:
17237
17264
  // if (this.secretkey) {
17238
17265
  // window._AMapSecurityConfig = {
@@ -17240,7 +17267,7 @@ var MapService = /*#__PURE__*/function () {
17240
17267
  // }
17241
17268
  // }
17242
17269
  plugin = ['AMap.Geolocation']; // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
17243
- _context3.next = 3;
17270
+ _context4.next = 3;
17244
17271
  return AMapLoader$1.load({
17245
17272
  key: this.key,
17246
17273
  version: '2.0',
@@ -17251,7 +17278,7 @@ var MapService = /*#__PURE__*/function () {
17251
17278
  }
17252
17279
  });
17253
17280
  case 3:
17254
- AMap = _context3.sent;
17281
+ AMap = _context4.sent;
17255
17282
  window.AMap = AMap;
17256
17283
  this.AMap = AMap;
17257
17284
  this.MapCore = window.AMap;
@@ -17262,9 +17289,9 @@ var MapService = /*#__PURE__*/function () {
17262
17289
  // console.log(window.AMap === aaaa)
17263
17290
  case 7:
17264
17291
  case "end":
17265
- return _context3.stop();
17292
+ return _context4.stop();
17266
17293
  }
17267
- }, _callee3, this);
17294
+ }, _callee4, this);
17268
17295
  }));
17269
17296
  function initAmap() {
17270
17297
  return _initAmap.apply(this, arguments);
@@ -17274,12 +17301,12 @@ var MapService = /*#__PURE__*/function () {
17274
17301
  }, {
17275
17302
  key: "initBaidu",
17276
17303
  value: function () {
17277
- var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17304
+ var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5() {
17278
17305
  var _this = this;
17279
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17280
- while (1) switch (_context4.prev = _context4.next) {
17306
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
17307
+ while (1) switch (_context5.prev = _context5.next) {
17281
17308
  case 0:
17282
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
17309
+ return _context5.abrupt("return", new Promise(function (resolve, reject) {
17283
17310
  window.BMAP_INITIAL_CALLBACK = function () {
17284
17311
  _this.BMap = window.BMap;
17285
17312
  _this.MapCore = window.BMap;
@@ -17300,9 +17327,9 @@ var MapService = /*#__PURE__*/function () {
17300
17327
  }));
17301
17328
  case 1:
17302
17329
  case "end":
17303
- return _context4.stop();
17330
+ return _context5.stop();
17304
17331
  }
17305
- }, _callee4);
17332
+ }, _callee5);
17306
17333
  }));
17307
17334
  function initBaidu() {
17308
17335
  return _initBaidu.apply(this, arguments);
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.11",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
@@ -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() {