浏览代码

留下接口供实施动态设置裁切图缓存大小

Michael Wang 4 年之前
父节点
当前提交
18ed677dff
共有 3 个文件被更改,包括 17 次插入1 次删除
  1. 5 0
      index.html
  2. 10 0
      src/types/global.d.ts
  3. 2 1
      src/utils/utils.ts

+ 5 - 0
index.html

@@ -8,6 +8,11 @@
   </head>
   </head>
   <body>
   <body>
     <div id="app"></div>
     <div id="app"></div>
+    <script>
+      window.APP_OPTIONS = {
+        OBJECT_URLS_MAP_MAX_SIZE: undefined,
+      };
+    </script>
     <script type="module" src="/src/main.ts"></script>
     <script type="module" src="/src/main.ts"></script>
   </body>
   </body>
 </html>
 </html>

+ 10 - 0
src/types/global.d.ts

@@ -20,3 +20,13 @@ declare module "axios/index" {
     setGlobalMask?: boolean | false;
     setGlobalMask?: boolean | false;
   }
   }
 }
 }
+
+interface Option {
+  OBJECT_URLS_MAP_MAX_SIZE?: number;
+}
+
+declare global {
+  interface Window {
+    APP_OPTIONS: Option;
+  }
+}

+ 2 - 1
src/utils/utils.ts

@@ -45,7 +45,8 @@ export async function loadImage(url: string): Promise<HTMLImageElement> {
 
 
 // 存放裁切图的ObjectUrls
 // 存放裁切图的ObjectUrls
 let objectUrlMap = new Map<string, string>();
 let objectUrlMap = new Map<string, string>();
-const OBJECT_URLS_MAP_MAX_SIZE = 100;
+const OBJECT_URLS_MAP_MAX_SIZE =
+  window.APP_OPTIONS?.OBJECT_URLS_MAP_MAX_SIZE ?? 100;
 
 
 export async function getDataUrlForSliceConfig(
 export async function getDataUrlForSliceConfig(
   image: HTMLImageElement,
   image: HTMLImageElement,