feat: NTRP测试入口接入

This commit is contained in:
2025-10-01 09:34:20 +08:00
parent 61b70773e3
commit 273da07959
14 changed files with 629 additions and 304 deletions

View File

@@ -10,6 +10,7 @@ import evaluateService, {
TestResultData,
} from "@/services/evaluateService";
import { useUserInfo, useUserActions } from "@/store/userStore";
import { useEvaluate, EvaluateScene } from "@/store/evaluateStore";
import { delay, getCurrentFullPath } from "@/utils";
import CloseIcon from "@/static/ntrp/ntrp_close_icon.svg";
import DocCopy from "@/static/ntrp/ntrp_doc_copy.svg";
@@ -28,15 +29,10 @@ enum StageType {
RESULT = "result",
}
enum SourceType {
DETAIL = 'detail',
PUBLISH = 'publish',
}
const sourceTypeToTextMap = new Map([
[SourceType.DETAIL, '继续加入球局'],
[SourceType.PUBLISH, '继续发布球局'],
])
[EvaluateScene.detail, "继续加入球局"],
[EvaluateScene.publish, "继续发布球局"],
]);
function adjustRadarLabels(
source: [string, number][],
@@ -80,18 +76,31 @@ function adjustRadarLabels(
return result as [string, number][];
}
function isEmptyArrowFunction(fn) {
return (
typeof fn === "function" &&
!fn.hasOwnProperty("prototype") && // 排除普通函数
fn.toString().replace(/\s+/g, "") === "()=>{}"
);
}
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<LastTimeTestResult>();
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<TestResultData>();
@@ -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) {
)}
<View className={styles.actions}>
<View className={styles.viewGame} onClick={handleGoon}>
<Button className={styles.viewGameBtn}>{sourceTypeToTextMap.get(type) || '去看看球局'}</Button>
<Button className={styles.viewGameBtn}>
{sourceTypeToTextMap.get(type) || "去看看球局"}
</Button>
</View>
<View className={styles.otherActions}>
<View className={styles.share}>
<Button className={styles.shareBtn} openType={userInfo.id ? 'share' : undefined} onClick={handleAuth}>
<Button
className={styles.shareBtn}
openType={userInfo.id ? "share" : undefined}
onClick={handleAuth}
>
<Image className={styles.wechatIcon} src={WechatIcon} />
<Text></Text>
</Button>
@@ -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 <Component redirect={redirect} />;
return <Component />;
}
export default withAuth(NtrpEvaluate);