From 713b8ae31ec7eab574661617fbf0aa476a931e6a Mon Sep 17 00:00:00 2001 From: xRain Date: Mon, 4 May 2026 03:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E4=B9=B1=E4=B8=83=E5=85=AB=E7=B3=9F=E4=B8=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/simapi.core.ts | 18 +++++++++++------- src/simapi.pinia.ts | 11 ++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/simapi.core.ts b/src/simapi.core.ts index 59e7a6c..c709b36 100644 --- a/src/simapi.core.ts +++ b/src/simapi.core.ts @@ -77,15 +77,15 @@ async function fetchPost( // ── SimApiCore ──────────────────────────────────────── export class SimApiCore { - debug: boolean = true - auth: SimApiAuthConfig = { + private debug: boolean = true + private auth: SimApiAuthConfig = { token_name: 'simapi-auth-token', check_url: '/auth/check', logout_url: '/auth/logout', login_url: '/auth/login', } - api: SimApiApiConfig = { + private api: SimApiApiConfig = { endpoints: {default: ''}, defaultEndpoint: 'default', businessCallback: { @@ -146,6 +146,14 @@ export class SimApiCore { } } + get isDebug() { + return this.debug + } + + setDebug(debug: boolean) { + this.debug = debug; + } + setEndpoints(endpoints: { [name: string]: string }): void { this.api.endpoints = {...this.api.endpoints, ...endpoints} } @@ -170,10 +178,6 @@ export class SimApiCore { localStorage.removeItem(this.auth.token_name) } - get isLoggedIn(): boolean { - return !!localStorage.getItem(this.auth.token_name) - } - genS4(): string { return (((1 + Math.random()) * 0x10000 * Date.parse(new Date().toString())) | 0) .toString(16) diff --git a/src/simapi.pinia.ts b/src/simapi.pinia.ts index b4f7fb9..c9a1cc2 100644 --- a/src/simapi.pinia.ts +++ b/src/simapi.pinia.ts @@ -10,16 +10,9 @@ export const useSimApi = defineStore('simapi', { // 在 state 中实例化 core _core: new SimApiCore(), }), - getters: { - // 直接映射 core 的属性和方法 - debug: (state) => state._core.debug, - token: (state) => state._core.getToken(), - isLoggedIn: (state) => state._core.isLoggedIn, - api: (state) => state._core.api, - auth: (state) => state._core.auth, + IsDebug: state => state._core.isDebug }, - actions: { // 所有方法直接代理到 core autoInit(): void { @@ -31,7 +24,7 @@ export const useSimApi = defineStore('simapi', { }, setDebug(debug: boolean): void { - this._core.debug = debug + this._core.setDebug(debug); }, setEndpoints(endpoints: { [name: string]: string }): void {