From b0a8f124eb0436e4be4ba9e54fbe84f2f6f59059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Tue, 24 Sep 2024 17:52:59 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BuildProfile.ets | 4 ++-- src/main/ets/http/HttpHelper.ts | 2 +- src/main/ets/utils/AppStorageHelper.ets | 23 ++++++++++++++++++----- src/main/ets/utils/PreferencesHelper.ets | 18 ++++++++++++++++-- 4 files changed, 37 insertions(+), 10 deletions(-) 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