- 统一替换所有 @react-native-async-storage/async-storage 导入为自定义 kvStore - 新增 kvStore.ts 封装 expo-sqlite/kv-store,保持与 AsyncStorage 完全兼容 - 新增同步读写方法,提升性能 - 引入 expo-sqlite 依赖并更新 lock 文件 BREAKING CHANGE: 移除 @react-native-async-storage/async-storage 依赖,需重新安装依赖并清理旧数据
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { STORAGE_KEYS } from '@/services/api';
|
|
import AsyncStorage from '@/utils/kvStore';
|
|
import { resetAllGuides } from './guideHelpers';
|
|
|
|
/**
|
|
* 开发工具函数 - 清除隐私同意状态
|
|
* 用于测试隐私同意弹窗功能
|
|
*/
|
|
export const clearPrivacyAgreement = async (): Promise<void> => {
|
|
try {
|
|
await AsyncStorage.removeItem(STORAGE_KEYS.privacyAgreed);
|
|
console.log('隐私同意状态已清除');
|
|
} catch (error) {
|
|
console.error('清除隐私同意状态失败:', error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 开发工具函数 - 检查隐私同意状态
|
|
*/
|
|
export const checkPrivacyAgreement = async (): Promise<boolean> => {
|
|
try {
|
|
const privacyAgreed = await AsyncStorage.getItem(STORAGE_KEYS.privacyAgreed);
|
|
const isAgreed = privacyAgreed === 'true';
|
|
console.log('隐私同意状态:', isAgreed);
|
|
return isAgreed;
|
|
} catch (error) {
|
|
console.error('检查隐私同意状态失败:', error);
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 开发工具函数 - 清除所有用户数据
|
|
* 用于完全重置应用状态
|
|
*/
|
|
export const clearAllUserData = async (): Promise<void> => {
|
|
try {
|
|
await Promise.all([
|
|
AsyncStorage.removeItem(STORAGE_KEYS.authToken),
|
|
AsyncStorage.removeItem(STORAGE_KEYS.userProfile),
|
|
AsyncStorage.removeItem(STORAGE_KEYS.privacyAgreed),
|
|
]);
|
|
console.log('所有用户数据已清除');
|
|
} catch (error) {
|
|
console.error('清除用户数据失败:', error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 重置所有用户引导状态(仅用于开发测试)
|
|
*/
|
|
export const resetGuideStates = async () => {
|
|
try {
|
|
await resetAllGuides();
|
|
console.log('✅ 所有用户引导状态已重置');
|
|
} catch (error) {
|
|
console.error('❌ 重置用户引导状态失败:', error);
|
|
}
|
|
};
|