{"id":93148,"date":"2026-08-12T01:32:46","date_gmt":"2026-08-11T17:32:46","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/93148.html"},"modified":"2026-08-12T01:32:46","modified_gmt":"2026-08-11T17:32:46","slug":"%e3%80%90%e7%bb%86%e8%83%9e%e5%b7%a5%e5%9d%8a%ef%bd%9c10%e3%80%91harmonyos-arkts-%e6%94%b6%e8%97%8f%e4%b8%8e%e7%ac%94%e8%ae%b0%e5%ae%9e%e6%88%98%ef%bc%9a%e6%8a%8a%e5%ae%9e%e9%aa%8c%e6%94%b6%e8%97%8f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/93148.html","title":{"rendered":"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences"},"content":{"rendered":"<p>\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\u3002<\/p>\n<p>\u672c\u6587\u9762\u5411 HarmonyOS 5.0 \u53ca\u4ee5\u4e0a\u7248\u672c&#xff0c;\u57fa\u4e8e \u7ec6\u80de\u5de5\u574a \u9879\u76ee\u771f\u5b9e\u6e90\u7801\u5c55\u5f00&#xff0c;\u6e90\u7801\u6839\u76ee\u5f55\u4e3a D:\\\\huawei\\\\one14-9\u3002\u672c\u6587\u91cd\u70b9\u590d\u6838\u8fd9\u4e9b\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>entry\/src\/main\/ets\/views\/experiment\/ExperimentSimPage.ets<\/li>\n<li>entry\/src\/main\/ets\/views\/mine\/FavoritesPage.ets<\/li>\n<li>entry\/src\/main\/ets\/views\/mine\/NotesPage.ets<\/li>\n<li>entry\/src\/main\/ets\/components\/NoteEditorDialog.ets<\/li>\n<li>entry\/src\/main\/ets\/utils\/DataStore.ets<\/li>\n<\/ul>\n<p>\u5148\u628a\u8fb9\u754c\u8bb2\u6e05\u695a&#xff1a;\u5f53\u524d\u6e90\u7801\u5b9e\u73b0\u7684\u662f\u5b9e\u9a8c\u6536\u85cf\u548c\u624b\u52a8\u5b66\u4e60\u7b14\u8bb0\u3002\u6536\u85cf\u4fdd\u5b58\u7684\u662f\u5b9e\u9a8c expId&#xff0c;\u6536\u85cf\u5217\u8868\u518d\u7528 getAllExperiments() \u628a ID \u6620\u5c04\u56de\u5b9e\u9a8c\u5361\u7247&#xff1b;\u7b14\u8bb0\u901a\u8fc7 NoteEditorDialog \u624b\u52a8\u8f93\u5165\u6807\u9898\u3001\u5185\u5bb9\u3001\u5206\u7c7b&#xff0c;\u518d\u4fdd\u5b58\u5230 user_notes\u3002\u6e90\u7801\u6ca1\u6709\u5b9e\u73b0\u77e5\u8bc6\u8be6\u60c5\u6536\u85cf\u3001\u7b14\u8bb0\u81ea\u52a8\u540c\u6b65\u77e5\u8bc6\u8be6\u60c5\u3001\u4e91\u540c\u6b65\u3001\u8d26\u53f7\u4f53\u7cfb\u3001\u8de8\u8bbe\u5907\u540c\u6b65\u6216\u5bcc\u6587\u672c\u7b14\u8bb0\u3002<\/p>\n<p><img decoding=\"async\" alt=\"\u5c01\u9762\u56fe\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260811173243-6a7b5cbbcac33.png\" \/><\/p>\n<h3>1. \u6536\u85cf\u548c\u7b14\u8bb0\u6700\u5bb9\u6613\u51fa\u9519\u7684\u5730\u65b9\u4e0d\u662f UI&#xff0c;\u800c\u662f\u8fb9\u754c<\/h3>\n<p>\u5728\u5b66\u4e60\u7c7b HarmonyOS \u5e94\u7528\u91cc&#xff0c;\u201c\u6536\u85cf\u201d\u548c\u201c\u7b14\u8bb0\u201d\u770b\u8d77\u6765\u53ea\u662f\u4e24\u4e2a\u5165\u53e3&#xff0c;\u4f46\u5b9e\u9645\u4f1a\u7275\u6d89\u591a\u4e2a\u9875\u9762&#xff1a;\u5b9e\u9a8c\u6a21\u62df\u9875\u8981\u80fd\u5207\u6362\u6536\u85cf\u72b6\u6001&#xff0c;\u6211\u7684\u6536\u85cf\u9875\u8981\u80fd\u91cd\u65b0\u52a0\u8f7d\u5217\u8868&#xff0c;\u7b14\u8bb0\u9875\u8981\u80fd\u65b0\u589e\u548c\u5220\u9664&#xff0c;\u6570\u636e\u5c42\u8981\u80fd\u628a\u8fd9\u4e9b\u8bb0\u5f55\u7a33\u5b9a\u4fdd\u5b58\u4e0b\u6765\u3002<\/p>\n<p>\u5982\u679c\u8fb9\u754c\u6ca1\u5212\u6e05&#xff0c;\u5e38\u89c1\u95ee\u9898\u4f1a\u5f88\u5feb\u51fa\u73b0&#xff1a;<\/p>\n<table>\n<tr>\u95ee\u9898\u8868\u73b0\u6e90\u7801\u91cc\u7684\u5904\u7406\u65b9\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>\u6536\u85cf\u6309\u94ae\u72b6\u6001\u548c\u5217\u8868\u4e0d\u4e00\u81f4<\/td>\n<td>\u5b9e\u9a8c\u9875\u70b9\u4e86\u6536\u85cf&#xff0c;\u8fd4\u56de\u5217\u8868\u770b\u4e0d\u5230<\/td>\n<td>FavoritesPage \u5728 aboutToAppear\/onPageShow \u8c03\u7528 reload()<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u85cf\u4fdd\u5b58\u6574\u4e2a\u5bf9\u8c61<\/td>\n<td>\u5b9e\u9a8c\u6539\u540d\u540e\u6536\u85cf\u91cc\u8fd8\u662f\u65e7\u5185\u5bb9<\/td>\n<td>\u53ea\u4fdd\u5b58\u5b9e\u9a8c ID&#xff0c;\u5c55\u793a\u65f6\u6620\u5c04\u6700\u65b0\u5b9e\u9a8c\u5b9a\u4e49<\/td>\n<\/tr>\n<tr>\n<td>\u7b14\u8bb0\u8f93\u5165\u4e3a\u7a7a\u4ecd\u4fdd\u5b58<\/td>\n<td>\u5217\u8868\u51fa\u73b0\u7a7a\u6807\u9898\u6216\u7a7a\u5185\u5bb9<\/td>\n<td>NoteEditorDialog \u5728\u4fdd\u5b58\u524d trim() \u5e76\u62e6\u622a\u7a7a\u503c<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u53ea\u6539 UI \u4e0d\u6539\u672c\u5730<\/td>\n<td>\u91cd\u8fdb\u9875\u9762\u540e\u88ab\u5220\u7b14\u8bb0\u53c8\u51fa\u73b0<\/td>\n<td>removeNote() \u66f4\u65b0\u72b6\u6001\u540e\u8c03\u7528 DataStore.saveNotes()<\/td>\n<\/tr>\n<tr>\n<td>\u672c\u5730\u7edf\u8ba1\u4e0d\u540c\u6b65<\/td>\n<td>\u6211\u7684\u9875\u9762\u6536\u85cf\u6570\u91cf\u4e0d\u53d8<\/td>\n<td>DataStore.notifyStatsChanged() \u66f4\u65b0 AppStorage \u5feb\u7167<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u8981\u89e3\u51b3\u7684\u5de5\u7a0b\u95ee\u9898\u662f&#xff1a;\u5728\u4e00\u4e2a ArkTS \u5e94\u7528\u91cc&#xff0c;\u7528\u8f7b\u91cf\u7ea7 Preferences \u5b9e\u73b0\u672c\u5730\u6536\u85cf\u548c\u7b14\u8bb0&#xff0c;\u9875\u9762\u72b6\u6001\u548c\u6301\u4e45\u5316\u72b6\u6001\u4fdd\u6301\u4e00\u81f4&#xff0c;\u540c\u65f6\u4e0d\u5938\u5927\u6e90\u7801\u6ca1\u6709\u5b9e\u73b0\u7684\u540c\u6b65\u80fd\u529b\u3002<\/p>\n<h3>2. DataStore&#xff1a;\u628a Preferences \u5305\u6210\u7edf\u4e00\u5165\u53e3<\/h3>\n<p>DataStore.ets \u662f\u672c\u5730\u6570\u636e\u5165\u53e3\u3002\u5b83\u4f7f\u7528 HarmonyOS \u6570\u636e\u7ba1\u7406\u91cc\u7684 Preferences&#xff1a;<\/p>\n<p>import { preferences } from &#039;&#064;kit.ArkData&#039;<br \/>\nimport { common } from &#039;&#064;kit.AbilityKit&#039;<\/p>\n<p>const PREF_NAME &#061; &#039;bio_lab_app_data&#039;<\/p>\n<p>export class DataStore {<br \/>\n  private static prefInstance: preferences.Preferences | null &#061; null<\/p>\n<p>  static async init(context: common.UIAbilityContext): Promise&lt;void&gt; {<br \/>\n    try {<br \/>\n      DataStore.prefInstance &#061; await preferences.getPreferences(context, PREF_NAME)<br \/>\n      await DataStore.refreshStatsSnapshot()<br \/>\n    } catch (_) {<br \/>\n      DataStore.prefInstance &#061; null<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u7684\u5173\u952e\u662f\u628a preferences.Preferences \u5b9e\u4f8b\u85cf\u5728 DataStore \u5185\u90e8\u3002\u9875\u9762\u4e0d\u76f4\u63a5\u8c03\u7528 preferences.getPreferences()&#xff0c;\u800c\u662f\u8c03\u7528 DataStore.loadFavorites()\u3001DataStore.saveNotes() \u8fd9\u7c7b\u4e1a\u52a1\u65b9\u6cd5\u3002<\/p>\n<p>\u8fd9\u79cd\u505a\u6cd5\u6709\u4e09\u4e2a\u597d\u5904&#xff1a;<\/p>\n<ul>\n<li>\u9875\u9762\u4e0d\u7528\u77e5\u9053 Preferences \u6587\u4ef6\u540d&#xff1b;<\/li>\n<li>JSON \u89e3\u6790\u548c\u5f02\u5e38\u515c\u5e95\u96c6\u4e2d\u5904\u7406&#xff1b;<\/li>\n<li>\u540e\u7eed\u5982\u679c\u4ece Preferences \u6362\u6210 RDB \u6216\u6587\u4ef6\u5b58\u50a8&#xff0c;\u9875\u9762\u6539\u52a8\u8303\u56f4\u66f4\u5c0f\u3002<\/li>\n<\/ul>\n<p>\u5f53\u524d\u6570\u636e\u91cf\u5f88\u5c0f&#xff0c;\u6536\u85cf\u53ea\u662f\u5b57\u7b26\u4e32 ID \u6570\u7ec4&#xff0c;\u7b14\u8bb0\u4e5f\u53ea\u662f\u672c\u5730\u5bf9\u8c61\u6570\u7ec4&#xff0c;Preferences \u662f\u5408\u9002\u9009\u62e9\u3002\u82e5\u540e\u7eed\u7b14\u8bb0\u652f\u6301\u5168\u6587\u641c\u7d22\u3001\u6807\u7b7e\u8fc7\u6ee4\u3001\u56fe\u7247\u9644\u4ef6\u6216\u5927\u91cf\u8bb0\u5f55&#xff0c;\u5c31\u5e94\u8003\u8651\u5173\u7cfb\u578b\u6570\u636e\u5e93\u6216\u6587\u4ef6\u5b58\u50a8\u3002<\/p>\n<h3>3. \u901a\u7528\u8bfb\u5199&#xff1a;\u5931\u8d25\u65f6\u8fd4\u56de\u9ed8\u8ba4\u503c&#xff0c;\u907f\u514d\u9875\u9762\u5d29\u6e83<\/h3>\n<p>DataStore \u7684\u57fa\u7840\u8bfb\u5199\u65b9\u6cd5\u90fd\u505a\u4e86\u5f02\u5e38\u515c\u5e95&#xff1a;<\/p>\n<p>static async putString(key: string, value: string): Promise&lt;void&gt; {<br \/>\n  if (!DataStore.prefInstance) return<br \/>\n  try {<br \/>\n    await DataStore.prefInstance.put(key, value)<br \/>\n    await DataStore.prefInstance.flush()<br \/>\n    DataStore.notifyStatsChanged(key, value)<br \/>\n  } catch (_) {<br \/>\n  }<br \/>\n}<\/p>\n<p>static async getString(key: string, defaultValue: string &#061; &#039;&#039;): Promise&lt;string&gt; {<br \/>\n  if (!DataStore.prefInstance) return defaultValue<br \/>\n  try {<br \/>\n    const value &#061; await DataStore.prefInstance.get(key, defaultValue)<br \/>\n    return value as string<br \/>\n  } catch (_) {<br \/>\n    return defaultValue<br \/>\n  }<br \/>\n}<\/p>\n<p>\u6536\u85cf\u548c\u7b14\u8bb0\u90fd\u4f9d\u8d56\u5b57\u7b26\u4e32 JSON\u3002\u5199\u5165\u65f6 flush() \u4fdd\u8bc1\u6570\u636e\u843d\u76d8&#xff1b;\u8bfb\u53d6\u5931\u8d25\u65f6\u8fd4\u56de\u9ed8\u8ba4\u503c&#xff0c;\u9875\u9762\u53ef\u4ee5\u7ee7\u7eed\u663e\u793a\u7a7a\u6001\u3002<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u5de5\u7a0b\u53d6\u820d\u4e5f\u5f88\u660e\u663e&#xff1a;\u5b83\u6ca1\u6709\u628a\u9519\u8bef\u629b\u5230 UI \u5c42&#xff0c;\u4e5f\u6ca1\u6709\u663e\u793a\u5931\u8d25\u63d0\u793a\u3002\u5bf9\u4e8e\u5f53\u524d\u8f7b\u91cf\u5b66\u4e60\u5de5\u5177\u6765\u8bf4&#xff0c;\u8fd9\u80fd\u4fdd\u8bc1\u9875\u9762\u7a33\u5b9a&#xff1b;\u5982\u679c\u662f\u5f3a\u4e00\u81f4\u7684\u751f\u4ea7\u8bb0\u5f55\u7cfb\u7edf&#xff0c;\u5c31\u5e94\u628a\u4fdd\u5b58\u5931\u8d25\u53cd\u9988\u7ed9\u7528\u6237&#xff0c;\u5e76\u63d0\u4f9b\u91cd\u8bd5\u3002<\/p>\n<h3>4. \u6536\u85cf\u6570\u636e\u7ed3\u6784&#xff1a;\u53ea\u4fdd\u5b58\u5b9e\u9a8c ID&#xff0c;\u4e0d\u4fdd\u5b58\u5b9e\u9a8c\u5bf9\u8c61<\/h3>\n<p>\u6536\u85cf\u65b9\u6cd5\u975e\u5e38\u660e\u786e&#xff1a;<\/p>\n<p>static async saveFavorites(ids: string[]): Promise&lt;void&gt; {<br \/>\n  await DataStore.putString(&#039;favorite_experiments&#039;, JSON.stringify(ids))<br \/>\n}<\/p>\n<p>static async loadFavorites(): Promise&lt;string[]&gt; {<br \/>\n  const json &#061; await DataStore.getString(&#039;favorite_experiments&#039;, &#039;[]&#039;)<br \/>\n  try {<br \/>\n    return JSON.parse(json) as string[]<br \/>\n  } catch {<br \/>\n    return []<br \/>\n  }<br \/>\n}<\/p>\n<p>\u5b83\u53ea\u4fdd\u5b58 string[]\u3002\u8fd9\u6bd4\u4fdd\u5b58\u5b8c\u6574\u5b9e\u9a8c\u5bf9\u8c61\u66f4\u7a33\u3002<\/p>\n<table>\n<tr>\u4fdd\u5b58\u65b9\u5f0f\u4f18\u70b9\u98ce\u9669<\/tr>\n<tbody>\n<tr>\n<td>\u4fdd\u5b58\u5b8c\u6574\u5b9e\u9a8c\u5bf9\u8c61<\/td>\n<td>\u5217\u8868\u6e32\u67d3\u4e0d\u9700\u8981\u518d\u67e5\u6a21\u578b<\/td>\n<td>\u5b9e\u9a8c\u540d\u79f0\u3001\u56fe\u6807\u3001\u5206\u7c7b\u66f4\u65b0\u540e&#xff0c;\u672c\u5730\u65e7\u5bf9\u8c61\u4f1a\u8fc7\u671f<\/td>\n<\/tr>\n<tr>\n<td>\u4fdd\u5b58\u5b9e\u9a8c ID<\/td>\n<td>\u672c\u5730\u6570\u636e\u5c0f&#xff0c;\u5c55\u793a\u65f6\u4f7f\u7528\u6700\u65b0\u6a21\u578b<\/td>\n<td>\u5982\u679c\u6a21\u578b\u91cc\u5220\u9664\u5b9e\u9a8c ID&#xff0c;\u9700\u8981\u8fc7\u6ee4\u4e0d\u5b58\u5728\u9879<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f53\u524d\u6e90\u7801\u9009\u62e9\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u3002FavoritesPage.reload() \u4f1a\u5904\u7406\u201cID \u5df2\u4e0d\u5b58\u5728\u201d\u7684\u60c5\u51b5&#xff0c;\u53ea\u628a\u80fd\u627e\u5230\u7684\u5b9e\u9a8c\u63a8\u5165\u5217\u8868\u3002<\/p>\n<h3>5. ExperimentSimPage&#xff1a;\u6536\u85cf\u5165\u53e3\u5728\u5b9e\u9a8c\u6a21\u62df\u9875<\/h3>\n<p>\u5b9e\u9a8c\u6a21\u62df\u9875\u7ef4\u62a4\u6536\u85cf\u72b6\u6001&#xff1a;<\/p>\n<p>&#064;State isFavorite: boolean &#061; false<br \/>\n&#064;State expId: string &#061; &#039;microscope_observation&#039;<\/p>\n<p>\u9875\u9762\u51fa\u73b0\u65f6\u52a0\u8f7d\u6536\u85cf\u72b6\u6001&#xff1a;<\/p>\n<p>aboutToAppear(): void {<br \/>\n  const params &#061; router.getParams() as SimRouterParams | undefined<br \/>\n  if (params?.expId) {<br \/>\n    this.expId &#061; params.expId<br \/>\n  }<br \/>\n  if (params?.expName) {<br \/>\n    this.title &#061; params.expName<br \/>\n  }<br \/>\n  this.initExperiment()<br \/>\n  this.resetExperiment()<br \/>\n  this.loadFavoriteState()<br \/>\n}<\/p>\n<p>private async loadFavoriteState(): Promise&lt;void&gt; {<br \/>\n  const ids &#061; await DataStore.loadFavorites()<br \/>\n  this.isFavorite &#061; ids.includes(this.expId)<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u5148\u8bfb\u8def\u7531\u53c2\u6570&#xff0c;\u518d\u521d\u59cb\u5316\u5b9e\u9a8c&#xff0c;\u518d\u52a0\u8f7d\u6536\u85cf\u72b6\u6001\u3002\u987a\u5e8f\u5f88\u5173\u952e&#xff1a;\u5982\u679c\u5148\u52a0\u8f7d\u6536\u85cf&#xff0c;\u518d\u66f4\u65b0 expId&#xff0c;\u6309\u94ae\u72b6\u6001\u5c31\u4f1a\u6839\u636e\u9ed8\u8ba4\u5b9e\u9a8c\u8ba1\u7b97&#xff0c;\u5bfc\u81f4\u8fdb\u5165\u5176\u4ed6\u5b9e\u9a8c\u65f6\u6536\u85cf\u56fe\u6807\u4e0d\u51c6\u786e\u3002<\/p>\n<p>\u6536\u85cf\u5207\u6362\u903b\u8f91\u5982\u4e0b&#xff1a;<\/p>\n<p>private async toggleFavorite(): Promise&lt;void&gt; {<br \/>\n  const ids &#061; await DataStore.loadFavorites()<br \/>\n  const idx &#061; ids.indexOf(this.expId)<br \/>\n  if (idx &gt;&#061; 0) {<br \/>\n    ids.splice(idx, 1)<br \/>\n    this.isFavorite &#061; false<br \/>\n  } else {<br \/>\n    ids.push(this.expId)<br \/>\n    this.isFavorite &#061; true<br \/>\n  }<br \/>\n  await DataStore.saveFavorites(ids)<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5148\u8bfb\u53d6\u5f53\u524d ID \u6570\u7ec4&#xff0c;\u518d\u6839\u636e expId \u662f\u5426\u5b58\u5728\u51b3\u5b9a\u6dfb\u52a0\u6216\u79fb\u9664\u3002\u9875\u9762\u72b6\u6001 isFavorite \u4f1a\u7acb\u5373\u66f4\u65b0&#xff0c;\u6700\u540e\u4fdd\u5b58\u5230\u672c\u5730\u3002\u5b83\u6ca1\u6709\u9632\u91cd\u590d\u6dfb\u52a0&#xff0c;\u56e0\u4e3a idx &gt;&#061; 0 \u5df2\u7ecf\u8986\u76d6\u4e86\u91cd\u590d\u70b9\u51fb\u573a\u666f\u3002<\/p>\n<h3>6. \u6536\u85cf\u6309\u94ae&#xff1a;UI \u72b6\u6001\u6765\u81ea isFavorite&#xff0c;\u800c\u4e0d\u662f\u5217\u8868\u957f\u5ea6<\/h3>\n<p>\u5b9e\u9a8c\u9875\u53f3\u4e0a\u89d2\u6309\u94ae\u6839\u636e isFavorite \u5207\u6362\u989c\u8272&#xff1a;<\/p>\n<p>Row() {<br \/>\n  Text(this.isFavorite ? &#039;\u2605&#039; : &#039;\u2606&#039;)<br \/>\n    .fontSize(20)<br \/>\n    .fontColor(this.isFavorite ? AppColors.ACCENT_GREEN : AppColors.TEXT_SECONDARY)<br \/>\n}<br \/>\n.width(40)<br \/>\n.height(40)<br \/>\n.borderRadius(20)<br \/>\n.backgroundColor(&#039;#111827&#039;)<br \/>\n.justifyContent(FlexAlign.Center)<br \/>\n.onClick(() &#061;&gt; { this.toggleFavorite() })<\/p>\n<p>\u6e90\u7801\u8f93\u51fa\u4e2d\u56fe\u6807\u5b57\u7b26\u53ef\u80fd\u56e0\u4e3a\u7f16\u7801\u663e\u793a\u4e3a\u4e71\u7801&#xff0c;\u4f46\u7ed3\u6784\u53ef\u4ee5\u786e\u8ba4&#xff1a;\u6309\u94ae\u663e\u793a\u7531 isFavorite \u63a7\u5236&#xff0c;\u70b9\u51fb\u8c03\u7528 toggleFavorite()\u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2a\u503c\u5f97\u4fdd\u7559\u7684\u539f\u5219&#xff1a;\u6536\u85cf\u6309\u94ae\u4e0d\u5e94\u8be5\u6bcf\u6b21\u6e32\u67d3\u90fd\u91cd\u65b0\u8bfb\u53d6 Preferences\u3002\u8bfb\u53d6\u672c\u5730\u6570\u636e\u662f\u5f02\u6b65\u64cd\u4f5c&#xff0c;\u9891\u7e41\u653e\u5728 UI \u6784\u5efa\u8def\u5f84\u91cc\u4f1a\u8ba9\u9875\u9762\u72b6\u6001\u4e0d\u53ef\u63a7\u3002\u5f53\u524d\u6e90\u7801\u5728\u751f\u547d\u5468\u671f\u4e2d\u52a0\u8f7d\u4e00\u6b21&#xff0c;\u70b9\u51fb\u65f6\u66f4\u65b0\u4e00\u6b21&#xff0c;\u662f\u5408\u7406\u7684\u3002<\/p>\n<h3>7. FavoritesPage&#xff1a;\u6536\u85cf\u5217\u8868\u901a\u8fc7 ID \u6620\u5c04\u5b9e\u9a8c\u5b9a\u4e49<\/h3>\n<p>\u6536\u85cf\u9875\u53ea\u4fdd\u5b58\u4e00\u4e2a\u72b6\u6001&#xff1a;<\/p>\n<p>&#064;State favorites: Experiment[] &#061; []<\/p>\n<p>\u52a0\u8f7d\u903b\u8f91\u662f&#xff1a;<\/p>\n<p>private async reload(): Promise&lt;void&gt; {<br \/>\n  const ids &#061; await DataStore.loadFavorites()<br \/>\n  const all &#061; getAllExperiments()<br \/>\n  const list: Experiment[] &#061; []<br \/>\n  for (const id of ids) {<br \/>\n    const found &#061; all.find(e &#061;&gt; e.id &#061;&#061;&#061; id)<br \/>\n    if (found) {<br \/>\n      list.push(found)<br \/>\n    }<br \/>\n  }<br \/>\n  this.favorites &#061; list<br \/>\n}<\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u628a\u672c\u5730 ID \u6570\u7ec4\u8f6c\u6362\u6210\u5f53\u524d\u5b9e\u9a8c\u5b9a\u4e49\u6570\u7ec4\u3002\u5b83\u6709\u4e00\u4e2a\u5f88\u5b9e\u7528\u7684\u5bb9\u9519&#xff1a;\u5982\u679c\u67d0\u4e2a ID \u5728 getAllExperiments() \u4e2d\u627e\u4e0d\u5230&#xff0c;\u5c31\u8df3\u8fc7&#xff0c;\u4e0d\u8ba9\u5217\u8868\u51fa\u73b0\u7a7a\u5bf9\u8c61\u3002<\/p>\n<p>\u8fd9\u4e5f\u89e3\u91ca\u4e86\u4e3a\u4ec0\u4e48\u6536\u85cf\u672c\u5730\u53ea\u4fdd\u5b58 ID&#xff1a;\u6536\u85cf\u9875\u5c55\u793a\u7684\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u56fe\u6807\u3001\u5206\u7c7b\u3001\u96be\u5ea6\u90fd\u6765\u81ea\u6a21\u578b\u6700\u65b0\u5b9a\u4e49&#xff0c;\u800c\u4e0d\u662f\u5386\u53f2\u7f13\u5b58\u3002<\/p>\n<p><img decoding=\"async\" alt=\"\u6d41\u7a0b\u56fe\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260811173244-6a7b5cbc9bbb2.png\" \/><\/p>\n<h3>8. \u751f\u547d\u5468\u671f reload&#xff1a;\u89e3\u51b3\u8fd4\u56de\u9875\u9762\u540e\u7684\u5217\u8868\u5237\u65b0<\/h3>\n<p>\u6536\u85cf\u9875\u548c\u7b14\u8bb0\u9875\u90fd\u4f7f\u7528\u4e86\u4e24\u4e2a\u751f\u547d\u5468\u671f\u5165\u53e3&#xff1a;<\/p>\n<p>aboutToAppear(): void {<br \/>\n  this.reload()<br \/>\n}<\/p>\n<p>onPageShow(): void {<br \/>\n  this.reload()<br \/>\n}<\/p>\n<p>aboutToAppear() \u8d1f\u8d23\u9875\u9762\u9996\u6b21\u8fdb\u5165\u65f6\u52a0\u8f7d&#xff1b;onPageShow() \u8d1f\u8d23\u9875\u9762\u91cd\u65b0\u663e\u793a\u65f6\u5237\u65b0\u3002\u5bf9\u4e8e\u6536\u85cf\u5217\u8868\u5c24\u5176\u91cd\u8981&#xff1a;\u7528\u6237\u53ef\u80fd\u4ece\u6536\u85cf\u9875\u8fdb\u5165\u5b9e\u9a8c\u6a21\u62df\u9875&#xff0c;\u5207\u6362\u6536\u85cf\u72b6\u6001\u540e\u8fd4\u56de\u6536\u85cf\u9875\u3002\u5982\u679c\u53ea\u5728\u9996\u6b21\u8fdb\u5165\u52a0\u8f7d&#xff0c;\u5217\u8868\u5c31\u53ef\u80fd\u663e\u793a\u65e7\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u7c7b\u672c\u5730\u6570\u636e\u9875\u9762\u4e00\u822c\u8981\u9075\u5b88\u4e00\u4e2a\u7b80\u5355\u89c4\u5219&#xff1a;<\/p>\n<table>\n<tr>\u9875\u9762\u5237\u65b0\u65f6\u673a<\/tr>\n<tbody>\n<tr>\n<td>\u8be6\u60c5\u9875\u6309\u94ae\u72b6\u6001<\/td>\n<td>\u8fdb\u5165\u8be6\u60c5\u65f6\u8bfb\u53d6\u4e00\u6b21&#xff0c;\u70b9\u51fb\u65f6\u66f4\u65b0<\/td>\n<\/tr>\n<tr>\n<td>\u5217\u8868\u9875<\/td>\n<td>\u9996\u6b21\u8fdb\u5165\u548c\u8fd4\u56de\u663e\u793a\u65f6\u91cd\u65b0\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>\u7edf\u8ba1\u9875<\/td>\n<td>\u4f9d\u8d56 AppStorage \u5feb\u7167\u6216\u8fdb\u5165\u65f6\u91cd\u65b0\u8ba1\u7b97<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f53\u524d FavoritesPage \u548c NotesPage \u90fd\u9009\u62e9\u4e86\u8fdb\u5165\/\u663e\u793a\u65f6\u91cd\u65b0\u52a0\u8f7d&#xff0c;\u9002\u5408\u672c\u5730\u8f7b\u91cf\u6570\u636e\u3002<\/p>\n<h3>9. \u6536\u85cf\u7a7a\u6001&#xff1a;\u6ca1\u6709\u6570\u636e\u65f6\u7ed9\u7528\u6237\u4e0b\u4e00\u6b65<\/h3>\n<p>\u6536\u85cf\u9875\u7a7a\u6001\u4ee3\u7801&#xff1a;<\/p>\n<p>if (this.favorites.length &#061;&#061;&#061; 0) {<br \/>\n  Column() {<br \/>\n    Text(&#039;\u6682\u65e0\u6536\u85cf&#039;)<br \/>\n      .fontSize(16)<br \/>\n      .fontColor(AppColors.TEXT_HINT)<br \/>\n    Text(&#039;\u53bb\u5b9e\u9a8c\u5ba4\u6536\u85cf\u4f60\u611f\u5174\u8da3\u7684\u5b9e\u9a8c\u5427&#039;)<br \/>\n      .fontSize(13)<br \/>\n      .fontColor(AppColors.TEXT_HINT)<br \/>\n      .margin({ top: 8 })<br \/>\n  }<br \/>\n  .width(&#039;100%&#039;)<br \/>\n  .layoutWeight(1)<br \/>\n  .justifyContent(FlexAlign.Center)<br \/>\n  .alignItems(HorizontalAlign.Center)<br \/>\n}<\/p>\n<p>\u7a7a\u6001\u4e0d\u662f\u88c5\u9970&#xff0c;\u5b83\u544a\u8bc9\u7528\u6237\u4e0b\u4e00\u6b65\u8be5\u53bb\u54ea&#xff1a;\u53bb\u5b9e\u9a8c\u5ba4\u6536\u85cf\u5b9e\u9a8c\u3002\u5bf9\u5b66\u4e60\u5de5\u5177\u6765\u8bf4&#xff0c;\u8fd9\u6bd4\u53ea\u663e\u793a\u7a7a\u767d\u9875\u9762\u66f4\u6e05\u695a&#xff0c;\u4e5f\u80fd\u907f\u514d\u7528\u6237\u8bef\u4ee5\u4e3a\u6570\u636e\u52a0\u8f7d\u5931\u8d25\u3002<\/p>\n<p>\u5982\u679c\u540e\u7eed\u8981\u589e\u5f3a&#xff0c;\u53ef\u4ee5\u5728\u7a7a\u6001\u52a0\u5165\u201c\u53bb\u5b9e\u9a8c\u5ba4\u201d\u6309\u94ae&#xff0c;\u76f4\u63a5\u8def\u7531\u5230\u5b9e\u9a8c\u5217\u8868\u3002\u4f46\u5f53\u524d\u6e90\u7801\u6ca1\u6709\u8fd9\u4e2a\u6309\u94ae&#xff0c;\u6587\u7ae0\u53ea\u63cf\u8ff0\u73b0\u6709\u63d0\u793a\u6587\u6848\u3002<\/p>\n<h3>10. \u6536\u85cf\u5217\u8868\u5361\u7247&#xff1a;\u70b9\u51fb\u540e\u56de\u5230\u5b9e\u9a8c\u6a21\u62df\u9875<\/h3>\n<p>\u6536\u85cf\u5217\u8868\u7684\u5361\u7247\u70b9\u51fb\u4f1a\u8fdb\u5165\u5b9e\u9a8c\u6a21\u62df&#xff1a;<\/p>\n<p>.onClick(() &#061;&gt; {<br \/>\n  router.pushUrl({<br \/>\n    url: &#039;views\/experiment\/ExperimentSimPage&#039;,<br \/>\n    params: { expId: exp.id, expName: exp.name }<br \/>\n  })<br \/>\n})<\/p>\n<p>\u8fd9\u91cc\u4f20\u5165 expId \u548c expName\u3002\u5b9e\u9a8c\u6a21\u62df\u9875\u518d\u901a\u8fc7 router.getParams() \u8bfb\u53d6\u8fd9\u4e9b\u53c2\u6570&#xff0c;\u521d\u59cb\u5316\u5f53\u524d\u5b9e\u9a8c\u3002<\/p>\n<p>\u8fd9\u6761\u94fe\u8def\u8bf4\u660e\u6536\u85cf\u5217\u8868\u662f\u5b9e\u9a8c\u5165\u53e3&#xff0c;\u4e0d\u662f\u77e5\u8bc6\u70b9\u6536\u85cf\u5165\u53e3\u3002\u5b83\u6ca1\u6709\u4f20 kpTitle\u3001kpSummary&#xff0c;\u4e5f\u6ca1\u6709\u8bb0\u5f55\u77e5\u8bc6\u70b9 ID\u3002\u77e5\u8bc6\u8be6\u60c5\u9875\u867d\u7136\u5b58\u5728 getRelatedExperiment() \u8fd9\u6837\u7684\u6620\u5c04\u903b\u8f91&#xff0c;\u4f46\u5f53\u524d\u6536\u85cf\u9875\u7684\u6301\u4e45\u5316\u5bf9\u8c61\u4ecd\u662f\u5b9e\u9a8c ID\u3002<\/p>\n<p>\u8fd9\u5c31\u662f\u672c\u6587\u6536\u7a84\u6807\u9898\u7684\u539f\u56e0&#xff1a;\u6e90\u7801\u652f\u6301\u201c\u5b9e\u9a8c\u6536\u85cf\u4e0e\u672c\u5730\u7b14\u8bb0\u201d&#xff0c;\u4e0d\u652f\u6301\u201c\u77e5\u8bc6\u8be6\u60c5\u3001\u6536\u85cf\u5217\u8868\u548c\u672c\u5730\u8bb0\u5f55\u4e09\u65b9\u540c\u6b65\u201d\u3002<\/p>\n<h3>11. NotesPage&#xff1a;\u7b14\u8bb0\u662f\u72ec\u7acb\u7684\u672c\u5730\u6570\u7ec4<\/h3>\n<p>\u7b14\u8bb0\u9875\u5b9a\u4e49\u672c\u5730\u63a5\u53e3&#xff1a;<\/p>\n<p>interface NoteItem {<br \/>\n  id: string<br \/>\n  title: string<br \/>\n  content: string<br \/>\n  timestamp: string<br \/>\n  category: string<br \/>\n}<\/p>\n<p>\u72b6\u6001\u5982\u4e0b&#xff1a;<\/p>\n<p>&#064;State notes: NoteItem[] &#061; []<br \/>\n&#064;State isEditing: boolean &#061; false<\/p>\n<p>notes \u662f\u5c55\u793a\u5217\u8868&#xff0c;isEditing \u51b3\u5b9a\u662f\u5426\u663e\u793a\u5220\u9664\u6309\u94ae\u3002\u9875\u9762\u52a0\u8f7d\u65f6&#xff1a;<\/p>\n<p>private async reload(): Promise&lt;void&gt; {<br \/>\n  this.notes &#061; await DataStore.loadNotes&lt;NoteItem&gt;()<br \/>\n}<\/p>\n<p>\u7b14\u8bb0\u6ca1\u6709\u548c\u77e5\u8bc6\u8be6\u60c5\u6216\u5b9e\u9a8c\u7ed3\u679c\u81ea\u52a8\u7ed1\u5b9a\u3002\u5b83\u662f\u7528\u6237\u624b\u52a8\u8f93\u5165\u7684\u5b66\u4e60\u8bb0\u5f55&#xff0c;\u5305\u542b\u6807\u9898\u3001\u5185\u5bb9\u3001\u65e5\u671f\u548c\u5206\u7c7b\u3002\u8fd9\u4e2a\u8fb9\u754c\u5f88\u91cd\u8981&#xff0c;\u56e0\u4e3a\u201c\u81ea\u52a8\u540c\u6b65\u77e5\u8bc6\u8be6\u60c5\u201d\u4f1a\u6d89\u53ca\u8def\u7531\u53c2\u6570\u3001\u5173\u8054 ID\u3001\u7b14\u8bb0\u6765\u6e90\u3001\u91cd\u590d\u5408\u5e76\u7b49\u903b\u8f91&#xff0c;\u5f53\u524d\u6e90\u7801\u6ca1\u6709\u5b9e\u73b0\u3002<\/p>\n<h3>12. NoteEditorDialog&#xff1a;\u4fdd\u5b58\u524d\u62e6\u622a\u7a7a\u6807\u9898\u548c\u7a7a\u5185\u5bb9<\/h3>\n<p>\u7b14\u8bb0\u5f39\u7a97\u901a\u8fc7 &#064;CustomDialog \u5b9e\u73b0&#xff1a;<\/p>\n<p>&#064;CustomDialog<br \/>\nexport struct NoteEditorDialog {<br \/>\n  controller: CustomDialogController<br \/>\n  title: string &#061; &#039;&#039;<br \/>\n  content: string &#061; &#039;&#039;<br \/>\n  category: string &#061; &#039;\u57fa\u7840&#039;<br \/>\n  onSave: (title: string, content: string, category: string) &#061;&gt; void &#061; () &#061;&gt; {}<br \/>\n}<\/p>\n<p>\u4fdd\u5b58\u6309\u94ae\u91cc\u505a\u4e86\u8f93\u5165\u6e05\u7406&#xff1a;<\/p>\n<p>.onClick(() &#061;&gt; {<br \/>\n  const t &#061; this.title.trim()<br \/>\n  const c &#061; this.content.trim()<br \/>\n  if (t.length &#061;&#061;&#061; 0 || c.length &#061;&#061;&#061; 0) {<br \/>\n    return<br \/>\n  }<br \/>\n  this.onSave(t, c, this.category)<br \/>\n  this.controller.close()<br \/>\n})<\/p>\n<p>\u8fd9\u6bb5\u903b\u8f91\u9632\u6b62\u7a7a\u6807\u9898\u548c\u7a7a\u5185\u5bb9\u8fdb\u5165\u672c\u5730\u6570\u7ec4\u3002\u5b83\u6ca1\u6709\u663e\u793a\u9519\u8bef\u63d0\u793a&#xff0c;\u53ea\u662f\u9759\u9ed8\u8fd4\u56de\u3002\u5bf9\u4e8e\u5f53\u524d\u7b80\u6d01\u5de5\u5177\u9875\u6765\u8bf4\u53ef\u4ee5\u63a5\u53d7&#xff1b;\u5982\u679c\u8981\u589e\u5f3a\u53ef\u7528\u6027&#xff0c;\u53ef\u4ee5\u5728\u5f39\u7a97\u5185\u589e\u52a0\u63d0\u793a\u72b6\u6001&#xff0c;\u4f8b\u5982 &#064;State errorText&#xff0c;\u4f46\u5f53\u524d\u6e90\u7801\u6ca1\u6709\u505a\u3002<\/p>\n<h3>13. \u65b0\u5efa\u7b14\u8bb0&#xff1a;\u5148\u66f4\u65b0\u9875\u9762\u72b6\u6001&#xff0c;\u518d\u4fdd\u5b58\u672c\u5730<\/h3>\n<p>\u7b14\u8bb0\u9875\u901a\u8fc7 CustomDialogController \u63a5\u6536\u4fdd\u5b58\u56de\u8c03&#xff1a;<\/p>\n<p>private editorController: CustomDialogController &#061; new CustomDialogController({<br \/>\n  builder: NoteEditorDialog({<br \/>\n    onSave: (title: string, content: string, category: string) &#061;&gt; {<br \/>\n      this.addNote(title, content, category)<br \/>\n    }<br \/>\n  }),<br \/>\n  autoCancel: true,<br \/>\n  customStyle: true<br \/>\n})<\/p>\n<p>\u65b0\u589e\u903b\u8f91&#xff1a;<\/p>\n<p>private async addNote(title: string, content: string, category: string): Promise&lt;void&gt; {<br \/>\n  const now &#061; new Date()<br \/>\n  const pad &#061; (n: number): string &#061;&gt; (n &lt; 10 ? &#039;0&#039; &#043; n : &#039;&#039; &#043; n)<br \/>\n  const ts &#061; now.getFullYear() &#043; &#039;-&#039; &#043; pad(now.getMonth() &#043; 1) &#043; &#039;-&#039; &#043; pad(now.getDate())<br \/>\n  const item: NoteItem &#061; {<br \/>\n    id: &#039;n_&#039; &#043; now.getTime(),<br \/>\n    title,<br \/>\n    content,<br \/>\n    timestamp: ts,<br \/>\n    category<br \/>\n  }<br \/>\n  this.notes &#061; [item, &#8230;this.notes]<br \/>\n  await DataStore.saveNotes&lt;NoteItem&gt;(this.notes)<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u6709\u51e0\u4e2a\u7ec6\u8282&#xff1a;<\/p>\n<ul>\n<li>id \u4f7f\u7528\u65f6\u95f4\u6233\u524d\u7f00&#xff0c;\u9002\u5408\u672c\u5730\u8f7b\u91cf\u8bb0\u5f55&#xff1b;<\/li>\n<li>timestamp \u53ea\u4fdd\u5b58\u65e5\u671f&#xff0c;\u4e0d\u4fdd\u5b58\u5177\u4f53\u65f6\u5206\u79d2&#xff1b;<\/li>\n<li>\u65b0\u7b14\u8bb0\u63d2\u5165\u6570\u7ec4\u5934\u90e8&#xff0c;\u5217\u8868\u4f18\u5148\u5c55\u793a\u6700\u8fd1\u521b\u5efa\u7684\u8bb0\u5f55&#xff1b;<\/li>\n<li>\u4fdd\u5b58\u7684\u662f\u6574\u4e2a notes \u6570\u7ec4&#xff0c;\u4e0d\u662f append \u5355\u6761\u3002<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u5f53\u524d\u8bb0\u5f55\u91cf\u4e0d\u4f1a\u5f88\u5927&#xff0c;\u4fdd\u5b58\u6574\u4e2a\u6570\u7ec4\u662f\u7b80\u5355\u6709\u6548\u7684\u3002\u8bb0\u5f55\u91cf\u53d8\u5927\u540e&#xff0c;\u5c31\u8981\u8003\u8651\u5206\u9875\u3001\u589e\u91cf\u5199\u5165\u548c\u7d22\u5f15\u3002<\/p>\n<h3>14. \u5220\u9664\u7b14\u8bb0&#xff1a;\u7f16\u8f91\u6001\u63a7\u5236\u5220\u9664\u5165\u53e3<\/h3>\n<p>\u5220\u9664\u903b\u8f91\u4e5f\u5f88\u76f4\u63a5&#xff1a;<\/p>\n<p>private async removeNote(id: string): Promise&lt;void&gt; {<br \/>\n  this.notes &#061; this.notes.filter(n &#061;&gt; n.id !&#061;&#061; id)<br \/>\n  await DataStore.saveNotes&lt;NoteItem&gt;(this.notes)<br \/>\n}<\/p>\n<p>UI \u4e0a\u53ea\u6709\u8fdb\u5165\u7f16\u8f91\u6001\u624d\u663e\u793a\u5220\u9664\u6309\u94ae&#xff1a;<\/p>\n<p>Text(this.isEditing ? &#039;\u5b8c\u6210&#039; : &#039;\u7f16\u8f91&#039;)<br \/>\n  .fontSize(14)<br \/>\n  .fontColor(AppColors.PRIMARY)<br \/>\n  .onClick(() &#061;&gt; { this.isEditing &#061; !this.isEditing })<\/p>\n<p>\u5217\u8868\u9879\u91cc&#xff1a;<\/p>\n<p>if (this.isEditing) {<br \/>\n  Text(&#039;\u2715&#039;)<br \/>\n    .fontSize(16)<br \/>\n    .fontColor(AppColors.ACCENT_RED)<br \/>\n    .onClick(() &#061;&gt; { this.removeNote(note.id) })<br \/>\n}<\/p>\n<p>\u8fd9\u907f\u514d\u4e86\u666e\u901a\u6d4f\u89c8\u72b6\u6001\u4e0b\u8bef\u89e6\u5220\u9664\u3002\u5f53\u524d\u6e90\u7801\u6ca1\u6709\u4e8c\u6b21\u786e\u8ba4&#xff0c;\u4e5f\u6ca1\u6709\u64a4\u9500\u3002\u5bf9\u4e8e\u5b66\u4e60\u7b14\u8bb0\u8fd9\u79cd\u7528\u6237\u8f93\u5165\u5185\u5bb9&#xff0c;\u540e\u7eed\u5982\u679c\u8981\u63d0\u9ad8\u5b89\u5168\u6027&#xff0c;\u5e94\u52a0\u786e\u8ba4\u5f39\u7a97\u6216\u64a4\u9500\u63d0\u793a\u3002\u5f53\u524d\u6587\u7ae0\u53ea\u6309\u5b9e\u9645\u6e90\u7801\u63cf\u8ff0\u201c\u7f16\u8f91\u6001\u5220\u9664\u5e76\u6301\u4e45\u5316\u201d\u3002<\/p>\n<h3>15. DataStore \u7684\u7edf\u8ba1\u5feb\u7167&#xff1a;\u6536\u85cf\u6570\u4f1a\u540c\u6b65\u5230 AppStorage<\/h3>\n<p>DataStore \u91cc\u8fd8\u6709\u4e00\u5c42\u7edf\u8ba1\u901a\u77e5&#xff1a;<\/p>\n<p>private static notifyStatsChanged(key: string, value: string | number): void {<br \/>\n  if (STAT_KEYS.indexOf(key) &lt; 0) return<br \/>\n  if (key &#061;&#061;&#061; &#039;favorite_experiments&#039;) {<br \/>\n    try {<br \/>\n      const ids &#061; JSON.parse(value as string) as string[]<br \/>\n      AppStorage.setOrCreate&lt;number&gt;(FAVORITE_COUNT_KEY, ids.length)<br \/>\n    } catch (_) {<br \/>\n      AppStorage.setOrCreate&lt;number&gt;(FAVORITE_COUNT_KEY, 0)<br \/>\n    }<br \/>\n  }<br \/>\n  DataStore.statsVersion&#043;&#043;<br \/>\n  AppStorage.setOrCreate&lt;number&gt;(STATS_VERSION_KEY, DataStore.statsVersion)<br \/>\n}<\/p>\n<p>\u8fd9\u8bf4\u660e\u4fdd\u5b58\u6536\u85cf\u540e&#xff0c;\u4e0d\u53ea\u662f Preferences \u53d8\u5316&#xff0c;AppStorage \u4e2d\u7684\u6536\u85cf\u6570\u91cf\u5feb\u7167\u4e5f\u4f1a\u66f4\u65b0\u3002\u8fd9\u6837\u201c\u6211\u7684\u201d\u9875\u9762\u6216\u5176\u4ed6\u7edf\u8ba1\u7ec4\u4ef6\u53ef\u4ee5\u4e0d\u91cd\u65b0\u89e3\u6790 JSON&#xff0c;\u4e5f\u80fd\u8bfb\u5230\u6536\u85cf\u6570\u91cf\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f&#xff1a;user_notes \u4e0d\u5728 STAT_KEYS \u4e2d&#xff0c;\u56e0\u6b64\u4fdd\u5b58\u7b14\u8bb0\u4e0d\u4f1a\u89e6\u53d1\u7edf\u8ba1\u5feb\u7167\u3002\u8fd9\u4e5f\u662f\u6e90\u7801\u8fb9\u754c\u4e4b\u4e00\u3002\u6587\u7ae0\u4e0d\u80fd\u5199\u6210\u201c\u7b14\u8bb0\u6570\u91cf\u540c\u6b65\u5230\u5168\u5c40\u7edf\u8ba1\u201d&#xff0c;\u56e0\u4e3a\u5f53\u524d\u4ee3\u7801\u6ca1\u6709\u8fd9\u6837\u7684\u952e\u3002<\/p>\n<p><img decoding=\"async\" alt=\"\u7ed3\u6784\u56fe\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260811173245-6a7b5cbd2f83c.png\" \/><\/p>\n<h3>16. \u6e05\u7406\u672c\u5730\u6570\u636e&#xff1a;\u6536\u85cf\u3001\u8bb0\u5f55\u548c\u7b14\u8bb0\u4e00\u8d77\u6e05<\/h3>\n<p>LOCAL_DATA_KEYS \u5305\u542b&#xff1a;<\/p>\n<p>const LOCAL_DATA_KEYS: string[] &#061; [<br \/>\n  &#039;favorite_experiments&#039;,<br \/>\n  &#039;experiment_records&#039;,<br \/>\n  &#039;user_notes&#039;,<br \/>\n  &#039;experiment_count&#039;,<br \/>\n  &#039;learning_seconds&#039;,<br \/>\n  &#039;learning_minutes&#039;<br \/>\n]<\/p>\n<p>clearCache() \u4f1a\u5220\u9664\u8fd9\u4e9b\u952e&#xff0c;\u5e76\u91cd\u7f6e\u7edf\u8ba1\u5feb\u7167&#xff1a;<\/p>\n<p>static async clearCache(): Promise&lt;void&gt; {<br \/>\n  if (!DataStore.prefInstance) return<br \/>\n  for (let i &#061; 0; i &lt; LOCAL_DATA_KEYS.length; i&#043;&#043;) {<br \/>\n    const key &#061; LOCAL_DATA_KEYS[i]<br \/>\n    try {<br \/>\n      await DataStore.prefInstance.delete(key)<br \/>\n    } catch (_) {<br \/>\n    }<br \/>\n  }<br \/>\n  try {<br \/>\n    await DataStore.prefInstance.flush()<br \/>\n  } catch (_) {<br \/>\n  }<br \/>\n  AppStorage.setOrCreate&lt;number&gt;(FAVORITE_COUNT_KEY, 0)<br \/>\n  AppStorage.setOrCreate&lt;number&gt;(EXPERIMENT_COUNT_KEY, 0)<br \/>\n  AppStorage.setOrCreate&lt;number&gt;(LEARNING_SECONDS_KEY, 0)<br \/>\n}<\/p>\n<p>\u8fd9\u610f\u5473\u7740\u6536\u85cf\u548c\u7b14\u8bb0\u90fd\u5c5e\u4e8e\u201c\u672c\u5730\u7f13\u5b58\/\u672c\u5730\u5b66\u4e60\u6570\u636e\u201d\u7684\u4e00\u90e8\u5206\u3002\u6e05\u7406\u52a8\u4f5c\u4f1a\u5f71\u54cd\u7528\u6237\u6536\u85cf\u548c\u7b14\u8bb0&#xff0c;\u4ea7\u54c1\u6587\u6848\u5fc5\u987b\u660e\u786e\u3002\u5f53\u524d\u8fd9\u7bc7\u6587\u7ae0\u53ea\u8ba8\u8bba\u6570\u636e\u5c42\u5b9e\u73b0&#xff0c;\u4e0d\u5047\u8bbe\u5df2\u6709\u5b8c\u6574\u7684\u6e05\u7406\u786e\u8ba4\u6d41\u7a0b\u3002<\/p>\n<h3>17. \u9002\u5408\u8fc1\u79fb\u7684\u670d\u52a1\u8fb9\u754c<\/h3>\n<p>\u5f53\u524d\u6e90\u7801\u4e2d DataStore \u5df2\u7ecf\u627f\u62c5\u4e86\u6570\u636e\u5165\u53e3\u804c\u8d23&#xff0c;\u4f46\u6536\u85cf\u548c\u7b14\u8bb0\u4e1a\u52a1\u89c4\u5219\u4ecd\u5206\u6563\u5728\u9875\u9762\u91cc\u3002\u5982\u679c\u540e\u7eed\u529f\u80fd\u53d8\u591a&#xff0c;\u53ef\u4ee5\u7ee7\u7eed\u62bd\u51fa\u670d\u52a1\u5c42&#xff1a;<\/p>\n<p>export class FavoriteService {<br \/>\n  static async toggleExperiment(expId: string): Promise&lt;boolean&gt; {<br \/>\n    const ids &#061; await DataStore.loadFavorites()<br \/>\n    const index &#061; ids.indexOf(expId)<br \/>\n    if (index &gt;&#061; 0) {<br \/>\n      ids.splice(index, 1)<br \/>\n      await DataStore.saveFavorites(ids)<br \/>\n      return false<br \/>\n    }<br \/>\n    ids.push(expId)<br \/>\n    await DataStore.saveFavorites(ids)<br \/>\n    return true<br \/>\n  }<br \/>\n}<\/p>\n<p>\u9875\u9762\u53ef\u4ee5\u6539\u6210&#xff1a;<\/p>\n<p>private async toggleFavorite(): Promise&lt;void&gt; {<br \/>\n  this.isFavorite &#061; await FavoriteService.toggleExperiment(this.expId)<br \/>\n}<\/p>\n<p>\u8fd9\u6837\u9875\u9762\u53ea\u5173\u5fc3\u6309\u94ae\u72b6\u6001&#xff0c;\u6536\u85cf\u6570\u7ec4\u7684\u8bfb\u5199\u3001\u53bb\u91cd\u3001\u6301\u4e45\u5316\u90fd\u653e\u5230\u670d\u52a1\u91cc\u3002\u5f53\u524d\u6e90\u7801\u8fd8\u6ca1\u6709\u8fd9\u4e2a\u670d\u52a1\u5c42&#xff0c;\u56e0\u6b64\u8fd9\u662f\u540e\u7eed\u53ef\u8fc1\u79fb\u5199\u6cd5&#xff0c;\u4e0d\u662f\u73b0\u6709\u5b9e\u73b0\u3002<\/p>\n<h3>18. \u9a8c\u8bc1\u6e05\u5355&#xff1a;\u4ece\u5b9e\u9a8c\u9875\u3001\u6536\u85cf\u9875\u3001\u7b14\u8bb0\u9875\u5206\u522b\u6d4b<\/h3>\n<p>\u9a8c\u8bc1\u6536\u85cf\u94fe\u8def&#xff1a;<\/p>\n<table>\n<tr>\u64cd\u4f5c\u9884\u671f<\/tr>\n<tbody>\n<tr>\n<td>\u4ece\u5b9e\u9a8c\u5217\u8868\u8fdb\u5165\u67d0\u4e2a\u5b9e\u9a8c\u6a21\u62df\u9875<\/td>\n<td>\u53f3\u4e0a\u89d2\u6536\u85cf\u6309\u94ae\u6839\u636e\u672c\u5730 ID \u72b6\u6001\u663e\u793a<\/td>\n<\/tr>\n<tr>\n<td>\u70b9\u51fb\u6536\u85cf\u6309\u94ae<\/td>\n<td>favorite_experiments \u589e\u52a0\u5f53\u524d expId<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u6211\u7684\u6536\u85cf\u9875<\/td>\n<td>\u5217\u8868\u51fa\u73b0\u8be5\u5b9e\u9a8c\u5361\u7247<\/td>\n<\/tr>\n<tr>\n<td>\u518d\u6b21\u8fdb\u5165\u5b9e\u9a8c\u9875\u53d6\u6d88\u6536\u85cf<\/td>\n<td>\u672c\u5730 ID \u88ab\u79fb\u9664&#xff0c;\u6536\u85cf\u9875 reload \u540e\u4e0d\u663e\u793a<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u578b\u5220\u9664\u67d0\u5b9e\u9a8c ID<\/td>\n<td>\u6536\u85cf\u9875\u8df3\u8fc7\u627e\u4e0d\u5230\u7684 ID&#xff0c;\u4e0d\u6e32\u67d3\u7a7a\u5361<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9a8c\u8bc1\u7b14\u8bb0\u94fe\u8def&#xff1a;<\/p>\n<table>\n<tr>\u64cd\u4f5c\u9884\u671f<\/tr>\n<tbody>\n<tr>\n<td>\u6253\u5f00\u6211\u7684\u7b14\u8bb0&#xff0c;\u5217\u8868\u4e3a\u7a7a<\/td>\n<td>\u663e\u793a\u201c\u6682\u65e0\u7b14\u8bb0\u201d\u7a7a\u6001<\/td>\n<\/tr>\n<tr>\n<td>\u70b9\u51fb\u65b0\u5efa\u7b14\u8bb0&#xff0c;\u6807\u9898\u6216\u5185\u5bb9\u4e3a\u7a7a\u4fdd\u5b58<\/td>\n<td>\u4e0d\u65b0\u589e\u8bb0\u5f55<\/td>\n<\/tr>\n<tr>\n<td>\u8f93\u5165\u6807\u9898\u3001\u5185\u5bb9\u3001\u5206\u7c7b\u540e\u4fdd\u5b58<\/td>\n<td>\u65b0\u7b14\u8bb0\u63d2\u5165\u5217\u8868\u9876\u90e8<\/td>\n<\/tr>\n<tr>\n<td>\u9000\u51fa\u518d\u8fdb\u5165\u7b14\u8bb0\u9875<\/td>\n<td>DataStore.loadNotes() \u91cd\u65b0\u52a0\u8f7d\u672c\u5730\u6570\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u70b9\u51fb\u7f16\u8f91&#xff0c;\u518d\u70b9\u5220\u9664<\/td>\n<td>\u8be5\u7b14\u8bb0\u4ece\u5217\u8868\u548c\u672c\u5730\u6570\u7ec4\u79fb\u9664<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9a8c\u8bc1\u6570\u636e\u5c42&#xff1a;<\/p>\n<table>\n<tr>\u64cd\u4f5c\u9884\u671f<\/tr>\n<tbody>\n<tr>\n<td>\u521d\u59cb\u5316 DataStore \u5931\u8d25<\/td>\n<td>\u9875\u9762\u8bfb\u53d6\u9ed8\u8ba4\u7a7a\u6570\u7ec4&#xff0c;\u4e0d\u5d29\u6e83<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u85cf JSON \u635f\u574f<\/td>\n<td>loadFavorites() \u8fd4\u56de\u7a7a\u6570\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u7b14\u8bb0 JSON \u635f\u574f<\/td>\n<td>loadNotes() \u8fd4\u56de\u7a7a\u6570\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u6e05\u7406\u7f13\u5b58<\/td>\n<td>\u6536\u85cf\u3001\u5b9e\u9a8c\u8bb0\u5f55\u3001\u7b14\u8bb0\u548c\u5b66\u4e60\u65f6\u957f\u952e\u88ab\u5220\u9664<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>19. \u5e38\u89c1\u95ee\u9898\u4e0e\u4fee\u590d\u65b9\u5411<\/h3>\n<table>\n<tr>\u95ee\u9898\u53ef\u80fd\u539f\u56e0\u4fee\u590d\u65b9\u5411<\/tr>\n<tbody>\n<tr>\n<td>\u6536\u85cf\u6309\u94ae\u72b6\u6001\u4e0d\u5bf9<\/td>\n<td>\u8fdb\u5165\u5b9e\u9a8c\u9875\u524d\u6ca1\u6709\u66f4\u65b0 expId<\/td>\n<td>\u5148\u8bfb\u53d6\u8def\u7531\u53c2\u6570&#xff0c;\u518d\u8c03\u7528 loadFavoriteState()<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u85cf\u9875\u8fd4\u56de\u540e\u4e0d\u5237\u65b0<\/td>\n<td>\u53ea\u5728\u9996\u6b21\u8fdb\u5165\u52a0\u8f7d\u6570\u636e<\/td>\n<td>\u5728 onPageShow() \u4e2d\u4e5f\u8c03\u7528 reload()<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u85cf\u5217\u8868\u51fa\u73b0\u7a7a\u767d\u5361<\/td>\n<td>\u672c\u5730 ID \u627e\u4e0d\u5230\u6a21\u578b<\/td>\n<td>\u6620\u5c04\u65f6\u8fc7\u6ee4 found \u4e3a\u7a7a\u7684\u8bb0\u5f55<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u7b14\u8bb0\u540e\u91cd\u8fdb\u53c8\u51fa\u73b0<\/td>\n<td>\u53ea\u6539\u4e86 notes \u72b6\u6001&#xff0c;\u6ca1\u6709\u4fdd\u5b58<\/td>\n<td>\u5220\u9664\u540e\u8c03\u7528 DataStore.saveNotes()<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a\u7b14\u8bb0\u88ab\u4fdd\u5b58<\/td>\n<td>\u5f39\u7a97\u4fdd\u5b58\u524d\u6ca1\u6709 trim() \u6821\u9a8c<\/td>\n<td>\u4fdd\u5b58\u524d\u62e6\u622a\u7a7a\u6807\u9898\u548c\u7a7a\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u85cf\u6570\u91cf\u7edf\u8ba1\u4e0d\u53d8<\/td>\n<td>\u4fdd\u5b58\u540e\u6ca1\u6709\u89e6\u53d1\u7edf\u8ba1\u5feb\u7167<\/td>\n<td>\u901a\u8fc7 putString() \u8c03\u7528 notifyStatsChanged()<\/td>\n<\/tr>\n<tr>\n<td>\u6e05\u7406\u7f13\u5b58\u540e UI \u8fd8\u663e\u793a\u65e7\u6570\u91cf<\/td>\n<td>AppStorage \u5feb\u7167\u6ca1\u5f52\u96f6<\/td>\n<td>clearCache() \u540c\u6b65\u91cd\u7f6e\u7edf\u8ba1\u952e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e9b\u95ee\u9898\u90fd\u80fd\u4ece\u5f53\u524d\u6e90\u7801\u91cc\u627e\u5230\u5bf9\u5e94\u7684\u9632\u7ebf\u3002\u5199\u8fd9\u7c7b\u9875\u9762\u65f6&#xff0c;\u4e0d\u8981\u53ea\u770b\u6309\u94ae\u80fd\u4e0d\u80fd\u70b9&#xff0c;\u8fd8\u8981\u68c0\u67e5\u9875\u9762\u8fd4\u56de\u3001\u91cd\u65b0\u8fdb\u5165\u3001\u6570\u636e\u635f\u574f\u548c\u6e05\u7406\u7f13\u5b58\u540e\u7684\u72b6\u6001\u3002<\/p>\n<h3>20. \u5c0f\u7ed3&#xff1a;\u672c\u5730\u5b66\u4e60\u8bb0\u5f55\u8981\u9760\u660e\u786e\u7684\u6570\u636e\u5f52\u5c5e<\/h3>\n<p>05-10 \u6536\u85cf\u4e0e\u7b14\u8bb0 \u7684\u6e90\u7801\u5b9e\u73b0\u5e76\u4e0d\u590d\u6742&#xff0c;\u4f46\u8fb9\u754c\u5f88\u6e05\u695a\u3002<\/p>\n<p>\u6536\u85cf\u5c5e\u4e8e\u5b9e\u9a8c\u7ef4\u5ea6&#xff1a;ExperimentSimPage \u5207\u6362\u6536\u85cf\u72b6\u6001&#xff0c;DataStore \u4fdd\u5b58 favorite_experiments&#xff0c;FavoritesPage \u91cd\u65b0\u52a0\u8f7d ID \u5e76\u6620\u5c04\u5230\u5b9e\u9a8c\u6a21\u578b\u3002<\/p>\n<p>\u7b14\u8bb0\u5c5e\u4e8e\u7528\u6237\u624b\u52a8\u8bb0\u5f55&#xff1a;NoteEditorDialog \u6536\u96c6\u6807\u9898\u3001\u5185\u5bb9\u548c\u5206\u7c7b&#xff0c;NotesPage \u751f\u6210 NoteItem&#xff0c;DataStore \u4fdd\u5b58 user_notes \u6570\u7ec4\u3002<\/p>\n<p>\u672c\u5730\u6570\u636e\u5c5e\u4e8e Preferences&#xff1a;DataStore \u7edf\u4e00\u5c01\u88c5\u8bfb\u5199\u3001JSON \u89e3\u6790\u3001\u9ed8\u8ba4\u503c\u515c\u5e95\u3001\u7edf\u8ba1\u5feb\u7167\u548c\u7f13\u5b58\u6e05\u7406\u3002\u9875\u9762\u4e0d\u76f4\u63a5\u64cd\u4f5c Preferences&#xff0c;\u8fd9\u8ba9 UI \u903b\u8f91\u4fdd\u6301\u7b80\u5355\u3002<\/p>\n<p>\u5f53\u524d\u6e90\u7801\u652f\u6301\u5b9e\u9a8c\u6536\u85cf\u4e0e\u624b\u52a8\u5b66\u4e60\u7b14\u8bb0\u7684\u672c\u5730\u6301\u4e45\u5316&#xff1b;\u6ca1\u6709\u77e5\u8bc6\u8be6\u60c5\u6536\u85cf\u3001\u7b14\u8bb0\u81ea\u52a8\u540c\u6b65\u3001\u4e91\u540c\u6b65\u6216\u8d26\u53f7\u4f53\u7cfb\u3002\u628a\u8fd9\u4e2a\u8fb9\u754c\u5199\u6e05\u695a&#xff0c;\u662f\u6280\u672f\u6587\u7ae0\u53ef\u590d\u6838\u7684\u524d\u63d0&#xff0c;\u4e5f\u662f\u540e\u7eed\u7ee7\u7eed\u6269\u5c55\u670d\u52a1\u5c42\u3001\u540c\u6b65\u5c42\u6216\u641c\u7d22\u80fd\u529b\u65f6\u7684\u5de5\u7a0b\u8d77\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\u3002\u672c\u6587\u9762\u5411 HarmonyOS 5.0 \u53ca\u4ee5\u4e0a\u7248\u672c&#xff0c;\u57fa\u4e8e \u7ec6\u80de\u5de5\u574a \u9879\u76ee\u771f\u5b9e\u6e90\u7801\u5c55\u5f00&#xff0c;\u6e90\u7801\u6839\u76ee\u5f55\u4e3a D:\\\\huawei\\\\one14-9\u3002\u672c\u6587\u91cd\u70b9\u590d\u6838\u8fd9\u4e9b\u6587\u4ef6&#xff1a;entry\/src\/main\/ets\/views\/experiment\/ExperimentSimPage.etsentry\/src\/main\/ets\/views\/mine\/FavoritesPage.etsentry\/src\/main\/ets\/views\/<\/p>\n","protected":false},"author":2,"featured_media":93145,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10283,10658,4362,280,2754],"topic":[],"class_list":["post-93148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-preferences","tag-10658","tag-arkts","tag-harmonyos","tag-2754"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/93148.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\u3002\u672c\u6587\u9762\u5411 HarmonyOS 5.0 \u53ca\u4ee5\u4e0a\u7248\u672c&#xff0c;\u57fa\u4e8e \u7ec6\u80de\u5de5\u574a \u9879\u76ee\u771f\u5b9e\u6e90\u7801\u5c55\u5f00&#xff0c;\u6e90\u7801\u6839\u76ee\u5f55\u4e3a D:\\huawei\\one14-9\u3002\u672c\u6587\u91cd\u70b9\u590d\u6838\u8fd9\u4e9b\u6587\u4ef6&#xff1a;entry\/src\/main\/ets\/views\/experiment\/ExperimentSimPage.etsentry\/src\/main\/ets\/views\/mine\/FavoritesPage.etsentry\/src\/main\/ets\/views\/\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/93148.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-11T17:32:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260811173243-6a7b5cbbcac33.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/93148.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/93148.html\",\"name\":\"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-11T17:32:46+00:00\",\"dateModified\":\"2026-08-11T17:32:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/93148.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/93148.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/93148.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/93148.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u90e8\u5206\u5185\u5bb9\u7531AI\u8f85\u52a9\u751f\u6210\u3002\u672c\u6587\u9762\u5411 HarmonyOS 5.0 \u53ca\u4ee5\u4e0a\u7248\u672c&#xff0c;\u57fa\u4e8e \u7ec6\u80de\u5de5\u574a \u9879\u76ee\u771f\u5b9e\u6e90\u7801\u5c55\u5f00&#xff0c;\u6e90\u7801\u6839\u76ee\u5f55\u4e3a D:\\huawei\\one14-9\u3002\u672c\u6587\u91cd\u70b9\u590d\u6838\u8fd9\u4e9b\u6587\u4ef6&#xff1a;entry\/src\/main\/ets\/views\/experiment\/ExperimentSimPage.etsentry\/src\/main\/ets\/views\/mine\/FavoritesPage.etsentry\/src\/main\/ets\/views\/","og_url":"https:\/\/www.wsisp.com\/helps\/93148.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-11T17:32:46+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260811173243-6a7b5cbbcac33.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/93148.html","url":"https:\/\/www.wsisp.com\/helps\/93148.html","name":"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-11T17:32:46+00:00","dateModified":"2026-08-11T17:32:46+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/93148.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/93148.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/93148.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u7ec6\u80de\u5de5\u574a\uff5c10\u3011HarmonyOS ArkTS \u6536\u85cf\u4e0e\u7b14\u8bb0\u5b9e\u6218\uff1a\u628a\u5b9e\u9a8c\u6536\u85cf\u548c\u672c\u5730\u7b14\u8bb0\u5199\u8fdb Preferences"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/93148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=93148"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/93148\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/93145"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=93148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=93148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=93148"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=93148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}