feat: 将list相关的代码迁移到game_pages目录
This commit is contained in:
@@ -37,7 +37,7 @@ const ListHeader = (props: IProps) => {
|
||||
|
||||
const handleInputClick = () => {
|
||||
Taro.navigateTo({
|
||||
url: "/pages/search/index",
|
||||
url: "/game_pages/search/index",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,11 @@ const ListHeader = (props: IProps) => {
|
||||
const pages = Taro.getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
const currentPagePath = currentPage.route;
|
||||
if (currentPagePath === "pages/searchResult/index") {
|
||||
if (currentPagePath === "game_pages/searchResult/index") {
|
||||
Taro.navigateBack();
|
||||
} else {
|
||||
Taro.navigateTo({
|
||||
url: "/pages/search/index",
|
||||
url: "/game_pages/search/index",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -56,7 +56,7 @@ const ListHeader = (props: IProps) => {
|
||||
// 点击logo
|
||||
const handleLogoClick = () => {
|
||||
Taro.redirectTo({
|
||||
url: "pages/list/index", // 列表页
|
||||
url: "game_pages/list/index", // 列表页
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -259,18 +259,18 @@ function StickyButton(props) {
|
||||
) {
|
||||
return {
|
||||
text: "球局已结束,查看其他球局",
|
||||
action: navto.bind(null, "/pages/list/index"),
|
||||
action: navto.bind(null, "/game_pages/list/index"),
|
||||
};
|
||||
}
|
||||
if (waiting_start) {
|
||||
return {
|
||||
text: "等待开始, 查看更多球局",
|
||||
action: navto.bind(null, "/pages/list/index"),
|
||||
action: navto.bind(null, "/game_pages/list/index"),
|
||||
};
|
||||
} else if (is_substituting) {
|
||||
return {
|
||||
text: "候补中,查看其他球局",
|
||||
action: navto.bind(null, "/pages/list/index"),
|
||||
action: navto.bind(null, "/game_pages/list/index"),
|
||||
};
|
||||
} else if (can_pay) {
|
||||
return {
|
||||
@@ -1036,7 +1036,7 @@ function Index() {
|
||||
const pages = Taro.getCurrentPages();
|
||||
if (pages.length <= 1) {
|
||||
Taro.redirectTo({
|
||||
url: "/pages/list/index",
|
||||
url: "/game_pages/list/index",
|
||||
});
|
||||
} else {
|
||||
Taro.navigateBack();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import SearchBar from "../../components/SearchBar";
|
||||
import SearchBar from "@/components/SearchBar";
|
||||
import FilterPopup from "@/components/FilterPopup";
|
||||
import styles from "./index.module.scss";
|
||||
import { useEffect } from "react";
|
||||
@@ -89,7 +89,7 @@ const ListPage = () => {
|
||||
console.error('更新用户位置失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 页面加载时获取数据
|
||||
getMatchesData();
|
||||
return location;
|
||||
@@ -159,7 +159,7 @@ const ListPage = () => {
|
||||
|
||||
const handleSearchClick = () => {
|
||||
Taro.navigateTo({
|
||||
url: "/pages/search/index",
|
||||
url: "/game_pages/search/index",
|
||||
});
|
||||
};
|
||||
|
||||
@@ -101,7 +101,7 @@ const ListSearch = () => {
|
||||
return;
|
||||
}
|
||||
Taro.navigateTo({
|
||||
url: `/pages/searchResult/index`,
|
||||
url: `/game_pages/searchResult/index`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -324,7 +324,7 @@ const OrderCheck = () => {
|
||||
<Button
|
||||
type="warn"
|
||||
onClick={() => {
|
||||
Taro.redirectTo({ url: "/pages/list/index" });
|
||||
Taro.redirectTo({ url: "/game_pages/list/index" });
|
||||
}}
|
||||
>
|
||||
回到首页
|
||||
|
||||
@@ -10,13 +10,13 @@ const HomePage: React.FC = () => {
|
||||
useEffect(() => {
|
||||
const handleLoginRedirect = async () => {
|
||||
const login_status = check_login_status();
|
||||
|
||||
|
||||
if (login_status) {
|
||||
try {
|
||||
// 先获取用户信息
|
||||
await fetchUserInfo();
|
||||
// 用户信息获取成功后跳转到列表页
|
||||
Taro.redirectTo({ url: '/pages/list/index' });
|
||||
Taro.redirectTo({ url: '/game_pages/list/index' });
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
// 如果获取用户信息失败,跳转到登录页
|
||||
|
||||
@@ -47,7 +47,7 @@ const LoginPage: React.FC = () => {
|
||||
if (redirect) {
|
||||
Taro.redirectTo({ url: decodeURIComponent(redirect) });
|
||||
} else {
|
||||
Taro.redirectTo({ url: '/pages/list/index' });
|
||||
Taro.redirectTo({ url: '/game_pages/list/index' });
|
||||
}
|
||||
}, 10);
|
||||
} else {
|
||||
|
||||
@@ -154,7 +154,7 @@ const VerificationPage: React.FC = () => {
|
||||
}
|
||||
setTimeout(() => {
|
||||
Taro.redirectTo({
|
||||
url: "/pages/list/index",
|
||||
url: "/game_pages/list/index",
|
||||
});
|
||||
}, 200);
|
||||
} else {
|
||||
@@ -182,7 +182,7 @@ const VerificationPage: React.FC = () => {
|
||||
if (res.code === 0) {
|
||||
setTimeout(() => {
|
||||
Taro.redirectTo({
|
||||
url: "/pages/list/index",
|
||||
url: "/game_pages/list/index",
|
||||
});
|
||||
}, 200);
|
||||
} else {
|
||||
@@ -353,7 +353,7 @@ const VerificationPage: React.FC = () => {
|
||||
className="cancel_button"
|
||||
onClick={() => {
|
||||
Taro.redirectTo({
|
||||
url: "/pages/list/index",
|
||||
url: "/game_pages/list/index",
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -20,13 +20,13 @@ import { useUserInfo, useUserStats, useIsLoggedIn } from '../store/userStore'
|
||||
function MyComponent() {
|
||||
// 获取用户信息
|
||||
const userInfo = useUserInfo()
|
||||
|
||||
|
||||
// 获取用户统计数据
|
||||
const userStats = useUserStats()
|
||||
|
||||
|
||||
// 获取登录状态
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>欢迎 {userInfo?.username}!</h1>
|
||||
@@ -43,24 +43,24 @@ function MyComponent() {
|
||||
import { useUserActions } from '../store/userStore'
|
||||
|
||||
function MyComponent() {
|
||||
const {
|
||||
updateUserInfo,
|
||||
incrementRequestCount,
|
||||
incrementMatchesCreated
|
||||
const {
|
||||
updateUserInfo,
|
||||
incrementRequestCount,
|
||||
incrementMatchesCreated
|
||||
} = useUserActions()
|
||||
|
||||
|
||||
const handleUpdateUsername = () => {
|
||||
updateUserInfo('username', '新用户名')
|
||||
}
|
||||
|
||||
|
||||
const handleApiRequest = () => {
|
||||
incrementRequestCount() // API 请求计数 +1
|
||||
}
|
||||
|
||||
|
||||
const handleCreateMatch = () => {
|
||||
incrementMatchesCreated() // 创建比赛计数 +1
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={handleUpdateUsername}>更新用户名</button>
|
||||
@@ -80,17 +80,17 @@ import { useUserActions } from '../store/userStore'
|
||||
function MyComponent() {
|
||||
const { incrementRequestCount } = useUserActions()
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
|
||||
const handleSendRequest = async () => {
|
||||
setLoading(true)
|
||||
|
||||
|
||||
try {
|
||||
// 模拟网络延迟
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
|
||||
|
||||
// 更新请求计数
|
||||
incrementRequestCount()
|
||||
|
||||
|
||||
console.log('请求成功!')
|
||||
} catch (error) {
|
||||
console.error('请求失败:', error)
|
||||
@@ -98,7 +98,7 @@ function MyComponent() {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button onClick={handleSendRequest} disabled={loading}>
|
||||
@@ -179,7 +179,7 @@ interface UserStats {
|
||||
|
||||
## 使用示例
|
||||
|
||||
查看 `src/pages/list/index.tsx` 获取完整的使用示例,包括:
|
||||
查看 `src/game_pages/list/index.tsx` 获取完整的使用示例,包括:
|
||||
|
||||
- 用户信息展示
|
||||
- 统计数据实时更新
|
||||
@@ -196,4 +196,4 @@ interface UserStats {
|
||||
3. 添加相应的 action 函数
|
||||
4. 导出便捷的 hooks(如果需要)
|
||||
|
||||
这种设计让用户状态管理既简单又强大,非常适合团队协作开发。
|
||||
这种设计让用户状态管理既简单又强大,非常适合团队协作开发。
|
||||
Reference in New Issue
Block a user