Compare commits

..
5 Commits
Author SHA1 Message Date
xrain 7aee4b708d fix config
Publish to npm / publish (push) Failing after 8s
2026-08-10 20:44:33 +08:00
xrain 1af5900593 fix config
Publish to npm / publish (push) Failing after 8s
2026-08-10 20:37:23 +08:00
xrain 78ef6d9ca0 fix cookie
Publish to npm / publish (push) Failing after 7s
2026-05-05 07:16:29 +08:00
xrain cee0bc4cfe fix cookie
Publish to npm / publish (push) Failing after 7s
2026-05-05 07:06:34 +08:00
xrain 9a8510d833 fix cookie
Publish to npm / publish (push) Failing after 5s
2026-05-05 07:01:21 +08:00
2 changed files with 23 additions and 34 deletions
+19 -31
View File
@@ -84,6 +84,7 @@ export class SimApiCore {
logout_url: '/auth/logout', logout_url: '/auth/logout',
login_url: '/auth/login', login_url: '/auth/login',
} }
webConfig: Map<string, Map<string, object>> = new Map();
private api: SimApiApiConfig = { private api: SimApiApiConfig = {
endpoints: {default: ''}, endpoints: {default: ''},
@@ -185,12 +186,12 @@ export class SimApiCore {
setToken(token: string): void { setToken(token: string): void {
const name = this.auth.token_name const name = this.auth.token_name
document.cookie = `${name}=${token}; path=/; max-age=315360000; samesite=none` document.cookie = `${name}=${token}; path=/; max-age=315360000; secure; samesite=none`
} }
removeToken(): void { removeToken(): void {
const name = this.auth.token_name const name = this.auth.token_name
document.cookie = `${name}=; path=/; max-age=0; samesite=none` document.cookie = `${name}=; path=/; max-age=0; secure; samesite=none`
} }
@@ -212,32 +213,19 @@ export class SimApiCore {
console.log('[DEBUG]', ...args) console.log('[DEBUG]', ...args)
} }
/** async getConfig(reload: boolean = false, endpointName: string = 'default'): Promise<Map<string, object>> {
* 获取版本信息 if (!this.webConfig.has(endpointName) || reload) {
* const versions: SimApiVersions = {
* @param endpointName - 指定从哪个 endpoint 获取版本,默认使用 default endpoint uiApp: typeof AppVersion === 'undefined' ? "0.0.0-develop" : AppVersion,
* @returns 版本信息对象 uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
* apiApp: '0.0.0',
* @example apiSimApi: '0.0.0',
* // 从默认 endpoint 获取 apiAppFull: '0.0.0',
* const versions = await api.getVersion() apiSimApiFull: '0.0.0',
* };
* // 从指定 endpoint 获取 const resp = await this.query<any>('/config', {}, endpointName)
* const versions = await api.getVersion('backup')
*/
async getVersion(endpointName?: string): Promise<SimApiVersions> {
const versions: SimApiVersions = {
uiApp: typeof AppVersion === 'undefined' ? "0.0.0-develop" : AppVersion,
uiSimApi: typeof SimApiVersion === 'undefined' ? "0.0.0-develop" : SimApiVersion,
apiApp: '0.0.0',
apiSimApi: '0.0.0',
apiAppFull: '0.0.0',
apiSimApiFull: '0.0.0',
};
try {
const resp = await this.query<any>('/versions', {}, endpointName)
if (resp?.data) { if (resp?.data) {
const d = resp.data const d = resp.data.versions;
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';
@@ -245,12 +233,12 @@ 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}`)
} }
return versions resp.data.versions = versions;
this.webConfig.set(endpointName, resp.data);
} }
} catch {
// 版本获取失败返回默认值
} }
return versions; return this.webConfig.get(endpointName)!;
} }
async query<T = any>( async query<T = any>(
+4 -3
View File
@@ -11,11 +11,12 @@ export const useSimApi = defineStore('simapi', {
_core: new SimApiCore(), _core: new SimApiCore(),
}), }),
getters: { getters: {
webConfig: state => state._core.webConfig,
IsDebug: state => state._core.isDebug IsDebug: state => state._core.isDebug
}, },
actions: { actions: {
// 所有方法直接代理到 core // 所有方法直接代理到 core
async loadFromFile(file: string = 'config.json'): Promise<void> { async loadFromFile(file: string = '/config.json'): Promise<void> {
return this._core.loadFromFile(file) return this._core.loadFromFile(file)
}, },
@@ -76,8 +77,8 @@ export const useSimApi = defineStore('simapi', {
return this._core.getEndpoint(name) return this._core.getEndpoint(name)
}, },
async getVersion(endpointName?: string): Promise<SimApiVersions> { async getConfig(reload = false, endpointName?: string): Promise<Map<string, object>> {
return this._core.getVersion(endpointName) return this._core.getConfig(reload, endpointName)
}, },
}, },
}) })