修改退出登录没带TOKEn
Publish to npm / publish (push) Failing after 14s
Publish to npm / publish (push) Failing after 14s
This commit is contained in:
+20
-16
@@ -28,6 +28,7 @@ export type {
|
||||
|
||||
declare const SimApiVersion: string;
|
||||
declare const AppVersion: string;
|
||||
|
||||
// ── Helper: Fetch with Timeout ────────────────────────────────────────
|
||||
|
||||
function fetchWithTimeout(
|
||||
@@ -85,15 +86,17 @@ export class SimApiCore {
|
||||
}
|
||||
|
||||
api: SimApiApiConfig = {
|
||||
endpoints: { default: '' },
|
||||
endpoints: {default: ''},
|
||||
defaultEndpoint: 'default',
|
||||
businessCallback: {
|
||||
401: () => localStorage.removeItem(this.auth.token_name),
|
||||
common: () => {},
|
||||
common: () => {
|
||||
},
|
||||
},
|
||||
responseCallback: {
|
||||
success: (response: any) => response,
|
||||
error: (_err: any) => {},
|
||||
error: (_err: any) => {
|
||||
},
|
||||
},
|
||||
timeout: 10000,
|
||||
}
|
||||
@@ -118,7 +121,7 @@ export class SimApiCore {
|
||||
this.debug = config.debug
|
||||
}
|
||||
if (config.endpoints) {
|
||||
this.api.endpoints = { ...this.api.endpoints, ...config.endpoints }
|
||||
this.api.endpoints = {...this.api.endpoints, ...config.endpoints}
|
||||
}
|
||||
if (config.defaultEndpoint) {
|
||||
this.api.defaultEndpoint = config.defaultEndpoint
|
||||
@@ -130,21 +133,21 @@ export class SimApiCore {
|
||||
this.debug = options.debug
|
||||
}
|
||||
if (options.auth) {
|
||||
this.auth = { ...this.auth, ...options.auth }
|
||||
this.auth = {...this.auth, ...options.auth}
|
||||
}
|
||||
if (options.api) {
|
||||
this.api = {
|
||||
...this.api,
|
||||
...options.api,
|
||||
endpoints: { ...this.api.endpoints, ...(options.api.endpoints ?? {}) },
|
||||
businessCallback: { ...this.api.businessCallback, ...(options.api.businessCallback ?? {}) },
|
||||
responseCallback: { ...this.api.responseCallback, ...(options.api.responseCallback ?? {}) },
|
||||
endpoints: {...this.api.endpoints, ...(options.api.endpoints ?? {})},
|
||||
businessCallback: {...this.api.businessCallback, ...(options.api.businessCallback ?? {})},
|
||||
responseCallback: {...this.api.responseCallback, ...(options.api.responseCallback ?? {})},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setEndpoints(endpoints: { [name: string]: string }): void {
|
||||
this.api.endpoints = { ...this.api.endpoints, ...endpoints }
|
||||
this.api.endpoints = {...this.api.endpoints, ...endpoints}
|
||||
}
|
||||
|
||||
getEndpoint(name?: string): string {
|
||||
@@ -215,10 +218,10 @@ export class SimApiCore {
|
||||
const resp = await this.query<any>('/versions', {}, endpointName)
|
||||
if (resp?.data) {
|
||||
const d = resp.data
|
||||
versions.apiApp= d.App?.split('+')[0] ?? '0.0.0';
|
||||
versions.apiSimApi= d.SimApi?.split('+')[0] ?? '0.0.0';
|
||||
versions.apiAppFull= d.App ?? '0.0.0';
|
||||
versions.apiSimApiFull= d.SimApi ?? '0.0.0';
|
||||
versions.apiApp = d.App?.split('+')[0] ?? '0.0.0';
|
||||
versions.apiSimApi = d.SimApi?.split('+')[0] ?? '0.0.0';
|
||||
versions.apiAppFull = d.App ?? '0.0.0';
|
||||
versions.apiSimApiFull = d.SimApi ?? '0.0.0';
|
||||
if (this.debug) {
|
||||
console.log(`UI主应用版本: ${versions.uiApp}\nUISimApi版本: ${versions.uiSimApi}\nAPI主应用版本: ${versions.apiApp}\nAPISimApi版本: ${versions.apiSimApi}`)
|
||||
}
|
||||
@@ -236,7 +239,7 @@ export class SimApiCore {
|
||||
endpointKey?: string,
|
||||
extraHeaders?: Record<string, string>
|
||||
): Promise<SimApiBaseResponse<T>> {
|
||||
const headers: Record<string, string> = { ...extraHeaders, ...{} }
|
||||
const headers: Record<string, string> = {...extraHeaders, ...{}}
|
||||
const queryId = this.genS4()
|
||||
|
||||
if (!(params instanceof FormData)) {
|
||||
@@ -307,16 +310,17 @@ export class SimApiCore {
|
||||
}
|
||||
|
||||
async logout(url?: string | null): Promise<any> {
|
||||
this.removeToken()
|
||||
if (url !== null) {
|
||||
return this.query(url ?? this.auth.logout_url).catch(() => true)
|
||||
}
|
||||
this.removeToken()
|
||||
return true
|
||||
}
|
||||
|
||||
async checkLogin(url?: string | null): Promise<void> {
|
||||
if (url !== null) {
|
||||
await this.query(url ?? this.auth.check_url).catch(() => {})
|
||||
await this.query(url ?? this.auth.check_url).catch(() => {
|
||||
})
|
||||
} else if (this.getToken()) {
|
||||
this.api.businessCallback[401]?.(null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user