@smart100/spu-web-plugin 1.0.18 → 1.0.19
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 +6 -1
- package/dist/spu-web-plugin.mjs +55 -51
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/login.ts +10 -8
- package/src/types/index.d.ts +6 -1
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: {
|
|
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
|
package/dist/spu-web-plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "1.0.
|
|
1
|
+
var version = "1.0.19";
|
|
2
2
|
|
|
3
3
|
/** Detect free variable `global` from Node.js. */
|
|
4
4
|
var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
|
|
@@ -16603,12 +16603,9 @@ var getSPUContainerToken = function getSPUContainerToken() {
|
|
|
16603
16603
|
if ((_window$aPaaS = window.aPaaS) !== null && _window$aPaaS !== void 0 && _window$aPaaS.getToken) {
|
|
16604
16604
|
window.aPaaS.getToken(function (res) {
|
|
16605
16605
|
console.log('window.aPaaS.getToken success', res);
|
|
16606
|
-
// 安卓返回 token tokenExpires refreshToken
|
|
16607
|
-
// ios返回 token tokenexpires refreshtoken
|
|
16608
|
-
// 改好按安卓
|
|
16609
16606
|
var token = res === null || res === void 0 ? void 0 : res.token;
|
|
16610
|
-
var tokenexpires =
|
|
16611
|
-
var refreshtoken =
|
|
16607
|
+
var tokenexpires = res === null || res === void 0 ? void 0 : res.tokenExpires;
|
|
16608
|
+
var refreshtoken = res === null || res === void 0 ? void 0 : res.refreshToken;
|
|
16612
16609
|
if (token && tokenexpires && refreshtoken) {
|
|
16613
16610
|
resolve({
|
|
16614
16611
|
token: token,
|
|
@@ -16677,7 +16674,7 @@ var fixLoginQuery = /*#__PURE__*/function () {
|
|
|
16677
16674
|
// 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
|
|
16678
16675
|
var fixAppTokenExpired = function fixAppTokenExpired() {
|
|
16679
16676
|
var _window$Native;
|
|
16680
|
-
if ((_window$Native = window.Native) !== null && _window$Native !== void 0 && _window$Native.onHostEnterForceground) {
|
|
16677
|
+
if (globalOptions.isfixapptokenexpired && (_window$Native = window.Native) !== null && _window$Native !== void 0 && _window$Native.onHostEnterForceground) {
|
|
16681
16678
|
console.log('listen App enter forceground');
|
|
16682
16679
|
window.Native.onHostEnterForceground( /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3() {
|
|
16683
16680
|
var loginState, tokenData;
|
|
@@ -16742,10 +16739,16 @@ function _singleLogin() {
|
|
|
16742
16739
|
// web 端有传 app没传 需要做兼容
|
|
16743
16740
|
context && lsProxy.setItem('context', decodeURIComponent(context));
|
|
16744
16741
|
};
|
|
16745
|
-
|
|
16742
|
+
query = cloneDeep$1(query);
|
|
16743
|
+
if (!globalOptions.isfixapptokenexpired) {
|
|
16744
|
+
_context7.next = 6;
|
|
16745
|
+
break;
|
|
16746
|
+
}
|
|
16747
|
+
_context7.next = 5;
|
|
16746
16748
|
return fixLoginQuery(query);
|
|
16747
|
-
case
|
|
16749
|
+
case 5:
|
|
16748
16750
|
query = _context7.sent;
|
|
16751
|
+
case 6:
|
|
16749
16752
|
flag = false; // 是否登录成功
|
|
16750
16753
|
token = query.token;
|
|
16751
16754
|
refreshtoken = query.refreshtoken;
|
|
@@ -16753,7 +16756,7 @@ function _singleLogin() {
|
|
|
16753
16756
|
envname = query.envname;
|
|
16754
16757
|
context = query.context;
|
|
16755
16758
|
if (!checkLoginByToken(token)) {
|
|
16756
|
-
_context7.next =
|
|
16759
|
+
_context7.next = 64;
|
|
16757
16760
|
break;
|
|
16758
16761
|
}
|
|
16759
16762
|
isneedlogin = true; // 是否需要走单点登录流程
|
|
@@ -16775,104 +16778,104 @@ function _singleLogin() {
|
|
|
16775
16778
|
// isneedlogin = true
|
|
16776
16779
|
// debugger
|
|
16777
16780
|
if (!isneedlogin) {
|
|
16778
|
-
_context7.next =
|
|
16781
|
+
_context7.next = 62;
|
|
16779
16782
|
break;
|
|
16780
16783
|
}
|
|
16781
16784
|
setBaseInfo();
|
|
16782
16785
|
// 单点登录写入 token 之后
|
|
16783
16786
|
// 1、如果 refreshtoken 不完整 则换取完整的 refreshtoken
|
|
16784
|
-
_context7.prev =
|
|
16787
|
+
_context7.prev = 18;
|
|
16785
16788
|
if (!checkLogin()) {
|
|
16786
|
-
_context7.next =
|
|
16789
|
+
_context7.next = 25;
|
|
16787
16790
|
break;
|
|
16788
16791
|
}
|
|
16789
16792
|
refreshTokenUser = getUserByToken(getRefreshToken());
|
|
16790
16793
|
tokenUser = getUserByToken(getToken());
|
|
16791
16794
|
if (!(!(refreshTokenUser !== null && refreshTokenUser !== void 0 && refreshTokenUser.tokenId) && tokenUser !== null && tokenUser !== void 0 && tokenUser.tokenId)) {
|
|
16792
|
-
_context7.next =
|
|
16795
|
+
_context7.next = 25;
|
|
16793
16796
|
break;
|
|
16794
16797
|
}
|
|
16795
|
-
_context7.next =
|
|
16798
|
+
_context7.next = 25;
|
|
16796
16799
|
return updateToken();
|
|
16797
|
-
case 23:
|
|
16798
|
-
_context7.next = 28;
|
|
16799
|
-
break;
|
|
16800
16800
|
case 25:
|
|
16801
|
-
_context7.
|
|
16802
|
-
|
|
16801
|
+
_context7.next = 30;
|
|
16802
|
+
break;
|
|
16803
|
+
case 27:
|
|
16804
|
+
_context7.prev = 27;
|
|
16805
|
+
_context7.t0 = _context7["catch"](18);
|
|
16803
16806
|
console.error(_context7.t0);
|
|
16804
|
-
case
|
|
16807
|
+
case 30:
|
|
16805
16808
|
// 2、重新计算刷新 token 时间 因为刚开始进入就 startRefreshtoken 检测到没有 token 会过10秒才执行刷新 token 操作
|
|
16806
16809
|
startRefreshtoken();
|
|
16807
16810
|
// 获取环境信息和租户配置信息
|
|
16808
|
-
_context7.next =
|
|
16811
|
+
_context7.next = 33;
|
|
16809
16812
|
return getEnvname();
|
|
16810
|
-
case
|
|
16813
|
+
case 33:
|
|
16811
16814
|
nowEnvname = _context7.sent;
|
|
16812
16815
|
if (!nowEnvname) {
|
|
16813
|
-
_context7.next =
|
|
16816
|
+
_context7.next = 54;
|
|
16814
16817
|
break;
|
|
16815
16818
|
}
|
|
16816
|
-
_context7.next =
|
|
16819
|
+
_context7.next = 37;
|
|
16817
16820
|
return requestEnvdata(nowEnvname);
|
|
16818
|
-
case
|
|
16821
|
+
case 37:
|
|
16819
16822
|
envData = _context7.sent;
|
|
16820
16823
|
if (!envData) {
|
|
16821
|
-
_context7.next =
|
|
16824
|
+
_context7.next = 50;
|
|
16822
16825
|
break;
|
|
16823
16826
|
}
|
|
16824
16827
|
saveEnvdata(envData);
|
|
16825
16828
|
if (!envData.tenantcode) {
|
|
16826
|
-
_context7.next =
|
|
16829
|
+
_context7.next = 46;
|
|
16827
16830
|
break;
|
|
16828
16831
|
}
|
|
16829
16832
|
setTecode(envData.tenantcode);
|
|
16830
16833
|
// 租户配置
|
|
16831
|
-
_context7.next =
|
|
16834
|
+
_context7.next = 44;
|
|
16832
16835
|
return tenantSetting.requestAndSetTenantSetting(envData.tenantcode);
|
|
16833
|
-
case 42:
|
|
16834
|
-
_context7.next = 46;
|
|
16835
|
-
break;
|
|
16836
16836
|
case 44:
|
|
16837
|
+
_context7.next = 48;
|
|
16838
|
+
break;
|
|
16839
|
+
case 46:
|
|
16837
16840
|
tenantSetting.removeTenantSetting();
|
|
16838
16841
|
removeTecode();
|
|
16839
|
-
case 46:
|
|
16840
|
-
_context7.next = 50;
|
|
16841
|
-
break;
|
|
16842
16842
|
case 48:
|
|
16843
|
+
_context7.next = 52;
|
|
16844
|
+
break;
|
|
16845
|
+
case 50:
|
|
16843
16846
|
removeEnvdata();
|
|
16844
16847
|
removeTecode();
|
|
16845
|
-
case 50:
|
|
16846
|
-
_context7.next = 54;
|
|
16847
|
-
break;
|
|
16848
16848
|
case 52:
|
|
16849
|
+
_context7.next = 56;
|
|
16850
|
+
break;
|
|
16851
|
+
case 54:
|
|
16849
16852
|
removeEnvdata();
|
|
16850
16853
|
removeTecode();
|
|
16851
|
-
case 54:
|
|
16852
|
-
_context7.next = 56;
|
|
16853
|
-
return getAndSetTenant();
|
|
16854
16854
|
case 56:
|
|
16855
16855
|
_context7.next = 58;
|
|
16856
|
-
return
|
|
16856
|
+
return getAndSetTenant();
|
|
16857
16857
|
case 58:
|
|
16858
|
+
_context7.next = 60;
|
|
16859
|
+
return getAndSetUserInfo();
|
|
16860
|
+
case 60:
|
|
16858
16861
|
// 单点登录后 获取 web 开发者模式 如果是则设置 isdebugger
|
|
16859
16862
|
urlquery.dealWebDebugger();
|
|
16860
16863
|
flag = true;
|
|
16861
|
-
case 60:
|
|
16862
|
-
_context7.next = 65;
|
|
16863
|
-
break;
|
|
16864
16864
|
case 62:
|
|
16865
|
+
_context7.next = 67;
|
|
16866
|
+
break;
|
|
16867
|
+
case 64:
|
|
16865
16868
|
flag = false;
|
|
16866
16869
|
setBaseInfo(); // 传递的token过期依然写入 如果不写入的话 有可能之前的token本来没过期 页面依然可用
|
|
16867
16870
|
console.error('单点登录失败,请检查链接所传 token/refreshtoken/tokenexpires 是否非法或过期。');
|
|
16868
|
-
case
|
|
16871
|
+
case 67:
|
|
16869
16872
|
if (!flag) {
|
|
16870
|
-
_context7.next =
|
|
16873
|
+
_context7.next = 70;
|
|
16871
16874
|
break;
|
|
16872
16875
|
}
|
|
16873
|
-
_context7.next =
|
|
16876
|
+
_context7.next = 70;
|
|
16874
16877
|
return core$1.initGetData();
|
|
16875
|
-
case
|
|
16878
|
+
case 70:
|
|
16876
16879
|
if (flag) {
|
|
16877
16880
|
// 单点登录成功 需要删除 query 中相关参数
|
|
16878
16881
|
token && delete query.token;
|
|
@@ -16885,11 +16888,11 @@ function _singleLogin() {
|
|
|
16885
16888
|
flag: flag,
|
|
16886
16889
|
query: query
|
|
16887
16890
|
});
|
|
16888
|
-
case
|
|
16891
|
+
case 72:
|
|
16889
16892
|
case "end":
|
|
16890
16893
|
return _context7.stop();
|
|
16891
16894
|
}
|
|
16892
|
-
}, _callee7, null, [[
|
|
16895
|
+
}, _callee7, null, [[18, 27]]);
|
|
16893
16896
|
}));
|
|
16894
16897
|
return _singleLogin.apply(this, arguments);
|
|
16895
16898
|
}
|
|
@@ -70312,6 +70315,7 @@ var getDefaultGlobalOptions = function getDefaultGlobalOptions() {
|
|
|
70312
70315
|
modulekey: arr[1] || '',
|
|
70313
70316
|
moduleversion: arr[2] || '',
|
|
70314
70317
|
storageproxyprefix: '',
|
|
70318
|
+
isfixapptokenexpired: false,
|
|
70315
70319
|
singleLoginCallback: null,
|
|
70316
70320
|
router: null
|
|
70317
70321
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
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
|
|
@@ -457,13 +458,9 @@ const getSPUContainerToken = (): Promise<any> => {
|
|
|
457
458
|
if (window.aPaaS?.getToken) {
|
|
458
459
|
window.aPaaS.getToken((res: any) => {
|
|
459
460
|
console.log('window.aPaaS.getToken success', res)
|
|
460
|
-
// 安卓返回 token tokenExpires refreshToken
|
|
461
|
-
// ios返回 token tokenexpires refreshtoken
|
|
462
|
-
// 改好按安卓
|
|
463
|
-
|
|
464
461
|
const token = res?.token
|
|
465
|
-
const tokenexpires = res?.tokenExpires
|
|
466
|
-
const refreshtoken = res?.refreshToken
|
|
462
|
+
const tokenexpires = res?.tokenExpires
|
|
463
|
+
const refreshtoken = res?.refreshToken
|
|
467
464
|
|
|
468
465
|
if (token && tokenexpires && refreshtoken) {
|
|
469
466
|
resolve({
|
|
@@ -508,7 +505,7 @@ const fixLoginQuery = async (query: IAny) => {
|
|
|
508
505
|
// 修复 App 切到后台时间过长导致 token 过期
|
|
509
506
|
// 监听 App 切换到前台 判断token是否过期 如果过期就调用获取tokne方法更新token
|
|
510
507
|
const fixAppTokenExpired = () => {
|
|
511
|
-
if (window.Native?.onHostEnterForceground) {
|
|
508
|
+
if (globalOptions.isfixapptokenexpired && window.Native?.onHostEnterForceground) {
|
|
512
509
|
console.log('listen App enter forceground')
|
|
513
510
|
window.Native.onHostEnterForceground(async () => {
|
|
514
511
|
console.log('App enter forceground')
|
|
@@ -533,7 +530,10 @@ const fixAppTokenExpired = () => {
|
|
|
533
530
|
|
|
534
531
|
// 单点登录
|
|
535
532
|
async function singleLogin(query: IAny) {
|
|
536
|
-
query =
|
|
533
|
+
query = cloneDeep(query)
|
|
534
|
+
if (globalOptions.isfixapptokenexpired) {
|
|
535
|
+
query = await fixLoginQuery(query)
|
|
536
|
+
}
|
|
537
537
|
|
|
538
538
|
let flag = false // 是否登录成功
|
|
539
539
|
const token = query.token
|
|
@@ -658,7 +658,9 @@ async function singleLogin(query: IAny) {
|
|
|
658
658
|
|
|
659
659
|
function installAuth(options: any) {
|
|
660
660
|
startRefreshtoken()
|
|
661
|
+
|
|
661
662
|
fixAppTokenExpired()
|
|
663
|
+
|
|
662
664
|
if (options.router) {
|
|
663
665
|
options.router.beforeEach(async (to: any, from: any, next: any) => {
|
|
664
666
|
// console.log(from)
|
package/src/types/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: {
|
|
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
|