wxy 4 mesiacov pred
rodič
commit
ee383a2e0a
1 zmenil súbory, kde vykonal 6 pridanie a 9 odobranie
  1. 6 9
      src/components/Search/index.vue

+ 6 - 9
src/components/Search/index.vue

@@ -59,35 +59,32 @@ const props = defineProps({
 
 const { SearchForm } = toRefs(props);
 
-// 初始化 formState,确保每个字段都是对象,包含 `value` 属性
 const formState = ref({});
 SearchForm.value.forEach(item => {
     formState.value[item.field] = {
-        value: item.value, // 初始化为字段的默认值
+        value: item.value, 
     };
 });
 
 // 字典加载
-const loadedDicts = ref({}); // 存储已加载的字典
+const loadedDicts = ref({}); 
 const loadDictOptions = async (index, dict) => {
     if (loadedDicts.value[dict]) {
-        // 如果字典已加载,则直接使用缓存的字典数据
         SearchForm.value[index].options = loadedDicts.value[dict];
         return;
     }
     const dictionary = await Getdictionary(dict);
-    loadedDicts.value[dict] = dictionary || []; // 更新缓存
-    SearchForm.value[index].options = loadedDicts.value[dict]; // 更新 options
+    loadedDicts.value[dict] = dictionary || []; 
+    SearchForm.value[index].options = loadedDicts.value[dict]; 
 };
 
-// 监听 SearchForm 更新,加载字典
 watch(
-  () => SearchForm.value, // 只监听 SearchForm 的变化
+  () => SearchForm.value, 
   async () => {
     for (let index = 0; index < SearchForm.value.length; index++) {
         const item = SearchForm.value[index];
         if (item.dict && !loadedDicts.value[item.dict]) {
-            await loadDictOptions(index, item.dict); // 加载字典
+            await loadDictOptions(index, item.dict); 
         }
     }
 }, { immediate: true });