@smart100/spu-web-plugin 1.0.7 → 1.0.9

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.7";
1
+ var version = "1.0.9";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -4139,63 +4139,6 @@ function getAugmentedNamespace(n) {
4139
4139
  return a;
4140
4140
  }
4141
4141
 
4142
- var dist = {exports: {}};
4143
-
4144
- (function (module, exports) {
4145
- (function(m,p){module.exports=p();})(commonjsGlobal,function(){function m(a){var b=[];a.AMapUI&&b.push(p(a.AMapUI));a.Loca&&b.push(r(a.Loca));return Promise.all(b)}function p(a){return new Promise(function(h,c){var f=[];if(a.plugins)for(var e=0;e<a.plugins.length;e+=1)-1==d.AMapUI.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(g.AMapUI===b.failed)c("\u524d\u6b21\u8bf7\u6c42 AMapUI \u5931\u8d25");
4146
- else if(g.AMapUI===b.notload){g.AMapUI=b.loading;d.AMapUI.version=a.version||d.AMapUI.version;e=d.AMapUI.version;var l=document.body||document.head,k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/ui/"+e+"/main.js";k.onerror=function(a){g.AMapUI=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25");};k.onload=function(){g.AMapUI=b.loaded;if(f.length)window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=
4147
- arguments[a];}for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();});else for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();};l.appendChild(k);}else g.AMapUI===b.loaded?a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a];}h();}):h():a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):
4148
- n.AMapUI.push(function(a){a?c(a):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a];}h();}):h();});})}function r(a){return new Promise(function(h,c){if(g.Loca===b.failed)c("\u524d\u6b21\u8bf7\u6c42 Loca \u5931\u8d25");else if(g.Loca===b.notload){g.Loca=b.loading;d.Loca.version=a.version||d.Loca.version;var f=d.Loca.version,e=d.AMap.version.startsWith("2"),l=f.startsWith("2");if(e&&!l||!e&&l)c("JSAPI \u4e0e Loca \u7248\u672c\u4e0d\u5bf9\u5e94\uff01\uff01");
4149
- else {e=d.key;l=document.body||document.head;var k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/loca?v="+f+"&key="+e;k.onerror=function(a){g.Loca=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25");};k.onload=function(){g.Loca=b.loaded;for(h();n.Loca.length;)n.Loca.splice(0,1)[0]();};l.appendChild(k);}}else g.Loca===b.loaded?a.version&&a.version!==d.Loca.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):h():a.version&&a.version!==d.Loca.version?
4150
- c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):n.Loca.push(function(a){a?c(a):c();});})}if(!window)throw Error("AMap JSAPI can only be used in Browser.");var b;(function(a){a.notload="notload";a.loading="loading";a.loaded="loaded";a.failed="failed";})(b||(b={}));var d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}},g={AMap:b.notload,AMapUI:b.notload,Loca:b.notload},n={AMap:[],AMapUI:[],Loca:[]},q=[],t=function(a){"function"==typeof a&&
4151
- (g.AMap===b.loaded?a(window.AMap):q.push(a));};return {load:function(a){return new Promise(function(h,c){if(g.AMap==b.failed)c("");else if(g.AMap==b.notload){var f=a.key,e=a.version,l=a.plugins;f?(window.AMap&&"lbs.amap.com"!==location.host&&c("\u7981\u6b62\u591a\u79cdAPI\u52a0\u8f7d\u65b9\u5f0f\u6df7\u7528"),d.key=f,d.AMap.version=e||d.AMap.version,d.AMap.plugins=l||d.AMap.plugins,g.AMap=b.loading,e=document.body||document.head,window.___onAPILoaded=function(d){delete window.___onAPILoaded;if(d)g.AMap=
4152
- b.failed,c(d);else for(g.AMap=b.loaded,m(a).then(function(){h(window.AMap);})["catch"](c);q.length;)q.splice(0,1)[0]();},l=document.createElement("script"),l.type="text/javascript",l.src="https://webapi.amap.com/maps?callback=___onAPILoaded&v="+d.AMap.version+"&key="+f+"&plugin="+d.AMap.plugins.join(","),l.onerror=function(a){g.AMap=b.failed;c(a);},e.appendChild(l)):c("\u8bf7\u586b\u5199key");}else if(g.AMap==b.loaded)if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&
4153
- a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");else {f=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(f.length)window.AMap.plugin(f,function(){m(a).then(function(){h(window.AMap);})["catch"](c);});else m(a).then(function(){h(window.AMap);})["catch"](c);}else if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");
4154
- else {var k=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&k.push(a.plugins[e]);t(function(){if(k.length)window.AMap.plugin(k,function(){m(a).then(function(){h(window.AMap);})["catch"](c);});else m(a).then(function(){h(window.AMap);})["catch"](c);});}})},reset:function(){delete window.AMap;delete window.AMapUI;delete window.Loca;d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}};g={AMap:b.notload,AMapUI:b.notload,
4155
- Loca:b.notload};n={AMap:[],AMapUI:[],Loca:[]};}}});
4156
- } (dist));
4157
-
4158
- var distExports = dist.exports;
4159
- var AMapLoader$1 = /*@__PURE__*/getDefaultExportFromCjs(distExports);
4160
-
4161
- // 高德地图 web端key 和 安全密钥
4162
- var amapKey = {
4163
- // 测试开发环境
4164
- dev: {
4165
- key: '38fa4702d240e1e6ee5cc8ca059b254f',
4166
- securityjscode: '96f2af5670b7a41a56dcd2e8b63c1e06'
4167
- },
4168
- // 生产环境
4169
- production: {
4170
- key: '1993ac213d2f4675ac1bffb1b03ef1f0',
4171
- securityjscode: '816fe46b7b7bce145940b93c1e4818fa'
4172
- }
4173
- };
4174
- // const amapkey = process.env.NODE_ENV !== 'production' ? amapKey.dev.key : amapKey.production.key
4175
- // const amapsecurityjscode = process.env.NODE_ENV !== 'production' ? amapKey.dev.securityjscode : amapKey.production.securityjscode
4176
- var amapkey = amapKey.production.key;
4177
- var amapsecurityjscode = amapKey.production.securityjscode;
4178
- var load = function load(options) {
4179
- var _options$AMapUI;
4180
- if (!window._AMapSecurityConfig) {
4181
- window._AMapSecurityConfig = {
4182
- securityJsCode: amapsecurityjscode
4183
- };
4184
- }
4185
- return AMapLoader$1.load({
4186
- key: amapkey,
4187
- version: '2.0',
4188
- plugins: (options === null || options === void 0 ? void 0 : options.plugins) || [],
4189
- AMapUI: {
4190
- version: '1.1',
4191
- plugins: (options === null || options === void 0 || (_options$AMapUI = options.AMapUI) === null || _options$AMapUI === void 0 ? void 0 : _options$AMapUI.plugins) || []
4192
- }
4193
- });
4194
- };
4195
- var AMapLoader = {
4196
- load: load
4197
- };
4198
-
4199
4142
  var vconsole_min = {exports: {}};
4200
4143
 
4201
4144
  /*!
@@ -16139,6 +16082,107 @@ function decrypt(base64) {
16139
16082
  return result;
16140
16083
  }
16141
16084
 
16085
+ var TenantSetting = /*#__PURE__*/function () {
16086
+ function TenantSetting() {
16087
+ _classCallCheck$1(this, TenantSetting);
16088
+ }
16089
+ _createClass$1(TenantSetting, [{
16090
+ key: "requestAndSetTenantSetting",
16091
+ value: function () {
16092
+ var _requestAndSetTenantSetting = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(tenantcode) {
16093
+ var _res$data, res, _tenantSetting;
16094
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
16095
+ while (1) switch (_context.prev = _context.next) {
16096
+ case 0:
16097
+ _context.prev = 0;
16098
+ _context.next = 3;
16099
+ return normalAxios$1.post('/api/auth/tenantsettings', {
16100
+ tenantcode: tenantcode || ''
16101
+ }, {
16102
+ isSendToken: false,
16103
+ isSendTecode: true,
16104
+ isShowErrorMessage: false
16105
+ });
16106
+ case 3:
16107
+ res = _context.sent;
16108
+ _tenantSetting = (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.econfig) || '';
16109
+ if (_tenantSetting) {
16110
+ _tenantSetting = decrypt(_tenantSetting);
16111
+ }
16112
+ // console.log(tenantSetting)
16113
+ // debugger
16114
+ if (_tenantSetting) {
16115
+ lsProxy.setItem('tenantsetting', _tenantSetting);
16116
+ } else {
16117
+ this.removeTenantSetting();
16118
+ }
16119
+ _context.next = 13;
16120
+ break;
16121
+ case 9:
16122
+ _context.prev = 9;
16123
+ _context.t0 = _context["catch"](0);
16124
+ console.error(_context.t0);
16125
+ this.removeTenantSetting();
16126
+ case 13:
16127
+ case "end":
16128
+ return _context.stop();
16129
+ }
16130
+ }, _callee, this, [[0, 9]]);
16131
+ }));
16132
+ function requestAndSetTenantSetting(_x) {
16133
+ return _requestAndSetTenantSetting.apply(this, arguments);
16134
+ }
16135
+ return requestAndSetTenantSetting;
16136
+ }()
16137
+ }, {
16138
+ key: "removeTenantSetting",
16139
+ value: function removeTenantSetting() {
16140
+ lsProxy.removeItem('tenantsetting');
16141
+ }
16142
+ }, {
16143
+ key: "get",
16144
+ value: function get(key) {
16145
+ var tenantsettingStr = lsProxy.getItem('tenantsetting');
16146
+ if (tenantsettingStr) {
16147
+ 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
+ if (key) {
16174
+ return tenantsetting[key];
16175
+ }
16176
+ return tenantsetting;
16177
+ } else {
16178
+ return null;
16179
+ }
16180
+ }
16181
+ }]);
16182
+ return TenantSetting;
16183
+ }();
16184
+ var tenantSetting = new TenantSetting();
16185
+
16142
16186
  function getToken() {
16143
16187
  return getData('token');
16144
16188
  // return lsProxy.getItem('token') as string
@@ -16169,95 +16213,6 @@ function setRefreshToken(value) {
16169
16213
  function removeRefreshToken() {
16170
16214
  removeData('refreshtoken');
16171
16215
  }
16172
- function updateToken() {
16173
- var loginState = getLoginState();
16174
- if (!loginState.islogin && loginState.type <= 1) {
16175
- console.warn('当前未登录/token过期,不支持自动刷新token。');
16176
- return false;
16177
- }
16178
- if (loginState.role === 'center') {
16179
- console.warn('当前登录为产品运营中心用户,不支持自动刷新token。');
16180
- return false;
16181
- }
16182
- var token = getToken();
16183
- var refreshtoken = getRefreshToken();
16184
- var sendToken = checkLoginByToken(token) ? token : refreshtoken;
16185
- return normalAxios$1.get('/api/auth/refreshtoken', {
16186
- params: {
16187
- refreshtoken: sendToken
16188
- },
16189
- isShowLoading: false,
16190
- isShowErrorMessage: false,
16191
- isSendToken: false,
16192
- isSendTecode: true,
16193
- headers: {
16194
- token: sendToken
16195
- }
16196
- }).then(function (res) {
16197
- // console.log(res)
16198
- var data = res === null || res === void 0 ? void 0 : res.data;
16199
- if (data) {
16200
- setToken(data.token);
16201
- setRefreshToken(data.refreshtoken);
16202
- setTokenExpires(data.tokenexpires);
16203
- }
16204
- });
16205
- }
16206
- var refreshtokenTimer = null;
16207
- function startRefreshtoken() {
16208
- var loginState = getLoginState();
16209
- // 如果是产品运营中心 则不走刷新token流程
16210
- if (loginState.role === 'center') {
16211
- console.warn('当前登录为产品运营中心用户,不支持自动刷新token。');
16212
- return false;
16213
- }
16214
- // stopRefreshtoken()
16215
- clearTimeout(refreshtokenTimer);
16216
- refreshtokenTimer = null;
16217
- // 如果有登录 但 refreshtoken 不是完整 token 则10秒后【需要等单点登录走完后才刷新不然会被覆盖】刷新一次取到完整 token
16218
- // 如果有登录 且 refreshtoken 是完整 token 如果剩余时间大于10分钟 则每隔10分钟刷一次 否则过期前15秒更新 token
16219
- // 如果没登录 每隔10秒走token更新逻辑(如果刚开始没登录 后面才登录【不需要再在登陆后写刷新token逻辑】)
16220
- var time = 0;
16221
- if (loginState.islogin) {
16222
- var user = getUserByToken(getRefreshToken());
16223
- if (user !== null && user !== void 0 && user.tokenId) {
16224
- time = Number(getTokenExpires()) - Date.now() - 1000 * 15;
16225
- // 如果剩余时间大于10分钟 则每隔10分钟刷一次
16226
- if (time > 600000) {
16227
- time = 600000;
16228
- } else if (time < 0) {
16229
- time = 0;
16230
- }
16231
- } else {
16232
- time = 10000;
16233
- }
16234
- } else {
16235
- if (loginState.type === 2) {
16236
- time = 0;
16237
- } else {
16238
- time = 10000;
16239
- }
16240
- }
16241
- // time = 5000
16242
- refreshtokenTimer = window.setTimeout( /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
16243
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
16244
- while (1) switch (_context.prev = _context.next) {
16245
- case 0:
16246
- if (!(getLoginState().type >= 2)) {
16247
- _context.next = 3;
16248
- break;
16249
- }
16250
- _context.next = 3;
16251
- return updateToken();
16252
- case 3:
16253
- startRefreshtoken();
16254
- case 4:
16255
- case "end":
16256
- return _context.stop();
16257
- }
16258
- }, _callee);
16259
- })), time);
16260
- }
16261
16216
  function getUser(key) {
16262
16217
  var user = getData('user');
16263
16218
  var userObj = user ? JSON.parse(user) : null;
@@ -16572,63 +16527,105 @@ function _getAndSetTenant() {
16572
16527
  }));
16573
16528
  return _getAndSetTenant.apply(this, arguments);
16574
16529
  }
16575
- function requestAndSetTenantSetting(_x2) {
16576
- return _requestAndSetTenantSetting.apply(this, arguments);
16530
+ function updateToken() {
16531
+ var loginState = getLoginState();
16532
+ if (!loginState.islogin && loginState.type <= 1) {
16533
+ console.warn('当前未登录/token过期,不支持自动刷新token。');
16534
+ return false;
16535
+ }
16536
+ if (loginState.role === 'center') {
16537
+ console.warn('当前登录为产品运营中心用户,不支持自动刷新token。');
16538
+ return false;
16539
+ }
16540
+ var token = getToken();
16541
+ var refreshtoken = getRefreshToken();
16542
+ var sendToken = checkLoginByToken(token) ? token : refreshtoken;
16543
+ return normalAxios$1.get('/api/auth/refreshtoken', {
16544
+ params: {
16545
+ refreshtoken: sendToken
16546
+ },
16547
+ isShowLoading: false,
16548
+ isShowErrorMessage: false,
16549
+ isSendToken: false,
16550
+ isSendTecode: true,
16551
+ headers: {
16552
+ token: sendToken
16553
+ }
16554
+ }).then(function (res) {
16555
+ // console.log(res)
16556
+ var data = res === null || res === void 0 ? void 0 : res.data;
16557
+ if (data) {
16558
+ setToken(data.token);
16559
+ setRefreshToken(data.refreshtoken);
16560
+ setTokenExpires(data.tokenexpires);
16561
+ }
16562
+ });
16577
16563
  }
16578
- function _requestAndSetTenantSetting() {
16579
- _requestAndSetTenantSetting = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(tenantcode) {
16580
- var _res$data2, res, tenantSetting;
16581
- return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16582
- while (1) switch (_context5.prev = _context5.next) {
16564
+ var refreshtokenTimer = null;
16565
+ function startRefreshtoken() {
16566
+ var loginState = getLoginState();
16567
+ // 如果是产品运营中心 则不走刷新token流程
16568
+ if (loginState.role === 'center') {
16569
+ console.warn('当前登录为产品运营中心用户,不支持自动刷新token。');
16570
+ return false;
16571
+ }
16572
+ // stopRefreshtoken()
16573
+ clearTimeout(refreshtokenTimer);
16574
+ refreshtokenTimer = null;
16575
+ // 如果有登录 但 refreshtoken 不是完整 token 则10秒后【需要等单点登录走完后才刷新不然会被覆盖】刷新一次取到完整 token
16576
+ // 如果有登录 且 refreshtoken 是完整 token 如果剩余时间大于10分钟 则每隔10分钟刷一次 否则过期前15秒更新 token
16577
+ // 如果没登录 每隔10秒走token更新逻辑(如果刚开始没登录 后面才登录【不需要再在登陆后写刷新token逻辑】)
16578
+ var time = 0;
16579
+ if (loginState.islogin) {
16580
+ var user = getUserByToken(getRefreshToken());
16581
+ if (user !== null && user !== void 0 && user.tokenId) {
16582
+ time = Number(getTokenExpires()) - Date.now() - 1000 * 15;
16583
+ // 如果剩余时间大于10分钟 则每隔10分钟刷一次
16584
+ if (time > 600000) {
16585
+ time = 600000;
16586
+ } else if (time < 0) {
16587
+ time = 0;
16588
+ }
16589
+ } else {
16590
+ time = 10000;
16591
+ }
16592
+ } else {
16593
+ if (loginState.type === 2) {
16594
+ time = 0;
16595
+ } else {
16596
+ // console.error('未登录,10秒后尝试更新token')
16597
+ time = 30000;
16598
+ }
16599
+ }
16600
+ // time = 5000
16601
+ refreshtokenTimer = window.setTimeout( /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
16602
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
16603
+ while (1) switch (_context.prev = _context.next) {
16583
16604
  case 0:
16584
- _context5.prev = 0;
16585
- _context5.next = 3;
16586
- return normalAxios$1.post('/api/auth/tenantsettings', {
16587
- tenantcode: tenantcode || ''
16588
- }, {
16589
- isSendToken: false,
16590
- isSendTecode: true,
16591
- isShowErrorMessage: false
16592
- });
16593
- case 3:
16594
- res = _context5.sent;
16595
- tenantSetting = (res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 || (_res$data2 = _res$data2.resp_data) === null || _res$data2 === void 0 ? void 0 : _res$data2.econfig) || '';
16596
- if (tenantSetting) {
16597
- tenantSetting = decrypt(tenantSetting);
16598
- }
16599
- // console.log(tenantSetting)
16600
- if (tenantSetting) {
16601
- lsProxy.setItem('tenantsetting', tenantSetting);
16602
- } else {
16603
- removeTenantSetting();
16605
+ if (!(getLoginState().type >= 2)) {
16606
+ _context.next = 3;
16607
+ break;
16604
16608
  }
16605
- _context5.next = 13;
16606
- break;
16607
- case 9:
16608
- _context5.prev = 9;
16609
- _context5.t0 = _context5["catch"](0);
16610
- console.error(_context5.t0);
16611
- removeTenantSetting();
16612
- case 13:
16609
+ _context.next = 3;
16610
+ return updateToken();
16611
+ case 3:
16612
+ startRefreshtoken();
16613
+ case 4:
16613
16614
  case "end":
16614
- return _context5.stop();
16615
+ return _context.stop();
16615
16616
  }
16616
- }, _callee5, null, [[0, 9]]);
16617
- }));
16618
- return _requestAndSetTenantSetting.apply(this, arguments);
16619
- }
16620
- function removeTenantSetting() {
16621
- lsProxy.removeItem('tenantsetting');
16617
+ }, _callee);
16618
+ })), time);
16622
16619
  }
16623
16620
  // 单点登录
16624
- function singleLogin(_x3) {
16621
+ function singleLogin(_x2) {
16625
16622
  return _singleLogin.apply(this, arguments);
16626
16623
  }
16627
16624
  function _singleLogin() {
16628
- _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6(query) {
16625
+ _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(query) {
16629
16626
  var flag, token, refreshtoken, tokenexpires, envname, context, setBaseInfo, isneedlogin, loginRole, refreshTokenUser, tokenUser, nowEnvname, envData;
16630
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
16631
- while (1) switch (_context6.prev = _context6.next) {
16627
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16628
+ while (1) switch (_context5.prev = _context5.next) {
16632
16629
  case 0:
16633
16630
  setBaseInfo = function _setBaseInfo() {
16634
16631
  setToken(token);
@@ -16648,7 +16645,7 @@ function _singleLogin() {
16648
16645
  envname = query.envname;
16649
16646
  context = query.context;
16650
16647
  if (!checkLoginByToken(token)) {
16651
- _context6.next = 48;
16648
+ _context5.next = 60;
16652
16649
  break;
16653
16650
  }
16654
16651
  isneedlogin = true; // 是否需要走单点登录流程
@@ -16670,91 +16667,104 @@ function _singleLogin() {
16670
16667
  // isneedlogin = true
16671
16668
  // debugger
16672
16669
  if (!isneedlogin) {
16673
- _context6.next = 46;
16670
+ _context5.next = 58;
16674
16671
  break;
16675
16672
  }
16676
16673
  setBaseInfo();
16677
- // 单点登录写入 token 之后 换取完整的 refreshtoken
16678
- try {
16679
- if (checkLogin()) {
16680
- refreshTokenUser = getUserByToken(getRefreshToken());
16681
- tokenUser = getUserByToken(getToken());
16682
- if (!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId) {
16683
- updateToken();
16684
- }
16685
- }
16686
- } catch (err) {
16687
- console.error(err);
16674
+ // 单点登录写入 token 之后
16675
+ // 1、如果 refreshtoken 不完整 则换取完整的 refreshtoken
16676
+ _context5.prev = 14;
16677
+ if (!checkLogin()) {
16678
+ _context5.next = 21;
16679
+ break;
16688
16680
  }
16681
+ refreshTokenUser = getUserByToken(getRefreshToken());
16682
+ tokenUser = getUserByToken(getToken());
16683
+ if (!(!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId)) {
16684
+ _context5.next = 21;
16685
+ break;
16686
+ }
16687
+ _context5.next = 21;
16688
+ return updateToken();
16689
+ case 21:
16690
+ _context5.next = 26;
16691
+ break;
16692
+ case 23:
16693
+ _context5.prev = 23;
16694
+ _context5.t0 = _context5["catch"](14);
16695
+ console.error(_context5.t0);
16696
+ case 26:
16697
+ // 2、重新计算刷新 token 时间 因为刚开始进入就 startRefreshtoken 检测到没有 token 会过10秒才执行刷新 token 操作
16698
+ startRefreshtoken();
16689
16699
  // 获取环境信息和租户配置信息
16690
- _context6.next = 17;
16700
+ _context5.next = 29;
16691
16701
  return getEnvname();
16692
- case 17:
16693
- nowEnvname = _context6.sent;
16702
+ case 29:
16703
+ nowEnvname = _context5.sent;
16694
16704
  if (!nowEnvname) {
16695
- _context6.next = 38;
16705
+ _context5.next = 50;
16696
16706
  break;
16697
16707
  }
16698
- _context6.next = 21;
16708
+ _context5.next = 33;
16699
16709
  return requestEnvdata(nowEnvname);
16700
- case 21:
16701
- envData = _context6.sent;
16710
+ case 33:
16711
+ envData = _context5.sent;
16702
16712
  if (!envData) {
16703
- _context6.next = 34;
16713
+ _context5.next = 46;
16704
16714
  break;
16705
16715
  }
16706
16716
  saveEnvdata(envData);
16707
16717
  if (!envData.tenantcode) {
16708
- _context6.next = 30;
16718
+ _context5.next = 42;
16709
16719
  break;
16710
16720
  }
16711
16721
  setTecode(envData.tenantcode);
16712
16722
  // 租户配置
16713
- _context6.next = 28;
16714
- return requestAndSetTenantSetting(envData.tenantcode);
16715
- case 28:
16716
- _context6.next = 32;
16723
+ _context5.next = 40;
16724
+ return tenantSetting.requestAndSetTenantSetting(envData.tenantcode);
16725
+ case 40:
16726
+ _context5.next = 44;
16717
16727
  break;
16718
- case 30:
16719
- removeTenantSetting();
16728
+ case 42:
16729
+ tenantSetting.removeTenantSetting();
16720
16730
  removeTecode();
16721
- case 32:
16722
- _context6.next = 36;
16731
+ case 44:
16732
+ _context5.next = 48;
16723
16733
  break;
16724
- case 34:
16734
+ case 46:
16725
16735
  removeEnvdata();
16726
16736
  removeTecode();
16727
- case 36:
16728
- _context6.next = 40;
16737
+ case 48:
16738
+ _context5.next = 52;
16729
16739
  break;
16730
- case 38:
16740
+ case 50:
16731
16741
  removeEnvdata();
16732
16742
  removeTecode();
16733
- case 40:
16734
- _context6.next = 42;
16743
+ case 52:
16744
+ _context5.next = 54;
16735
16745
  return getAndSetTenant();
16736
- case 42:
16737
- _context6.next = 44;
16746
+ case 54:
16747
+ _context5.next = 56;
16738
16748
  return getAndSetUserInfo();
16739
- case 44:
16749
+ case 56:
16740
16750
  // 单点登录后 获取 web 开发者模式 如果是则设置 isdebugger
16741
16751
  urlquery.dealWebDebugger();
16742
16752
  flag = true;
16743
- case 46:
16744
- _context6.next = 51;
16753
+ case 58:
16754
+ _context5.next = 63;
16745
16755
  break;
16746
- case 48:
16756
+ case 60:
16747
16757
  flag = false;
16748
16758
  setBaseInfo(); // 传递的token过期依然写入 如果不写入的话 有可能之前的token本来没过期 页面依然可用
16749
16759
  console.error('单点登录失败,请检查链接所传 token/refreshtoken/tokenexpires 是否非法或过期。');
16750
- case 51:
16760
+ case 63:
16751
16761
  if (!flag) {
16752
- _context6.next = 54;
16762
+ _context5.next = 66;
16753
16763
  break;
16754
16764
  }
16755
- _context6.next = 54;
16765
+ _context5.next = 66;
16756
16766
  return core$1.initGetData();
16757
- case 54:
16767
+ case 66:
16758
16768
  if (flag) {
16759
16769
  // 单点登录成功 需要删除 query 中相关参数
16760
16770
  token && delete query.token;
@@ -16763,15 +16773,15 @@ function _singleLogin() {
16763
16773
  envname && delete query.envname;
16764
16774
  context && delete query.context;
16765
16775
  }
16766
- return _context6.abrupt("return", {
16776
+ return _context5.abrupt("return", {
16767
16777
  flag: flag,
16768
16778
  query: query
16769
16779
  });
16770
- case 56:
16780
+ case 68:
16771
16781
  case "end":
16772
- return _context6.stop();
16782
+ return _context5.stop();
16773
16783
  }
16774
- }, _callee6);
16784
+ }, _callee5, null, [[14, 23]]);
16775
16785
  }));
16776
16786
  return _singleLogin.apply(this, arguments);
16777
16787
  }
@@ -16812,7 +16822,7 @@ function installAuth(options) {
16812
16822
  }
16813
16823
  }, _callee2);
16814
16824
  }));
16815
- return function (_x4, _x5, _x6) {
16825
+ return function (_x3, _x4, _x5) {
16816
16826
  return _ref2.apply(this, arguments);
16817
16827
  };
16818
16828
  }());
@@ -16898,6 +16908,44 @@ function toggleHttpOrHttps(url) {
16898
16908
  }
16899
16909
  return res;
16900
16910
  }
16911
+ var urlMap = new Map();
16912
+ function importJS(url) {
16913
+ var attrName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
16914
+ var p = urlMap.get(url);
16915
+ if (p) {
16916
+ return p.then(function () {
16917
+ return Promise.resolve(attrName ? get$1(window, attrName) : undefined);
16918
+ });
16919
+ }
16920
+ var script = document.createElement('script');
16921
+ script.setAttribute('type', 'text/javascript');
16922
+ script.setAttribute('src', url);
16923
+ document.getElementsByTagName('head')[0].appendChild(script);
16924
+ p = new Promise(function (resolve, reject) {
16925
+ script.onload = script.onreadystatechange = function () {
16926
+ var f = script.readyState;
16927
+ if (f && f !== 'loaded' && f !== 'complete') return;
16928
+ script.onload = script.onreadystatechange = null;
16929
+ resolve(undefined);
16930
+ };
16931
+ script.onerror = function () {
16932
+ return reject(new Error('加载失败'));
16933
+ };
16934
+ });
16935
+ urlMap.set(url, p);
16936
+ // console.log('importJS:', url, attrName)
16937
+ return p.then(function () {
16938
+ return Promise.resolve(attrName ? get$1(window, attrName) : undefined);
16939
+ });
16940
+ }
16941
+ var delay = function delay() {
16942
+ var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
16943
+ return new Promise(function (resolve) {
16944
+ setTimeout(function () {
16945
+ resolve(null);
16946
+ }, timeout);
16947
+ });
16948
+ };
16901
16949
 
16902
16950
  var Urlquery = /*#__PURE__*/function () {
16903
16951
  function Urlquery() {
@@ -16973,347 +17021,1249 @@ function installUrlquery() {
16973
17021
  urlquery.init();
16974
17022
  }
16975
17023
 
16976
- var AMap = null;
16977
- var geocoder = null;
16978
- var geolocation = null;
17024
+ // 高德地图 web端key 和 安全密钥
17025
+ var AMapKey = {
17026
+ // 测试开发环境
17027
+ dev: {
17028
+ key: '38fa4702d240e1e6ee5cc8ca059b254f',
17029
+ securityJsCode: '96f2af5670b7a41a56dcd2e8b63c1e06'
17030
+ },
17031
+ // 生产环境
17032
+ production: {
17033
+ key: '1993ac213d2f4675ac1bffb1b03ef1f0',
17034
+ securityJsCode: '816fe46b7b7bce145940b93c1e4818fa'
17035
+ }
17036
+ };
17037
+ var getAMapKey = function getAMapKey() {
17038
+ if (mapService.isLbssettingEnable && mapService.type === 'amap') {
17039
+ return {
17040
+ key: mapService.key,
17041
+ securityJsCode: mapService.secretkey
17042
+ };
17043
+ } else {
17044
+ return {
17045
+ key: AMapKey.production.key,
17046
+ securityJsCode: AMapKey.production.securityJsCode
17047
+ };
17048
+ }
17049
+ };
17050
+
17051
+ var dist = {exports: {}};
17052
+
17053
+ (function (module, exports) {
17054
+ (function(m,p){module.exports=p();})(commonjsGlobal,function(){function m(a){var b=[];a.AMapUI&&b.push(p(a.AMapUI));a.Loca&&b.push(r(a.Loca));return Promise.all(b)}function p(a){return new Promise(function(h,c){var f=[];if(a.plugins)for(var e=0;e<a.plugins.length;e+=1)-1==d.AMapUI.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(g.AMapUI===b.failed)c("\u524d\u6b21\u8bf7\u6c42 AMapUI \u5931\u8d25");
17055
+ else if(g.AMapUI===b.notload){g.AMapUI=b.loading;d.AMapUI.version=a.version||d.AMapUI.version;e=d.AMapUI.version;var l=document.body||document.head,k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/ui/"+e+"/main.js";k.onerror=function(a){g.AMapUI=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25");};k.onload=function(){g.AMapUI=b.loaded;if(f.length)window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=
17056
+ arguments[a];}for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();});else for(h();n.AMapUI.length;)n.AMapUI.splice(0,1)[0]();};l.appendChild(k);}else g.AMapUI===b.loaded?a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a];}h();}):h():a.version&&a.version!==d.AMapUI.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c AMapUI \u6df7\u7528"):
17057
+ n.AMapUI.push(function(a){a?c(a):f.length?window.AMapUI.loadUI(f,function(){for(var a=0,b=f.length;a<b;a++){var c=f[a].split("/").slice(-1)[0];window.AMapUI[c]=arguments[a];}h();}):h();});})}function r(a){return new Promise(function(h,c){if(g.Loca===b.failed)c("\u524d\u6b21\u8bf7\u6c42 Loca \u5931\u8d25");else if(g.Loca===b.notload){g.Loca=b.loading;d.Loca.version=a.version||d.Loca.version;var f=d.Loca.version,e=d.AMap.version.startsWith("2"),l=f.startsWith("2");if(e&&!l||!e&&l)c("JSAPI \u4e0e Loca \u7248\u672c\u4e0d\u5bf9\u5e94\uff01\uff01");
17058
+ else {e=d.key;l=document.body||document.head;var k=document.createElement("script");k.type="text/javascript";k.src="https://webapi.amap.com/loca?v="+f+"&key="+e;k.onerror=function(a){g.Loca=b.failed;c("\u8bf7\u6c42 AMapUI \u5931\u8d25");};k.onload=function(){g.Loca=b.loaded;for(h();n.Loca.length;)n.Loca.splice(0,1)[0]();};l.appendChild(k);}}else g.Loca===b.loaded?a.version&&a.version!==d.Loca.version?c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):h():a.version&&a.version!==d.Loca.version?
17059
+ c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c Loca \u6df7\u7528"):n.Loca.push(function(a){a?c(a):c();});})}if(!window)throw Error("AMap JSAPI can only be used in Browser.");var b;(function(a){a.notload="notload";a.loading="loading";a.loaded="loaded";a.failed="failed";})(b||(b={}));var d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}},g={AMap:b.notload,AMapUI:b.notload,Loca:b.notload},n={AMap:[],AMapUI:[],Loca:[]},q=[],t=function(a){"function"==typeof a&&
17060
+ (g.AMap===b.loaded?a(window.AMap):q.push(a));};return {load:function(a){return new Promise(function(h,c){if(g.AMap==b.failed)c("");else if(g.AMap==b.notload){var f=a.key,e=a.version,l=a.plugins;f?(window.AMap&&"lbs.amap.com"!==location.host&&c("\u7981\u6b62\u591a\u79cdAPI\u52a0\u8f7d\u65b9\u5f0f\u6df7\u7528"),d.key=f,d.AMap.version=e||d.AMap.version,d.AMap.plugins=l||d.AMap.plugins,g.AMap=b.loading,e=document.body||document.head,window.___onAPILoaded=function(d){delete window.___onAPILoaded;if(d)g.AMap=
17061
+ b.failed,c(d);else for(g.AMap=b.loaded,m(a).then(function(){h(window.AMap);})["catch"](c);q.length;)q.splice(0,1)[0]();},l=document.createElement("script"),l.type="text/javascript",l.src="https://webapi.amap.com/maps?callback=___onAPILoaded&v="+d.AMap.version+"&key="+f+"&plugin="+d.AMap.plugins.join(","),l.onerror=function(a){g.AMap=b.failed;c(a);},e.appendChild(l)):c("\u8bf7\u586b\u5199key");}else if(g.AMap==b.loaded)if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&
17062
+ a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");else {f=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&f.push(a.plugins[e]);if(f.length)window.AMap.plugin(f,function(){m(a).then(function(){h(window.AMap);})["catch"](c);});else m(a).then(function(){h(window.AMap);})["catch"](c);}else if(a.key&&a.key!==d.key)c("\u591a\u4e2a\u4e0d\u4e00\u81f4\u7684 key");else if(a.version&&a.version!==d.AMap.version)c("\u4e0d\u5141\u8bb8\u591a\u4e2a\u7248\u672c JSAPI \u6df7\u7528");
17063
+ else {var k=[];if(a.plugins)for(e=0;e<a.plugins.length;e+=1)-1==d.AMap.plugins.indexOf(a.plugins[e])&&k.push(a.plugins[e]);t(function(){if(k.length)window.AMap.plugin(k,function(){m(a).then(function(){h(window.AMap);})["catch"](c);});else m(a).then(function(){h(window.AMap);})["catch"](c);});}})},reset:function(){delete window.AMap;delete window.AMapUI;delete window.Loca;d={key:"",AMap:{version:"1.4.15",plugins:[]},AMapUI:{version:"1.1",plugins:[]},Loca:{version:"1.3.2"}};g={AMap:b.notload,AMapUI:b.notload,
17064
+ Loca:b.notload};n={AMap:[],AMapUI:[],Loca:[]};}}});
17065
+ } (dist));
17066
+
17067
+ var distExports = dist.exports;
17068
+ var AMapLoader$1 = /*@__PURE__*/getDefaultExportFromCjs(distExports);
17069
+
17070
+ var MapService = /*#__PURE__*/function () {
17071
+ function MapService() {
17072
+ _classCallCheck$1(this, MapService);
17073
+ _defineProperty$1(this, "isInit", false);
17074
+ }
17075
+ _createClass$1(MapService, [{
17076
+ key: "isLbssettingEnable",
17077
+ get: function get() {
17078
+ var _tenantSetting$get;
17079
+ return ((_tenantSetting$get = tenantSetting.get('lbssetting')) === null || _tenantSetting$get === void 0 ? void 0 : _tenantSetting$get.enable) === '1';
17080
+ }
17081
+ }, {
17082
+ key: "setting",
17083
+ get: function get() {
17084
+ var _tenantSetting$get2;
17085
+ return (_tenantSetting$get2 = tenantSetting.get('lbssetting')) === null || _tenantSetting$get2 === void 0 ? void 0 : _tenantSetting$get2.setting;
17086
+ }
17087
+ }, {
17088
+ key: "key",
17089
+ get: function get() {
17090
+ if (this.isLbssettingEnable) {
17091
+ var _this$setting;
17092
+ return ((_this$setting = this.setting) === null || _this$setting === void 0 || (_this$setting = _this$setting.key) === null || _this$setting === void 0 ? void 0 : _this$setting.web) || '';
17093
+ } else {
17094
+ return AMapKey.production.key;
17095
+ }
17096
+ }
17097
+ }, {
17098
+ key: "secretkey",
17099
+ get: function get() {
17100
+ if (this.isLbssettingEnable) {
17101
+ var _this$setting2;
17102
+ return ((_this$setting2 = this.setting) === null || _this$setting2 === void 0 || (_this$setting2 = _this$setting2.secretkey) === null || _this$setting2 === void 0 ? void 0 : _this$setting2.web) || '';
17103
+ } else {
17104
+ return AMapKey.production.securityJsCode;
17105
+ }
17106
+ }
17107
+ }, {
17108
+ key: "type",
17109
+ get: function get() {
17110
+ if (this.isLbssettingEnable) {
17111
+ var _this$setting3;
17112
+ return ((_this$setting3 = this.setting) === null || _this$setting3 === void 0 ? void 0 : _this$setting3.type) || 'amap';
17113
+ } else {
17114
+ return 'amap';
17115
+ }
17116
+ }
17117
+ }, {
17118
+ key: "AMap",
17119
+ get: function get() {
17120
+ if (!this.isInit || this.type !== 'amap') {
17121
+ return null;
17122
+ }
17123
+ return window.AMap;
17124
+ }
17125
+ }, {
17126
+ key: "TMap",
17127
+ get: function get() {
17128
+ if (!this.isInit || this.type !== 'tencent') {
17129
+ return null;
17130
+ }
17131
+ return window.TMap;
17132
+ }
17133
+ }, {
17134
+ key: "BMap",
17135
+ get: function get() {
17136
+ if (!this.isInit || this.type !== 'baidu') {
17137
+ return null;
17138
+ }
17139
+ return window.BMap;
17140
+ }
17141
+ }, {
17142
+ key: "init",
17143
+ value: function () {
17144
+ var _init = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17145
+ var type;
17146
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
17147
+ while (1) switch (_context.prev = _context.next) {
17148
+ case 0:
17149
+ if (!this.isInit) {
17150
+ _context.next = 2;
17151
+ break;
17152
+ }
17153
+ return _context.abrupt("return");
17154
+ case 2:
17155
+ this.isInit = true;
17156
+ type = this.type; // if (process.env.NODE_ENV === 'development') {
17157
+ // type = 'baidu'
17158
+ // }
17159
+ if (!(type === 'tencent')) {
17160
+ _context.next = 9;
17161
+ break;
17162
+ }
17163
+ _context.next = 7;
17164
+ return this.initTecent();
17165
+ case 7:
17166
+ _context.next = 17;
17167
+ break;
17168
+ case 9:
17169
+ if (!(type === 'amap')) {
17170
+ _context.next = 14;
17171
+ break;
17172
+ }
17173
+ _context.next = 12;
17174
+ return this.initAmap();
17175
+ case 12:
17176
+ _context.next = 17;
17177
+ break;
17178
+ case 14:
17179
+ if (!(type === 'baidu')) {
17180
+ _context.next = 17;
17181
+ break;
17182
+ }
17183
+ _context.next = 17;
17184
+ return this.initBaidu();
17185
+ case 17:
17186
+ case "end":
17187
+ return _context.stop();
17188
+ }
17189
+ }, _callee, this);
17190
+ }));
17191
+ function init() {
17192
+ return _init.apply(this, arguments);
17193
+ }
17194
+ return init;
17195
+ }() // reset() {
17196
+ // this.isInit = false
17197
+ // }
17198
+ }, {
17199
+ key: "initTecent",
17200
+ value: function () {
17201
+ var _initTecent = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17202
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17203
+ while (1) switch (_context2.prev = _context2.next) {
17204
+ case 0:
17205
+ _context2.next = 2;
17206
+ return importJS("https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=".concat(this.key),
17207
+ // `https://map.qq.com/api/gljs?v=1.exp&key=${this.key}`,
17208
+ 'TMap');
17209
+ case 2:
17210
+ _context2.next = 4;
17211
+ return delay(300);
17212
+ case 4:
17213
+ case "end":
17214
+ return _context2.stop();
17215
+ }
17216
+ }, _callee2, this);
17217
+ }));
17218
+ function initTecent() {
17219
+ return _initTecent.apply(this, arguments);
17220
+ }
17221
+ return initTecent;
17222
+ }()
17223
+ }, {
17224
+ key: "initAmap",
17225
+ value: function () {
17226
+ var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17227
+ var plugin, AMap;
17228
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17229
+ while (1) switch (_context3.prev = _context3.next) {
17230
+ case 0:
17231
+ // if (this.secretkey) {
17232
+ // window._AMapSecurityConfig = {
17233
+ // securityJsCode: this.secretkey
17234
+ // }
17235
+ // }
17236
+ plugin = ['AMap.Geolocation']; // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
17237
+ _context3.next = 3;
17238
+ return AMapLoader$1.load({
17239
+ key: this.key,
17240
+ version: '2.0',
17241
+ plugins: plugin,
17242
+ AMapUI: {
17243
+ version: '1.1',
17244
+ plugins: []
17245
+ }
17246
+ });
17247
+ case 3:
17248
+ AMap = _context3.sent;
17249
+ window.AMap = AMap;
17250
+ // console.log(window)
17251
+ // console.log(window.AMap)
17252
+ // console.log(window.AMapUI)
17253
+ // console.log(window.AMapLoader)
17254
+ // console.log(window.AMap === aaaa)
17255
+ case 5:
17256
+ case "end":
17257
+ return _context3.stop();
17258
+ }
17259
+ }, _callee3, this);
17260
+ }));
17261
+ function initAmap() {
17262
+ return _initAmap.apply(this, arguments);
17263
+ }
17264
+ return initAmap;
17265
+ }()
17266
+ }, {
17267
+ key: "initBaidu",
17268
+ value: function () {
17269
+ var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17270
+ var _this = this;
17271
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17272
+ while (1) switch (_context4.prev = _context4.next) {
17273
+ case 0:
17274
+ return _context4.abrupt("return", new Promise(function (resolve, reject) {
17275
+ window.__baiduMapInitial = function () {
17276
+ // 启用google标准坐标体系
17277
+ // coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
17278
+ window.BMap.coordType = 'BMAP_COORD_GCJ02';
17279
+ resolve(null);
17280
+ };
17281
+ var script = document.createElement('script');
17282
+ // 使用最新 3.0 api https://lbsyun.baidu.com/index.php?title=jspopular3.0
17283
+ script.src = "https://api.map.baidu.com/api?v=3.0&ak=".concat(_this.key, "&callback=__baiduMapInitial");
17284
+ // script.src = `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}&callback=__baiduMapInitial`
17285
+ script.onerror = function (err) {
17286
+ reject(err);
17287
+ };
17288
+ document.body.appendChild(script);
17289
+ }));
17290
+ case 1:
17291
+ case "end":
17292
+ return _context4.stop();
17293
+ }
17294
+ }, _callee4);
17295
+ }));
17296
+ function initBaidu() {
17297
+ return _initBaidu.apply(this, arguments);
17298
+ }
17299
+ return initBaidu;
17300
+ }()
17301
+ }]);
17302
+ return MapService;
17303
+ }();
17304
+ var mapService = new MapService();
17305
+
17306
+ function transformLat(x, y) {
17307
+ var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
17308
+ ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
17309
+ ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0;
17310
+ ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0;
17311
+ return ret;
17312
+ }
17313
+ function transformLon(x, y) {
17314
+ var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
17315
+ ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0;
17316
+ ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0;
17317
+ ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0;
17318
+ return ret;
17319
+ }
17320
+ function outOfChina(lng, lat) {
17321
+ return lng < 72.004 || lng > 137.8347 || lat < 0.8293 || lat > 55.8271;
17322
+ }
17323
+ function delta(lng, lat) {
17324
+ var a = 6378245.0; // 地球长半轴
17325
+ var ee = 0.00669342162296594323; // 扁率
17326
+ var dLat = transformLat(lng - 105.0, lat - 35.0);
17327
+ var dLng = transformLon(lng - 105.0, lat - 35.0);
17328
+ var radLat = lat / 180.0 * Math.PI;
17329
+ var magic = Math.sin(radLat);
17330
+ magic = 1 - ee * magic * magic;
17331
+ var sqrtMagic = Math.sqrt(magic);
17332
+ dLat = dLat * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * Math.PI);
17333
+ dLng = dLng * 180.0 / (a / sqrtMagic * Math.cos(radLat) * Math.PI);
17334
+ return {
17335
+ lat: dLat,
17336
+ lng: dLng
17337
+ };
17338
+ }
17339
+ function wgs84ToGcj02(lng, lat) {
17340
+ if (outOfChina(lng, lat)) {
17341
+ return {
17342
+ lng: lng,
17343
+ lat: lat
17344
+ };
17345
+ }
17346
+ var d = delta(lng, lat);
17347
+ return {
17348
+ lng: lng + d.lng,
17349
+ lat: lat + d.lat
17350
+ };
17351
+ }
17352
+ /**
17353
+ * 坐标常量说明:
17354
+ * COORDINATES_WGS84 = 1, WGS84坐标
17355
+ * COORDINATES_WGS84_MC = 2, WGS84的平面墨卡托坐标
17356
+ * COORDINATES_GCJ02 = 3,GCJ02坐标
17357
+ * COORDINATES_GCJ02_MC = 4, GCJ02的平面墨卡托坐标
17358
+ * COORDINATES_BD09 = 5, 百度bd09经纬度坐标
17359
+ * COORDINATES_BD09_MC = 6,百度bd09墨卡托坐标
17360
+ * COORDINATES_MAPBAR = 7,mapbar地图坐标
17361
+ * COORDINATES_51 = 8,51地图坐标
17362
+ */
17363
+ var BMapTransformBD09ToGCJ02Points = function BMapTransformBD09ToGCJ02Points(points) {
17364
+ return new Promise(function (resolve, reject) {
17365
+ new window.BMap.Convertor().translate(points, 5, 3, function (data) {
17366
+ if (!data.status) {
17367
+ resolve(data.points);
17368
+ } else {
17369
+ console.error(data);
17370
+ // reject(data.status)
17371
+ resolve(points);
17372
+ }
17373
+ });
17374
+ });
17375
+ };
17376
+
17377
+ var cachetime = 30000; // 缓存时间30秒
16979
17378
  var datetime = null;
16980
17379
  var lastLocation = null;
16981
17380
  var runing = false;
16982
17381
  var locationPromise;
16983
- function init() {
16984
- return _init.apply(this, arguments);
16985
- }
16986
- function _init() {
16987
- _init = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17382
+ // app端默认坐标为 gcj02
17383
+ var getLocationByNative = /*#__PURE__*/function () {
17384
+ var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
16988
17385
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
16989
17386
  while (1) switch (_context.prev = _context.next) {
16990
17387
  case 0:
16991
- if (AMap) {
16992
- _context.next = 6;
16993
- break;
16994
- }
16995
- _context.next = 3;
16996
- return AMapLoader.load({
16997
- plugins: ['AMap.Geolocation', 'AMap.Geocoder']
16998
- });
16999
- case 3:
17000
- AMap = _context.sent;
17001
- geocoder = new AMap.Geocoder({
17002
- city: '',
17003
- radius: 500
17004
- });
17005
- geolocation = new AMap.Geolocation({
17006
- enableHighAccuracy: true,
17007
- timeout: 3000
17008
- });
17009
- case 6:
17388
+ console.log('getLocationByNative start...');
17389
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
17390
+ var isload = false;
17391
+ setTimeout(function () {
17392
+ if (!isload) {
17393
+ console.error('getLocationByNative fail: timeout 30000');
17394
+ resolve(null);
17395
+ }
17396
+ }, 30000);
17397
+ window.Native.getLocation(function (res, error, status) {
17398
+ // console.log('getLocation res', res)
17399
+ // console.log('getLocation error', error)
17400
+ // console.log('getLocation status', status)
17401
+ isload = true;
17402
+ if (res && res !== null && res !== void 0 && res.longitude && res !== null && res !== void 0 && res.latitude) {
17403
+ var result = {
17404
+ longitude: res.longitude.toString(),
17405
+ latitude: res.latitude.toString(),
17406
+ address: res.address || ''
17407
+ };
17408
+ console.log("getLocationByNative success: ".concat(JSON.stringify(result)));
17409
+ resolve(result);
17410
+ } else {
17411
+ console.error('getLocationByNative fail');
17412
+ resolve(null);
17413
+ }
17414
+ });
17415
+ }));
17416
+ case 2:
17010
17417
  case "end":
17011
17418
  return _context.stop();
17012
17419
  }
17013
17420
  }, _callee);
17014
17421
  }));
17015
- return _init.apply(this, arguments);
17016
- }
17017
- function getAmapLocation() {
17018
- return _getAmapLocation.apply(this, arguments);
17019
- }
17020
- function _getAmapLocation() {
17021
- _getAmapLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17422
+ return function getLocationByNative() {
17423
+ return _ref.apply(this, arguments);
17424
+ };
17425
+ }();
17426
+ // 浏览器定位: 需要开启https
17427
+ var getLocationByNavigator = /*#__PURE__*/function () {
17428
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2() {
17022
17429
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
17023
17430
  while (1) switch (_context2.prev = _context2.next) {
17024
17431
  case 0:
17025
- _context2.next = 2;
17026
- return init();
17027
- case 2:
17432
+ console.log('getLocationByNavigator start...');
17028
17433
  return _context2.abrupt("return", new Promise(function (resolve, reject) {
17029
- // https://blog.csdn.net/Liu331013/article/details/115423749
17030
- geolocation.getCurrentPosition(function (status, result) {
17031
- console.log(status, result);
17032
- if (status === 'complete') {
17033
- var _result$position = result.position,
17034
- lng = _result$position.lng,
17035
- lat = _result$position.lat;
17036
- // console.log('getAmapLocation success')
17037
- resolve({
17038
- longitude: lng.toString(),
17039
- latitude: lat.toString(),
17040
- address: ''
17041
- });
17042
- } else {
17043
- // reject(new Error('getAmapLocation fail'))
17044
- console.error('getAmapLocation fail');
17434
+ if ('geolocation' in navigator) {
17435
+ var time = setTimeout(function () {
17436
+ console.error('getLocationByNavigator fail: timeout 5000');
17045
17437
  resolve(null);
17046
- }
17047
- });
17438
+ }, 5000);
17439
+ navigator.geolocation.getCurrentPosition(function (position) {
17440
+ // console.log(position)
17441
+ // debugger
17442
+ clearTimeout(time);
17443
+ if (position.coords) {
17444
+ // 浏览器定位默认返回 WGS84 坐标 需要转化为 GCJ02 坐标
17445
+ var Gcj02 = wgs84ToGcj02(position.coords.longitude, position.coords.latitude);
17446
+ // console.log(Gcj02)
17447
+ // debugger
17448
+ var result = {
17449
+ latitude: Gcj02.lat.toString(),
17450
+ longitude: Gcj02.lng.toString()
17451
+ };
17452
+ console.log("getLocationByNavigator success: ".concat(JSON.stringify(result)));
17453
+ resolve(result);
17454
+ } else {
17455
+ console.error('getLocationByNavigator fail');
17456
+ resolve(null);
17457
+ }
17458
+ }, function () {
17459
+ clearTimeout(time);
17460
+ console.error('getLocationByNavigator fail');
17461
+ resolve(null);
17462
+ });
17463
+ } else {
17464
+ console.error('getLocationByNavigator fail: navigator.geolocation not support');
17465
+ resolve(null);
17466
+ }
17048
17467
  }));
17049
- case 3:
17468
+ case 2:
17050
17469
  case "end":
17051
17470
  return _context2.stop();
17052
17471
  }
17053
17472
  }, _callee2);
17054
17473
  }));
17055
- return _getAmapLocation.apply(this, arguments);
17056
- }
17057
- function getSpuLocation() {
17058
- return _getSpuLocation.apply(this, arguments);
17059
- }
17060
- function _getSpuLocation() {
17061
- _getSpuLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
17474
+ return function getLocationByNavigator() {
17475
+ return _ref2.apply(this, arguments);
17476
+ };
17477
+ }();
17478
+ // ipaas ip 定位
17479
+ var getIPLocationByIpaas = /*#__PURE__*/function () {
17480
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3(ip) {
17062
17481
  return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
17063
17482
  while (1) switch (_context3.prev = _context3.next) {
17064
17483
  case 0:
17484
+ console.log('getIPLocationByIpaas start...');
17065
17485
  return _context3.abrupt("return", new Promise(function (resolve, reject) {
17066
- var isload = false;
17067
- setTimeout(function () {
17068
- if (!isload) {
17069
- console.error('getSpuLocation timeout 30000');
17070
- resolve(null);
17071
- }
17072
- }, 30000);
17073
- window.Native.getLocation(function (result, error, status) {
17074
- isload = true;
17075
- // console.log('getLocation result', result)
17076
- // console.log('getLocation error', error)
17077
- // console.log('getLocation status', status)
17078
- if (result && result !== null && result !== void 0 && result.longitude && result !== null && result !== void 0 && result.latitude) {
17079
- resolve({
17080
- longitude: result.longitude.toString(),
17081
- latitude: result.latitude.toString(),
17082
- address: result.address || ''
17486
+ var AMapKey = getAMapKey();
17487
+ normalAxios$1.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271', {
17488
+ key: AMapKey.key,
17489
+ ip: ip || ''
17490
+ }).then(function (res) {
17491
+ // console.log(res)
17492
+ // debugger
17493
+ // res.data.rectangle = '113.1017375,22.93212254;113.6770499,23.3809537'
17494
+ if (res.data.rectangle) {
17495
+ var rectangle = res.data.rectangle;
17496
+ var rects = rectangle.split(';').map(function (rect) {
17497
+ var _rect$split = rect.split(','),
17498
+ _rect$split2 = _slicedToArray(_rect$split, 2),
17499
+ longitude = _rect$split2[0],
17500
+ latitude = _rect$split2[1];
17501
+ return {
17502
+ longitude: Number(longitude),
17503
+ latitude: Number(latitude)
17504
+ };
17083
17505
  });
17506
+ var result = {
17507
+ longitude: ((rects[0].longitude + rects[1].longitude) / 2).toString(),
17508
+ latitude: ((rects[0].latitude + rects[1].latitude) / 2).toString()
17509
+ };
17510
+ console.log("getIPLocationByIpaas success: ".concat(JSON.stringify(result)));
17511
+ resolve(result);
17084
17512
  } else {
17085
- console.error('getSpuLocation fail');
17513
+ console.error('getIPLocationByIpaas fail');
17086
17514
  resolve(null);
17087
17515
  }
17516
+ })["catch"](function (err) {
17517
+ console.error(err);
17518
+ console.error('getIPLocationByIpaas fail');
17519
+ resolve(null);
17088
17520
  });
17089
17521
  }));
17090
- case 1:
17522
+ case 2:
17091
17523
  case "end":
17092
17524
  return _context3.stop();
17093
17525
  }
17094
17526
  }, _callee3);
17095
17527
  }));
17096
- return _getSpuLocation.apply(this, arguments);
17097
- }
17098
- function getAmapCityLocation() {
17099
- return _getAmapCityLocation.apply(this, arguments);
17100
- }
17101
- function _getAmapCityLocation() {
17102
- _getAmapCityLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
17103
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17104
- while (1) switch (_context4.prev = _context4.next) {
17528
+ return function getIPLocationByIpaas(_x) {
17529
+ return _ref3.apply(this, arguments);
17530
+ };
17531
+ }();
17532
+ // ipaas 逆地址解析
17533
+ var getAddressByIpaas = /*#__PURE__*/function () {
17534
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(position) {
17535
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
17536
+ while (1) switch (_context5.prev = _context5.next) {
17105
17537
  case 0:
17106
- _context4.next = 2;
17107
- return init();
17538
+ console.log('getAddressByIpaas start...');
17539
+ // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
17540
+ return _context5.abrupt("return", new Promise( /*#__PURE__*/function () {
17541
+ var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(resolve, reject) {
17542
+ var _result$data, AMapKey, result, address;
17543
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
17544
+ while (1) switch (_context4.prev = _context4.next) {
17545
+ case 0:
17546
+ if (!position) {
17547
+ _context4.next = 15;
17548
+ break;
17549
+ }
17550
+ _context4.prev = 1;
17551
+ AMapKey = getAMapKey();
17552
+ _context4.next = 5;
17553
+ return normalAxios$1.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906', {
17554
+ longitude: position.longitude,
17555
+ latitude: position.latitude,
17556
+ key: AMapKey.key
17557
+ // extensions: 'all'
17558
+ });
17559
+ case 5:
17560
+ result = _context4.sent;
17561
+ // console.log(result)
17562
+ address = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.formatted_address;
17563
+ if (address) {
17564
+ console.log("getAddressByIpaas success: ".concat(address));
17565
+ resolve(address);
17566
+ } else {
17567
+ console.error('getAddressByIpaas fail');
17568
+ resolve('');
17569
+ }
17570
+ _context4.next = 15;
17571
+ break;
17572
+ case 10:
17573
+ _context4.prev = 10;
17574
+ _context4.t0 = _context4["catch"](1);
17575
+ console.error(_context4.t0);
17576
+ console.error('getAddressByIpaas fail');
17577
+ resolve('');
17578
+ case 15:
17579
+ case "end":
17580
+ return _context4.stop();
17581
+ }
17582
+ }, _callee4, null, [[1, 10]]);
17583
+ }));
17584
+ return function (_x3, _x4) {
17585
+ return _ref5.apply(this, arguments);
17586
+ };
17587
+ }()));
17108
17588
  case 2:
17109
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
17110
- geolocation.getCityInfo(function (status, result) {
17589
+ case "end":
17590
+ return _context5.stop();
17591
+ }
17592
+ }, _callee5);
17593
+ }));
17594
+ return function getAddressByIpaas(_x2) {
17595
+ return _ref4.apply(this, arguments);
17596
+ };
17597
+ }();
17598
+ // 高德定位
17599
+ var getLocationByAmap = /*#__PURE__*/function () {
17600
+ var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
17601
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
17602
+ while (1) switch (_context6.prev = _context6.next) {
17603
+ case 0:
17604
+ console.log('getLocationByAmap start...');
17605
+ return _context6.abrupt("return", new Promise(function (resolve, reject) {
17606
+ var geolocation = new window.AMap.Geolocation({
17607
+ enableHighAccuracy: true,
17608
+ timeout: 15000
17609
+ });
17610
+ geolocation.getCurrentPosition(function (status, res) {
17611
+ // console.log(status, result)
17612
+ // debugger
17111
17613
  if (status === 'complete') {
17112
- var lng = result.position[0].toString();
17113
- var lat = result.position[1].toString();
17114
- // console.log('getAmapCityLocation success')
17115
- // resolve([lng, lat])
17116
- resolve({
17614
+ var _res$position = res.position,
17615
+ lng = _res$position.lng,
17616
+ lat = _res$position.lat;
17617
+ var result = {
17117
17618
  longitude: lng.toString(),
17118
- latitude: lat.toString(),
17119
- address: ''
17120
- });
17619
+ latitude: lat.toString()
17620
+ };
17621
+ console.log("getLocationByAmap success: ".concat(JSON.stringify(result)));
17622
+ resolve(result);
17121
17623
  } else {
17122
- // reject(new Error('getAmapCityLocation fail'))
17123
- console.error('getAmapCityLocation fail');
17624
+ console.error('getLocationByAmap fail');
17124
17625
  resolve(null);
17125
17626
  }
17126
17627
  });
17127
17628
  }));
17128
- case 3:
17629
+ case 2:
17129
17630
  case "end":
17130
- return _context4.stop();
17631
+ return _context6.stop();
17131
17632
  }
17132
- }, _callee4);
17633
+ }, _callee6);
17133
17634
  }));
17134
- return _getAmapCityLocation.apply(this, arguments);
17135
- }
17136
- function getAddress(_x) {
17137
- return _getAddress.apply(this, arguments);
17138
- } // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 高德地图高精度定位 > 百度地图定位 > 高德城市定位
17139
- function _getAddress() {
17140
- _getAddress = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(position) {
17141
- return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
17142
- while (1) switch (_context5.prev = _context5.next) {
17635
+ return function getLocationByAmap() {
17636
+ return _ref6.apply(this, arguments);
17637
+ };
17638
+ }();
17639
+ // 高德城市定位
17640
+ var getCityLocationByAmap = /*#__PURE__*/function () {
17641
+ var _ref7 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7() {
17642
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
17643
+ while (1) switch (_context7.prev = _context7.next) {
17644
+ case 0:
17645
+ console.log('getCityLocationByAmap start...');
17646
+ return _context7.abrupt("return", new Promise(function (resolve, reject) {
17647
+ var geolocation = new window.AMap.Geolocation({
17648
+ enableHighAccuracy: true,
17649
+ timeout: 15000
17650
+ });
17651
+ geolocation.getCityInfo(function (status, res) {
17652
+ // console.log(res)
17653
+ // debugger
17654
+ if (status === 'complete') {
17655
+ var lng = res.position[0].toString();
17656
+ var lat = res.position[1].toString();
17657
+ var result = {
17658
+ longitude: lng.toString(),
17659
+ latitude: lat.toString()
17660
+ };
17661
+ console.log("getCityLocationByAmap success: ".concat(JSON.stringify(result)));
17662
+ resolve(result);
17663
+ } else {
17664
+ console.error('getCityLocationByAmap fail');
17665
+ resolve(null);
17666
+ }
17667
+ });
17668
+ }));
17669
+ case 2:
17670
+ case "end":
17671
+ return _context7.stop();
17672
+ }
17673
+ }, _callee7);
17674
+ }));
17675
+ return function getCityLocationByAmap() {
17676
+ return _ref7.apply(this, arguments);
17677
+ };
17678
+ }();
17679
+ // 高德逆地址解析
17680
+ var getAddressByAmap = /*#__PURE__*/function () {
17681
+ var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(position) {
17682
+ var address;
17683
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
17684
+ while (1) switch (_context8.prev = _context8.next) {
17143
17685
  case 0:
17144
- _context5.next = 2;
17145
- return init();
17686
+ console.log('getAddressByAmap start...');
17687
+ console.log('getAddressByAmap changeto getAddressByIpaas');
17688
+ // return new Promise((resolve, reject) => {
17689
+ // if (position) {
17690
+ // new window.AMap.Geocoder({
17691
+ // city: '',
17692
+ // radius: 500
17693
+ // }).getAddress([position.longitude, position.latitude], (status: string, result: any) => {
17694
+ // if (status === 'complete' && result.info === 'OK' && result.regeocode) {
17695
+ // resolve(result?.regeocode?.formattedAddress || '')
17696
+ // } else {
17697
+ // console.error('getAddressByAmap fail')
17698
+ // resolve('')
17699
+ // }
17700
+ // })
17701
+ // }
17702
+ // })
17703
+ // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
17704
+ _context8.next = 4;
17705
+ return getAddressByIpaas(position);
17706
+ case 4:
17707
+ address = _context8.sent;
17708
+ return _context8.abrupt("return", address);
17709
+ case 6:
17710
+ case "end":
17711
+ return _context8.stop();
17712
+ }
17713
+ }, _callee8);
17714
+ }));
17715
+ return function getAddressByAmap(_x5) {
17716
+ return _ref8.apply(this, arguments);
17717
+ };
17718
+ }();
17719
+ // 腾讯ip定位:通过终端设备IP地址获取其当前所在地理位置,精确到市级,常用于显示当地城市天气预报、初始化用户城市等非精确定位场景。
17720
+ var getIPLocationByTMap = /*#__PURE__*/function () {
17721
+ var _ref9 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee9(ip) {
17722
+ return _regeneratorRuntime$1().wrap(function _callee9$(_context9) {
17723
+ while (1) switch (_context9.prev = _context9.next) {
17724
+ case 0:
17725
+ console.log('getIPLocationByTMap start...');
17726
+ return _context9.abrupt("return", new Promise(function (resolve, reject) {
17727
+ var ipLocation = new window.TMap.service.IPLocation();
17728
+ var params = ip ? {
17729
+ ip: ip
17730
+ } : {};
17731
+ ipLocation.locate(params).then(function (res) {
17732
+ var result = {
17733
+ longitude: res.result.location.lng.toString(),
17734
+ latitude: res.result.location.lat.toString()
17735
+ };
17736
+ console.log("getIPLocationByTMap success: ".concat(JSON.stringify(result)));
17737
+ resolve(result);
17738
+ })["catch"](function (err) {
17739
+ console.error(err);
17740
+ console.error("getIPLocationByTMap fail: ".concat(JSON.stringify(err)));
17741
+ resolve(null);
17742
+ });
17743
+ }));
17146
17744
  case 2:
17147
- return _context5.abrupt("return", new Promise(function (resolve, reject) {
17745
+ case "end":
17746
+ return _context9.stop();
17747
+ }
17748
+ }, _callee9);
17749
+ }));
17750
+ return function getIPLocationByTMap(_x6) {
17751
+ return _ref9.apply(this, arguments);
17752
+ };
17753
+ }();
17754
+ // 腾讯逆地址解析
17755
+ var getAddressByTMap = /*#__PURE__*/function () {
17756
+ var _ref10 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee10(position) {
17757
+ return _regeneratorRuntime$1().wrap(function _callee10$(_context10) {
17758
+ while (1) switch (_context10.prev = _context10.next) {
17759
+ case 0:
17760
+ console.log('getAddressByTMap start...');
17761
+ return _context10.abrupt("return", new Promise(function (resolve, reject) {
17148
17762
  if (position) {
17149
- geocoder.getAddress([position.longitude, position.latitude], function (status, result) {
17150
- if (status === 'complete' && result.regeocode) {
17151
- resolve(result.regeocode.formattedAddress);
17152
- } else {
17153
- // reject(new Error('getAddress fail'))
17154
- console.error('getAddress fail');
17155
- resolve('');
17156
- }
17763
+ var location = new window.TMap.LatLng(position.latitude, position.longitude);
17764
+ // console.log(position)
17765
+ // console.log(location)
17766
+ // debugger
17767
+ new window.TMap.service.Geocoder().getAddress({
17768
+ location: location,
17769
+ getPoi: false
17770
+ }).then(function (res) {
17771
+ var _res$result, _res$result2;
17772
+ // console.log(res)
17773
+ // debugger
17774
+ var address = (res === null || res === void 0 || (_res$result = res.result) === null || _res$result === void 0 || (_res$result = _res$result.formatted_addresses) === null || _res$result === void 0 ? void 0 : _res$result.recommend) || (res === null || res === void 0 || (_res$result2 = res.result) === null || _res$result2 === void 0 ? void 0 : _res$result2.address);
17775
+ console.log("getAddressByTMap success: ".concat(address));
17776
+ resolve(address);
17777
+ })["catch"](function (err) {
17778
+ console.error(err);
17779
+ console.error("getAddressByTMap fail: ".concat(JSON.stringify(err)));
17780
+ resolve('');
17157
17781
  });
17158
17782
  }
17159
17783
  }));
17160
- case 3:
17784
+ case 2:
17161
17785
  case "end":
17162
- return _context5.stop();
17786
+ return _context10.stop();
17163
17787
  }
17164
- }, _callee5);
17788
+ }, _callee10);
17165
17789
  }));
17166
- return _getAddress.apply(this, arguments);
17167
- }
17168
- function getLocationPromise() {
17169
- return _getLocationPromise.apply(this, arguments);
17170
- }
17171
- function _getLocationPromise() {
17172
- _getLocationPromise = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
17790
+ return function getAddressByTMap(_x7) {
17791
+ return _ref10.apply(this, arguments);
17792
+ };
17793
+ }();
17794
+ // 百度浏览器定位
17795
+ var getLocationByBMap = /*#__PURE__*/function () {
17796
+ var _ref11 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee12() {
17797
+ return _regeneratorRuntime$1().wrap(function _callee12$(_context12) {
17798
+ while (1) switch (_context12.prev = _context12.next) {
17799
+ case 0:
17800
+ console.log('getLocationByBMap start...');
17801
+ return _context12.abrupt("return", new Promise(function (resolve, reject) {
17802
+ new window.BMap.Geolocation().getCurrentPosition( /*#__PURE__*/function () {
17803
+ var _ref12 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee11(res) {
17804
+ var lng, lat, result;
17805
+ return _regeneratorRuntime$1().wrap(function _callee11$(_context11) {
17806
+ while (1) switch (_context11.prev = _context11.next) {
17807
+ case 0:
17808
+ if (res) {
17809
+ _context11.next = 4;
17810
+ break;
17811
+ }
17812
+ console.error('getLocationByBMap fail');
17813
+ resolve(null);
17814
+ return _context11.abrupt("return");
17815
+ case 4:
17816
+ // 初始化已经指定 window.BMap.coordType = 'BMAP_COORD_GCJ02' 定位返回的定位信息,外层[latitude,longitude]依然是BD09,然后point里面的是GCJ02
17817
+ // {
17818
+ // "accuracy": 150,
17819
+ // "altitude": null,
17820
+ // "altitudeAccuracy": null,
17821
+ // "heading": null,
17822
+ // "latitude": 39.915018933989,
17823
+ // "longitude": 116.40383261074,
17824
+ // "speed": null,
17825
+ // "timestamp": null,
17826
+ // "point": {
17827
+ // "lng": 116.39745977716758,
17828
+ // "lat": 39.908676092571405
17829
+ // },
17830
+ // "address": {
17831
+ // "country": "",
17832
+ // "city": "北京市",
17833
+ // "city_code": 0,
17834
+ // "district": "东城区",
17835
+ // "province": "北京市",
17836
+ // "street": "东华门大街",
17837
+ // "street_number": "66号"
17838
+ // }
17839
+ // }
17840
+ // 不用转换
17841
+ // const point: any = await BMapTransformBD09ToGCJ02Points([{
17842
+ // lng: res.longitude,
17843
+ // lat: res.latitude
17844
+ // }])
17845
+ // console.log(point)
17846
+ // debugger
17847
+ lng = res.point.lng.toString();
17848
+ lat = res.point.lat.toString();
17849
+ result = {
17850
+ longitude: lng,
17851
+ latitude: lat
17852
+ };
17853
+ console.log("getLocationByBMap success: ".concat(JSON.stringify(result)));
17854
+ resolve(result);
17855
+ case 9:
17856
+ case "end":
17857
+ return _context11.stop();
17858
+ }
17859
+ }, _callee11);
17860
+ }));
17861
+ return function (_x8) {
17862
+ return _ref12.apply(this, arguments);
17863
+ };
17864
+ }(), {
17865
+ enableHighAccuracy: true
17866
+ });
17867
+ }));
17868
+ case 2:
17869
+ case "end":
17870
+ return _context12.stop();
17871
+ }
17872
+ }, _callee12);
17873
+ }));
17874
+ return function getLocationByBMap() {
17875
+ return _ref11.apply(this, arguments);
17876
+ };
17877
+ }();
17878
+ // 百度城市定位
17879
+ var getCityLocationByBMap = /*#__PURE__*/function () {
17880
+ var _ref13 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee14() {
17881
+ return _regeneratorRuntime$1().wrap(function _callee14$(_context14) {
17882
+ while (1) switch (_context14.prev = _context14.next) {
17883
+ case 0:
17884
+ console.log('getCityLocationByBMap start...');
17885
+ return _context14.abrupt("return", new Promise(function (resolve, reject) {
17886
+ new window.BMap.LocalCity().get( /*#__PURE__*/function () {
17887
+ var _ref14 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee13(res) {
17888
+ var lng, lat, point, result;
17889
+ return _regeneratorRuntime$1().wrap(function _callee13$(_context13) {
17890
+ while (1) switch (_context13.prev = _context13.next) {
17891
+ case 0:
17892
+ // console.log(res)
17893
+ // debugger
17894
+ lng = res.center.lng.toString();
17895
+ lat = res.center.lat.toString();
17896
+ if (!(lng && lat)) {
17897
+ _context13.next = 11;
17898
+ break;
17899
+ }
17900
+ _context13.next = 5;
17901
+ return BMapTransformBD09ToGCJ02Points([{
17902
+ lng: lng,
17903
+ lat: lat
17904
+ }]);
17905
+ case 5:
17906
+ point = _context13.sent;
17907
+ // console.log(point)
17908
+ // debugger
17909
+ result = {
17910
+ longitude: point[0].lng,
17911
+ latitude: point[0].lat
17912
+ };
17913
+ console.log("getCityLocationByBMap success: ".concat(JSON.stringify(result)));
17914
+ resolve(result);
17915
+ _context13.next = 13;
17916
+ break;
17917
+ case 11:
17918
+ console.error('getCityLocationByBMap fail');
17919
+ resolve(null);
17920
+ case 13:
17921
+ case "end":
17922
+ return _context13.stop();
17923
+ }
17924
+ }, _callee13);
17925
+ }));
17926
+ return function (_x9) {
17927
+ return _ref14.apply(this, arguments);
17928
+ };
17929
+ }());
17930
+ }));
17931
+ case 2:
17932
+ case "end":
17933
+ return _context14.stop();
17934
+ }
17935
+ }, _callee14);
17936
+ }));
17937
+ return function getCityLocationByBMap() {
17938
+ return _ref13.apply(this, arguments);
17939
+ };
17940
+ }();
17941
+ // 百度逆地址解析
17942
+ var getAddressByBmap = /*#__PURE__*/function () {
17943
+ var _ref15 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee16(position) {
17944
+ return _regeneratorRuntime$1().wrap(function _callee16$(_context16) {
17945
+ while (1) switch (_context16.prev = _context16.next) {
17946
+ case 0:
17947
+ console.log('getAddressByBmap start...');
17948
+ return _context16.abrupt("return", new Promise( /*#__PURE__*/function () {
17949
+ var _ref16 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee15(resolve, reject) {
17950
+ var point;
17951
+ return _regeneratorRuntime$1().wrap(function _callee15$(_context15) {
17952
+ while (1) switch (_context15.prev = _context15.next) {
17953
+ case 0:
17954
+ if (position) {
17955
+ _context15.next = 4;
17956
+ break;
17957
+ }
17958
+ console.error('getAddressByBmap fail');
17959
+ resolve('');
17960
+ return _context15.abrupt("return");
17961
+ case 4:
17962
+ // // 把 GCJ02 转化为百度 BD09 地址
17963
+ // const points: any = await transformGCJ02ToBD09Points([{
17964
+ // lng: position.longitude,
17965
+ // lat: position.latitude
17966
+ // }])
17967
+ // const point = points[0]
17968
+ // 指定了 window.BMap.coordType = 'BMAP_COORD_GCJ02' 不需要转换
17969
+ point = new window.BMap.Point(position.longitude, position.latitude); // console.log(point)
17970
+ // debugger
17971
+ new window.BMap.Geocoder().getLocation(point, function (result) {
17972
+ // console.log(result)
17973
+ var address = result === null || result === void 0 ? void 0 : result.address;
17974
+ if (address) {
17975
+ console.log("getAddressByBmap success: ".concat(address));
17976
+ resolve(address);
17977
+ } else {
17978
+ console.error('getAddressByBmap fail');
17979
+ resolve('');
17980
+ }
17981
+ });
17982
+ case 6:
17983
+ case "end":
17984
+ return _context15.stop();
17985
+ }
17986
+ }, _callee15);
17987
+ }));
17988
+ return function (_x11, _x12) {
17989
+ return _ref16.apply(this, arguments);
17990
+ };
17991
+ }()));
17992
+ case 2:
17993
+ case "end":
17994
+ return _context16.stop();
17995
+ }
17996
+ }, _callee16);
17997
+ }));
17998
+ return function getAddressByBmap(_x10) {
17999
+ return _ref15.apply(this, arguments);
18000
+ };
18001
+ }();
18002
+ // 定位流程: 缓存 > 判断环境(APP,小程序,企微)基于环境获取定位 > 地图商高精度定位 > 地图商城市ip定位
18003
+ var getLocationPromise = /*#__PURE__*/function () {
18004
+ var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
17173
18005
  var _window;
17174
18006
  var location;
17175
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
17176
- while (1) switch (_context6.prev = _context6.next) {
18007
+ return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18008
+ while (1) switch (_context17.prev = _context17.next) {
17177
18009
  case 0:
17178
18010
  location = null; // 在 SPU 容器里使用 Native-API 的定位
17179
18011
  if (!((_window = window) !== null && _window !== void 0 && (_window = _window.Native) !== null && _window !== void 0 && _window.getLocation)) {
17180
- _context6.next = 5;
18012
+ _context17.next = 5;
17181
18013
  break;
17182
18014
  }
17183
- _context6.next = 4;
17184
- return getSpuLocation();
18015
+ _context17.next = 4;
18016
+ return getLocationByNative();
17185
18017
  case 4:
17186
- location = _context6.sent;
18018
+ location = _context17.sent;
17187
18019
  case 5:
17188
18020
  if (location) {
17189
- _context6.next = 9;
18021
+ _context17.next = 9;
17190
18022
  break;
17191
18023
  }
17192
- _context6.next = 8;
17193
- return getAmapLocation();
18024
+ _context17.next = 8;
18025
+ return getLocationByNavigator();
17194
18026
  case 8:
17195
- location = _context6.sent;
18027
+ location = _context17.sent;
17196
18028
  case 9:
17197
- if (!(!location && urlquery.isvirtuallocation)) {
17198
- _context6.next = 13;
18029
+ if (location) {
18030
+ _context17.next = 34;
17199
18031
  break;
17200
18032
  }
17201
- _context6.next = 12;
17202
- return getAmapCityLocation();
17203
- case 12:
17204
- location = _context6.sent;
18033
+ if (!(mapService.type === 'amap')) {
18034
+ _context17.next = 20;
18035
+ break;
18036
+ }
18037
+ _context17.next = 13;
18038
+ return getLocationByAmap();
17205
18039
  case 13:
17206
- // 测试虚拟定位
18040
+ location = _context17.sent;
18041
+ if (location) {
18042
+ _context17.next = 18;
18043
+ break;
18044
+ }
18045
+ _context17.next = 17;
18046
+ return getCityLocationByAmap();
18047
+ case 17:
18048
+ location = _context17.sent;
18049
+ case 18:
18050
+ _context17.next = 34;
18051
+ break;
18052
+ case 20:
18053
+ if (!(mapService.type === 'tencent')) {
18054
+ _context17.next = 26;
18055
+ break;
18056
+ }
18057
+ _context17.next = 23;
18058
+ return getIPLocationByTMap();
18059
+ case 23:
18060
+ location = _context17.sent;
18061
+ _context17.next = 34;
18062
+ break;
18063
+ case 26:
18064
+ if (!(mapService.type === 'baidu')) {
18065
+ _context17.next = 34;
18066
+ break;
18067
+ }
18068
+ _context17.next = 29;
18069
+ return getLocationByBMap();
18070
+ case 29:
18071
+ location = _context17.sent;
18072
+ if (location) {
18073
+ _context17.next = 34;
18074
+ break;
18075
+ }
18076
+ _context17.next = 33;
18077
+ return getCityLocationByBMap();
18078
+ case 33:
18079
+ location = _context17.sent;
18080
+ case 34:
18081
+ if (location) {
18082
+ _context17.next = 38;
18083
+ break;
18084
+ }
18085
+ _context17.next = 37;
18086
+ return getIPLocationByIpaas();
18087
+ case 37:
18088
+ location = _context17.sent;
18089
+ case 38:
18090
+ // 开发模式下为了方便测试提供虚拟定位
17207
18091
  if (!location && urlquery.isvirtuallocation) {
17208
18092
  location = {
17209
- longitude: '113.34331353081598',
17210
- latitude: '23.105349663628473',
17211
- address: ''
18093
+ longitude: '116.397454',
18094
+ latitude: '39.908671'
17212
18095
  };
17213
18096
  }
17214
18097
  if (!(location && !location.address)) {
17215
- _context6.next = 21;
18098
+ _context17.next = 46;
17216
18099
  break;
17217
18100
  }
17218
- _context6.next = 17;
18101
+ _context17.next = 42;
17219
18102
  return getAddress(location);
17220
- case 17:
17221
- _context6.t0 = _context6.sent;
17222
- if (_context6.t0) {
17223
- _context6.next = 20;
18103
+ case 42:
18104
+ _context17.t0 = _context17.sent;
18105
+ if (_context17.t0) {
18106
+ _context17.next = 45;
17224
18107
  break;
17225
18108
  }
17226
- _context6.t0 = '经纬度获取成功,但地址获取失败。';
17227
- case 20:
17228
- location.address = _context6.t0;
17229
- case 21:
17230
- return _context6.abrupt("return", location);
17231
- case 22:
18109
+ _context17.t0 = '经纬度获取成功,但地址获取失败。';
18110
+ case 45:
18111
+ location.address = _context17.t0;
18112
+ case 46:
18113
+ return _context17.abrupt("return", location);
18114
+ case 47:
17232
18115
  case "end":
17233
- return _context6.stop();
18116
+ return _context17.stop();
17234
18117
  }
17235
- }, _callee6);
18118
+ }, _callee17);
17236
18119
  }));
17237
- return _getLocationPromise.apply(this, arguments);
17238
- }
18120
+ return function getLocationPromise() {
18121
+ return _ref17.apply(this, arguments);
18122
+ };
18123
+ }();
18124
+ // WGS84 GCJ-02 BD-09 坐标系
18125
+ // https://www.jianshu.com/p/559029832a67
17239
18126
  function getLocation() {
17240
18127
  return _getLocation.apply(this, arguments);
17241
- }
18128
+ } // 逆地址解析
17242
18129
  function _getLocation() {
17243
- _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7() {
18130
+ _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
17244
18131
  var locationRes;
17245
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
17246
- while (1) switch (_context7.prev = _context7.next) {
18132
+ return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18133
+ while (1) switch (_context20.prev = _context20.next) {
17247
18134
  case 0:
17248
- if (!(datetime && Date.now() - datetime <= 30000 && lastLocation && !runing)) {
17249
- _context7.next = 2;
18135
+ _context20.next = 2;
18136
+ return mapService.init();
18137
+ case 2:
18138
+ if (!(datetime && Date.now() - datetime <= cachetime && lastLocation && !runing)) {
18139
+ _context20.next = 4;
17250
18140
  break;
17251
18141
  }
17252
- return _context7.abrupt("return", cloneDeep$1(lastLocation));
17253
- case 2:
18142
+ return _context20.abrupt("return", cloneDeep$1(lastLocation));
18143
+ case 4:
17254
18144
  if (!(runing && locationPromise)) {
17255
- _context7.next = 4;
18145
+ _context20.next = 6;
17256
18146
  break;
17257
18147
  }
17258
- return _context7.abrupt("return", locationPromise);
17259
- case 4:
18148
+ return _context20.abrupt("return", locationPromise);
18149
+ case 6:
17260
18150
  // console.log('runing')
17261
18151
  runing = true;
17262
18152
  locationPromise = getLocationPromise();
17263
- _context7.next = 8;
18153
+ _context20.next = 10;
17264
18154
  return locationPromise;
17265
- case 8:
17266
- locationRes = _context7.sent;
18155
+ case 10:
18156
+ locationRes = _context20.sent;
17267
18157
  runing = false;
17268
18158
  if (locationRes) {
17269
18159
  datetime = Date.now();
17270
18160
  lastLocation = locationRes;
17271
18161
  }
17272
- return _context7.abrupt("return", locationRes);
17273
- case 12:
18162
+ return _context20.abrupt("return", locationRes);
18163
+ case 14:
17274
18164
  case "end":
17275
- return _context7.stop();
18165
+ return _context20.stop();
17276
18166
  }
17277
- }, _callee7);
18167
+ }, _callee20);
17278
18168
  }));
17279
18169
  return _getLocation.apply(this, arguments);
17280
18170
  }
17281
- function getDistance(_x2, _x3) {
17282
- return _getDistance.apply(this, arguments);
17283
- } // // 两个经纬度距离计算
17284
- // function getDistance (latlng1, latlng2) {
17285
- // console.log(latlng1)
17286
- // console.log(latlng2)
17287
- // const lng1 = Number(latlng1[0])
17288
- // const lat1 = Number(latlng1[1])
17289
- // const lng2 = Number(latlng2[0])
17290
- // const lat2 = Number(latlng2[1])
17291
- // const radLat1 = (lat1 * Math.PI) / 180.0
17292
- // const radLat2 = (lat2 * Math.PI) / 180.0
17293
- // const a = radLat1 - radLat2
17294
- // const b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0
17295
- // let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
17296
- // s = s * 6378.137 // EARTH_RADIUS
17297
- // s = Math.round(s * 10000) / 10000
17298
- // return s * 1000
17299
- // }
17300
- function _getDistance() {
17301
- _getDistance = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(p1, p2) {
17302
- return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
17303
- while (1) switch (_context8.prev = _context8.next) {
18171
+ var getAddress = /*#__PURE__*/function () {
18172
+ var _ref18 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee18(position) {
18173
+ var address;
18174
+ return _regeneratorRuntime$1().wrap(function _callee18$(_context18) {
18175
+ while (1) switch (_context18.prev = _context18.next) {
17304
18176
  case 0:
17305
- _context8.next = 2;
17306
- return init();
18177
+ _context18.next = 2;
18178
+ return mapService.init();
17307
18179
  case 2:
17308
- return _context8.abrupt("return", AMap.GeometryUtil.distance(p1, p2));
17309
- case 3:
18180
+ address = ''; // 先统一用ipaas解析 因为需要储存一致的地址格式(各地图商逆地址查询的地址格式不统一)
18181
+ // 如果不行再按照各地图商解析
18182
+ _context18.next = 5;
18183
+ return getAddressByIpaas(position);
18184
+ case 5:
18185
+ address = _context18.sent;
18186
+ if (address) {
18187
+ _context18.next = 23;
18188
+ break;
18189
+ }
18190
+ if (!(mapService.type === 'amap')) {
18191
+ _context18.next = 13;
18192
+ break;
18193
+ }
18194
+ _context18.next = 10;
18195
+ return getAddressByAmap(position);
18196
+ case 10:
18197
+ address = _context18.sent;
18198
+ _context18.next = 23;
18199
+ break;
18200
+ case 13:
18201
+ if (!(mapService.type === 'tencent')) {
18202
+ _context18.next = 19;
18203
+ break;
18204
+ }
18205
+ _context18.next = 16;
18206
+ return getAddressByTMap(position);
18207
+ case 16:
18208
+ address = _context18.sent;
18209
+ _context18.next = 23;
18210
+ break;
18211
+ case 19:
18212
+ if (!(mapService.type === 'baidu')) {
18213
+ _context18.next = 23;
18214
+ break;
18215
+ }
18216
+ _context18.next = 22;
18217
+ return getAddressByBmap(position);
18218
+ case 22:
18219
+ address = _context18.sent;
18220
+ case 23:
18221
+ return _context18.abrupt("return", address);
18222
+ case 24:
17310
18223
  case "end":
17311
- return _context8.stop();
18224
+ return _context18.stop();
17312
18225
  }
17313
- }, _callee8);
18226
+ }, _callee18);
17314
18227
  }));
17315
- return _getDistance.apply(this, arguments);
17316
- }
18228
+ return function getAddress(_x13) {
18229
+ return _ref18.apply(this, arguments);
18230
+ };
18231
+ }();
18232
+ // const getDistance = async (p1: [number, number], p2: [number, number]) => {
18233
+ // await mapService.init()
18234
+ // return window.AMap.GeometryUtil.distance(p1, p2)
18235
+ // }
18236
+ // 两个经纬度距离计算
18237
+ var getDistance = /*#__PURE__*/function () {
18238
+ var _ref19 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee19(latlng1, latlng2) {
18239
+ var lng1, lat1, lng2, lat2, radLat1, radLat2, a, b, s;
18240
+ return _regeneratorRuntime$1().wrap(function _callee19$(_context19) {
18241
+ while (1) switch (_context19.prev = _context19.next) {
18242
+ case 0:
18243
+ // console.log(latlng1)
18244
+ // console.log(latlng2)
18245
+ lng1 = Number(latlng1[0]);
18246
+ lat1 = Number(latlng1[1]);
18247
+ lng2 = Number(latlng2[0]);
18248
+ lat2 = Number(latlng2[1]);
18249
+ radLat1 = lat1 * Math.PI / 180.0;
18250
+ radLat2 = lat2 * Math.PI / 180.0;
18251
+ a = radLat1 - radLat2;
18252
+ b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
18253
+ s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
18254
+ s = s * 6378.137; // EARTH_RADIUS
18255
+ s = Math.round(s * 10000) / 10000;
18256
+ return _context19.abrupt("return", s * 1000);
18257
+ case 12:
18258
+ case "end":
18259
+ return _context19.stop();
18260
+ }
18261
+ }, _callee19);
18262
+ }));
18263
+ return function getDistance(_x14, _x15) {
18264
+ return _ref19.apply(this, arguments);
18265
+ };
18266
+ }();
17317
18267
 
17318
18268
  var modulekey = '';
17319
18269
  var SpuConfig = /*#__PURE__*/function () {
@@ -51886,6 +52836,38 @@ var uploadService = {
51886
52836
  upload: upload
51887
52837
  };
51888
52838
 
52839
+ var isinit = false;
52840
+ var load = function load(options) {
52841
+ var _options$AMapUI;
52842
+ var AMapKey = getAMapKey();
52843
+ if (!isinit) {
52844
+ isinit = true;
52845
+ if (AMapKey.securityJsCode) {
52846
+ // 本来想改成取消安全秘钥 但考虑到其他spu有可能用了需要安全秘钥的功能 因此不取消
52847
+ // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
52848
+ window._AMapSecurityConfig = {
52849
+ securityJsCode: AMapKey.securityJsCode
52850
+ };
52851
+ }
52852
+ }
52853
+ // 不开放地址查询 改用ipaas
52854
+ var plugin = ['AMap.Geolocation'];
52855
+ // plugin.push('AMap.Geocoder') // 不开放地址查询 改用ipaas
52856
+ return AMapLoader$1.load({
52857
+ key: AMapKey.key,
52858
+ version: '2.0',
52859
+ plugins: (options === null || options === void 0 ? void 0 : options.plugins) || plugin,
52860
+ AMapUI: {
52861
+ version: '1.1',
52862
+ plugins: (options === null || options === void 0 || (_options$AMapUI = options.AMapUI) === null || _options$AMapUI === void 0 ? void 0 : _options$AMapUI.plugins) || []
52863
+ }
52864
+ });
52865
+ };
52866
+ var AMapLoader = {
52867
+ AMapKey: AMapKey,
52868
+ load: load
52869
+ };
52870
+
51889
52871
  // import SpuLoadding from './loadding'
51890
52872
  // import SpuExpandexp from './expandexp'
51891
52873
  var index = {
@@ -69022,4 +70004,4 @@ var SPUWebPlugin = {
69022
70004
  version: version
69023
70005
  };
69024
70006
 
69025
- export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getDistance, getLocation, getRefreshToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
70007
+ export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getDistance, getLocation, getRefreshToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };