fix:修复所有的包导入错误问题
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
*
|
||||
* 注:仅在浏览器环境可用;SSR/Server Components 中调用会抛错。
|
||||
*/
|
||||
import { authStorage } from "../data/storage/auth_storage";
|
||||
import { AuthStorage } from "../data/storage/auth/auth_storage";
|
||||
import { SpAsyncUtil } from "./storage";
|
||||
import { StorageKeys } from "../data/storage/storage_keys";
|
||||
|
||||
export class DeviceIdentifier {
|
||||
private cachedId: string | null = null;
|
||||
@@ -30,16 +32,18 @@ export class DeviceIdentifier {
|
||||
/**
|
||||
* 重置缓存与持久化(用于测试或多账号切换)
|
||||
*/
|
||||
reset(): void {
|
||||
async reset(): Promise<void> {
|
||||
this.cachedId = null;
|
||||
this.initPromise = null;
|
||||
authStorage.removeDeviceId();
|
||||
await SpAsyncUtil.remove(StorageKeys.deviceId);
|
||||
}
|
||||
|
||||
private async initialize(): Promise<string> {
|
||||
// 1. 优先从 localStorage 读取
|
||||
const stored = authStorage.getDeviceId();
|
||||
if (stored) return stored;
|
||||
const storedR = await AuthStorage.getInstance().getDeviceId();
|
||||
if (storedR.success && storedR.data && storedR.data.length > 0) {
|
||||
return storedR.data;
|
||||
}
|
||||
|
||||
// 2. SSR/Node 环境守卫:调用方必须保证在浏览器中调用
|
||||
if (typeof window === "undefined") {
|
||||
@@ -55,7 +59,7 @@ export class DeviceIdentifier {
|
||||
const result = await fp.get();
|
||||
|
||||
// 4. 持久化
|
||||
authStorage.setDeviceId(result.visitorId);
|
||||
await AuthStorage.getInstance().setDeviceId(result.visitorId);
|
||||
return result.visitorId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
/**
|
||||
* SpAsyncUtil — 键值对持久化工具类(基于 unstorage)
|
||||
*
|
||||
* 原始 Dart: `lib/utils/src/sp_async_util.dart`(`SpAsyncUtil` 静态类)
|
||||
*
|
||||
* 设计目标:
|
||||
* - **完全静态类化**:所有状态/方法/函数均封装在 SpAsyncUtil 类内
|
||||
* - 底层基于 unstorage 抽象(浏览器 localStorage / SSR memory 自动切换)
|
||||
* - 保留 `Promise<Result<T>>` API 兼容(state machines、interceptor、repositories 零修改)
|
||||
*
|
||||
* 用法:
|
||||
* ```ts
|
||||
* import { SpAsyncUtil } from "@/utils/storage";
|
||||
|
||||
Reference in New Issue
Block a user