Просмотр исходного кода

🐛 fix(EditTagModal): add fetchTagModels function to retrieve models based on tag

RedwindA 9 месяцев назад
Родитель
Сommit
4989892830
1 измененных файлов с 20 добавлено и 1 удалено
  1. 20 1
      web/src/pages/Channel/EditTagModal.js

+ 20 - 1
web/src/pages/Channel/EditTagModal.js

@@ -194,6 +194,24 @@ const EditTagModal = (props) => {
   }, [originModelOptions, inputs.models]);
   }, [originModelOptions, inputs.models]);
 
 
   useEffect(() => {
   useEffect(() => {
+    const fetchTagModels = async () => {
+      if (!tag) return;
+      setLoading(true);
+      try {
+        const res = await API.get(`/api/channel/tag/models?tag=${tag}`);
+        if (res?.data?.success) {
+          const models = res.data.data ? res.data.data.split(',') : [];
+          setInputs((inputs) => ({ ...inputs, models: models }));
+        } else {
+          showError(res.data.message);
+        }
+      } catch (error) {
+        showError(error.message);
+      } finally {
+        setLoading(false);
+      }
+    };
+
     setInputs({
     setInputs({
       ...originInputs,
       ...originInputs,
       tag: tag,
       tag: tag,
@@ -201,7 +219,8 @@ const EditTagModal = (props) => {
     });
     });
     fetchModels().then();
     fetchModels().then();
     fetchGroups().then();
     fetchGroups().then();
-  }, [visible]);
+    fetchTagModels().then(); // Call the new function
+  }, [visible, tag]); // Add tag to dependency array
 
 
   const addCustomModels = () => {
   const addCustomModels = () => {
     if (customModel.trim() === '') return;
     if (customModel.trim() === '') return;