@ibiz-template/runtime 0.4.9 → 0.4.10
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.esm.js +26 -3
- package/dist/index.system.min.js +2 -2
- package/out/interface/service/service/i-auth.service.d.ts +8 -0
- package/out/interface/service/service/i-auth.service.d.ts.map +1 -1
- package/out/service/service/auth/v7-auth.service.d.ts +1 -0
- package/out/service/service/auth/v7-auth.service.d.ts.map +1 -1
- package/out/service/service/auth/v7-auth.service.js +23 -3
- package/package.json +4 -4
- package/src/interface/service/service/i-auth.service.ts +9 -0
- package/src/service/service/auth/v7-auth.service.ts +30 -3
|
@@ -25,5 +25,13 @@ export interface IAuthService {
|
|
|
25
25
|
* @return {*} {Promise<boolean>}
|
|
26
26
|
*/
|
|
27
27
|
logout(): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* 页面未关闭情况下,自动延长登录时间
|
|
30
|
+
*
|
|
31
|
+
* @author chitanda
|
|
32
|
+
* @date 2023-12-11 11:12:54
|
|
33
|
+
* @return {*} {Promise<void>}
|
|
34
|
+
*/
|
|
35
|
+
extendLogin(): Promise<void>;
|
|
28
36
|
}
|
|
29
37
|
//# sourceMappingURL=i-auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"i-auth.service.d.ts","sourceRoot":"","sources":["../../../../src/interface/service/service/i-auth.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"i-auth.service.d.ts","sourceRoot":"","sources":["../../../../src/interface/service/service/i-auth.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3B;;;;;;OAMG;IACH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B"}
|
|
@@ -10,5 +10,6 @@ import { IAuthService } from '../../../interface';
|
|
|
10
10
|
export declare class V7AuthService implements IAuthService {
|
|
11
11
|
login(loginname: string, password: string, rememberme?: boolean): Promise<boolean>;
|
|
12
12
|
logout(): Promise<boolean>;
|
|
13
|
+
extendLogin(): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=v7-auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v7-auth.service.d.ts","sourceRoot":"","sources":["../../../../src/service/service/auth/v7-auth.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,qBAAa,aAAc,YAAW,YAAY;IAC1C,KAAK,CACT,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"v7-auth.service.d.ts","sourceRoot":"","sources":["../../../../src/service/service/auth/v7-auth.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;GAOG;AACH,qBAAa,aAAc,YAAW,YAAY;IAC1C,KAAK,CACT,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,OAAO,GACnB,OAAO,CAAC,OAAO,CAAC;IA8Bb,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAe1B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAqBnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoreConst } from '@ibiz-template/core';
|
|
2
|
-
import { clearCookie, setCookie } from 'qx-util';
|
|
2
|
+
import { clearCookie, getCookie, setCookie } from 'qx-util';
|
|
3
3
|
/**
|
|
4
4
|
* 认证服务
|
|
5
5
|
*
|
|
@@ -19,9 +19,9 @@ export class V7AuthService {
|
|
|
19
19
|
});
|
|
20
20
|
const { data } = res;
|
|
21
21
|
if (data && data.token) {
|
|
22
|
-
setCookie(CoreConst.TOKEN, data.token, 0, true);
|
|
22
|
+
setCookie(CoreConst.TOKEN, data.token, rememberme ? 7 : 0, true);
|
|
23
23
|
const expiredDate = new Date().getTime() + (data.expirein || 7199) * 1000;
|
|
24
|
-
setCookie(CoreConst.TOKEN_EXPIRES, `${expiredDate}`, 0, true);
|
|
24
|
+
setCookie(CoreConst.TOKEN_EXPIRES, `${expiredDate}`, rememberme ? 7 : 0, true);
|
|
25
25
|
}
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
@@ -48,4 +48,24 @@ export class V7AuthService {
|
|
|
48
48
|
}
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
+
async extendLogin() {
|
|
52
|
+
const token = getCookie(CoreConst.TOKEN);
|
|
53
|
+
const expirein = getCookie(CoreConst.TOKEN_EXPIRES);
|
|
54
|
+
if (token && expirein) {
|
|
55
|
+
// 计算到过期时间所需的延时毫秒数,预留提前量
|
|
56
|
+
let wait = Number(expirein) - new Date().getTime();
|
|
57
|
+
const early = 5 * 60 * 1000;
|
|
58
|
+
wait = wait > early ? wait - early : 0;
|
|
59
|
+
setTimeout(async () => {
|
|
60
|
+
const res = await ibiz.net.get(`/uaa/refreshtoken2`);
|
|
61
|
+
if (res.ok) {
|
|
62
|
+
setCookie(CoreConst.TOKEN, res.data.token, 0, true);
|
|
63
|
+
const expiredDate = new Date().getTime() + (res.data.expirein || 7199) * 1000;
|
|
64
|
+
setCookie(CoreConst.TOKEN_EXPIRES, `${expiredDate}`, 0, true);
|
|
65
|
+
}
|
|
66
|
+
// 下一次延时做准备
|
|
67
|
+
this.extendLogin();
|
|
68
|
+
}, wait);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
51
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiz-template/runtime",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"description": "控制器包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@ibiz-template/core": "^0.4.9",
|
|
33
|
-
"@ibiz/model-core": "^0.0.
|
|
33
|
+
"@ibiz/model-core": "^0.0.27",
|
|
34
34
|
"@types/path-browserify": "^1.0.2",
|
|
35
35
|
"@types/qs": "^6.9.10",
|
|
36
36
|
"@types/systemjs": "^6.13.5",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@ibiz-template/core": "^0.4.0",
|
|
50
|
-
"@ibiz/model-core": "^0.0.
|
|
50
|
+
"@ibiz/model-core": "^0.0.27",
|
|
51
51
|
"async-validator": "^4.2.5",
|
|
52
52
|
"dayjs": "^1.11.7",
|
|
53
53
|
"echarts": "^5.4.3",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"qx-util": "^0.4.8",
|
|
60
60
|
"ramda": "^0.29.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "88ed67d86d5cb1fe5d8e0683cef777f1c607611f"
|
|
63
63
|
}
|
|
@@ -30,4 +30,13 @@ export interface IAuthService {
|
|
|
30
30
|
* @return {*} {Promise<boolean>}
|
|
31
31
|
*/
|
|
32
32
|
logout(): Promise<boolean>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 页面未关闭情况下,自动延长登录时间
|
|
36
|
+
*
|
|
37
|
+
* @author chitanda
|
|
38
|
+
* @date 2023-12-11 11:12:54
|
|
39
|
+
* @return {*} {Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
extendLogin(): Promise<void>;
|
|
33
42
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CoreConst, HttpError } from '@ibiz-template/core';
|
|
2
|
-
import { clearCookie, setCookie } from 'qx-util';
|
|
2
|
+
import { clearCookie, getCookie, setCookie } from 'qx-util';
|
|
3
3
|
import { IAuthService } from '../../../interface';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -25,10 +25,15 @@ export class V7AuthService implements IAuthService {
|
|
|
25
25
|
});
|
|
26
26
|
const { data } = res;
|
|
27
27
|
if (data && data.token) {
|
|
28
|
-
setCookie(CoreConst.TOKEN, data.token, 0, true);
|
|
28
|
+
setCookie(CoreConst.TOKEN, data.token, rememberme ? 7 : 0, true);
|
|
29
29
|
const expiredDate =
|
|
30
30
|
new Date().getTime() + (data.expirein || 7199) * 1000;
|
|
31
|
-
setCookie(
|
|
31
|
+
setCookie(
|
|
32
|
+
CoreConst.TOKEN_EXPIRES,
|
|
33
|
+
`${expiredDate}`,
|
|
34
|
+
rememberme ? 7 : 0,
|
|
35
|
+
true,
|
|
36
|
+
);
|
|
32
37
|
}
|
|
33
38
|
return true;
|
|
34
39
|
} catch (err: unknown) {
|
|
@@ -54,4 +59,26 @@ export class V7AuthService implements IAuthService {
|
|
|
54
59
|
}
|
|
55
60
|
return false;
|
|
56
61
|
}
|
|
62
|
+
|
|
63
|
+
async extendLogin(): Promise<void> {
|
|
64
|
+
const token = getCookie(CoreConst.TOKEN);
|
|
65
|
+
const expirein = getCookie(CoreConst.TOKEN_EXPIRES);
|
|
66
|
+
if (token && expirein) {
|
|
67
|
+
// 计算到过期时间所需的延时毫秒数,预留提前量
|
|
68
|
+
let wait = Number(expirein) - new Date().getTime();
|
|
69
|
+
const early = 5 * 60 * 1000;
|
|
70
|
+
wait = wait > early ? wait - early : 0;
|
|
71
|
+
setTimeout(async () => {
|
|
72
|
+
const res = await ibiz.net.get(`/uaa/refreshtoken2`);
|
|
73
|
+
if (res.ok) {
|
|
74
|
+
setCookie(CoreConst.TOKEN, res.data.token, 0, true);
|
|
75
|
+
const expiredDate =
|
|
76
|
+
new Date().getTime() + (res.data.expirein || 7199) * 1000;
|
|
77
|
+
setCookie(CoreConst.TOKEN_EXPIRES, `${expiredDate}`, 0, true);
|
|
78
|
+
}
|
|
79
|
+
// 下一次延时做准备
|
|
80
|
+
this.extendLogin();
|
|
81
|
+
}, wait);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
57
84
|
}
|