徐勤民 пре 6 месеци
родитељ
комит
b0a8f124eb

+ 2 - 2
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';
 
 /**

+ 1 - 1
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,

+ 18 - 5
src/main/ets/utils/AppStorageHelper.ets

@@ -3,20 +3,33 @@
  */
 export class AppStorageHelper {
   /**
-   * 缓存string
+   * 缓存
    * @param key
    * @param value
    */
-  public static save<T>(key: string, value: T|undefined) {
-    PersistentStorage.persistProp(key, value)
+  public static save<T>(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<T>(key: string):T|undefined {
+  public static get<T>(key: string): T | undefined {
     return AppStorage.get<T>(key)
   }
 }

+ 16 - 2
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<void> {
+    return new Promise(async (resolve, reject) => {
+
+      const pref = await preferences.getPreferences(getContext(), 'PreferencesHelper')
+      pref.delete(key).then(() => {
+        resolve()
+      })
+    })
+
+  }
 }