feat: 结果页
This commit is contained in:
@@ -1,26 +1,46 @@
|
|||||||
import Taro, { useReady } from "@tarojs/taro";
|
import Taro, { useReady } from "@tarojs/taro";
|
||||||
import { View, Canvas, Button } from "@tarojs/components";
|
import { View, Canvas, Button } from "@tarojs/components";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
const RadarChart: React.FC = () => {
|
const RadarChart: React.FC = (props) => {
|
||||||
const labels = [
|
const { data } = props
|
||||||
"正手球质",
|
|
||||||
"正手控制",
|
const renderFnRef = useRef()
|
||||||
"反手球质",
|
// const labels = [
|
||||||
"反手控制",
|
// "正手球质",
|
||||||
"底线相持",
|
// "正手控制",
|
||||||
"场地覆盖",
|
// "反手球质",
|
||||||
"发球接发",
|
// "反手控制",
|
||||||
"接随机球",
|
// "底线相持",
|
||||||
"战术设计",
|
// "场地覆盖",
|
||||||
];
|
// "发球接发",
|
||||||
const values = [50, 75, 60, 20, 40, 70, 65, 35, 75];
|
// "接随机球",
|
||||||
|
// "战术设计",
|
||||||
|
// ];
|
||||||
|
// const values = [50, 75, 60, 20, 40, 70, 65, 35, 75];
|
||||||
const maxValue = 100;
|
const maxValue = 100;
|
||||||
const levels = 4;
|
const levels = 4;
|
||||||
const radius = 100;
|
const radius = 100;
|
||||||
const center = { x: 160, y: 160 };
|
const center = { x: 160, y: 160 };
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data.length > 0) {
|
||||||
|
const {texts, vals} = data.reduce((res, item) => {
|
||||||
|
const [text, val] = item
|
||||||
|
return {
|
||||||
|
texts: [...res.texts, text],
|
||||||
|
vals: [...res.vals, val]
|
||||||
|
}
|
||||||
|
}, { texts: [], vals: [] })
|
||||||
|
renderFnRef.current && renderFnRef.current(texts, vals)
|
||||||
|
}
|
||||||
|
}, [data])
|
||||||
|
|
||||||
useReady(() => {
|
useReady(() => {
|
||||||
|
renderFnRef.current = renderCanvas
|
||||||
|
});
|
||||||
|
|
||||||
|
function renderCanvas (labels, values) {
|
||||||
const query = Taro.createSelectorQuery();
|
const query = Taro.createSelectorQuery();
|
||||||
query
|
query
|
||||||
.select("#radarCanvas")
|
.select("#radarCanvas")
|
||||||
@@ -93,10 +113,10 @@ const RadarChart: React.FC = () => {
|
|||||||
ctx.fillStyle = "rgba(0,200,180,0.3)";
|
ctx.fillStyle = "rgba(0,200,180,0.3)";
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
ctx.strokeStyle = "#00c8b4";
|
ctx.strokeStyle = "#00c8b4";
|
||||||
ctx.lineWidth = 4;
|
ctx.lineWidth = 3;
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
|
||||||
// 保存为图片
|
// 保存为图片
|
||||||
|
|||||||
@@ -545,6 +545,10 @@
|
|||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 900;
|
font-weight: 900;
|
||||||
line-height: 44px;
|
line-height: 44px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
.level {
|
.level {
|
||||||
color: #00E5AD;
|
color: #00E5AD;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { withAuth, RadarChart } from "@/components";
|
|||||||
import evaluateService, {
|
import evaluateService, {
|
||||||
LastTimeTestResult,
|
LastTimeTestResult,
|
||||||
Question,
|
Question,
|
||||||
|
TestResultData,
|
||||||
} from "@/services/evaluateService";
|
} from "@/services/evaluateService";
|
||||||
import { useUserInfo, useUserActions } from "@/store/userStore";
|
import { useUserInfo, useUserActions } from "@/store/userStore";
|
||||||
import { delay } from "@/utils";
|
import { delay } from "@/utils";
|
||||||
@@ -323,12 +324,28 @@ function Test(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Result() {
|
function Result() {
|
||||||
|
const { params } = useRouter();
|
||||||
|
const { id } = params;
|
||||||
const userInfo = useUserInfo();
|
const userInfo = useUserInfo();
|
||||||
const { fetchUserInfo } = useUserActions();
|
const { fetchUserInfo } = useUserActions();
|
||||||
|
|
||||||
|
const [result, setResult] = useState<TestResultData>();
|
||||||
|
const [radarData, setRadarData] = useState<[propName: string, prop: number][]>([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchUserInfo()
|
getResultById();
|
||||||
}, [])
|
fetchUserInfo();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function getResultById() {
|
||||||
|
const res = await evaluateService.getTestResult({ record_id: Number(id) });
|
||||||
|
if (res.code === 0) {
|
||||||
|
setResult(res.data);
|
||||||
|
setRadarData(Object.entries(res.data.radar_data.abilities).map(([key, value]) => [key, value.current_score]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(result, "result");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View className={styles.resultContainer}>
|
<View className={styles.resultContainer}>
|
||||||
@@ -357,14 +374,14 @@ function Result() {
|
|||||||
</View>
|
</View>
|
||||||
<View className={styles.levelWrap}>
|
<View className={styles.levelWrap}>
|
||||||
<Text>NTRP</Text>
|
<Text>NTRP</Text>
|
||||||
<Text className={styles.level}>{1.1}</Text>
|
<Text className={styles.level}>{result?.ntrp_level}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View className={styles.slogan}>
|
<View className={styles.slogan}>
|
||||||
<Text>变线+网前,下一步就是赢比赛!</Text>
|
<Text>变线+网前,下一步就是赢比赛!</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<RadarChart />
|
<RadarChart data={radarData} />
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user