@smart100/spu-web-plugin 1.0.18 → 1.0.20

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.
package/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ interface IUploadService {
80
80
  // modulename: string
81
81
  // moduleversion: string
82
82
  // storageproxyprefix?: string
83
+ // isfixapptokenexpired?: boolean
83
84
  // router?: any
84
85
  // }
85
86
 
@@ -104,7 +105,11 @@ export const getLocation: (isuseiplocation?: boolean) => Promise<{
104
105
  [propName: string]: any
105
106
  } | null>
106
107
  export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
107
- export const getAddress: (location: { longitude: string; latitude: string; [propName: string]: any }) => Promise<string>
108
+ export const getAddress: (location: {
109
+ longitude: string
110
+ latitude: string
111
+ [propName: string]: any
112
+ }) => Promise<string>
108
113
  export const spuAxios: any
109
114
  export const apaasAxios: any
110
115
  export const axios: any
@@ -132,6 +137,9 @@ export const updateToken: () => Promise<void>
132
137
  export const getToken: () => string
133
138
  export const getTokenExpires: () => string
134
139
  export const getRefreshToken: () => string
140
+ export const setToken: (value: string) => void
141
+ export const setTokenExpires: (value: string) => void
142
+ export const setRefreshToken: (value: string) => void
135
143
  export const getUser: (key?: string) => any
136
144
  export const checkLogin: () => boolean
137
145
  export const Module: any
@@ -1,4 +1,4 @@
1
- var version = "1.0.18";
1
+ var version = "1.0.20";
2
2
 
3
3
  /** Detect free variable `global` from Node.js. */
4
4
  var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
@@ -8368,6 +8368,12 @@ var Core = /*#__PURE__*/function () {
8368
8368
  }
8369
8369
  return getSpuContainerType;
8370
8370
  }()
8371
+ }, {
8372
+ key: "checkInAppSpuWebview",
8373
+ value: function checkInAppSpuWebview() {
8374
+ var _window3;
8375
+ return !!((_window3 = window) !== null && _window3 !== void 0 && (_window3 = _window3.aPaaS) !== null && _window3 !== void 0 && _window3.getPhoto);
8376
+ }
8371
8377
  }]);
8372
8378
  return Core;
8373
8379
  }();
@@ -16390,13 +16396,13 @@ function getAndSetUserInfo() {
16390
16396
  return _getAndSetUserInfo.apply(this, arguments);
16391
16397
  }
16392
16398
  function _getAndSetUserInfo() {
16393
- _getAndSetUserInfo = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5() {
16399
+ _getAndSetUserInfo = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
16394
16400
  var accountinfo;
16395
- return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16396
- while (1) switch (_context5.prev = _context5.next) {
16401
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
16402
+ while (1) switch (_context6.prev = _context6.next) {
16397
16403
  case 0:
16398
- _context5.prev = 0;
16399
- _context5.next = 3;
16404
+ _context6.prev = 0;
16405
+ _context6.next = 3;
16400
16406
  return normalAxios$1.post('/api/teapi/rolepermission/account/getaccountinfo', {
16401
16407
  positionid: getUser('positioncode') || '',
16402
16408
  deviceinfo: '',
@@ -16410,22 +16416,22 @@ function _getAndSetUserInfo() {
16410
16416
  }
16411
16417
  });
16412
16418
  case 3:
16413
- accountinfo = _context5.sent;
16419
+ accountinfo = _context6.sent;
16414
16420
  if (accountinfo) {
16415
16421
  setUser(accountinfo);
16416
16422
  }
16417
- _context5.next = 11;
16423
+ _context6.next = 11;
16418
16424
  break;
16419
16425
  case 7:
16420
- _context5.prev = 7;
16421
- _context5.t0 = _context5["catch"](0);
16422
- console.error(_context5.t0);
16426
+ _context6.prev = 7;
16427
+ _context6.t0 = _context6["catch"](0);
16428
+ console.error(_context6.t0);
16423
16429
  console.warn('获取用户信息失败,当前您登录的帐号可能为非标准租户帐号。');
16424
16430
  case 11:
16425
16431
  case "end":
16426
- return _context5.stop();
16432
+ return _context6.stop();
16427
16433
  }
16428
- }, _callee5, null, [[0, 7]]);
16434
+ }, _callee6, null, [[0, 7]]);
16429
16435
  }));
16430
16436
  return _getAndSetUserInfo.apply(this, arguments);
16431
16437
  }
@@ -16458,19 +16464,19 @@ function getAndSetTenant(_x) {
16458
16464
  return _getAndSetTenant.apply(this, arguments);
16459
16465
  }
16460
16466
  function _getAndSetTenant() {
16461
- _getAndSetTenant = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6(tenantcode) {
16467
+ _getAndSetTenant = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7(tenantcode) {
16462
16468
  var tenantsRes, tenant, normalizedTenant;
16463
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
16464
- while (1) switch (_context6.prev = _context6.next) {
16469
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
16470
+ while (1) switch (_context7.prev = _context7.next) {
16465
16471
  case 0:
16466
- _context6.prev = 0;
16467
- _context6.next = 3;
16472
+ _context7.prev = 0;
16473
+ _context7.next = 3;
16468
16474
  return normalAxios$1.get('/api/auth/tenantlist', {}).then(function (res) {
16469
16475
  var _res$data;
16470
16476
  return res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.tenants;
16471
16477
  });
16472
16478
  case 3:
16473
- tenantsRes = _context6.sent;
16479
+ tenantsRes = _context7.sent;
16474
16480
  tenant = null;
16475
16481
  if (tenantsRes !== null && tenantsRes !== void 0 && tenantsRes.length) {
16476
16482
  if (!tenantcode) {
@@ -16491,18 +16497,18 @@ function _getAndSetTenant() {
16491
16497
  cloudServ.set(normalizedTenant);
16492
16498
  }
16493
16499
  }
16494
- _context6.next = 13;
16500
+ _context7.next = 13;
16495
16501
  break;
16496
16502
  case 9:
16497
- _context6.prev = 9;
16498
- _context6.t0 = _context6["catch"](0);
16499
- console.error(_context6.t0);
16503
+ _context7.prev = 9;
16504
+ _context7.t0 = _context7["catch"](0);
16505
+ console.error(_context7.t0);
16500
16506
  console.warn('获取租户信息失败,当前您登录的帐号可能为非标准租户帐号。');
16501
16507
  case 13:
16502
16508
  case "end":
16503
- return _context6.stop();
16509
+ return _context7.stop();
16504
16510
  }
16505
- }, _callee6, null, [[0, 9]]);
16511
+ }, _callee7, null, [[0, 9]]);
16506
16512
  }));
16507
16513
  return _getAndSetTenant.apply(this, arguments);
16508
16514
  }
@@ -16599,16 +16605,15 @@ function startRefreshtoken() {
16599
16605
  // 获取 spu 容器 token
16600
16606
  var getSPUContainerToken = function getSPUContainerToken() {
16601
16607
  return new Promise(function (resolve, reject) {
16602
- var _window$aPaaS;
16603
- if ((_window$aPaaS = window.aPaaS) !== null && _window$aPaaS !== void 0 && _window$aPaaS.getToken) {
16608
+ var _window$aPaaS, _window$aPaaS2;
16609
+ // 在spuwebview中
16610
+ if (core$1.checkInAppSpuWebview() && (_window$aPaaS = window.aPaaS) !== null && _window$aPaaS !== void 0 && _window$aPaaS.getToken) {
16611
+ console.log('in App spuwebview');
16604
16612
  window.aPaaS.getToken(function (res) {
16605
16613
  console.log('window.aPaaS.getToken success', res);
16606
- // 安卓返回 token tokenExpires refreshToken
16607
- // ios返回 token tokenexpires refreshtoken
16608
- // 改好按安卓
16609
16614
  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);
16615
+ var tokenexpires = res === null || res === void 0 ? void 0 : res.tokenExpires;
16616
+ var refreshtoken = res === null || res === void 0 ? void 0 : res.refreshToken;
16612
16617
  if (token && tokenexpires && refreshtoken) {
16613
16618
  resolve({
16614
16619
  token: token,
@@ -16620,6 +16625,49 @@ var getSPUContainerToken = function getSPUContainerToken() {
16620
16625
  resolve(null);
16621
16626
  }
16622
16627
  });
16628
+ } else if ((_window$aPaaS2 = window.aPaaS) !== null && _window$aPaaS2 !== void 0 && _window$aPaaS2.getToken && globalOptions.modulekey === 'portalEngine') {
16629
+ console.log('in App interactivewebview');
16630
+ // 兼容门户引擎在 interactivewebview 的情况
16631
+ var u = navigator.userAgent;
16632
+ var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
16633
+ if (isAndroid) {
16634
+ console.log('in Android, use window.aPaaS.getToken and window.getTokenComplete');
16635
+ window.getTokenComplete = function (res) {
16636
+ console.log('window.getTokenComplete success', res);
16637
+ var token = res === null || res === void 0 ? void 0 : res.token;
16638
+ var tokenexpires = res === null || res === void 0 ? void 0 : res.tokenExpires;
16639
+ var refreshtoken = res === null || res === void 0 ? void 0 : res.refreshToken;
16640
+ if (token && tokenexpires && refreshtoken) {
16641
+ resolve({
16642
+ token: token,
16643
+ tokenexpires: tokenexpires,
16644
+ refreshtoken: refreshtoken
16645
+ });
16646
+ } else {
16647
+ console.error('window.getTokenComplete fail');
16648
+ resolve(null);
16649
+ }
16650
+ };
16651
+ window.aPaaS.getToken(window.getTokenComplete);
16652
+ } else {
16653
+ console.log('in IOS, use window.aPaaS.getToken');
16654
+ window.aPaaS.getToken(function (res) {
16655
+ console.log('window.aPaaS.getToken success', res);
16656
+ var token = res === null || res === void 0 ? void 0 : res.token;
16657
+ var tokenexpires = res === null || res === void 0 ? void 0 : res.tokenExpires;
16658
+ var refreshtoken = res === null || res === void 0 ? void 0 : res.refreshToken;
16659
+ if (token && tokenexpires && refreshtoken) {
16660
+ resolve({
16661
+ token: token,
16662
+ tokenexpires: tokenexpires,
16663
+ refreshtoken: refreshtoken
16664
+ });
16665
+ } else {
16666
+ console.error('window.aPaaS.getToken fail');
16667
+ resolve(null);
16668
+ }
16669
+ });
16670
+ }
16623
16671
  } else {
16624
16672
  console.warn('window.aPaaS.getToken fail: not in SPU container');
16625
16673
  resolve(null);
@@ -16633,21 +16681,26 @@ var getSPUContainerToken = function getSPUContainerToken() {
16633
16681
  // 因此 在APP端 单点登录不使用url上的token 而是直接拿App端的 App端能保证拿到的token一直不过期
16634
16682
  var fixLoginQuery = /*#__PURE__*/function () {
16635
16683
  var _ref2 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee2(query) {
16636
- var _window$aPaaS2;
16637
- var newQuery, type, tokenData;
16684
+ var _window$aPaaS3;
16685
+ var newQuery, tokenData;
16638
16686
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
16639
16687
  while (1) switch (_context2.prev = _context2.next) {
16640
16688
  case 0:
16641
16689
  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;
16690
+ if ((_window$aPaaS3 = window.aPaaS) !== null && _window$aPaaS3 !== void 0 && _window$aPaaS3.getToken) {
16691
+ _context2.next = 5;
16648
16692
  break;
16649
16693
  }
16650
- console.log('SPU is in App, singleLogin use App token.');
16694
+ console.log('SPU is not in App, singleLogin use query token.');
16695
+ _context2.next = 10;
16696
+ break;
16697
+ case 5:
16698
+ if (core$1.checkInAppSpuWebview()) {
16699
+ console.log('SPU is in App spuwebview, singleLogin use App token.');
16700
+ } else if (globalOptions.modulekey === 'portalEngine') {
16701
+ // 兼容门户引擎在 interactivewebview 的情况
16702
+ console.log('SPU is in App interactivewebview, singleLogin use App token.');
16703
+ }
16651
16704
  _context2.next = 8;
16652
16705
  return getSPUContainerToken();
16653
16706
  case 8:
@@ -16657,13 +16710,9 @@ var fixLoginQuery = /*#__PURE__*/function () {
16657
16710
  newQuery.tokenexpires = tokenData.tokenexpires;
16658
16711
  newQuery.refreshtoken = tokenData.refreshtoken;
16659
16712
  }
16660
- _context2.next = 13;
16661
- break;
16662
- case 12:
16663
- console.log('SPU is not in App, singleLogin use query token.');
16664
- case 13:
16713
+ case 10:
16665
16714
  return _context2.abrupt("return", newQuery);
16666
- case 14:
16715
+ case 11:
16667
16716
  case "end":
16668
16717
  return _context2.stop();
16669
16718
  }
@@ -16673,64 +16722,94 @@ var fixLoginQuery = /*#__PURE__*/function () {
16673
16722
  return _ref2.apply(this, arguments);
16674
16723
  };
16675
16724
  }();
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;
16725
+ var checkTokenExpiredAndUpdate = /*#__PURE__*/function () {
16726
+ var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
16727
+ var loginState, tokenData;
16728
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
16729
+ while (1) switch (_context3.prev = _context3.next) {
16730
+ case 0:
16731
+ loginState = getLoginState();
16732
+ if (!(!loginState.islogin && loginState.type === 2 && loginState.role !== 'center')) {
16733
+ _context3.next = 19;
16705
16734
  break;
16706
- case 12:
16707
- _context3.prev = 12;
16708
- _context3.next = 15;
16709
- return updateToken();
16710
- case 15:
16711
- _context3.next = 20;
16735
+ }
16736
+ _context3.next = 4;
16737
+ return getSPUContainerToken();
16738
+ case 4:
16739
+ tokenData = _context3.sent;
16740
+ if (!tokenData) {
16741
+ _context3.next = 11;
16712
16742
  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
- };
16743
+ }
16744
+ setToken(tokenData.token);
16745
+ setRefreshToken(tokenData.refreshtoken);
16746
+ setTokenExpires(tokenData.tokenexpires);
16747
+ _context3.next = 19;
16748
+ break;
16749
+ case 11:
16750
+ _context3.prev = 11;
16751
+ _context3.next = 14;
16752
+ return updateToken();
16753
+ case 14:
16754
+ _context3.next = 19;
16755
+ break;
16756
+ case 16:
16757
+ _context3.prev = 16;
16758
+ _context3.t0 = _context3["catch"](11);
16759
+ console.error(_context3.t0);
16760
+ case 19:
16761
+ case "end":
16762
+ return _context3.stop();
16763
+ }
16764
+ }, _callee3, null, [[11, 16]]);
16765
+ }));
16766
+ return function checkTokenExpiredAndUpdate() {
16767
+ return _ref3.apply(this, arguments);
16768
+ };
16769
+ }();
16770
+ // 修复 App 切到后台时间过长导致 token 过期
16771
+ // 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
16772
+ var fixAppTokenExpired = /*#__PURE__*/function () {
16773
+ var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4() {
16774
+ var _window$Native, _window$aPaaS4;
16775
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
16776
+ while (1) switch (_context4.prev = _context4.next) {
16777
+ case 0:
16778
+ if (globalOptions.isfixapptokenexpired && core$1.checkInAppSpuWebview() && (_window$Native = window.Native) !== null && _window$Native !== void 0 && _window$Native.onHostEnterForceground) {
16779
+ console.log('SPU is in App spuwebview, listen App enter forceground.');
16780
+ window.Native.onHostEnterForceground(function () {
16781
+ console.log('App enter forceground');
16782
+ checkTokenExpiredAndUpdate();
16783
+ });
16784
+ } else if (globalOptions.isfixapptokenexpired && globalOptions.modulekey === 'portalEngine' && (_window$aPaaS4 = window.aPaaS) !== null && _window$aPaaS4 !== void 0 && _window$aPaaS4.getToken) {
16785
+ console.log('SPU is in App interactivewebview, listen App enter forceground.');
16786
+ setTimeout(function () {
16787
+ window.Native = window.Native || {};
16788
+ window.Native.onHostEnterForceground = function () {
16789
+ console.log('App enter forceground');
16790
+ checkTokenExpiredAndUpdate();
16791
+ };
16792
+ }, 1000);
16793
+ }
16794
+ case 1:
16795
+ case "end":
16796
+ return _context4.stop();
16797
+ }
16798
+ }, _callee4);
16799
+ }));
16800
+ return function fixAppTokenExpired() {
16801
+ return _ref4.apply(this, arguments);
16802
+ };
16803
+ }();
16725
16804
  // 单点登录
16726
16805
  function singleLogin(_x3) {
16727
16806
  return _singleLogin.apply(this, arguments);
16728
16807
  }
16729
16808
  function _singleLogin() {
16730
- _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7(query) {
16809
+ _singleLogin = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(query) {
16731
16810
  var flag, token, refreshtoken, tokenexpires, envname, context, setBaseInfo, isneedlogin, loginRole, refreshTokenUser, tokenUser, nowEnvname, envData;
16732
- return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
16733
- while (1) switch (_context7.prev = _context7.next) {
16811
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
16812
+ while (1) switch (_context8.prev = _context8.next) {
16734
16813
  case 0:
16735
16814
  setBaseInfo = function _setBaseInfo() {
16736
16815
  setToken(token);
@@ -16742,10 +16821,16 @@ function _singleLogin() {
16742
16821
  // web 端有传 app没传 需要做兼容
16743
16822
  context && lsProxy.setItem('context', decodeURIComponent(context));
16744
16823
  };
16745
- _context7.next = 3;
16824
+ query = cloneDeep$1(query);
16825
+ if (!globalOptions.isfixapptokenexpired) {
16826
+ _context8.next = 6;
16827
+ break;
16828
+ }
16829
+ _context8.next = 5;
16746
16830
  return fixLoginQuery(query);
16747
- case 3:
16748
- query = _context7.sent;
16831
+ case 5:
16832
+ query = _context8.sent;
16833
+ case 6:
16749
16834
  flag = false; // 是否登录成功
16750
16835
  token = query.token;
16751
16836
  refreshtoken = query.refreshtoken;
@@ -16753,7 +16838,7 @@ function _singleLogin() {
16753
16838
  envname = query.envname;
16754
16839
  context = query.context;
16755
16840
  if (!checkLoginByToken(token)) {
16756
- _context7.next = 62;
16841
+ _context8.next = 64;
16757
16842
  break;
16758
16843
  }
16759
16844
  isneedlogin = true; // 是否需要走单点登录流程
@@ -16775,104 +16860,104 @@ function _singleLogin() {
16775
16860
  // isneedlogin = true
16776
16861
  // debugger
16777
16862
  if (!isneedlogin) {
16778
- _context7.next = 60;
16863
+ _context8.next = 62;
16779
16864
  break;
16780
16865
  }
16781
16866
  setBaseInfo();
16782
16867
  // 单点登录写入 token 之后
16783
16868
  // 1、如果 refreshtoken 不完整 则换取完整的 refreshtoken
16784
- _context7.prev = 16;
16869
+ _context8.prev = 18;
16785
16870
  if (!checkLogin()) {
16786
- _context7.next = 23;
16871
+ _context8.next = 25;
16787
16872
  break;
16788
16873
  }
16789
16874
  refreshTokenUser = getUserByToken(getRefreshToken());
16790
16875
  tokenUser = getUserByToken(getToken());
16791
16876
  if (!(!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId)) {
16792
- _context7.next = 23;
16877
+ _context8.next = 25;
16793
16878
  break;
16794
16879
  }
16795
- _context7.next = 23;
16880
+ _context8.next = 25;
16796
16881
  return updateToken();
16797
- case 23:
16798
- _context7.next = 28;
16799
- break;
16800
16882
  case 25:
16801
- _context7.prev = 25;
16802
- _context7.t0 = _context7["catch"](16);
16803
- console.error(_context7.t0);
16804
- case 28:
16883
+ _context8.next = 30;
16884
+ break;
16885
+ case 27:
16886
+ _context8.prev = 27;
16887
+ _context8.t0 = _context8["catch"](18);
16888
+ console.error(_context8.t0);
16889
+ case 30:
16805
16890
  // 2、重新计算刷新 token 时间 因为刚开始进入就 startRefreshtoken 检测到没有 token 会过10秒才执行刷新 token 操作
16806
16891
  startRefreshtoken();
16807
16892
  // 获取环境信息和租户配置信息
16808
- _context7.next = 31;
16893
+ _context8.next = 33;
16809
16894
  return getEnvname();
16810
- case 31:
16811
- nowEnvname = _context7.sent;
16895
+ case 33:
16896
+ nowEnvname = _context8.sent;
16812
16897
  if (!nowEnvname) {
16813
- _context7.next = 52;
16898
+ _context8.next = 54;
16814
16899
  break;
16815
16900
  }
16816
- _context7.next = 35;
16901
+ _context8.next = 37;
16817
16902
  return requestEnvdata(nowEnvname);
16818
- case 35:
16819
- envData = _context7.sent;
16903
+ case 37:
16904
+ envData = _context8.sent;
16820
16905
  if (!envData) {
16821
- _context7.next = 48;
16906
+ _context8.next = 50;
16822
16907
  break;
16823
16908
  }
16824
16909
  saveEnvdata(envData);
16825
16910
  if (!envData.tenantcode) {
16826
- _context7.next = 44;
16911
+ _context8.next = 46;
16827
16912
  break;
16828
16913
  }
16829
16914
  setTecode(envData.tenantcode);
16830
16915
  // 租户配置
16831
- _context7.next = 42;
16916
+ _context8.next = 44;
16832
16917
  return tenantSetting.requestAndSetTenantSetting(envData.tenantcode);
16833
- case 42:
16834
- _context7.next = 46;
16835
- break;
16836
16918
  case 44:
16919
+ _context8.next = 48;
16920
+ break;
16921
+ case 46:
16837
16922
  tenantSetting.removeTenantSetting();
16838
16923
  removeTecode();
16839
- case 46:
16840
- _context7.next = 50;
16841
- break;
16842
16924
  case 48:
16925
+ _context8.next = 52;
16926
+ break;
16927
+ case 50:
16843
16928
  removeEnvdata();
16844
16929
  removeTecode();
16845
- case 50:
16846
- _context7.next = 54;
16847
- break;
16848
16930
  case 52:
16931
+ _context8.next = 56;
16932
+ break;
16933
+ case 54:
16849
16934
  removeEnvdata();
16850
16935
  removeTecode();
16851
- case 54:
16852
- _context7.next = 56;
16853
- return getAndSetTenant();
16854
16936
  case 56:
16855
- _context7.next = 58;
16856
- return getAndSetUserInfo();
16937
+ _context8.next = 58;
16938
+ return getAndSetTenant();
16857
16939
  case 58:
16940
+ _context8.next = 60;
16941
+ return getAndSetUserInfo();
16942
+ case 60:
16858
16943
  // 单点登录后 获取 web 开发者模式 如果是则设置 isdebugger
16859
16944
  urlquery.dealWebDebugger();
16860
16945
  flag = true;
16861
- case 60:
16862
- _context7.next = 65;
16863
- break;
16864
16946
  case 62:
16947
+ _context8.next = 67;
16948
+ break;
16949
+ case 64:
16865
16950
  flag = false;
16866
16951
  setBaseInfo(); // 传递的token过期依然写入 如果不写入的话 有可能之前的token本来没过期 页面依然可用
16867
16952
  console.error('单点登录失败,请检查链接所传 token/refreshtoken/tokenexpires 是否非法或过期。');
16868
- case 65:
16953
+ case 67:
16869
16954
  if (!flag) {
16870
- _context7.next = 68;
16955
+ _context8.next = 70;
16871
16956
  break;
16872
16957
  }
16873
- _context7.next = 68;
16958
+ _context8.next = 70;
16874
16959
  return core$1.initGetData();
16875
- case 68:
16960
+ case 70:
16876
16961
  if (flag) {
16877
16962
  // 单点登录成功 需要删除 query 中相关参数
16878
16963
  token && delete query.token;
@@ -16881,15 +16966,15 @@ function _singleLogin() {
16881
16966
  envname && delete query.envname;
16882
16967
  context && delete query.context;
16883
16968
  }
16884
- return _context7.abrupt("return", {
16969
+ return _context8.abrupt("return", {
16885
16970
  flag: flag,
16886
16971
  query: query
16887
16972
  });
16888
- case 70:
16973
+ case 72:
16889
16974
  case "end":
16890
- return _context7.stop();
16975
+ return _context8.stop();
16891
16976
  }
16892
- }, _callee7, null, [[16, 25]]);
16977
+ }, _callee8, null, [[18, 27]]);
16893
16978
  }));
16894
16979
  return _singleLogin.apply(this, arguments);
16895
16980
  }
@@ -16898,19 +16983,19 @@ function installAuth(options) {
16898
16983
  fixAppTokenExpired();
16899
16984
  if (options.router) {
16900
16985
  options.router.beforeEach( /*#__PURE__*/function () {
16901
- var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(to, from, next) {
16986
+ var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(to, from, next) {
16902
16987
  var singleLoginRes;
16903
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
16904
- while (1) switch (_context4.prev = _context4.next) {
16988
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
16989
+ while (1) switch (_context5.prev = _context5.next) {
16905
16990
  case 0:
16906
16991
  if (!to.query.token) {
16907
- _context4.next = 8;
16992
+ _context5.next = 8;
16908
16993
  break;
16909
16994
  }
16910
- _context4.next = 3;
16995
+ _context5.next = 3;
16911
16996
  return singleLogin(to.query);
16912
16997
  case 3:
16913
- singleLoginRes = _context4.sent;
16998
+ singleLoginRes = _context5.sent;
16914
16999
  if (singleLoginRes.flag) {
16915
17000
  // next()
16916
17001
  next({
@@ -16922,18 +17007,18 @@ function installAuth(options) {
16922
17007
  next();
16923
17008
  }
16924
17009
  options.singleLoginCallback && options.singleLoginCallback(singleLoginRes);
16925
- _context4.next = 9;
17010
+ _context5.next = 9;
16926
17011
  break;
16927
17012
  case 8:
16928
17013
  next();
16929
17014
  case 9:
16930
17015
  case "end":
16931
- return _context4.stop();
17016
+ return _context5.stop();
16932
17017
  }
16933
- }, _callee4);
17018
+ }, _callee5);
16934
17019
  }));
16935
17020
  return function (_x4, _x5, _x6) {
16936
- return _ref4.apply(this, arguments);
17021
+ return _ref5.apply(this, arguments);
16937
17022
  };
16938
17023
  }());
16939
17024
  } else {
@@ -70312,6 +70397,7 @@ var getDefaultGlobalOptions = function getDefaultGlobalOptions() {
70312
70397
  modulekey: arr[1] || '',
70313
70398
  moduleversion: arr[2] || '',
70314
70399
  storageproxyprefix: '',
70400
+ isfixapptokenexpired: false,
70315
70401
  singleLoginCallback: null,
70316
70402
  router: null
70317
70403
  };
@@ -70356,4 +70442,4 @@ var SPUWebPlugin = {
70356
70442
  version: version
70357
70443
  };
70358
70444
 
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 };
70445
+ 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, setRefreshToken, setTitle, setToken, setTokenExpires, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart100/spu-web-plugin",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "dev": "npm run build:types && rollup -c -w",
package/src/core.js CHANGED
@@ -40,7 +40,11 @@ class Core {
40
40
  const nowEnvname = await getEnvname()
41
41
  const nowTenantCode = getUser('tenantcode') || ''
42
42
  // console.log(tenantCode)
43
- if (this.cache.envName === nowEnvname && this.cache.tenantCode === nowTenantCode && this.loadStatus === 2) {
43
+ if (
44
+ this.cache.envName === nowEnvname &&
45
+ this.cache.tenantCode === nowTenantCode &&
46
+ this.loadStatus === 2
47
+ ) {
44
48
  return this.cache
45
49
  }
46
50
 
@@ -332,7 +336,9 @@ class Core {
332
336
  if (!indextag) {
333
337
  errorMsg = '缺少 indextag,请检查。'
334
338
  } else {
335
- indextagData = (moduleData.data.protocol.indexs || []).find((item) => item.indextag === indextag)
339
+ indextagData = (moduleData.data.protocol.indexs || []).find(
340
+ (item) => item.indextag === indextag
341
+ )
336
342
  if (indextagData) {
337
343
  const queryUrl = this.getQueryUrl(indextagData.query || [], queryvalue)
338
344
  const context = await this.getContext(modulekey)
@@ -348,9 +354,13 @@ class Core {
348
354
  }
349
355
 
350
356
  if (url.indexOf('?') === -1) {
351
- url += `?${queryUrl}indextag=${indextag}&context=${encodeURIComponent(JSON.stringify(context))}`
357
+ url += `?${queryUrl}indextag=${indextag}&context=${encodeURIComponent(
358
+ JSON.stringify(context)
359
+ )}`
352
360
  } else {
353
- url += `&${queryUrl}indextag=${indextag}&context=${encodeURIComponent(JSON.stringify(context))}`
361
+ url += `&${queryUrl}indextag=${indextag}&context=${encodeURIComponent(
362
+ JSON.stringify(context)
363
+ )}`
354
364
  }
355
365
  } else {
356
366
  errorMsg = `找不到 indextag = ${indextag} 的页面信息。`
@@ -405,6 +415,10 @@ class Core {
405
415
  return ''
406
416
  }
407
417
  }
418
+
419
+ checkInAppSpuWebview() {
420
+ return !!window?.aPaaS?.getPhoto
421
+ }
408
422
  }
409
423
 
410
424
  const core = new Core()
package/src/index.ts CHANGED
@@ -23,10 +23,13 @@ import { mapService } from './map/MapService'
23
23
  import AMapLoader from './map/AMapLoader'
24
24
  import {
25
25
  getToken,
26
- checkLogin,
27
- getUser,
26
+ setToken,
28
27
  getRefreshToken,
28
+ setRefreshToken,
29
29
  getTokenExpires,
30
+ setTokenExpires,
31
+ checkLogin,
32
+ getUser,
30
33
  updateToken,
31
34
  singleLogin,
32
35
  installAuth
@@ -53,6 +56,7 @@ const getDefaultGlobalOptions = () => {
53
56
  modulekey: arr[1] || '',
54
57
  moduleversion: arr[2] || '',
55
58
  storageproxyprefix: '',
59
+ isfixapptokenexpired: false, // 是否修复apptoken过期问题 目前版本暂时不默认修复 等门户引擎验证通过之后 再改成默认修复
56
60
  singleLoginCallback: null,
57
61
  router: null
58
62
  }
@@ -134,6 +138,9 @@ export {
134
138
  getToken,
135
139
  getTokenExpires,
136
140
  getRefreshToken,
141
+ setToken,
142
+ setTokenExpires,
143
+ setRefreshToken,
137
144
  getUser,
138
145
  checkLogin,
139
146
  Module,
package/src/login.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  removeTecode
18
18
  } from './envService'
19
19
  import { tenantSetting } from './tenantSetting'
20
+ import { globalOptions } from './index'
20
21
 
21
22
  type JwtResult = {
22
23
  LoginUser: IAny
@@ -454,16 +455,14 @@ function startRefreshtoken() {
454
455
  // 获取 spu 容器 token
455
456
  const getSPUContainerToken = (): Promise<any> => {
456
457
  return new Promise((resolve, reject) => {
457
- if (window.aPaaS?.getToken) {
458
+ // 在spuwebview中
459
+ if (core.checkInAppSpuWebview() && window.aPaaS?.getToken) {
460
+ console.log('in App spuwebview')
458
461
  window.aPaaS.getToken((res: any) => {
459
462
  console.log('window.aPaaS.getToken success', res)
460
- // 安卓返回 token tokenExpires refreshToken
461
- // ios返回 token tokenexpires refreshtoken
462
- // 改好按安卓
463
-
464
463
  const token = res?.token
465
- const tokenexpires = res?.tokenExpires || res?.tokenexpires
466
- const refreshtoken = res?.refreshToken || res?.refreshtoken
464
+ const tokenexpires = res?.tokenExpires
465
+ const refreshtoken = res?.refreshToken
467
466
 
468
467
  if (token && tokenexpires && refreshtoken) {
469
468
  resolve({
@@ -476,6 +475,50 @@ const getSPUContainerToken = (): Promise<any> => {
476
475
  resolve(null)
477
476
  }
478
477
  })
478
+ } else if (window.aPaaS?.getToken && globalOptions.modulekey === 'portalEngine') {
479
+ console.log('in App interactivewebview')
480
+ // 兼容门户引擎在 interactivewebview 的情况
481
+ const u = navigator.userAgent
482
+ const isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
483
+ if (isAndroid) {
484
+ console.log('in Android, use window.aPaaS.getToken and window.getTokenComplete')
485
+ window.getTokenComplete = (res: any) => {
486
+ console.log('window.getTokenComplete success', res)
487
+ const token = res?.token
488
+ const tokenexpires = res?.tokenExpires
489
+ const refreshtoken = res?.refreshToken
490
+ if (token && tokenexpires && refreshtoken) {
491
+ resolve({
492
+ token,
493
+ tokenexpires,
494
+ refreshtoken
495
+ })
496
+ } else {
497
+ console.error('window.getTokenComplete fail')
498
+ resolve(null)
499
+ }
500
+ }
501
+ window.aPaaS.getToken(window.getTokenComplete)
502
+ } else {
503
+ console.log('in IOS, use window.aPaaS.getToken')
504
+ window.aPaaS.getToken((res: any) => {
505
+ console.log('window.aPaaS.getToken success', res)
506
+ const token = res?.token
507
+ const tokenexpires = res?.tokenExpires
508
+ const refreshtoken = res?.refreshToken
509
+
510
+ if (token && tokenexpires && refreshtoken) {
511
+ resolve({
512
+ token,
513
+ tokenexpires,
514
+ refreshtoken
515
+ })
516
+ } else {
517
+ console.error('window.aPaaS.getToken fail')
518
+ resolve(null)
519
+ }
520
+ })
521
+ }
479
522
  } else {
480
523
  console.warn('window.aPaaS.getToken fail: not in SPU container')
481
524
  resolve(null)
@@ -490,50 +533,79 @@ const getSPUContainerToken = (): Promise<any> => {
490
533
  // 因此 在APP端 单点登录不使用url上的token 而是直接拿App端的 App端能保证拿到的token一直不过期
491
534
  const fixLoginQuery = async (query: IAny) => {
492
535
  const newQuery = cloneDeep(query)
493
- const type = await Module.getSpuContainerType()
494
- if (type === 'app' && window.aPaaS?.getToken) {
495
- console.log('SPU is in App, singleLogin use App token.')
536
+ if (!window.aPaaS?.getToken) {
537
+ console.log('SPU is not in App, singleLogin use query token.')
538
+ } else {
539
+ if (core.checkInAppSpuWebview()) {
540
+ console.log('SPU is in App spuwebview, singleLogin use App token.')
541
+ } else if (globalOptions.modulekey === 'portalEngine') {
542
+ // 兼容门户引擎在 interactivewebview 的情况
543
+ console.log('SPU is in App interactivewebview, singleLogin use App token.')
544
+ }
496
545
  const tokenData = await getSPUContainerToken()
497
546
  if (tokenData) {
498
547
  newQuery.token = tokenData.token
499
548
  newQuery.tokenexpires = tokenData.tokenexpires
500
549
  newQuery.refreshtoken = tokenData.refreshtoken
501
550
  }
502
- } else {
503
- console.log('SPU is not in App, singleLogin use query token.')
504
551
  }
552
+
505
553
  return newQuery
506
554
  }
507
555
 
556
+ const checkTokenExpiredAndUpdate = async () => {
557
+ const loginState = getLoginState()
558
+ if (!loginState.islogin && loginState.type === 2 && loginState.role !== 'center') {
559
+ const tokenData = await getSPUContainerToken()
560
+ if (tokenData) {
561
+ setToken(tokenData.token)
562
+ setRefreshToken(tokenData.refreshtoken)
563
+ setTokenExpires(tokenData.tokenexpires)
564
+ } else {
565
+ try {
566
+ await updateToken()
567
+ } catch (err) {
568
+ console.error(err)
569
+ }
570
+ }
571
+ }
572
+ }
573
+
508
574
  // 修复 App 切到后台时间过长导致 token 过期
509
575
  // 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
510
- const fixAppTokenExpired = () => {
511
- if (window.Native?.onHostEnterForceground) {
512
- console.log('listen App enter forceground')
513
- window.Native.onHostEnterForceground(async () => {
576
+ const fixAppTokenExpired = async () => {
577
+ if (
578
+ globalOptions.isfixapptokenexpired &&
579
+ core.checkInAppSpuWebview() &&
580
+ window.Native?.onHostEnterForceground
581
+ ) {
582
+ console.log('SPU is in App spuwebview, listen App enter forceground.')
583
+ window.Native.onHostEnterForceground(() => {
514
584
  console.log('App enter forceground')
515
- const loginState = getLoginState()
516
- if (!loginState.islogin && loginState.type === 2 && loginState.role !== 'center') {
517
- const tokenData = await getSPUContainerToken()
518
- if (tokenData) {
519
- setToken(tokenData.token)
520
- setRefreshToken(tokenData.refreshtoken)
521
- setTokenExpires(tokenData.tokenexpires)
522
- } else {
523
- try {
524
- await updateToken()
525
- } catch (err) {
526
- console.error(err)
527
- }
528
- }
529
- }
585
+ checkTokenExpiredAndUpdate()
530
586
  })
587
+ } else if (
588
+ globalOptions.isfixapptokenexpired &&
589
+ globalOptions.modulekey === 'portalEngine' &&
590
+ window.aPaaS?.getToken
591
+ ) {
592
+ console.log('SPU is in App interactivewebview, listen App enter forceground.')
593
+ setTimeout(() => {
594
+ window.Native = window.Native || {}
595
+ window.Native.onHostEnterForceground = () => {
596
+ console.log('App enter forceground')
597
+ checkTokenExpiredAndUpdate()
598
+ }
599
+ }, 1000)
531
600
  }
532
601
  }
533
602
 
534
603
  // 单点登录
535
604
  async function singleLogin(query: IAny) {
536
- query = await fixLoginQuery(query)
605
+ query = cloneDeep(query)
606
+ if (globalOptions.isfixapptokenexpired) {
607
+ query = await fixLoginQuery(query)
608
+ }
537
609
 
538
610
  let flag = false // 是否登录成功
539
611
  const token = query.token
@@ -658,7 +730,9 @@ async function singleLogin(query: IAny) {
658
730
 
659
731
  function installAuth(options: any) {
660
732
  startRefreshtoken()
733
+
661
734
  fixAppTokenExpired()
735
+
662
736
  if (options.router) {
663
737
  options.router.beforeEach(async (to: any, from: any, next: any) => {
664
738
  // console.log(from)
@@ -698,13 +772,13 @@ function installAuth(options: any) {
698
772
  export {
699
773
  installAuth,
700
774
  getToken,
701
- // setToken,
775
+ setToken,
702
776
  // removeToken,
703
777
  getTokenExpires,
704
- // setTokenExpires,
778
+ setTokenExpires,
705
779
  // removeTokenExpires,
706
780
  getRefreshToken,
707
- // setRefreshToken,
781
+ setRefreshToken,
708
782
  // removeRefreshToken,
709
783
  updateToken,
710
784
  // startRefreshtoken,
@@ -80,6 +80,7 @@ interface IUploadService {
80
80
  // modulename: string
81
81
  // moduleversion: string
82
82
  // storageproxyprefix?: string
83
+ // isfixapptokenexpired?: boolean
83
84
  // router?: any
84
85
  // }
85
86
 
@@ -104,7 +105,11 @@ export const getLocation: (isuseiplocation?: boolean) => Promise<{
104
105
  [propName: string]: any
105
106
  } | null>
106
107
  export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
107
- export const getAddress: (location: { longitude: string; latitude: string; [propName: string]: any }) => Promise<string>
108
+ export const getAddress: (location: {
109
+ longitude: string
110
+ latitude: string
111
+ [propName: string]: any
112
+ }) => Promise<string>
108
113
  export const spuAxios: any
109
114
  export const apaasAxios: any
110
115
  export const axios: any
@@ -132,6 +137,9 @@ export const updateToken: () => Promise<void>
132
137
  export const getToken: () => string
133
138
  export const getTokenExpires: () => string
134
139
  export const getRefreshToken: () => string
140
+ export const setToken: (value: string) => void
141
+ export const setTokenExpires: (value: string) => void
142
+ export const setRefreshToken: (value: string) => void
135
143
  export const getUser: (key?: string) => any
136
144
  export const checkLogin: () => boolean
137
145
  export const Module: any
@@ -35,6 +35,8 @@ interface Window {
35
35
  __baiduMapInitial: any
36
36
  // 腾讯地图
37
37
  TMap: any
38
+ // InteractiveWebView 中 getToken 回调函数
39
+ getTokenComplete: any
38
40
  // wx: IAny;
39
41
  // AMapUI: IAny;
40
42
  // lsProxy: any;