diff --git a/src/components/NTRPEvaluatePopup/index.module.scss b/src/components/NTRPEvaluatePopup/index.module.scss index 4c5cb6a..cbb3cdf 100644 --- a/src/components/NTRPEvaluatePopup/index.module.scss +++ b/src/components/NTRPEvaluatePopup/index.module.scss @@ -9,6 +9,7 @@ justify-content: space-between; // padding: 20px; box-sizing: border-box; + padding-bottom: 40px; .entryCard { width: 100%; @@ -56,5 +57,47 @@ .picker { width: 100%; - height: 300px; + height: 252px; +} + +.actions { + width: 100%; + padding: 10px; + box-sizing: border-box; + display: flex; + align-items: center; + justify-content: space-between; + gap: 8px; + + .buttonWrap { + width: 50%; + height: 50px; + + border-radius: 16px; + border: 1px solid rgba(0, 0, 0, 0.06); + box-shadow: 0 8px 64px 0 rgba(0, 0, 0, 0.1); + backdrop-filter: blur(16px); + overflow: hidden; + + .button { + width: 100%; + height: 50px; + color: #000; + background: #fff; + font-feature-settings: "liga" off, "clig" off; + font-family: "PingFang SC"; + font-size: 16px; + font-style: normal; + font-weight: 600; + line-height: normal; + display: flex; + align-items: center; + justify-content: center; + + &.primary { + color: #fff; + background: #000; + } + } + } } diff --git a/src/components/NTRPEvaluatePopup/index.tsx b/src/components/NTRPEvaluatePopup/index.tsx index 85caebc..ed3bec4 100644 --- a/src/components/NTRPEvaluatePopup/index.tsx +++ b/src/components/NTRPEvaluatePopup/index.tsx @@ -7,21 +7,25 @@ import React, { } from "react"; import { Button, Input, View, Text, Image } from "@tarojs/components"; import Taro from "@tarojs/taro"; +import classnames from "classnames"; import CommonPopup from "../CommonPopup"; import { getCurrentFullPath } from "@/utils"; import evaluateService from "@/services/evaluateService"; +import { useUserActions } from "@/store/userStore"; +import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore"; import NTRPTestEntryCard from "../NTRPTestEntryCard"; import NtrpPopupGuide from "../NTRPPopupGuide"; import Picker from "../Picker/Picker"; import CloseIcon from "@/static/ntrp/ntrp_popup_close.svg"; import styles from "./index.module.scss"; -const options = ["1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5"].map( - (item) => ({ +const ntrpLevels = ["1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5"]; +const options = [ + ntrpLevels.map((item) => ({ text: item, value: item, - }) -); + })), +]; export enum EvaluateType { EDIT = "edit", @@ -41,45 +45,57 @@ export enum SceneType { } interface NTRPEvaluatePopupProps { - types: EvaluateType[]; - displayCondition: DisplayConditionType; - scene: SceneType; + // types: EvaluateType[]; + // displayCondition: DisplayConditionType; + // scene: SceneType; showGuide: boolean; - children: React.ReactNode; + type: EvaluateScene; + // children: React.ReactNode; } -function showCondition(scene, ntrp) { - if (scene === "list") { - // TODO: 显示频率 - return Math.random() < 0.1 && [0, undefined].includes(ntrp); - } - return ntrp === "0"; -} +// function showCondition(scene, ntrp) { +// if (scene === "list") { +// // TODO: 显示频率 +// return Math.random() < 0.1 && [0, undefined].includes(ntrp); +// } +// return true; +// return !ntrpLevels.includes(ntrp); +// } const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { const { - types = ["edit", "evaluate"], - displayCondition = "auto", - scene = "list", + // types = ["edit", "evaluate"], + // displayCondition = "auto", + // scene = "list", + type, showGuide = false, } = props; - const [visible, setVisible] = useState(true); - const [ntrp, setNtrp] = useState(); - const [guideShow, setGuideShow] = useState(() => props.showGuide); + const [visible, setVisible] = useState(false); + const [ntrp, setNtrp] = useState(""); + const [guideShow, setGuideShow] = useState(() => showGuide); + const { updateUserInfo } = useUserActions(); + const [evaCallback, setEvaCallback] = useState({ + type: "", + next: () => {}, + onCancel: () => {}, + }); useImperativeHandle(ref, () => ({ - show: () => setVisible(true), + show: (evaluateCallback) => { + setVisible(true); + setEvaCallback(evaluateCallback); + }, })); - function handleEvaluate() { - setVisible(false); - // TODO: 实现NTRP评估逻辑 - Taro.navigateTo({ - url: `/other_pages/ntrp-evaluate/index?redirect=${encodeURIComponent( - getCurrentFullPath() - )}`, - }); - } + // function handleEvaluate() { + // setVisible(false); + // // TODO: 实现NTRP评估逻辑 + // Taro.navigateTo({ + // url: `/other_pages/ntrp-evaluate/index?redirect=${encodeURIComponent( + // getCurrentFullPath() + // )}`, + // }); + // } useEffect(() => { getNtrp(); @@ -88,20 +104,32 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { async function getNtrp() { const res = await evaluateService.getLastResult(); if (res.code === 0 && res.data.has_ntrp_level) { - // setNtrp(res.data.user_ntrp_level) - setNtrp("0"); + setNtrp(res.data.user_ntrp_level); } else { - setNtrp("0"); + setNtrp(""); } } - const showEntry = - displayCondition === "auto" - ? showCondition(scene, ntrp) - : displayCondition === "always"; + // const showEntry = + // displayCondition === "auto" + // ? showCondition(scene, ntrp) + // : displayCondition === "always"; function handleClose() { + console.log("hide ...."); setVisible(false); + setGuideShow(showGuide); + } + + async function handleChangeNtrp() { + Taro.showLoading({ title: "修改中" }); + await updateUserInfo({ ntrp_level: ntrp }); + Taro.showToast({ + title: "NTRP水平修改成功", + icon: "none", + }); + evaCallback.next(true); + handleClose(); } return ( @@ -116,10 +144,11 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { > {guideShow ? ( handleClose()} skipGuide={() => { setGuideShow(false); }} + evaluateCallback={evaCallback} /> ) : ( @@ -130,23 +159,42 @@ const NTRPEvaluatePopup = (props: NTRPEvaluatePopupProps, ref) => { - + - { - console.log(val); - setNtrp(val.values); - }} - /> + {/* FIXME: 有异常渲染问题 */} + {visible && ( + { + console.log(val[0]); + if (val[0]?.value) { + setNtrp(val[0]?.value as string); + } + }} + /> + )} + + + + + + + + )} - {showEntry ? props.children : ""} ); }; diff --git a/src/components/NTRPPopupGuide/index.tsx b/src/components/NTRPPopupGuide/index.tsx index 7623915..426aade 100644 --- a/src/components/NTRPPopupGuide/index.tsx +++ b/src/components/NTRPPopupGuide/index.tsx @@ -3,22 +3,32 @@ import { View, Text, Button, Image } from "@tarojs/components"; import Taro from "@tarojs/taro"; import classnames from "classnames"; import { useUserInfo } from "@/store/userStore"; +import { useEvaluate, EvaluateCallback } from "@/store/evaluateStore"; +import { delay } from "@/utils"; import ArrwoRight from "@/static/ntrp/ntrp_arrow_right.svg"; import CloseIcon from "@/static/ntrp/ntrp_popup_close.svg"; import DocCopy from "@/static/ntrp/ntrp_doc_copy.svg"; import styles from "./index.module.scss"; -function NtrpPopupGuide(props: { close: () => void; skipGuide: () => void }) { - const { close, skipGuide } = props; +function NtrpPopupGuide(props: { + close: () => void; + skipGuide: () => void; + evaluateCallback: EvaluateCallback; +}) { + const { close, skipGuide, evaluateCallback } = props; const userInfo = useUserInfo(); + const { setCallback } = useEvaluate(); - function handleTest() { - Taro.redirectTo({ - url: `/other_pages/ntrp-evaluate/index`, + async function handleTest() { + setCallback(evaluateCallback); + Taro.navigateTo({ + url: `/other_pages/ntrp-evaluate/index?stage=test`, }); + await delay(1000); + close(); } return ( - + e.stopPropagation()}> diff --git a/src/components/NTRPTestEntryCard/index.tsx b/src/components/NTRPTestEntryCard/index.tsx index c1875dc..879e112 100644 --- a/src/components/NTRPTestEntryCard/index.tsx +++ b/src/components/NTRPTestEntryCard/index.tsx @@ -1,20 +1,72 @@ import React, { useEffect } from "react"; import { View, Image, Text } from "@tarojs/components"; +import Taro from "@tarojs/taro"; import { useUserInfo, useUserActions } from "@/store/userStore"; +// import { getCurrentFullPath } from "@/utils"; import DocCopy from "@/static/ntrp/ntrp_doc_copy.svg"; import ArrowRight from "@/static/ntrp/ntrp_arrow_right_color.svg"; +import { + EvaluateScene, + useEvaluate, + EvaluateCallback, +} from "@/store/evaluateStore"; import styles from "./index.module.scss"; -function NTRPTestEntryCard(props) { +function NTRPTestEntryCard(props: { + type: EvaluateScene; + evaluateCallback?: EvaluateCallback; +}) { + const { type, evaluateCallback } = props; const userInfo = useUserInfo(); + const { setCallback } = useEvaluate(); // const { fetchUserInfo } = useUserActions() // useEffect(() => { // fetchUserInfo() // }, []) - const { type } = props; - return type === "list" ? ( - + + function handleTest() { + switch (type) { + case (EvaluateScene.list, EvaluateScene.share): + setCallback({ + type, + next: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + onCancel: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + }); + case (EvaluateScene.detail, EvaluateScene.publish): + setCallback(evaluateCallback as EvaluateCallback); + case (EvaluateScene.user, EvaluateScene.userEdit): + setCallback({ + type, + next: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + onCancel: () => { + Taro.redirectTo({ url: "/user_pages/myself/index" }); + }, + }); + default: + setCallback({ + type, + next: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + onCancel: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + }); + } + Taro.redirectTo({ + url: `/other_pages/ntrp-evaluate/index?stage=test`, + }); + } + + return type === EvaluateScene.list ? ( + @@ -48,7 +100,7 @@ function NTRPTestEntryCard(props) { ) : ( - + 不知道自己的 diff --git a/src/components/Picker/PopupPicker.tsx b/src/components/Picker/PopupPicker.tsx index 75de996..a63d5ce 100644 --- a/src/components/Picker/PopupPicker.tsx +++ b/src/components/Picker/PopupPicker.tsx @@ -7,6 +7,8 @@ import { renderYearMonthDay, renderHourMinute, } from "./PickerData"; +import NTRPTestEntryCard from "../NTRPTestEntryCard"; +import { EvaluateScene } from "@/store/evaluateStore"; import imgs from "@/config/images"; import styles from "./index.module.scss"; interface PickerOption { @@ -106,25 +108,28 @@ const PopupPicker = ({ zIndex={1000} > {type === "ntrp" && ( - - - - 不知道自己的(NTRP)水平 - - - 快速测试 - - - - - - - - - - - + + + // + // + // + // 不知道自己的(NTRP)水平 + // + // + // 快速测试 + // + // + // + // + // + // + // + // + // + // + // + // )} void; @@ -13,6 +20,10 @@ export interface PublishMenuProps { const PublishMenu: React.FC = () => { const [isVisible, setIsVisible] = useState(false); const [aiImportVisible, setAiImportVisible] = useState(false); + const userInfo = useUserInfo(); + const ntrpRef = useRef<{ + show: (evaluateCallback: EvaluateCallback) => void; + }>({ show: () => {} }); const handleIconClick = () => { setIsVisible(!isVisible); @@ -20,18 +31,42 @@ const PublishMenu: React.FC = () => { const handleOverlayClick = () => { setIsVisible(false); }; - const handleMenuItemClick = (type: "individual" | "group" | "ai") => { + const handleMenuClick = (type: "individual" | "group" | "ai") => { // 跳转到publishBall页面并传递type参数 console.log(type, "type"); + setIsVisible(false); if (type === "ai") { setAiImportVisible(true); - setIsVisible(false); return; } Taro.navigateTo({ url: `/publish_pages/publishBall/index?type=${type}`, }); - setIsVisible(false); + }; + const handleMenuItemClick = (type: "individual" | "group" | "ai") => { + if (!userInfo.ntrp_level) { + ntrpRef.current.show({ + type: EvaluateScene.publish, + next: (flag) => { + if (flag) { + handleMenuClick(type); + } else if (type === "ai") { + Taro.navigateBack(); + setAiImportVisible(true); + } else { + Taro.redirectTo({ + url: `/publish_pages/publishBall/index?type=${type}`, + }); + } + }, + onCancel: () => { + Taro.navigateBack(); + }, + }); + setIsVisible(false); + return; + } + handleMenuClick(type); }; const handleAiImportClose = () => { @@ -136,6 +171,8 @@ const PublishMenu: React.FC = () => { onClose={handleAiImportClose} onManualPublish={handleManualPublish} /> + + ); }; diff --git a/src/components/index.ts b/src/components/index.ts index 49d9462..73f42fe 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -24,6 +24,7 @@ import Comments from "./Comments"; import GeneralNavbar from "./GeneralNavbar"; import RadarChart from './Radar' import EmptyState from './EmptyState'; +import NTRPTestEntryCard from './NTRPTestEntryCard' export { ActivityTypeSwitch, @@ -53,4 +54,5 @@ export { GeneralNavbar, RadarChart, EmptyState, + NTRPTestEntryCard, }; diff --git a/src/container/listContainer/index.tsx b/src/container/listContainer/index.tsx index ffd3833..b7b730c 100644 --- a/src/container/listContainer/index.tsx +++ b/src/container/listContainer/index.tsx @@ -3,6 +3,10 @@ import ListCard from "@/components/ListCard"; import ListLoadError from "@/components/ListLoadError"; import ListCardSkeleton from "@/components/ListCardSkeleton"; import { useReachBottom } from "@tarojs/taro"; +import { useUserInfo } from "@/store/userStore"; +import { setStorage, getStorage } from "@/store/storage"; +import { NTRPTestEntryCard } from "@/components"; +import { EvaluateScene } from "@/store/evaluateStore"; import "./index.scss"; import { useRef, useEffect } from "react"; @@ -17,6 +21,8 @@ const ListContainer = (props) => { } = props; const timerRef = useRef(null); + const userInfo = useUserInfo(); + useReachBottom(() => { // 加载更多方法 timerRef.current = setTimeout(() => { @@ -46,19 +52,46 @@ const ListContainer = (props) => { ); }; + // 对于没有ntrp等级的用户每个月展示一次, 插在第三个位置 + function insertEvaluateCard(list) { + if (!list || list.length === 0) { + return list; + } + if (userInfo.ntrp_level) { + return list; + } + const lastShowTime = getStorage("list_evaluate_card"); + if (!lastShowTime) { + setStorage("list_evaluate_card", Date.now()); + } + if (Date.now() - Number(lastShowTime) < 30 * 24 * 60 * 60 * 1000) { + return list; + } + if (list.length <= 3) { + return [...list, { type: "evaluateCard" }]; + } + const [item1, item2, item3, ...rest] = list; + return [item1, item2, item3, { type: "evaluateCard" }, ...rest]; + } + // 渲染列表 const renderList = (list) => { // 请求数据为空 - if (!loading && list?.length === 0) { + if (!loading && (!list || list?.length === 0)) { return ; } // 渲染数据 return ( <> - {list?.map((match, index) => ( - - ))} + {insertEvaluateCard(list).map((match, index) => { + if (match.type === "evaluateCard") { + return ( + + ); + } + return ; + })} ); }; @@ -74,15 +107,15 @@ const ListContainer = (props) => { onScrollToLower={handleScrollToLower} upperThreshold={60} > */} - {renderList(data)} - {/* 显示骨架屏 */} - {loading && renderSkeleton()} - {/* + {renderList(data)} + {/* 显示骨架屏 */} + {loading && renderSkeleton()} + {/* 搜索结果较少,已为你推荐其他内容 {renderList(recommendList)} */} - {/* 到底了 */} - {data?.length > 0 && 到底了} + {/* 到底了 */} + {data?.length > 0 && 到底了} {/* */} ); diff --git a/src/game_pages/detail/index.tsx b/src/game_pages/detail/index.tsx index d1183e0..637e69b 100644 --- a/src/game_pages/detail/index.tsx +++ b/src/game_pages/detail/index.tsx @@ -24,11 +24,11 @@ import { GameManagePopup, Comments, } from "@/components"; -import { - EvaluateType, - SceneType, - DisplayConditionType, -} from "@/components/NTRPEvaluatePopup"; +// import { +// EvaluateType, +// SceneType, +// DisplayConditionType, +// } from "@/components/NTRPEvaluatePopup"; import DetailService, { MATCH_STATUS, IsSubstituteSupported, @@ -36,7 +36,9 @@ import DetailService, { import * as LoginService from "@/services/loginService"; import OrderService from "@/services/orderService"; import { getCurrentLocation, calculateDistance } from "@/utils/locationUtils"; +// import { getCurrentFullPath } from "@/utils"; import { useUserInfo, useUserActions } from "@/store/userStore"; +import { EvaluateCallback, EvaluateScene } from "@/store/evaluateStore"; import img from "@/config/images"; import styles from "./style.module.scss"; import "./index.scss"; @@ -280,7 +282,9 @@ function StickyButton(props) { getCommentCount, } = props; const [commentCount, setCommentCount] = useState(0); - const ntrpRef = useRef(null); + const ntrpRef = useRef<{ + show: (evaluateCallback: EvaluateCallback) => void; + }>({ show: () => {} }); const { id, price, @@ -294,8 +298,22 @@ function StickyButton(props) { const gameManageRef = useRef(); function handleSelfEvaluate() { - // TODO: 打开自评弹窗 - ntrpRef?.current?.show(); + ntrpRef?.current?.show({ + type: EvaluateScene.detail, + next: (flag) => { + if (flag) { + Taro.navigateTo({ + url: `/order_pages/orderDetail/index?gameId=${id}`, + }); + return; + } + Taro.redirectTo({ url: `/order_pages/orderDetail/index?gameId=${id}` }); + }, + onCancel: () => { + // Taro.redirectTo({ url: `/game_pages/detail/index?id=${id}` }); + Taro.navigateBack(); + }, + }); } useEffect(() => { @@ -313,8 +331,8 @@ function StickyButton(props) { return; } const displayPrice = is_organizer ? 0 : price; - user_action_status.can_assess = true; - user_action_status.can_join = false; + // user_action_status.can_assess = true; + // user_action_status.can_join = false; // console.log(user_action_status, "user_action"); const { can_assess, @@ -385,17 +403,7 @@ function StickyButton(props) { }; } else if (can_assess) { return { - text: () => ( - - ¥{displayPrice} 立即加入 - - ), + text: () => ¥{displayPrice} 立即加入, action: handleSelfEvaluate, }; } @@ -477,6 +485,7 @@ function StickyButton(props) { + ); } diff --git a/src/game_pages/list/index.tsx b/src/game_pages/list/index.tsx index 6b77a4a..9ab1e57 100644 --- a/src/game_pages/list/index.tsx +++ b/src/game_pages/list/index.tsx @@ -2,7 +2,11 @@ import SearchBar from "@/components/SearchBar"; import FilterPopup from "@/components/FilterPopup"; import styles from "./index.module.scss"; import { useEffect, useRef, useCallback, useState } from "react"; -import Taro, { usePageScroll, useShareAppMessage, useShareTimeline } from "@tarojs/taro"; +import Taro, { + usePageScroll, + useShareAppMessage, + useShareTimeline, +} from "@tarojs/taro"; import { useListStore } from "@/store/listStore"; import { useGlobalState } from "@/store/global"; import { View } from "@tarojs/components"; @@ -13,14 +17,17 @@ import DistanceQuickFilter from "@/components/DistanceQuickFilter"; import { withAuth } from "@/components"; import { updateUserLocation } from "@/services/userService"; // import ShareCardCanvas from "@/components/ShareCardCanvas"; +import { useUserActions } from "@/store/userStore"; import { useDictionaryStore } from "@/store/dictionaryStore"; const ListPage = () => { - // 从 store 获取数据和方法 const store = useListStore() || {}; - const { statusNavbarHeightInfo, getCurrentLocationInfo } = useGlobalState() || {}; + const { fetchUserInfo } = useUserActions(); + + const { statusNavbarHeightInfo, getCurrentLocationInfo } = + useGlobalState() || {}; const { totalHeight } = statusNavbarHeightInfo || {}; const { @@ -49,48 +56,52 @@ const ListPage = () => { filterOptions, distanceQuickFilter, isShowInputCustomerNavBar, - pageOption + pageOption, } = listPageState || {}; // 防抖的滚动处理函数 - const handleScroll = useCallback((res) => { - const currentScrollTop = res?.scrollTop || 0; + const handleScroll = useCallback( + (res) => { + const currentScrollTop = res?.scrollTop || 0; - // 添加缓冲区,避免临界点频繁切换 - const buffer = 10; // 10px 缓冲区 - const shouldShowInputNav = currentScrollTop >= (totalHeight + buffer); - const shouldHideInputNav = currentScrollTop < (totalHeight - buffer); + // 添加缓冲区,避免临界点频繁切换 + const buffer = 10; // 10px 缓冲区 + const shouldShowInputNav = currentScrollTop >= totalHeight + buffer; + const shouldHideInputNav = currentScrollTop < totalHeight - buffer; - // 清除之前的定时器 - if (scrollTimeoutRef.current) { - clearTimeout(scrollTimeoutRef.current); - } - - // 防抖处理,避免频繁更新状态 - scrollTimeoutRef.current = setTimeout(() => { - // 只有在状态真正需要改变时才更新 - if (shouldShowInputNav && !isShowInputCustomerNavBar) { - updateListPageState({ - isShowInputCustomerNavBar: true - }); - } else if (shouldHideInputNav && isShowInputCustomerNavBar) { - updateListPageState({ - isShowInputCustomerNavBar: false - }); + // 清除之前的定时器 + if (scrollTimeoutRef.current) { + clearTimeout(scrollTimeoutRef.current); } - lastScrollTopRef.current = currentScrollTop; - }, 16); // 约60fps的防抖间隔 - }, [totalHeight, isShowInputCustomerNavBar, updateState]); + // 防抖处理,避免频繁更新状态 + scrollTimeoutRef.current = setTimeout(() => { + // 只有在状态真正需要改变时才更新 + if (shouldShowInputNav && !isShowInputCustomerNavBar) { + updateListPageState({ + isShowInputCustomerNavBar: true, + }); + } else if (shouldHideInputNav && isShowInputCustomerNavBar) { + updateListPageState({ + isShowInputCustomerNavBar: false, + }); + } + + lastScrollTopRef.current = currentScrollTop; + }, 16); // 约60fps的防抖间隔 + }, + [totalHeight, isShowInputCustomerNavBar, updateState] + ); usePageScroll(handleScroll); - const scrollContextRef = useRef(null) - const scrollTimeoutRef = useRef(null) - const lastScrollTopRef = useRef(0) + const scrollContextRef = useRef(null); + const scrollTimeoutRef = useRef(null); + const lastScrollTopRef = useRef(0); useEffect(() => { - getLocation() + getLocation(); + fetchUserInfo(); }, []); // 监听数据变化,如果是第一页就滚动到顶部 @@ -98,7 +109,7 @@ const ListPage = () => { if (pageOption?.page === 1 && matches?.length > 0) { Taro.pageScrollTo({ scrollTop: 0, - duration: 300 + duration: 300, }); } }, [matches, pageOption?.page]); @@ -112,7 +123,6 @@ const ListPage = () => { }; }, []); - // 监听距离和排序方式变化,自动调用接口 // useEffect(() => { // // 只有当 distanceQuickFilter 有值时才调用接口 @@ -126,7 +136,7 @@ const ListPage = () => { // 获取位置信息 const getLocation = async () => { - const location = await getCurrentLocationInfo() + const location = await getCurrentLocationInfo(); // 保存位置到全局状态 updateState({ location }); @@ -136,7 +146,7 @@ const ListPage = () => { try { await updateUserLocation(location.latitude, location.longitude); } catch (error) { - console.error('更新用户位置失败:', error); + console.error("更新用户位置失败:", error); } } fetchGetGamesCount(); @@ -144,7 +154,7 @@ const ListPage = () => { // 页面加载时获取数据 getMatchesData(); return location; - } + }; const refreshMatches = () => { initialFilterSearch(true); @@ -188,7 +198,7 @@ const ListPage = () => { const handleFilterConfirm = () => { toggleShowPopup(); getMatchesData(); - } + }; /** * @description 综合筛选弹框 @@ -196,7 +206,7 @@ const ListPage = () => { */ const toggleShowPopup = () => { updateListPageState({ - isShowFilterPopup: !isShowFilterPopup + isShowFilterPopup: !isShowFilterPopup, }); }; @@ -208,7 +218,7 @@ const ListPage = () => { updateFilterOptions(params); }; - const handleSearchChange = () => { }; + const handleSearchChange = () => {}; // 距离筛选 const handleDistanceOrQuickChange = (name, value) => { @@ -278,10 +288,10 @@ const ListPage = () => { } catch (error) { console.error("初始化字典数据失败:", error); } - } + }; useEffect(() => { - initDictionaryData() + initDictionaryData(); }, []); return ( @@ -311,9 +321,7 @@ const ListPage = () => { /> )} - + 0} @@ -322,13 +330,14 @@ const ListPage = () => { value={searchValue} onInputClick={handleSearchClick} /> - {/* 筛选 */} - + }} + > {}" + ); +} + function CommonGuideBar(props) { const { title, confirm } = props; - const { params } = useRouter(); - const { redirect } = params; + const { onCancel } = useEvaluate(); + // const userInfo = useUserInfo() function handleClose() { //TODO: 二次确认 if (confirm) { } - Taro.redirectTo({ - url: redirect ? redirect : "/game_pages/list/index", - }); + try { + if (isEmptyArrowFunction(onCancel)) { + Taro.redirectTo({ url: "/game_pages/list/index" }); + } + onCancel(); + } catch { + Taro.redirectTo({ url: "/game_pages/list/index" }); + } } return ( @@ -106,12 +115,12 @@ function CommonGuideBar(props) { ); } -function Intro(props) { - const { redirect } = props; +function Intro() { const [ntrpData, setNtrpData] = useState(); const userInfo = useUserInfo(); const { fetchUserInfo } = useUserActions(); const [ready, setReady] = useState(false); + const { setCallback } = useEvaluate(); const { last_test_result: { ntrp_level, create_time, id } = {} } = ntrpData || {}; @@ -136,10 +145,24 @@ function Intro(props) { } function handleNext(type) { + setCallback({ + type: EvaluateScene.share, + next: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + }, + onCancel: () => { + Taro.redirectTo({ url: "/game_pages/list/index" }); + // if (userInfo.id) { + // Taro.redirectTo({ url: "/game_pages/list/index" }); + // } else { + // Taro.exitMiniProgram(); + // } + }, + }); Taro.redirectTo({ url: `/other_pages/ntrp-evaluate/index?stage=${type}${ type === StageType.RESULT ? `&id=${id}` : "" - }${redirect ? `&redirect=${redirect}` : ""}`, + }`, }); } @@ -249,8 +272,7 @@ function Intro(props) { ); } -function Test(props) { - const { redirect } = props; +function Test() { const [disabled, setDisabled] = useState(false); const [index, setIndex] = useState(0); const [questions, setQuestions] = useState< @@ -295,9 +317,7 @@ function Test(props) { }); if (res.code === 0) { Taro.redirectTo({ - url: `/other_pages/ntrp-evaluate/index?stage=${StageType.RESULT}&id=${ - res.data.record_id - }${redirect ? `&redirect=${redirect}` : ""}`, + url: `/other_pages/ntrp-evaluate/index?stage=${StageType.RESULT}&id=${res.data.record_id}`, }); } } catch (e) { @@ -378,11 +398,12 @@ function Test(props) { ); } -function Result(props) { +function Result() { const { params } = useRouter(); - const { id, type, redirect } = params; + const { id } = params; const userInfo = useUserInfo(); const { fetchUserInfo } = useUserActions(); + const { type, next, clear } = useEvaluate(); const radarRef = useRef(); const [result, setResult] = useState(); @@ -425,9 +446,7 @@ function Result(props) { function handleReTest() { Taro.redirectTo({ - url: `/other_pages/ntrp-evaluate/index?stage=${StageType.TEST}${ - redirect ? `&redirect=${redirect}` : "" - }`, + url: `/other_pages/ntrp-evaluate/index?stage=${StageType.TEST}`, }); } @@ -437,11 +456,13 @@ function Result(props) { }); } - function handleGoon () { + async function handleGoon() { if (type) { - Taro.redirectTo({ url: redirect }) + next(); + await delay(1500); + clear(); } else { - handleViewGames() + handleViewGames(); } } @@ -495,7 +516,7 @@ function Result(props) { async function handleSaveImage() { if (!userInfo.id) { - return + return; } const url = await genCardImage(); Taro.saveImageToPhotosAlbum({ filePath: url }); @@ -511,11 +532,11 @@ function Result(props) { }; }); - function handleAuth () { + function handleAuth() { if (userInfo.id) { - return true + return true; } - const currentPage = getCurrentFullPath() + const currentPage = getCurrentFullPath(); Taro.redirectTo({ url: `/login_pages/index/index${ currentPage ? `?redirect=${encodeURIComponent(currentPage)}` : "" @@ -576,11 +597,17 @@ function Result(props) { )} - + - @@ -614,30 +641,30 @@ const ComponentsMap = { }; function NtrpEvaluate() { - const { updateUserInfo } = useUserActions(); + // const { updateUserInfo } = useUserActions(); const { params } = useRouter(); - const { redirect } = params; + // const { redirect } = params; const stage = params.stage as StageType; - async function handleUpdateNtrp() { - await updateUserInfo({ - ntrp_level: "4.0", - }); - Taro.showToast({ - title: "更新成功", - icon: "success", - duration: 2000, - }); - await delay(2000); - if (redirect) { - Taro.redirectTo({ url: decodeURIComponent(redirect) }); - } - } + // async function handleUpdateNtrp() { + // await updateUserInfo({ + // ntrp_level: "4.0", + // }); + // Taro.showToast({ + // title: "更新成功", + // icon: "success", + // duration: 2000, + // }); + // await delay(2000); + // if (redirect) { + // Taro.redirectTo({ url: decodeURIComponent(redirect) }); + // } + // } const Component = ComponentsMap[stage]; - return ; + return ; } export default withAuth(NtrpEvaluate); diff --git a/src/store/evaluateStore.ts b/src/store/evaluateStore.ts new file mode 100644 index 0000000..eb49ac9 --- /dev/null +++ b/src/store/evaluateStore.ts @@ -0,0 +1,43 @@ +import { create } from "zustand"; + +export enum EvaluateScene { + list, + publish, + detail, + user, + userEdit, + share, +} + +export interface EvaluateCallback { + type: EvaluateScene | '' + next: (flag?: boolean) => void, + onCancel: () => void, +} + +export interface EvaluateCallbackType extends EvaluateCallback { + setCallback: (options: { type: EvaluateScene | '', next: () => void, onCancel: () => void }) => void, + clear: () => void, +} + +export const useEvaluateCallback = create()((set) => ({ + type: '', + next: () => { }, + onCancel: () => { }, + setCallback: ({ type, next, onCancel }) => { + set({ + type, + next, + onCancel, + }) + }, + clear: () => { set({ type: '', next: () => { }, onCancel: () => { } }) } +})); + +export const useEvaluate = () => useEvaluateCallback(({ type, next, onCancel, setCallback, clear }) => ({ + type, + next, + onCancel, + setCallback, + clear, +})) diff --git a/src/user_pages/myself/index.tsx b/src/user_pages/myself/index.tsx index e952215..19137d0 100644 --- a/src/user_pages/myself/index.tsx +++ b/src/user_pages/myself/index.tsx @@ -7,7 +7,8 @@ import { UserInfoCard, UserInfo } from "@/components/UserInfo/index"; import { UserService } from "@/services/userService"; import ListContainer from "@/container/listContainer"; import { TennisMatch } from "@/../types/list/types"; -import { withAuth } from "@/components"; +import { withAuth, NTRPTestEntryCard } from "@/components"; +import { EvaluateScene } from "@/store/evaluateStore"; const MyselfPage: React.FC = () => { // 获取页面参数 @@ -34,9 +35,9 @@ const MyselfPage: React.FC = () => { occupation: "加载中...", ntrp_level: "NTRP 3.0", personal_profile: "加载中...", - gender: '', - country: '', - province: '', + gender: "", + country: "", + province: "", }); // 球局记录状态 @@ -50,7 +51,7 @@ const MyselfPage: React.FC = () => { // 当前激活的标签页 const [active_tab, setActiveTab] = useState<"hosted" | "participated">( - "hosted", + "hosted" ); // 加载用户数据 @@ -131,7 +132,10 @@ const MyselfPage: React.FC = () => { games_data = await UserService.get_participated_games(user_info.id); } const sorted_games = games_data.sort((a, b) => { - return new Date(a.original_start_time.replace(/\s/, 'T')).getTime() - new Date(b.original_start_time.replace(/\s/, 'T')).getTime(); + return ( + new Date(a.original_start_time.replace(/\s/, "T")).getTime() - + new Date(b.original_start_time.replace(/\s/, "T")).getTime() + ); }); const { notEndGames, finishedGames } = classifyGameRecords(sorted_games); set_game_records(notEndGames); @@ -147,7 +151,7 @@ const MyselfPage: React.FC = () => { try { const new_following_state = await UserService.toggle_follow( user_id, - is_following, + is_following ); setIsFollowing(new_following_state); @@ -221,6 +225,8 @@ const MyselfPage: React.FC = () => { + + {/* 球局类型标签页 */} @@ -231,7 +237,9 @@ const MyselfPage: React.FC = () => { 我主办的 setActiveTab("participated")} > 我参与的 @@ -248,7 +256,7 @@ const MyselfPage: React.FC = () => { loading={loading} error={null} reload={load_game_data} - loadMoreMatches={() => { }} + loadMoreMatches={() => {}} /> @@ -271,7 +279,7 @@ const MyselfPage: React.FC = () => { loading={loading} error={null} reload={load_game_data} - loadMoreMatches={() => { }} + loadMoreMatches={() => {}} /> {/* */}