diff --git a/BuildProfile.ets b/BuildProfile.ets index ac4967e..fd7a039 100644 --- a/BuildProfile.ets +++ b/BuildProfile.ets @@ -2,8 +2,8 @@ * Use these variables when you tailor your ArkTS code. They must be of the const type. */ export const HAR_VERSION = '1.0.2'; -export const BUILD_MODE_NAME = 'release'; -export const DEBUG = false; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; export const TARGET_NAME = 'default'; /** diff --git a/src/main/ets/http/HttpHelper.ts b/src/main/ets/http/HttpHelper.ts index 743b966..52070c3 100644 --- a/src/main/ets/http/HttpHelper.ts +++ b/src/main/ets/http/HttpHelper.ts @@ -74,9 +74,9 @@ export class HttpHelper { // "Accept": "application/json", ...params.headers } + console.log('>>>>>', 'POST:', params.url) // console.log('>>>>>', '接口请求', JSON.stringify(header)) // console.log('>>>>>', '接口请求', data) - console.log('>>>>>', 'POST:', params.url) httpRequest.request(this.getUrl(params.url, params.query), { method: http.RequestMethod.POST, diff --git a/src/main/ets/utils/AppStorageHelper.ets b/src/main/ets/utils/AppStorageHelper.ets index e383c5f..bdab5aa 100644 --- a/src/main/ets/utils/AppStorageHelper.ets +++ b/src/main/ets/utils/AppStorageHelper.ets @@ -3,20 +3,33 @@ */ export class AppStorageHelper { /** - * 缓存string + * 缓存 * @param key * @param value */ - public static save(key: string, value: T|undefined) { - PersistentStorage.persistProp(key, value) + public static save(key: string, value: T | undefined) { + if (!value) { + PersistentStorage.deleteProp(key) + } else { + PersistentStorage.persistProp(key, value) + } } /** - * 获取已缓存的string + * 删除缓存 + * @param key + * @param value + */ + public static delete(key: string) { + PersistentStorage.deleteProp(key) + } + + /** + * 获取已缓存的内容 * @param key * @returns */ - public static get(key: string):T|undefined { + public static get(key: string): T | undefined { return AppStorage.get(key) } } \ No newline at end of file diff --git a/src/main/ets/utils/PreferencesHelper.ets b/src/main/ets/utils/PreferencesHelper.ets index c39d5bd..de1a6b5 100644 --- a/src/main/ets/utils/PreferencesHelper.ets +++ b/src/main/ets/utils/PreferencesHelper.ets @@ -1,11 +1,15 @@ import preferences from '@ohos.data.preferences'; export class PreferencesHelper { - public static async put(key: string, value: preferences.ValueType|undefined) { + public static async put(key: string, value: preferences.ValueType | undefined) { const pref = await preferences.getPreferences(getContext(), 'PreferencesHelper') // 写入数据 - await pref.put(key, value) + if (value) { + await pref.put(key, value) + } else { + await pref.delete(key) + } // 刷盘 await pref.flush() } @@ -20,4 +24,14 @@ export class PreferencesHelper { }) } + public static async delete(key: string): Promise { + return new Promise(async (resolve, reject) => { + + const pref = await preferences.getPreferences(getContext(), 'PreferencesHelper') + pref.delete(key).then(() => { + resolve() + }) + }) + + } } \ No newline at end of file