Explorar el Código

根据eslint调整代码

zhangzf hace 1 día
padre
commit
5ae5ecbb1b
Se han modificado 1 ficheros con 10 adiciones y 15 borrados
  1. 10 15
      src/components/layout/navbar/TopSwiperBanner.tsx

+ 10 - 15
src/components/layout/navbar/TopSwiperBanner.tsx

@@ -13,20 +13,18 @@ export interface AnnouncementItem {
   title: string;
   title: string;
 }
 }
 
 
- interface AnnouncementBarProps {
+interface AnnouncementBarProps {
   items?: AnnouncementItem[];
   items?: AnnouncementItem[];
 }
 }
 
 
-export default function AnnouncementBar({ items = [] }: AnnouncementBarProps) {
+export default function TopSwiperBanner({ items = [] }: AnnouncementBarProps) {
   const [index, setIndex] = useState(0);
   const [index, setIndex] = useState(0);
+
   const [enableTransition, setEnableTransition] = useState(true);
   const [enableTransition, setEnableTransition] = useState(true);
 
 
-  // 没有数据不显示
-  if (!items.length) {
-    return null;
-  }
+  const loopItems = [...items, ...(items.length ? [items[0]] : [])];
 
 
-  const loopItems = [...items, items[0]];
+  // 自动滚动
   useEffect(() => {
   useEffect(() => {
     if (items.length <= 1) {
     if (items.length <= 1) {
       return;
       return;
@@ -41,6 +39,7 @@ export default function AnnouncementBar({ items = [] }: AnnouncementBarProps) {
     };
     };
   }, [items.length]);
   }, [items.length]);
 
 
+  // 无缝循环重置
   useEffect(() => {
   useEffect(() => {
     if (index !== items.length) {
     if (index !== items.length) {
       return;
       return;
@@ -62,6 +61,9 @@ export default function AnnouncementBar({ items = [] }: AnnouncementBarProps) {
       window.clearTimeout(timer);
       window.clearTimeout(timer);
     };
     };
   }, [index, items.length]);
   }, [index, items.length]);
+  if (!items.length) {
+    return null;
+  }
 
 
   return (
   return (
     <div
     <div
@@ -98,14 +100,7 @@ export default function AnnouncementBar({ items = [] }: AnnouncementBarProps) {
                 "
                 "
           >
           >
             {item.link ? (
             {item.link ? (
-              <Link
-                href={item.link}
-                className="
-                        hover:underline
-                      "
-              >
-                {item.title}
-              </Link>
+              <Link href={item.link}>{item.title}</Link>
             ) : (
             ) : (
               <span>{item.title}</span>
               <span>{item.title}</span>
             )}
             )}