From 0edc4bd930c97e3591615a6e396758f38a4f8d19 Mon Sep 17 00:00:00 2001 From: answershuto Date: Wed, 2 Aug 2023 16:34:07 +0800 Subject: [PATCH] feat: add bizID --- examples/cavans-project/src/pages/home.tsx | 4 +++- packages/cache-canvas/src/index.tsx | 14 +++++++++----- packages/cache-canvas/src/storage.tsx | 13 ++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/cavans-project/src/pages/home.tsx b/examples/cavans-project/src/pages/home.tsx index b8d8acf7ee..b27b8efec8 100644 --- a/examples/cavans-project/src/pages/home.tsx +++ b/examples/cavans-project/src/pages/home.tsx @@ -24,13 +24,15 @@ export default function Home() { setTimeout(() => { console.log('canvas paint ready!'); resolve(true); - }, 5000); + }, 10000); }); }; + return ( <>

Home Page

Promise; useCache?: Boolean; getSnapshot?: () => String; @@ -53,6 +54,7 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { fallback, style, className, + bizID = '', ...rest } = props; @@ -72,9 +74,11 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { } // Cache base64 string when canvas rendered. if (renderedCanvas && strBase64) { - Storage.setItem(cacheKey, strBase64); + Storage.setItem(cacheKey, strBase64, { + bizID, + }); } - }, [id, renderedCanvas, cacheKey, getSnapshot]); + }, [id, renderedCanvas, cacheKey, getSnapshot, bizID]); useImperativeHandle(ref, () => ({ cacheCanvasToStorage: cacheCanvasFunc, @@ -129,13 +133,13 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { { (typeof fallback === 'function') && (
{ fallback() @@ -156,7 +160,7 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { }); if (canIUse) { - const res = window.__megability_bridge__.syncCall('userKVStorage', 'getItem', { key: '${cacheKey}' }); + const res = window.__megability_bridge__.syncCall('userKVStorage', 'getItem', { key: '${cacheKey}', bizID: '${bizID}' }); if (res && res.statusCode === 0 && res.data && res.data.result) { base64Data = res.data.result; } diff --git a/packages/cache-canvas/src/storage.tsx b/packages/cache-canvas/src/storage.tsx index 3e03ab8f01..a674185717 100644 --- a/packages/cache-canvas/src/storage.tsx +++ b/packages/cache-canvas/src/storage.tsx @@ -1,7 +1,7 @@ const cache = {}; export const Storage = { - setItem: (key, value) => { + setItem: (key, value, { bizID = '' }) => { try { if ( typeof window !== 'undefined' && @@ -17,6 +17,7 @@ export const Storage = { const res = window.__megability_bridge__.syncCall('userKVStorage', 'setItem', { key, value, + bizID, }); if (res && res.statusCode === 0) { return; @@ -33,7 +34,7 @@ export const Storage = { console.error('Storage setItem error:', e); } }, - getItem: (key) => { + getItem: (key, { bizID = '' }) => { try { if ( typeof window !== 'undefined' && @@ -46,7 +47,13 @@ export const Storage = { }); if (canIUse) { - const res = window.__megability_bridge__.syncCall('userKVStorage', 'getItem', { key }); + const res = window.__megability_bridge__.syncCall( + 'userKVStorage', + 'getItem', + { + key, + bizID, + }); if (res && res.statusCode === 0 && res.data && res.data.result) { return res.data.result; }