Parcourir la source

无社区数据不显示 #1389

visuddhinanda il y a 2 ans
Parent
commit
76c53d350f
1 fichiers modifiés avec 12 ajouts et 2 suppressions
  1. 12 2
      dashboard/src/components/dict/Community.tsx

+ 12 - 2
dashboard/src/components/dict/Community.tsx

@@ -34,6 +34,7 @@ interface IWidget {
 }
 }
 const CommunityWidget = ({ word }: IWidget) => {
 const CommunityWidget = ({ word }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
+  const [loaded, setLoaded] = useState(false);
   const [wordData, setWordData] = useState<IWord>();
   const [wordData, setWordData] = useState<IWord>();
   const minScore = 100; //分数阈值。低于这个分数只显示在弹出菜单中
   const minScore = 100; //分数阈值。低于这个分数只显示在弹出菜单中
 
 
@@ -44,7 +45,13 @@ const CommunityWidget = ({ word }: IWidget) => {
     const url = `/v2/userdict?view=community&word=${word}`;
     const url = `/v2/userdict?view=community&word=${word}`;
     get<IApiResponseDictList>(url)
     get<IApiResponseDictList>(url)
       .then((json) => {
       .then((json) => {
-        console.log("community", json.data.rows);
+        if (json.ok === false) {
+          console.log("dict community", json.message);
+          return;
+        }
+        if (json.data.count > 0) {
+          setLoaded(true);
+        }
         let meaning = new Map<string, number>();
         let meaning = new Map<string, number>();
         let grammar = new Map<string, number>();
         let grammar = new Map<string, number>();
         let parent = new Map<string, number>();
         let parent = new Map<string, number>();
@@ -170,7 +177,8 @@ const CommunityWidget = ({ word }: IWidget) => {
       </Dropdown>
       </Dropdown>
     ) : undefined
     ) : undefined
   ) : undefined;
   ) : undefined;
-  return (
+
+  return loaded ? (
     <Card>
     <Card>
       <Title level={5} id={`community`}>
       <Title level={5} id={`community`}>
         {"社区字典"}
         {"社区字典"}
@@ -267,6 +275,8 @@ const CommunityWidget = ({ word }: IWidget) => {
         </Space>
         </Space>
       </div>
       </div>
     </Card>
     </Card>
+  ) : (
+    <></>
   );
   );
 };
 };