From a745c37f90e57cb7a6437e7d30850b193c850c35 Mon Sep 17 00:00:00 2001 From: kongxiaojun Date: Wed, 7 Aug 2024 14:47:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96Taro=20Storage?= =?UTF-8?q?=E7=BC=93=E5=AD=98=EF=BC=8C=E8=A7=A3=E5=86=B3=E8=B7=A8Web?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E4=BF=AE=E6=94=B9Storage=E5=90=8E=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E4=B8=8D=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/mini-program-example/src/pages/index/index.tsx | 2 +- .../src/api/apis/NativeApi.ts | 8 +++++++- .../src/api/apis/harmony-native/ApiDecorator.ts | 2 +- .../api/apis/harmony-native/StorageCacheAndSyncProxy.ts | 9 +++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/mini-program-example/src/pages/index/index.tsx b/examples/mini-program-example/src/pages/index/index.tsx index 135869ac3e75..b7be9d7d7661 100644 --- a/examples/mini-program-example/src/pages/index/index.tsx +++ b/examples/mini-program-example/src/pages/index/index.tsx @@ -60,7 +60,7 @@ export default function Index() { onClick={()=>{ nativeApi.harmonyNavigateTo({ indexHtmlPath: '/spa/new/index.html', - taroPath: 'pages/api/index/index' + taroPath: '/pages/api/index/index' }) }}> 单实例(单SPA):接口列表页 diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts index e1ed2f0cc34f..28e7a4f8ee17 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts @@ -1,6 +1,6 @@ // import {timeLog} from "./NativeApiLog"; import { syncApiCache } from './harmony-native/ApiCache' -import { asyncAndNotRelease, asyncAndRelease, syncAndRelease } from './harmony-native/ApiDecorator' +import { asyncAndNotRelease, asyncAndRelease, syncAndNotRelease, syncAndRelease } from './harmony-native/ApiDecorator' import { storageCacheAndSyncProxy } from './harmony-native/StorageCacheAndSyncProxy' import { NativeDataChangeListener, SyncCacheProxyHandler } from './NativeApiSyncCacheProxy' @@ -627,6 +627,12 @@ export class NativeApi { exitMiniProgram (option?: any): any { return option } + + @(syncAndNotRelease) + onStorageStatusChange (_options: any): void {} + + @(syncAndNotRelease) + offStorageStatusChange (_options: any): void {} } export interface Status { diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts index 06badb60464c..99b13e109a6e 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts @@ -2,7 +2,7 @@ export const syncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target) // @ts-ignore -// const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target) +export const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target) // @ts-ignore export const asyncAndRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: true, autoRelease: true }) || (target => target) diff --git a/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/StorageCacheAndSyncProxy.ts b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/StorageCacheAndSyncProxy.ts index c2edd9ae56c7..93f0d9e06b07 100644 --- a/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/StorageCacheAndSyncProxy.ts +++ b/packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/StorageCacheAndSyncProxy.ts @@ -1,3 +1,4 @@ +const TYPE_STORAGE_UPDATE_EVENT_CLEAR = 'TYPE_STORAGE_UPDATE_EVENT_CLEAR' class ProxyHandler { private cacheMap: Map private pageHasShowed: boolean = false @@ -28,6 +29,14 @@ class ProxyHandler { }) }, 2000) }) + + native.onStorageStatusChange((type: string, key: string) => { + if (type === TYPE_STORAGE_UPDATE_EVENT_CLEAR) { + this.cacheMap.clear() + } else { + this.cacheMap.delete(key) + } + }) } get (target, propKey, receiver) { From d81023de7f623dc0586155dd94d4372a63cee1c4 Mon Sep 17 00:00:00 2001 From: kongxiaojun Date: Wed, 7 Aug 2024 15:53:53 +0800 Subject: [PATCH 2/3] fix: examples update --- .../mini-program-example/src/pages/index/index.tsx | 13 ++++++------- examples/mini-program-example/src/util/nativeApi.ts | 13 +++++++------ .../build/config/harmony-definition.json | 7 +------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/mini-program-example/src/pages/index/index.tsx b/examples/mini-program-example/src/pages/index/index.tsx index b7be9d7d7661..e19348e697b8 100644 --- a/examples/mini-program-example/src/pages/index/index.tsx +++ b/examples/mini-program-example/src/pages/index/index.tsx @@ -49,21 +49,20 @@ export default function Index() { ) diff --git a/examples/mini-program-example/src/util/nativeApi.ts b/examples/mini-program-example/src/util/nativeApi.ts index f9d8ed5af7c5..36f7576fa80d 100644 --- a/examples/mini-program-example/src/util/nativeApi.ts +++ b/examples/mini-program-example/src/util/nativeApi.ts @@ -1,13 +1,14 @@ // @ts-ignore -const decorator = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target) +const sync = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target) // @proxyClassSign('') class NativeApi { - // @ts-ignore - @decorator - harmonyNavigateTo(options: any) { - return options - } + @sync + navigateToTaroHybrid(_options: any) {} + + + @sync + navigateToNative(_options: any){} } const nativeApi = new NativeApi() diff --git a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json index 817537f12991..789b05edaae3 100644 --- a/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json +++ b/packages/taro-platform-harmony-hybrid/build/config/harmony-definition.json @@ -757,12 +757,7 @@ "TARO_ENV": true, "USER_DATA_PATH": true }, - "exitMiniProgram": { - "object": { - "url": true, - "events": true - } - }, + "exitMiniProgram": true, "exitVoIPChat": false, "faceDetect": false, "faceVerifyForPay": false, From 936c61e4a25d6fa79a514661a1993f39ec4e838b Mon Sep 17 00:00:00 2001 From: kongxiaojun Date: Wed, 7 Aug 2024 17:28:52 +0800 Subject: [PATCH 3/3] fix: examples update --- examples/mini-program-example/src/pages/index/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mini-program-example/src/pages/index/index.tsx b/examples/mini-program-example/src/pages/index/index.tsx index e19348e697b8..0cf6a80a890d 100644 --- a/examples/mini-program-example/src/pages/index/index.tsx +++ b/examples/mini-program-example/src/pages/index/index.tsx @@ -62,7 +62,7 @@ export default function Index() { taroPath: '/pages/index/index' }) }}> - 单实例(单SPA):首页 + 多实例(单SPA):首页 )