Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1597c98f39 | ||
|
|
7dbb48ad90 |
+16
-4
@@ -83,6 +83,7 @@ export class SimApiCore {
|
|||||||
check_url: '/user/info',
|
check_url: '/user/info',
|
||||||
logout_url: '/auth/logout',
|
logout_url: '/auth/logout',
|
||||||
login_url: '/auth/login',
|
login_url: '/auth/login',
|
||||||
|
tokenStore: "localstorage"
|
||||||
}
|
}
|
||||||
private webConfig: Map<string, Record<string, object>> = new Map();
|
private webConfig: Map<string, Record<string, object>> = new Map();
|
||||||
|
|
||||||
@@ -99,7 +100,7 @@ export class SimApiCore {
|
|||||||
error: (_err: any) => {
|
error: (_err: any) => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
timeout: 10000,
|
timeout: 10000
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(options?: SimApiOptions) {
|
constructor(options?: SimApiOptions) {
|
||||||
@@ -179,20 +180,31 @@ export class SimApiCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getToken(): string {
|
getToken(): string {
|
||||||
|
if (this.auth.tokenStore === 'localstorage') {
|
||||||
|
return localStorage.getItem(this.auth.token_name) ?? ''
|
||||||
|
}
|
||||||
const name = this.auth.token_name
|
const name = this.auth.token_name
|
||||||
const match = document.cookie.match(new RegExp(`(?:^|;)\\s?${name}=([^;]+)`))
|
const match = document.cookie.match(new RegExp(`(?:^|;)\\s?${name}=([^;]+)`))
|
||||||
return match ? match[1] : ''
|
return match ? match[1] : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
setToken(token: string): void {
|
setToken(token: string): void {
|
||||||
|
if (this.auth.tokenStore === 'localstorage') {
|
||||||
|
localStorage.setItem(this.auth.token_name, token)
|
||||||
|
} else {
|
||||||
const name = this.auth.token_name
|
const name = this.auth.token_name
|
||||||
document.cookie = `${name}=${token}; path=/; max-age=315360000; secure; samesite=none`
|
document.cookie = `${name}=${token}; path=/; max-age=315360000; secure; samesite=none`
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
removeToken(): void {
|
removeToken(): void {
|
||||||
|
if (this.auth.tokenStore === 'localstorage') {
|
||||||
|
localStorage.removeItem(this.auth.token_name)
|
||||||
|
} else {
|
||||||
const name = this.auth.token_name
|
const name = this.auth.token_name
|
||||||
document.cookie = `${name}=; path=/; max-age=0; secure; samesite=none`
|
document.cookie = `${name}=; path=/; max-age=0; secure; samesite=none`
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
genS4(): string {
|
genS4(): string {
|
||||||
@@ -233,9 +245,9 @@ export class SimApiCore {
|
|||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log(`UI主应用版本: ${versions.uiApp}\nUISimApi版本: ${versions.uiSimApi}\nAPI主应用版本: ${versions.apiApp}\nAPISimApi版本: ${versions.apiSimApi}`)
|
console.log(`UI主应用版本: ${versions.uiApp}\nUISimApi版本: ${versions.uiSimApi}\nAPI主应用版本: ${versions.apiApp}\nAPISimApi版本: ${versions.apiSimApi}`)
|
||||||
}
|
}
|
||||||
resp.data.Versions = versions;
|
const conf = JSON.parse(JSON.stringify(resp.data));
|
||||||
this.webConfig.set(endpointName, resp.data);
|
conf.Versions = versions;
|
||||||
|
this.webConfig.set(endpointName, conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.webConfig.get(endpointName)!;
|
return this.webConfig.get(endpointName)!;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ export interface SimApiAuthConfig {
|
|||||||
logout_url: string
|
logout_url: string
|
||||||
/** 登录接口,默认 '/auth/login' */
|
/** 登录接口,默认 '/auth/login' */
|
||||||
login_url: string
|
login_url: string
|
||||||
|
/** Token 存储位置 */
|
||||||
|
tokenStore: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 业务错误码回调 */
|
/** 业务错误码回调 */
|
||||||
|
|||||||
Reference in New Issue
Block a user