修改退出登录没带TOKEn
Publish to npm / publish (push) Failing after 14s

This commit is contained in:
2026-05-03 23:11:55 +08:00
parent 88be4210aa
commit 13c836b4ab
+20 -16
View File
@@ -28,6 +28,7 @@ export type {
declare const SimApiVersion: string; declare const SimApiVersion: string;
declare const AppVersion: string; declare const AppVersion: string;
// ── Helper: Fetch with Timeout ──────────────────────────────────────── // ── Helper: Fetch with Timeout ────────────────────────────────────────
function fetchWithTimeout( function fetchWithTimeout(
@@ -85,15 +86,17 @@ export class SimApiCore {
} }
api: SimApiApiConfig = { api: SimApiApiConfig = {
endpoints: { default: '' }, endpoints: {default: ''},
defaultEndpoint: 'default', defaultEndpoint: 'default',
businessCallback: { businessCallback: {
401: () => localStorage.removeItem(this.auth.token_name), 401: () => localStorage.removeItem(this.auth.token_name),
common: () => {}, common: () => {
},
}, },
responseCallback: { responseCallback: {
success: (response: any) => response, success: (response: any) => response,
error: (_err: any) => {}, error: (_err: any) => {
},
}, },
timeout: 10000, timeout: 10000,
} }
@@ -118,7 +121,7 @@ export class SimApiCore {
this.debug = config.debug this.debug = config.debug
} }
if (config.endpoints) { if (config.endpoints) {
this.api.endpoints = { ...this.api.endpoints, ...config.endpoints } this.api.endpoints = {...this.api.endpoints, ...config.endpoints}
} }
if (config.defaultEndpoint) { if (config.defaultEndpoint) {
this.api.defaultEndpoint = config.defaultEndpoint this.api.defaultEndpoint = config.defaultEndpoint
@@ -130,21 +133,21 @@ export class SimApiCore {
this.debug = options.debug this.debug = options.debug
} }
if (options.auth) { if (options.auth) {
this.auth = { ...this.auth, ...options.auth } this.auth = {...this.auth, ...options.auth}
} }
if (options.api) { if (options.api) {
this.api = { this.api = {
...this.api, ...this.api,
...options.api, ...options.api,
endpoints: { ...this.api.endpoints, ...(options.api.endpoints ?? {}) }, endpoints: {...this.api.endpoints, ...(options.api.endpoints ?? {})},
businessCallback: { ...this.api.businessCallback, ...(options.api.businessCallback ?? {}) }, businessCallback: {...this.api.businessCallback, ...(options.api.businessCallback ?? {})},
responseCallback: { ...this.api.responseCallback, ...(options.api.responseCallback ?? {}) }, responseCallback: {...this.api.responseCallback, ...(options.api.responseCallback ?? {})},
} }
} }
} }
setEndpoints(endpoints: { [name: string]: string }): void { setEndpoints(endpoints: { [name: string]: string }): void {
this.api.endpoints = { ...this.api.endpoints, ...endpoints } this.api.endpoints = {...this.api.endpoints, ...endpoints}
} }
getEndpoint(name?: string): string { getEndpoint(name?: string): string {
@@ -215,10 +218,10 @@ export class SimApiCore {
const resp = await this.query<any>('/versions', {}, endpointName) const resp = await this.query<any>('/versions', {}, endpointName)
if (resp?.data) { if (resp?.data) {
const d = resp.data const d = resp.data
versions.apiApp= d.App?.split('+')[0] ?? '0.0.0'; versions.apiApp = d.App?.split('+')[0] ?? '0.0.0';
versions.apiSimApi= d.SimApi?.split('+')[0] ?? '0.0.0'; versions.apiSimApi = d.SimApi?.split('+')[0] ?? '0.0.0';
versions.apiAppFull= d.App ?? '0.0.0'; versions.apiAppFull = d.App ?? '0.0.0';
versions.apiSimApiFull= d.SimApi ?? '0.0.0'; versions.apiSimApiFull = d.SimApi ?? '0.0.0';
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}`)
} }
@@ -236,7 +239,7 @@ export class SimApiCore {
endpointKey?: string, endpointKey?: string,
extraHeaders?: Record<string, string> extraHeaders?: Record<string, string>
): Promise<SimApiBaseResponse<T>> { ): Promise<SimApiBaseResponse<T>> {
const headers: Record<string, string> = { ...extraHeaders, ...{} } const headers: Record<string, string> = {...extraHeaders, ...{}}
const queryId = this.genS4() const queryId = this.genS4()
if (!(params instanceof FormData)) { if (!(params instanceof FormData)) {
@@ -307,16 +310,17 @@ export class SimApiCore {
} }
async logout(url?: string | null): Promise<any> { async logout(url?: string | null): Promise<any> {
this.removeToken()
if (url !== null) { if (url !== null) {
return this.query(url ?? this.auth.logout_url).catch(() => true) return this.query(url ?? this.auth.logout_url).catch(() => true)
} }
this.removeToken()
return true return true
} }
async checkLogin(url?: string | null): Promise<void> { async checkLogin(url?: string | null): Promise<void> {
if (url !== null) { 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()) { } else if (this.getToken()) {
this.api.businessCallback[401]?.(null) this.api.businessCallback[401]?.(null)
} }