فهرست منبع

修复 index.js ↔ dict.js 循环依赖导致的 TDZ 初始化错误

- 将 storage 抽离到独立 storage.js,断开 utils/index.js 与 utils/dict.js
  之间的循环引用
- 循环依赖导致 bundler 处理时 storage 在 TDZ 中被引用,触发
  "Cannot access before initialization"

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 14 ساعت پیش
والد
کامیت
268605e208
3فایلهای تغییر یافته به همراه27 افزوده شده و 46 حذف شده
  1. 1 1
      admin-h5/src/utils/dict.js
  2. 1 45
      admin-h5/src/utils/index.js
  3. 25 0
      admin-h5/src/utils/storage.js

+ 1 - 1
admin-h5/src/utils/dict.js

@@ -1,5 +1,5 @@
 import { getDataDictList } from '../api/dict.js'
-import { storage } from './index.js'
+import { storage } from './storage.js'
 
 const DICT_KEY = 'dicts'
 

+ 1 - 45
admin-h5/src/utils/index.js

@@ -32,51 +32,7 @@ export const showToast = (title, icon = 'none', duration = 2000) => {
   })
 }
 
-/**
- * 缓存工具类
- */
-export const storage = {
-  /**
-   * 设置缓存
-   * @param {string} key - 缓存键
-   * @param {any} value - 缓存值
-   */
-  set(key, value) {
-    if (typeof value === 'object') {
-      value = JSON.stringify(value)
-    }
-    uni.setStorageSync(key, value)
-  },
-
-  /**
-   * 获取缓存
-   * @param {string} key - 缓存键
-   * @returns {any} 缓存值
-   */
-  get(key) {
-    const value = uni.getStorageSync(key)
-    try {
-      return JSON.parse(value)
-    } catch (e) {
-      return value
-    }
-  },
-
-  /**
-   * 删除缓存
-   * @param {string} key - 缓存键
-   */
-  remove(key) {
-    uni.removeStorageSync(key)
-  },
-
-  /**
-   * 清空缓存
-   */
-  clear() {
-    uni.clearStorageSync()
-  }
-}
+export { storage } from './storage.js'
 
 /**
  * 时间格式化

+ 25 - 0
admin-h5/src/utils/storage.js

@@ -0,0 +1,25 @@
+export const storage = {
+  set(key, value) {
+    if (typeof value === 'object') {
+      value = JSON.stringify(value)
+    }
+    uni.setStorageSync(key, value)
+  },
+
+  get(key) {
+    const value = uni.getStorageSync(key)
+    try {
+      return JSON.parse(value)
+    } catch (e) {
+      return value
+    }
+  },
+
+  remove(key) {
+    uni.removeStorageSync(key)
+  },
+
+  clear() {
+    uni.clearStorageSync()
+  }
+}