Procházet zdrojové kódy

♻️ refactor(auth): 移除商品分类和首页的登录依赖

- 移除商品分类页面中对 `useAuth` 的导入和 `isLoggedIn` 状态依赖
- 移除首页页面中对 `isLoggedIn` 状态依赖
- 移除两个页面中 `useQuery` 钩子的 `enabled` 选项,使数据查询不再依赖登录状态
yourname před 3 týdny
rodič
revize
4b65d49baf

+ 1 - 4
mini/src/pages/category/index.tsx

@@ -2,7 +2,6 @@ import React, { useState, useEffect } from 'react';
 import { View } from '@tarojs/components';
 import { useQuery } from '@tanstack/react-query';
 import { goodsCategoryClient, advertisementClient } from '@/api';
-import { useAuth } from '@/utils/auth';
 import CategorySidebar from '@/components/category/CategorySidebar';
 import CategorySidebarItem from '@/components/category/CategorySidebarItem';
 import CategoryTabbar, { TabItem } from '@/components/category/CategoryTabbar';
@@ -22,7 +21,6 @@ type AdvertisementResponse = InferResponseType<typeof advertisementClient.$get,
 type Advertisement = AdvertisementResponse['data'][0]
 
 const CategoryPage: React.FC = () => {
-  const { isLoggedIn } = useAuth();
   const [activeCategoryIndex, setActiveCategoryIndex] = useState<number>(0);
   const [activeSubCategoryId, setActiveSubCategoryId] = useState<string>('');
   const [toastVisible, setToastVisible] = useState<boolean>(false);
@@ -143,8 +141,7 @@ const CategoryPage: React.FC = () => {
       }
       return response.json();
     },
-    staleTime: 5 * 60 * 1000,
-    enabled: isLoggedIn,
+    staleTime: 5 * 60 * 1000
   });
 
   //console.log("categoryData:",categoryData);

+ 1 - 2
mini/src/pages/index/index.tsx

@@ -43,8 +43,7 @@ const HomePage: React.FC = () => {
       }
       return response.json()
     },
-    staleTime: 5 * 60 * 1000, // 5分钟缓存
-    enabled: isLoggedIn,
+    staleTime: 5 * 60 * 1000 // 5分钟缓存
   })
 
   const {