feat: ntrp逻辑变更 & 替换海报二维码

This commit is contained in:
2025-10-06 14:52:31 +08:00
parent f2e9d20094
commit 05b941613c
11 changed files with 430 additions and 207 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useEffect, useRef, useId } from "react";
import { useState, useEffect, useRef, useId, useMemo } from "react";
import { View, Text, Image, Button, Canvas } from "@tarojs/components";
import Taro, { useRouter, useShareAppMessage } from "@tarojs/taro";
import dayjs from "dayjs";
@@ -289,10 +289,15 @@ function Test() {
setDisabled(questions[index]?.choosen === -1);
}, [index, questions]);
const doneFlag = useMemo(() => {
const [q1, q2, q3] = questions;
return [q1, q2, q3].every((q) => q?.choosen === 0);
}, [questions]);
async function getQUestions() {
const res = await evaluateService.getQuestions();
if (res.code === 0) {
setQuestions(res.data.map((item) => ({ ...item, choosen: 3 })));
setQuestions(res.data.map((item) => ({ ...item, choosen: -1 })));
}
}
@@ -309,10 +314,12 @@ function Test() {
setDisabled(true);
try {
const res = await evaluateService.submit({
answers: questions.map((item) => ({
question_id: item.id,
answer_index: item.choosen,
})),
answers: questions
.filter((item) => item.choosen >= 0)
.map((item) => ({
question_id: item.id,
answer_index: item.choosen,
})),
test_duration: (Date.now() - startTimeRef.current) / 1000,
});
if (res.code === 0) {
@@ -332,7 +339,7 @@ function Test() {
if (disabled && direction > 0) {
return;
}
if (index === questions.length - 1 && direction > 0) {
if ((index === questions.length - 1 || doneFlag) && direction > 0) {
handleSubmit();
return;
}
@@ -384,7 +391,7 @@ function Test() {
onClick={() => handIndexChange(1)}
>
<Button className={styles.nextBtn} type="primary">
{index === questions.length - 1 ? "完成测试" : "继续"}
{index === questions.length - 1 || doneFlag ? "完成测试" : "继续"}
</Button>
</View>
{index !== 0 && (
@@ -476,7 +483,7 @@ function Result() {
.exec((res2) => {
const canvas = res2[0].node;
const ctx = canvas.getContext("2d");
const dpr = Taro.getSystemInfoSync().pixelRatio;
const dpr = Taro.getWindowInfo().pixelRatio;
const width = 300;
const height = 400;
canvas.width = width * dpr;
@@ -515,11 +522,33 @@ function Result() {
}
async function handleSaveImage() {
console.log(userInfo);
if (!userInfo.id) {
return;
}
const url = await genCardImage();
Taro.saveImageToPhotosAlbum({ filePath: url });
Taro.getSetting().then(async (res) => {
if (!res.authSetting["scope.writePhotosAlbum"]) {
Taro.authorize({
scope: "scope.writePhotosAlbum",
success: async () => {
const url = await genCardImage();
Taro.saveImageToPhotosAlbum({ filePath: url });
},
fail: () => {
Taro.showModal({
title: "提示",
content: "需要开启相册权限才能保存图片",
success: (r) => {
if (r.confirm) Taro.openSetting();
},
});
},
});
} else {
const url = await genCardImage();
Taro.saveImageToPhotosAlbum({ filePath: url });
}
});
}
useShareAppMessage(async (res) => {
@@ -553,7 +582,7 @@ function Result() {
<Image
className={styles.avatarUrl}
src={userInfo.avatar_url}
mode="aspectFit"
mode="aspectFill"
/>
</View>
{/* avatar side */}