@smart100/spu-web-plugin 1.0.16 → 1.0.18

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.16";
1
+ var version = "1.0.18";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -16143,53 +16143,6 @@ var TenantSetting = /*#__PURE__*/function () {
16143
16143
  }, {
16144
16144
  key: "get",
16145
16145
  value: function get(key) {
16146
- // const tenantsetting = {
16147
- // lbssetting: {
16148
- // enable: '1',
16149
- // setting: {
16150
- // type: '',
16151
- // key: {
16152
- // web: '',
16153
- // android: '',
16154
- // ios: '',
16155
- // harmony: ''
16156
- // },
16157
- // secretkey: {
16158
- // web: '',
16159
- // android: '',
16160
- // ios: '',
16161
- // harmony: ''
16162
- // }
16163
- // }
16164
- // }
16165
- // }
16166
- // 高德地图key配置错误
16167
- // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
16168
- // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
16169
- // // 高德地图公司key
16170
- // tenantsetting.lbssetting.setting.type = 'amap'
16171
- // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
16172
- // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
16173
- // // 高德地图个人key
16174
- // tenantsetting.lbssetting.setting.type = 'amap'
16175
- // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
16176
- // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
16177
- // tencent地图key配置错误
16178
- // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
16179
- // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
16180
- // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
16181
- // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
16182
- // tenantsetting.lbssetting.setting.type = 'tencent'
16183
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
16184
- // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
16185
- // 百度地图key配置错误alert以下信息
16186
- // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
16187
- // tenantsetting.lbssetting.setting.type = 'baidu'
16188
- // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
16189
- // tenantsetting.lbssetting.setting.type = 'tencent'
16190
- // tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT是的是的'
16191
- // tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0对对对'
16192
- // lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
16193
16146
  var tenantsettingStr = lsProxy.getItem('tenantsetting');
16194
16147
  if (tenantsettingStr) {
16195
16148
  var tenantsetting = JSON.parse(tenantsettingStr);
@@ -16207,11 +16160,13 @@ var TenantSetting = /*#__PURE__*/function () {
16207
16160
  var tenantSetting = new TenantSetting();
16208
16161
 
16209
16162
  function getToken() {
16210
- return getData('token');
16211
- // return lsProxy.getItem('token') as string
16163
+ var token = getData('token');
16164
+ // const token = lsProxy.getItem('token') as string
16165
+ return token;
16212
16166
  }
16213
-
16214
16167
  function setToken(value) {
16168
+ // console.log('setToken', value)
16169
+ // debugger
16215
16170
  setData('token', value);
16216
16171
  }
16217
16172
  function getTokenExpires() {
@@ -16277,6 +16232,7 @@ function removeUser() {
16277
16232
  removeData('user');
16278
16233
  }
16279
16234
  function parseToken(token) {
16235
+ // debugger
16280
16236
  if (!token) {
16281
16237
  console.error('token为空 jwt解析token出错');
16282
16238
  return null;
@@ -16434,13 +16390,13 @@ function getAndSetUserInfo() {
16434
16390
  return _getAndSetUserInfo.apply(this, arguments);
16435
16391
  }
16436
16392
  function _getAndSetUserInfo() {
16437
- _getAndSetUserInfo = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
16393
+ _getAndSetUserInfo = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5() {
16438
16394
  var accountinfo;
16439
- return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
16440
- while (1) switch (_context3.prev = _context3.next) {
16395
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16396
+ while (1) switch (_context5.prev = _context5.next) {
16441
16397
  case 0:
16442
- _context3.prev = 0;
16443
- _context3.next = 3;
16398
+ _context5.prev = 0;
16399
+ _context5.next = 3;
16444
16400
  return normalAxios$1.post('/api/teapi/rolepermission/account/getaccountinfo', {
16445
16401
  positionid: getUser('positioncode') || '',
16446
16402
  deviceinfo: '',
@@ -16454,22 +16410,22 @@ function _getAndSetUserInfo() {
16454
16410
  }
16455
16411
  });
16456
16412
  case 3:
16457
- accountinfo = _context3.sent;
16413
+ accountinfo = _context5.sent;
16458
16414
  if (accountinfo) {
16459
16415
  setUser(accountinfo);
16460
16416
  }
16461
- _context3.next = 11;
16417
+ _context5.next = 11;
16462
16418
  break;
16463
16419
  case 7:
16464
- _context3.prev = 7;
16465
- _context3.t0 = _context3["catch"](0);
16466
- console.error(_context3.t0);
16420
+ _context5.prev = 7;
16421
+ _context5.t0 = _context5["catch"](0);
16422
+ console.error(_context5.t0);
16467
16423
  console.warn('获取用户信息失败,当前您登录的帐号可能为非标准租户帐号。');
16468
16424
  case 11:
16469
16425
  case "end":
16470
- return _context3.stop();
16426
+ return _context5.stop();
16471
16427
  }
16472
- }, _callee3, null, [[0, 7]]);
16428
+ }, _callee5, null, [[0, 7]]);
16473
16429
  }));
16474
16430
  return _getAndSetUserInfo.apply(this, arguments);
16475
16431
  }
@@ -16502,19 +16458,19 @@ function getAndSetTenant(_x) {
16502
16458
  return _getAndSetTenant.apply(this, arguments);
16503
16459
  }
16504
16460
  function _getAndSetTenant() {
16505
- _getAndSetTenant = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(tenantcode) {
16461
+ _getAndSetTenant = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6(tenantcode) {
16506
16462
  var tenantsRes, tenant, normalizedTenant;
16507
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
16508
- while (1) switch (_context4.prev = _context4.next) {
16463
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
16464
+ while (1) switch (_context6.prev = _context6.next) {
16509
16465
  case 0:
16510
- _context4.prev = 0;
16511
- _context4.next = 3;
16466
+ _context6.prev = 0;
16467
+ _context6.next = 3;
16512
16468
  return normalAxios$1.get('/api/auth/tenantlist', {}).then(function (res) {
16513
16469
  var _res$data;
16514
16470
  return res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.tenants;
16515
16471
  });
16516
16472
  case 3:
16517
- tenantsRes = _context4.sent;
16473
+ tenantsRes = _context6.sent;
16518
16474
  tenant = null;
16519
16475
  if (tenantsRes !== null && tenantsRes !== void 0 && tenantsRes.length) {
16520
16476
  if (!tenantcode) {
@@ -16535,18 +16491,18 @@ function _getAndSetTenant() {
16535
16491
  cloudServ.set(normalizedTenant);
16536
16492
  }
16537
16493
  }
16538
- _context4.next = 13;
16494
+ _context6.next = 13;
16539
16495
  break;
16540
16496
  case 9:
16541
- _context4.prev = 9;
16542
- _context4.t0 = _context4["catch"](0);
16543
- console.error(_context4.t0);
16497
+ _context6.prev = 9;
16498
+ _context6.t0 = _context6["catch"](0);
16499
+ console.error(_context6.t0);
16544
16500
  console.warn('获取租户信息失败,当前您登录的帐号可能为非标准租户帐号。');
16545
16501
  case 13:
16546
16502
  case "end":
16547
- return _context4.stop();
16503
+ return _context6.stop();
16548
16504
  }
16549
- }, _callee4, null, [[0, 9]]);
16505
+ }, _callee6, null, [[0, 9]]);
16550
16506
  }));
16551
16507
  return _getAndSetTenant.apply(this, arguments);
16552
16508
  }
@@ -16640,15 +16596,141 @@ function startRefreshtoken() {
16640
16596
  }, _callee);
16641
16597
  })), time);
16642
16598
  }
16599
+ // 获取 spu 容器 token
16600
+ var getSPUContainerToken = function getSPUContainerToken() {
16601
+ return new Promise(function (resolve, reject) {
16602
+ var _window$aPaaS;
16603
+ if ((_window$aPaaS = window.aPaaS) !== null && _window$aPaaS !== void 0 && _window$aPaaS.getToken) {
16604
+ window.aPaaS.getToken(function (res) {
16605
+ console.log('window.aPaaS.getToken success', res);
16606
+ // 安卓返回 token tokenExpires refreshToken
16607
+ // ios返回 token tokenexpires refreshtoken
16608
+ // 改好按安卓
16609
+ var token = res === null || res === void 0 ? void 0 : res.token;
16610
+ var tokenexpires = (res === null || res === void 0 ? void 0 : res.tokenExpires) || (res === null || res === void 0 ? void 0 : res.tokenexpires);
16611
+ var refreshtoken = (res === null || res === void 0 ? void 0 : res.refreshToken) || (res === null || res === void 0 ? void 0 : res.refreshtoken);
16612
+ if (token && tokenexpires && refreshtoken) {
16613
+ resolve({
16614
+ token: token,
16615
+ tokenexpires: tokenexpires,
16616
+ refreshtoken: refreshtoken
16617
+ });
16618
+ } else {
16619
+ console.error('window.aPaaS.getToken fail');
16620
+ resolve(null);
16621
+ }
16622
+ });
16623
+ } else {
16624
+ console.warn('window.aPaaS.getToken fail: not in SPU container');
16625
+ resolve(null);
16626
+ }
16627
+ });
16628
+ };
16629
+ // 如果APP端在SPU页面切到后台 然后又切回前台 有可能发生
16630
+ // 1、切后台时间过长导致 token 过期
16631
+ // 2、切后台后打开太多别的应用 导致切回前台时内存不足 从而导致 SPU 的 webview reload
16632
+ // 如果 1 2 同时发生 那么当前SPU页面重走单点登录流程 而url上的token已经过期 会导致单点登录失败
16633
+ // 因此 在APP端 单点登录不使用url上的token 而是直接拿App端的 App端能保证拿到的token一直不过期
16634
+ var fixLoginQuery = /*#__PURE__*/function () {
16635
+ var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(query) {
16636
+ var _window$aPaaS2;
16637
+ var newQuery, type, tokenData;
16638
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
16639
+ while (1) switch (_context2.prev = _context2.next) {
16640
+ case 0:
16641
+ newQuery = cloneDeep$1(query);
16642
+ _context2.next = 3;
16643
+ return Module.getSpuContainerType();
16644
+ case 3:
16645
+ type = _context2.sent;
16646
+ if (!(type === 'app' && (_window$aPaaS2 = window.aPaaS) !== null && _window$aPaaS2 !== void 0 && _window$aPaaS2.getToken)) {
16647
+ _context2.next = 12;
16648
+ break;
16649
+ }
16650
+ console.log('SPU is in App, singleLogin use App token.');
16651
+ _context2.next = 8;
16652
+ return getSPUContainerToken();
16653
+ case 8:
16654
+ tokenData = _context2.sent;
16655
+ if (tokenData) {
16656
+ newQuery.token = tokenData.token;
16657
+ newQuery.tokenexpires = tokenData.tokenexpires;
16658
+ newQuery.refreshtoken = tokenData.refreshtoken;
16659
+ }
16660
+ _context2.next = 13;
16661
+ break;
16662
+ case 12:
16663
+ console.log('SPU is not in App, singleLogin use query token.');
16664
+ case 13:
16665
+ return _context2.abrupt("return", newQuery);
16666
+ case 14:
16667
+ case "end":
16668
+ return _context2.stop();
16669
+ }
16670
+ }, _callee2);
16671
+ }));
16672
+ return function fixLoginQuery(_x2) {
16673
+ return _ref2.apply(this, arguments);
16674
+ };
16675
+ }();
16676
+ // 修复 App 切到后台时间过长导致 token 过期
16677
+ // 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
16678
+ var fixAppTokenExpired = function fixAppTokenExpired() {
16679
+ var _window$Native;
16680
+ if ((_window$Native = window.Native) !== null && _window$Native !== void 0 && _window$Native.onHostEnterForceground) {
16681
+ console.log('listen App enter forceground');
16682
+ window.Native.onHostEnterForceground( /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
16683
+ var loginState, tokenData;
16684
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
16685
+ while (1) switch (_context3.prev = _context3.next) {
16686
+ case 0:
16687
+ console.log('App enter forceground');
16688
+ loginState = getLoginState();
16689
+ if (!(!loginState.islogin && loginState.type === 2 && loginState.role !== 'center')) {
16690
+ _context3.next = 20;
16691
+ break;
16692
+ }
16693
+ _context3.next = 5;
16694
+ return getSPUContainerToken();
16695
+ case 5:
16696
+ tokenData = _context3.sent;
16697
+ if (!tokenData) {
16698
+ _context3.next = 12;
16699
+ break;
16700
+ }
16701
+ setToken(tokenData.token);
16702
+ setRefreshToken(tokenData.refreshtoken);
16703
+ setTokenExpires(tokenData.tokenexpires);
16704
+ _context3.next = 20;
16705
+ break;
16706
+ case 12:
16707
+ _context3.prev = 12;
16708
+ _context3.next = 15;
16709
+ return updateToken();
16710
+ case 15:
16711
+ _context3.next = 20;
16712
+ break;
16713
+ case 17:
16714
+ _context3.prev = 17;
16715
+ _context3.t0 = _context3["catch"](12);
16716
+ console.error(_context3.t0);
16717
+ case 20:
16718
+ case "end":
16719
+ return _context3.stop();
16720
+ }
16721
+ }, _callee3, null, [[12, 17]]);
16722
+ })));
16723
+ }
16724
+ };
16643
16725
  // 单点登录
16644
- function singleLogin(_x2) {
16726
+ function singleLogin(_x3) {
16645
16727
  return _singleLogin.apply(this, arguments);
16646
16728
  }
16647
16729
  function _singleLogin() {
16648
- _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(query) {
16730
+ _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7(query) {
16649
16731
  var flag, token, refreshtoken, tokenexpires, envname, context, setBaseInfo, isneedlogin, loginRole, refreshTokenUser, tokenUser, nowEnvname, envData;
16650
- return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16651
- while (1) switch (_context5.prev = _context5.next) {
16732
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
16733
+ while (1) switch (_context7.prev = _context7.next) {
16652
16734
  case 0:
16653
16735
  setBaseInfo = function _setBaseInfo() {
16654
16736
  setToken(token);
@@ -16660,7 +16742,10 @@ function _singleLogin() {
16660
16742
  // web 端有传 app没传 需要做兼容
16661
16743
  context && lsProxy.setItem('context', decodeURIComponent(context));
16662
16744
  };
16663
- query = cloneDeep$1(query);
16745
+ _context7.next = 3;
16746
+ return fixLoginQuery(query);
16747
+ case 3:
16748
+ query = _context7.sent;
16664
16749
  flag = false; // 是否登录成功
16665
16750
  token = query.token;
16666
16751
  refreshtoken = query.refreshtoken;
@@ -16668,7 +16753,7 @@ function _singleLogin() {
16668
16753
  envname = query.envname;
16669
16754
  context = query.context;
16670
16755
  if (!checkLoginByToken(token)) {
16671
- _context5.next = 60;
16756
+ _context7.next = 62;
16672
16757
  break;
16673
16758
  }
16674
16759
  isneedlogin = true; // 是否需要走单点登录流程
@@ -16690,104 +16775,104 @@ function _singleLogin() {
16690
16775
  // isneedlogin = true
16691
16776
  // debugger
16692
16777
  if (!isneedlogin) {
16693
- _context5.next = 58;
16778
+ _context7.next = 60;
16694
16779
  break;
16695
16780
  }
16696
16781
  setBaseInfo();
16697
16782
  // 单点登录写入 token 之后
16698
16783
  // 1、如果 refreshtoken 不完整 则换取完整的 refreshtoken
16699
- _context5.prev = 14;
16784
+ _context7.prev = 16;
16700
16785
  if (!checkLogin()) {
16701
- _context5.next = 21;
16786
+ _context7.next = 23;
16702
16787
  break;
16703
16788
  }
16704
16789
  refreshTokenUser = getUserByToken(getRefreshToken());
16705
16790
  tokenUser = getUserByToken(getToken());
16706
16791
  if (!(!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId)) {
16707
- _context5.next = 21;
16792
+ _context7.next = 23;
16708
16793
  break;
16709
16794
  }
16710
- _context5.next = 21;
16795
+ _context7.next = 23;
16711
16796
  return updateToken();
16712
- case 21:
16713
- _context5.next = 26;
16714
- break;
16715
16797
  case 23:
16716
- _context5.prev = 23;
16717
- _context5.t0 = _context5["catch"](14);
16718
- console.error(_context5.t0);
16719
- case 26:
16798
+ _context7.next = 28;
16799
+ break;
16800
+ case 25:
16801
+ _context7.prev = 25;
16802
+ _context7.t0 = _context7["catch"](16);
16803
+ console.error(_context7.t0);
16804
+ case 28:
16720
16805
  // 2、重新计算刷新 token 时间 因为刚开始进入就 startRefreshtoken 检测到没有 token 会过10秒才执行刷新 token 操作
16721
16806
  startRefreshtoken();
16722
16807
  // 获取环境信息和租户配置信息
16723
- _context5.next = 29;
16808
+ _context7.next = 31;
16724
16809
  return getEnvname();
16725
- case 29:
16726
- nowEnvname = _context5.sent;
16810
+ case 31:
16811
+ nowEnvname = _context7.sent;
16727
16812
  if (!nowEnvname) {
16728
- _context5.next = 50;
16813
+ _context7.next = 52;
16729
16814
  break;
16730
16815
  }
16731
- _context5.next = 33;
16816
+ _context7.next = 35;
16732
16817
  return requestEnvdata(nowEnvname);
16733
- case 33:
16734
- envData = _context5.sent;
16818
+ case 35:
16819
+ envData = _context7.sent;
16735
16820
  if (!envData) {
16736
- _context5.next = 46;
16821
+ _context7.next = 48;
16737
16822
  break;
16738
16823
  }
16739
16824
  saveEnvdata(envData);
16740
16825
  if (!envData.tenantcode) {
16741
- _context5.next = 42;
16826
+ _context7.next = 44;
16742
16827
  break;
16743
16828
  }
16744
16829
  setTecode(envData.tenantcode);
16745
16830
  // 租户配置
16746
- _context5.next = 40;
16831
+ _context7.next = 42;
16747
16832
  return tenantSetting.requestAndSetTenantSetting(envData.tenantcode);
16748
- case 40:
16749
- _context5.next = 44;
16750
- break;
16751
16833
  case 42:
16834
+ _context7.next = 46;
16835
+ break;
16836
+ case 44:
16752
16837
  tenantSetting.removeTenantSetting();
16753
16838
  removeTecode();
16754
- case 44:
16755
- _context5.next = 48;
16756
- break;
16757
16839
  case 46:
16840
+ _context7.next = 50;
16841
+ break;
16842
+ case 48:
16758
16843
  removeEnvdata();
16759
16844
  removeTecode();
16760
- case 48:
16761
- _context5.next = 52;
16762
- break;
16763
16845
  case 50:
16846
+ _context7.next = 54;
16847
+ break;
16848
+ case 52:
16764
16849
  removeEnvdata();
16765
16850
  removeTecode();
16766
- case 52:
16767
- _context5.next = 54;
16768
- return getAndSetTenant();
16769
16851
  case 54:
16770
- _context5.next = 56;
16771
- return getAndSetUserInfo();
16852
+ _context7.next = 56;
16853
+ return getAndSetTenant();
16772
16854
  case 56:
16855
+ _context7.next = 58;
16856
+ return getAndSetUserInfo();
16857
+ case 58:
16773
16858
  // 单点登录后 获取 web 开发者模式 如果是则设置 isdebugger
16774
16859
  urlquery.dealWebDebugger();
16775
16860
  flag = true;
16776
- case 58:
16777
- _context5.next = 63;
16778
- break;
16779
16861
  case 60:
16862
+ _context7.next = 65;
16863
+ break;
16864
+ case 62:
16780
16865
  flag = false;
16781
16866
  setBaseInfo(); // 传递的token过期依然写入 如果不写入的话 有可能之前的token本来没过期 页面依然可用
16782
16867
  console.error('单点登录失败,请检查链接所传 token/refreshtoken/tokenexpires 是否非法或过期。');
16783
- case 63:
16868
+ case 65:
16784
16869
  if (!flag) {
16785
- _context5.next = 66;
16870
+ _context7.next = 68;
16786
16871
  break;
16787
16872
  }
16788
- _context5.next = 66;
16873
+ _context7.next = 68;
16789
16874
  return core$1.initGetData();
16790
- case 66:
16875
+ case 68:
16791
16876
  if (flag) {
16792
16877
  // 单点登录成功 需要删除 query 中相关参数
16793
16878
  token && delete query.token;
@@ -16796,36 +16881,38 @@ function _singleLogin() {
16796
16881
  envname && delete query.envname;
16797
16882
  context && delete query.context;
16798
16883
  }
16799
- return _context5.abrupt("return", {
16884
+ return _context7.abrupt("return", {
16800
16885
  flag: flag,
16801
16886
  query: query
16802
16887
  });
16803
- case 68:
16888
+ case 70:
16804
16889
  case "end":
16805
- return _context5.stop();
16890
+ return _context7.stop();
16806
16891
  }
16807
- }, _callee5, null, [[14, 23]]);
16892
+ }, _callee7, null, [[16, 25]]);
16808
16893
  }));
16809
16894
  return _singleLogin.apply(this, arguments);
16810
16895
  }
16811
16896
  function installAuth(options) {
16812
16897
  startRefreshtoken();
16898
+ fixAppTokenExpired();
16813
16899
  if (options.router) {
16814
16900
  options.router.beforeEach( /*#__PURE__*/function () {
16815
- var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(to, from, next) {
16901
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(to, from, next) {
16816
16902
  var singleLoginRes;
16817
- return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
16818
- while (1) switch (_context2.prev = _context2.next) {
16903
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
16904
+ while (1) switch (_context4.prev = _context4.next) {
16819
16905
  case 0:
16820
16906
  if (!to.query.token) {
16821
- _context2.next = 8;
16907
+ _context4.next = 8;
16822
16908
  break;
16823
16909
  }
16824
- _context2.next = 3;
16910
+ _context4.next = 3;
16825
16911
  return singleLogin(to.query);
16826
16912
  case 3:
16827
- singleLoginRes = _context2.sent;
16913
+ singleLoginRes = _context4.sent;
16828
16914
  if (singleLoginRes.flag) {
16915
+ // next()
16829
16916
  next({
16830
16917
  path: to.path,
16831
16918
  params: to.params,
@@ -16835,22 +16922,22 @@ function installAuth(options) {
16835
16922
  next();
16836
16923
  }
16837
16924
  options.singleLoginCallback && options.singleLoginCallback(singleLoginRes);
16838
- _context2.next = 9;
16925
+ _context4.next = 9;
16839
16926
  break;
16840
16927
  case 8:
16841
16928
  next();
16842
16929
  case 9:
16843
16930
  case "end":
16844
- return _context2.stop();
16931
+ return _context4.stop();
16845
16932
  }
16846
- }, _callee2);
16933
+ }, _callee4);
16847
16934
  }));
16848
- return function (_x3, _x4, _x5) {
16849
- return _ref2.apply(this, arguments);
16935
+ return function (_x4, _x5, _x6) {
16936
+ return _ref4.apply(this, arguments);
16850
16937
  };
16851
16938
  }());
16852
16939
  } else {
16853
- console.warn('@smart100/spu-web-plugin 需要传入一个 vue-router 实例以便执行单点登录逻辑,如果您没传 vue-router 实例则需要自行在合适的位置执行单点登录代码。');
16940
+ console.warn('@smart100/spu-web-plugin 需要传入一个 vue-router 实例以便执行单点登录逻辑,如果您没传 vue-router 实例则需要自行在合适的位置执行单点登录代码,如果您已自行实现,请忽略该提示。');
16854
16941
  }
16855
16942
  if (checkLogin()) {
16856
16943
  core$1.initGetData();
@@ -16969,6 +17056,32 @@ var delay = function delay() {
16969
17056
  }, timeout);
16970
17057
  });
16971
17058
  };
17059
+ var getServerTime = function getServerTime() {
17060
+ return new Promise(function (resolve, reject) {
17061
+ var _window4;
17062
+ if ((_window4 = window) !== null && _window4 !== void 0 && (_window4 = _window4.Native) !== null && _window4 !== void 0 && _window4.getServerTime) {
17063
+ window.Native.getServerTime(function (res) {
17064
+ if (res) {
17065
+ resolve(res.toString());
17066
+ } else {
17067
+ resolve(Date.now().toString());
17068
+ }
17069
+ });
17070
+ } else {
17071
+ normalAxios$1.get('/api/teapi/offline/servertime', {}, {
17072
+ isShowLoading: false
17073
+ }).then(function (res) {
17074
+ if (res.data) {
17075
+ resolve(res.data.toString());
17076
+ } else {
17077
+ resolve(Date.now().toString());
17078
+ }
17079
+ })["catch"](function (err) {
17080
+ resolve(Date.now().toString());
17081
+ });
17082
+ }
17083
+ });
17084
+ };
16972
17085
 
16973
17086
  var Urlquery = /*#__PURE__*/function () {
16974
17087
  function Urlquery() {
@@ -17098,19 +17211,58 @@ var MapService = /*#__PURE__*/function () {
17098
17211
  _defineProperty$1(this, "AMap", null);
17099
17212
  _defineProperty$1(this, "TMap", null);
17100
17213
  _defineProperty$1(this, "BMap", null);
17101
- _defineProperty$1(this, "MapCore", null);
17102
17214
  }
17103
17215
  _createClass$1(MapService, [{
17216
+ key: "lbssetting",
17217
+ get: function get() {
17218
+ return tenantSetting.get('lbssetting');
17219
+ // const lbssetting: any = {
17220
+ // enable: '1',
17221
+ // setting: {
17222
+ // type: '',
17223
+ // key: {
17224
+ // web: '',
17225
+ // android: '',
17226
+ // ios: '',
17227
+ // harmony: ''
17228
+ // },
17229
+ // secretkey: {
17230
+ // web: '',
17231
+ // android: '',
17232
+ // ios: '',
17233
+ // harmony: ''
17234
+ // }
17235
+ // }
17236
+ // }
17237
+ // // // 高德地图公司key
17238
+ // // lbssetting.setting.type = 'amap'
17239
+ // // lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
17240
+ // // lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
17241
+ // // 高德地图个人key
17242
+ // lbssetting.setting.type = 'amap'
17243
+ // lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
17244
+ // lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
17245
+ // // // 腾讯地图
17246
+ // // lbssetting.setting.type = 'tencent'
17247
+ // // lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
17248
+ // // lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
17249
+ // // // 百度地图
17250
+ // // lbssetting.setting.type = 'baidu'
17251
+ // // lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
17252
+ // // lbssetting.setting.secretkey.web = ''
17253
+ // return lbssetting
17254
+ }
17255
+ }, {
17104
17256
  key: "isLbssettingEnable",
17105
17257
  get: function get() {
17106
- var _tenantSetting$get;
17107
- return ((_tenantSetting$get = tenantSetting.get('lbssetting')) === null || _tenantSetting$get === void 0 ? void 0 : _tenantSetting$get.enable) === '1';
17258
+ var _this$lbssetting;
17259
+ return ((_this$lbssetting = this.lbssetting) === null || _this$lbssetting === void 0 ? void 0 : _this$lbssetting.enable) === '1';
17108
17260
  }
17109
17261
  }, {
17110
17262
  key: "setting",
17111
17263
  get: function get() {
17112
- var _tenantSetting$get2;
17113
- return (_tenantSetting$get2 = tenantSetting.get('lbssetting')) === null || _tenantSetting$get2 === void 0 ? void 0 : _tenantSetting$get2.setting;
17264
+ var _this$lbssetting2;
17265
+ return (_this$lbssetting2 = this.lbssetting) === null || _this$lbssetting2 === void 0 ? void 0 : _this$lbssetting2.setting;
17114
17266
  }
17115
17267
  }, {
17116
17268
  key: "key",
@@ -17144,31 +17296,7 @@ var MapService = /*#__PURE__*/function () {
17144
17296
  }
17145
17297
  }, {
17146
17298
  key: "init",
17147
- value: // get AMap() {
17148
- // if (!this.isInit || this.type !== 'amap') {
17149
- // return null
17150
- // }
17151
- // return window.AMap
17152
- // }
17153
- // get TMap() {
17154
- // if (!this.isInit || this.type !== 'tencent') {
17155
- // return null
17156
- // }
17157
- // return window.TMap
17158
- // }
17159
- // get BMap() {
17160
- // if (!this.isInit || this.type !== 'baidu') {
17161
- // return null
17162
- // }
17163
- // return window.BMap
17164
- // }
17165
- // get MapCore() {
17166
- // if (!this.isInit) {
17167
- // return null
17168
- // }
17169
- // return window.BMap
17170
- // }
17171
- function () {
17299
+ value: function () {
17172
17300
  var _init2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
17173
17301
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
17174
17302
  while (1) switch (_context.prev = _context.next) {
@@ -17278,9 +17406,11 @@ var MapService = /*#__PURE__*/function () {
17278
17406
  return _init3.apply(this, arguments);
17279
17407
  }
17280
17408
  return _init;
17281
- }() // reset() {
17282
- // this.isInit = false
17283
- // }
17409
+ }() // 腾讯地图 key 配置错误
17410
+ // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
17411
+ // 2 如果是调用 api 会返回 catch 和详细的错误信息
17412
+ // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
17413
+ // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
17284
17414
  }, {
17285
17415
  key: "initTecent",
17286
17416
  value: function () {
@@ -17294,10 +17424,9 @@ var MapService = /*#__PURE__*/function () {
17294
17424
  'TMap');
17295
17425
  case 2:
17296
17426
  this.TMap = window.TMap;
17297
- this.MapCore = window.TMap;
17298
- _context3.next = 6;
17427
+ _context3.next = 5;
17299
17428
  return delay(300);
17300
- case 6:
17429
+ case 5:
17301
17430
  case "end":
17302
17431
  return _context3.stop();
17303
17432
  }
@@ -17307,7 +17436,9 @@ var MapService = /*#__PURE__*/function () {
17307
17436
  return _initTecent.apply(this, arguments);
17308
17437
  }
17309
17438
  return initTecent;
17310
- }()
17439
+ }() // 高德地图 key 配置错误
17440
+ // 1 如果是 key 格式不对 那么没返回 promise 连 window.AMap 都拿不到 地图和都不能用
17441
+ // 1 如果是 key 格式对 但 key 不对 有返回 window.AMap 但 api 定位调用失败 地图可以渲染空白地图
17311
17442
  }, {
17312
17443
  key: "initAmap",
17313
17444
  value: function () {
@@ -17349,14 +17480,13 @@ var MapService = /*#__PURE__*/function () {
17349
17480
  clearTimeout(time);
17350
17481
  window.AMap = AMap;
17351
17482
  _this.AMap = window.AMap;
17352
- _this.MapCore = window.AMap;
17353
17483
  // console.log(window)
17354
17484
  // console.log(window.AMap)
17355
17485
  // console.log(window.AMapUI)
17356
17486
  // console.log(window.AMapLoader)
17357
17487
  // console.log(window.AMap === aaaa)
17358
17488
  resolve(window.AMap);
17359
- case 11:
17489
+ case 10:
17360
17490
  case "end":
17361
17491
  return _context4.stop();
17362
17492
  }
@@ -17376,7 +17506,8 @@ var MapService = /*#__PURE__*/function () {
17376
17506
  return _initAmap.apply(this, arguments);
17377
17507
  }
17378
17508
  return initAmap;
17379
- }()
17509
+ }() // 百度地图 key 配置错误
17510
+ // alert以下信息: 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
17380
17511
  }, {
17381
17512
  key: "initBaidu",
17382
17513
  value: function () {
@@ -17390,7 +17521,6 @@ var MapService = /*#__PURE__*/function () {
17390
17521
  // console.log(e)
17391
17522
  // debugger
17392
17523
  _this2.BMap = window.BMap;
17393
- _this2.MapCore = window.BMap;
17394
17524
  // debugger
17395
17525
  // 启用google标准坐标体系
17396
17526
  // coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
@@ -18048,13 +18178,13 @@ var getAddressByBmap = /*#__PURE__*/function () {
18048
18178
  var getLocationPromise = /*#__PURE__*/function () {
18049
18179
  var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
18050
18180
  var _window9;
18051
- var isuseiplocarion,
18181
+ var isuseiplocation,
18052
18182
  location,
18053
18183
  _args17 = arguments;
18054
18184
  return _regeneratorRuntime$1().wrap(function _callee17$(_context17) {
18055
18185
  while (1) switch (_context17.prev = _context17.next) {
18056
18186
  case 0:
18057
- isuseiplocarion = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18187
+ isuseiplocation = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
18058
18188
  location = null; // 在 SPU 容器里使用 Native-API 的定位
18059
18189
  if (!((_window9 = window) !== null && _window9 !== void 0 && (_window9 = _window9.Native) !== null && _window9 !== void 0 && _window9.getLocation)) {
18060
18190
  _context17.next = 6;
@@ -18066,66 +18196,67 @@ var getLocationPromise = /*#__PURE__*/function () {
18066
18196
  location = _context17.sent;
18067
18197
  case 6:
18068
18198
  if (location) {
18069
- _context17.next = 10;
18070
- break;
18071
- }
18072
- _context17.next = 9;
18073
- return getLocationByNavigator();
18074
- case 9:
18075
- location = _context17.sent;
18076
- case 10:
18077
- if (location) {
18078
- _context17.next = 35;
18199
+ _context17.next = 31;
18079
18200
  break;
18080
18201
  }
18081
18202
  if (!(mapService.type === 'amap')) {
18082
- _context17.next = 21;
18203
+ _context17.next = 17;
18083
18204
  break;
18084
18205
  }
18085
- _context17.next = 14;
18206
+ _context17.next = 10;
18086
18207
  return getLocationByAMap();
18087
- case 14:
18208
+ case 10:
18088
18209
  location = _context17.sent;
18089
- if (!(!location && isuseiplocarion)) {
18090
- _context17.next = 19;
18210
+ if (!(!location && isuseiplocation)) {
18211
+ _context17.next = 15;
18091
18212
  break;
18092
18213
  }
18093
- _context17.next = 18;
18214
+ _context17.next = 14;
18094
18215
  return getCityLocationByAMap();
18095
- case 18:
18216
+ case 14:
18096
18217
  location = _context17.sent;
18097
- case 19:
18098
- _context17.next = 35;
18218
+ case 15:
18219
+ _context17.next = 31;
18099
18220
  break;
18100
- case 21:
18101
- if (!(mapService.type === 'tencent' && isuseiplocarion)) {
18102
- _context17.next = 27;
18221
+ case 17:
18222
+ if (!(mapService.type === 'tencent' && isuseiplocation)) {
18223
+ _context17.next = 23;
18103
18224
  break;
18104
18225
  }
18105
- _context17.next = 24;
18226
+ _context17.next = 20;
18106
18227
  return getIPLocationByTMap();
18107
- case 24:
18228
+ case 20:
18108
18229
  location = _context17.sent;
18109
- _context17.next = 35;
18230
+ _context17.next = 31;
18110
18231
  break;
18111
- case 27:
18232
+ case 23:
18112
18233
  if (!(mapService.type === 'baidu')) {
18113
- _context17.next = 35;
18234
+ _context17.next = 31;
18114
18235
  break;
18115
18236
  }
18116
- _context17.next = 30;
18237
+ _context17.next = 26;
18117
18238
  return getLocationByBMap();
18239
+ case 26:
18240
+ location = _context17.sent;
18241
+ if (!(!location && isuseiplocation)) {
18242
+ _context17.next = 31;
18243
+ break;
18244
+ }
18245
+ _context17.next = 30;
18246
+ return getCityLocationByBMap();
18118
18247
  case 30:
18119
18248
  location = _context17.sent;
18120
- if (!(!location && isuseiplocarion)) {
18249
+ case 31:
18250
+ if (location) {
18121
18251
  _context17.next = 35;
18122
18252
  break;
18123
18253
  }
18124
18254
  _context17.next = 34;
18125
- return getCityLocationByBMap();
18255
+ return getLocationByNavigator();
18126
18256
  case 34:
18127
18257
  location = _context17.sent;
18128
18258
  case 35:
18259
+ // location = null
18129
18260
  // 开发模式下为了方便测试提供虚拟定位
18130
18261
  if (!location && urlquery.isvirtuallocation) {
18131
18262
  location = {
@@ -18181,13 +18312,13 @@ function getLocation() {
18181
18312
  } // 逆地址解析
18182
18313
  function _getLocation() {
18183
18314
  _getLocation = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee20() {
18184
- var isuseiplocarion,
18315
+ var isuseiplocation,
18185
18316
  locationRes,
18186
18317
  _args20 = arguments;
18187
18318
  return _regeneratorRuntime$1().wrap(function _callee20$(_context20) {
18188
18319
  while (1) switch (_context20.prev = _context20.next) {
18189
18320
  case 0:
18190
- isuseiplocarion = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18321
+ isuseiplocation = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : false;
18191
18322
  _context20.next = 3;
18192
18323
  return mapService.init();
18193
18324
  case 3:
@@ -18205,7 +18336,7 @@ function _getLocation() {
18205
18336
  case 7:
18206
18337
  // console.log('runing')
18207
18338
  runing = true;
18208
- locationPromise = getLocationPromise(isuseiplocarion);
18339
+ locationPromise = getLocationPromise(isuseiplocation);
18209
18340
  _context20.next = 11;
18210
18341
  return locationPromise;
18211
18342
  case 11:
@@ -70204,7 +70335,7 @@ var install = function install(app, options) {
70204
70335
  console.log("@smart100/spu-web-plugin@".concat(version, " globalOptions"));
70205
70336
  console.log(globalOptions);
70206
70337
  // setTimeout(() => {
70207
- // console.error('5416546544')
70338
+ // console.error('9999')
70208
70339
  // }, 1000)
70209
70340
  // if (install.installed) return
70210
70341
  // install.installed = true
@@ -70225,4 +70356,4 @@ var SPUWebPlugin = {
70225
70356
  version: version
70226
70357
  };
70227
70358
 
70228
- export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getAddress, getCloudServ, getDistance, getLocation, getRefreshToken, getServToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
70359
+ export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getAddress, getCloudServ, getDistance, getLocation, getRefreshToken, getServToken, getServerTime, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };