diff --git a/mbti-test-mini/src/app.config.ts b/mbti-test-mini/src/app.config.ts
index 71ae772..cdd5450 100644
--- a/mbti-test-mini/src/app.config.ts
+++ b/mbti-test-mini/src/app.config.ts
@@ -2,6 +2,7 @@ export default defineAppConfig({
pages: [
'pages/index/index',
'pages/doQuestion/index',
+ 'pages/result/index',
],
window: {
backgroundTextStyle: 'light',
diff --git a/mbti-test-mini/src/data/question_results.json b/mbti-test-mini/src/data/question_results.json
new file mode 100644
index 0000000..f06b26d
--- /dev/null
+++ b/mbti-test-mini/src/data/question_results.json
@@ -0,0 +1,178 @@
+[
+ {
+ "resultProp": [
+ "I",
+ "S",
+ "T",
+ "J"
+ ],
+ "resultDesc": "忠诚可靠,被公认为务实,注重细节。",
+ "resultPicture": "icon_url_istj",
+ "resultName": "ISTJ(物流师)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "S",
+ "F",
+ "J"
+ ],
+ "resultDesc": "善良贴心,以同情心和责任为特点。",
+ "resultPicture": "icon_url_isfj",
+ "resultName": "ISFJ(守护者)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "N",
+ "F",
+ "J"
+ ],
+ "resultDesc": "理想主义者,有着深刻的洞察力,善于理解他人。",
+ "resultPicture": "icon_url_infj",
+ "resultName": "INFJ(占有者)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "N",
+ "T",
+ "J"
+ ],
+ "resultDesc": "独立思考者,善于规划和实现目标,理性而果断。",
+ "resultPicture": "icon_url_intj",
+ "resultName": "INTJ(设计师)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "S",
+ "T",
+ "P"
+ ],
+ "resultDesc": "冷静自持,善于解决问题,擅长实践技能。",
+ "resultPicture": "icon_url_istp",
+ "resultName": "ISTP(运动员)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "S",
+ "F",
+ "P"
+ ],
+ "resultDesc": "具有艺术感和敏感性,珍视个人空间和自由。",
+ "resultPicture": "icon_url_isfp",
+ "resultName": "ISFP(艺术家)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "N",
+ "F",
+ "P"
+ ],
+ "resultDesc": "理想主义者,富有创造力,以同情心和理解他人著称。",
+ "resultPicture": "icon_url_infp",
+ "resultName": "INFP(治愈者)"
+ },
+ {
+ "resultProp": [
+ "I",
+ "N",
+ "T",
+ "P"
+ ],
+ "resultDesc": "思维清晰,探索精神,独立思考且理性。",
+ "resultPicture": "icon_url_intp",
+ "resultName": "INTP(学者)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "S",
+ "T",
+ "P"
+ ],
+ "resultDesc": "敢于冒险,乐于冒险,思维敏捷,行动果断。",
+ "resultPicture": "icon_url_estp",
+ "resultName": "ESTP(拓荒者)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "S",
+ "F",
+ "P"
+ ],
+ "resultDesc": "热情开朗,善于社交,热爱生活,乐于助人。",
+ "resultPicture": "icon_url_esfp",
+ "resultName": "ESFP(表演者)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "N",
+ "F",
+ "P"
+ ],
+ "resultDesc": "富有想象力,充满热情,善于激发他人的活力和潜力。",
+ "resultPicture": "icon_url_enfp",
+ "resultName": "ENFP(倡导者)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "N",
+ "T",
+ "P"
+ ],
+ "resultDesc": "充满创造力,善于辩论,挑战传统,喜欢探索新领域。",
+ "resultPicture": "icon_url_entp",
+ "resultName": "ENTP(发明家)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "S",
+ "T",
+ "J"
+ ],
+ "resultDesc": "务实果断,善于组织和管理,重视效率和目标。",
+ "resultPicture": "icon_url_estj",
+ "resultName": "ESTJ(主管)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "S",
+ "F",
+ "J"
+ ],
+ "resultDesc": "友善热心,以协调、耐心和关怀为特点,善于团队合作。",
+ "resultPicture": "icon_url_esfj",
+ "resultName": "ESFJ(尽责者)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "N",
+ "F",
+ "J"
+ ],
+ "resultDesc": "热情关爱,善于帮助他人,具有领导力和社交能力。",
+ "resultPicture": "icon_url_enfj",
+ "resultName": "ENFJ(教导着)"
+ },
+ {
+ "resultProp": [
+ "E",
+ "N",
+ "T",
+ "J"
+ ],
+ "resultDesc": "果断自信,具有领导才能,善于规划和执行目标。",
+ "resultPicture": "icon_url_entj",
+ "resultName": "ENTJ(统帅)"
+ }
+ ]
\ No newline at end of file
diff --git a/mbti-test-mini/src/pages/result/index.config.ts b/mbti-test-mini/src/pages/result/index.config.ts
new file mode 100644
index 0000000..d9c53d7
--- /dev/null
+++ b/mbti-test-mini/src/pages/result/index.config.ts
@@ -0,0 +1,3 @@
+export default definePageConfig({
+ navigationBarTitleText: '测试结果'
+})
diff --git a/mbti-test-mini/src/pages/result/index.scss b/mbti-test-mini/src/pages/result/index.scss
new file mode 100644
index 0000000..e680e7e
--- /dev/null
+++ b/mbti-test-mini/src/pages/result/index.scss
@@ -0,0 +1,24 @@
+.resultPage {
+ background-image: url('../../assets/headerBg.jpg');
+ background-size: cover;
+ background-position: center;
+ background-repeat: no-repeat;
+ min-height: 100vh; // 保证全屏
+
+ .title {
+ color: #fff;
+ padding-top: 48px;
+ margin-bottom: 24px;
+ text-align: center;
+ }
+
+ .subTitle {
+ color: #fff;
+ margin-bottom: 48px;
+ }
+
+ .enterBtn {
+ width: 60vw;
+ min-width: 180px;
+ }
+}
diff --git a/mbti-test-mini/src/pages/result/index.tsx b/mbti-test-mini/src/pages/result/index.tsx
new file mode 100644
index 0000000..ea7c44d
--- /dev/null
+++ b/mbti-test-mini/src/pages/result/index.tsx
@@ -0,0 +1,49 @@
+import {View, Image} from "@tarojs/components";
+import {AtButton} from "taro-ui";
+import Taro from "@tarojs/taro";
+import headerBg from "../../assets/headerBg.jpg";
+import GlobalFooter from "../../components/GlobalFooter";
+import {getBestQuestionResult} from "../../utils/bizUtils";
+import questions from "../../data/questions.json";
+import questionResults from "../../data/question_results.json";
+import "./index.scss";
+
+/**
+ * 测试结果页面
+ * @author 程序员鱼皮
+ * @from 编程导航学习圈
+ */
+export default () => {
+ // 获取答案
+ const answerList = Taro.getStorageSync("answerList");
+ if (!answerList || answerList.length < 1) {
+ Taro.showToast({
+ title: "答案为空",
+ icon: "error",
+ duration: 3000,
+ });
+ }
+ // 获取测试结果
+ const result = getBestQuestionResult(answerList, questions, questionResults);
+
+ return (
+
+ {result.resultName}
+ {result.resultDesc}
+ {
+ Taro.reLaunch({
+ url: "/pages/index/index",
+ });
+ }}
+ >
+ 返回主页
+
+
+
+
+ );
+};
\ No newline at end of file
diff --git a/mbti-test-mini/src/utils/bizUtils.ts b/mbti-test-mini/src/utils/bizUtils.ts
new file mode 100644
index 0000000..0674fea
--- /dev/null
+++ b/mbti-test-mini/src/utils/bizUtils.ts
@@ -0,0 +1,140 @@
+/**
+ * 获取最佳题目评分结果
+ * @param answerList
+ * @param questions
+ * @param question_results
+ */
+
+export function getBestQuestionResult(answerList, questions, question_results) {
+ // 初始化一个对象,用于存储每个选项的计数
+ const optionCount = {};
+
+ // 用户选择 A, B, C
+ // 对应 result:I, I, J
+ // optionCount[I] = 2; optionCount[J] = 1
+
+ // 遍历题目列表
+ for (const question of questions) {
+ // 遍历答案列表
+ for (const answer of answerList) {
+ // 遍历题目中的选项
+ for (const option of question.options) {
+ // 如果答案和选项的key匹配
+ if (option.key === answer) {
+ // 获取选项的result属性
+ const result = option.result;
+
+ // 如果result属性不在optionCount中,初始化为0
+ if (!optionCount[result]) {
+ optionCount[result] = 0;
+ }
+
+ // 在optionCount中增加计数
+ optionCount[result]++;
+ }
+ }
+ }
+ }
+
+ // 初始化最高分数和最高分数对应的评分结果
+ let maxScore = 0;
+ let maxScoreResult = question_results[0];
+
+ // 遍历评分结果列表
+ for (const result of question_results) {
+ // 计算当前评分结果的分数
+ const score = result.resultProp.reduce((count, prop) => {
+ return count + (optionCount[prop] || 0);
+ }, 0);
+
+ // 如果分数高于当前最高分数,更新最高分数和最高分数对应的评分结果
+ if (score > maxScore) {
+ maxScore = score;
+ maxScoreResult = result;
+ }
+ }
+
+ // 返回最高分数和最高分数对应的评分结果
+ return maxScoreResult;
+ }
+
+ // 示例数据
+ const answerList = ["B","B","B","A"];
+ const questions = [
+ {
+ title: "你通常更喜欢",
+ options: [
+ {
+ result: "I",
+ value: "独自工作",
+ key: "A",
+ },
+ {
+ result: "E",
+ value: "与他人合作",
+ key: "B",
+ },
+ ],
+ },
+ {
+ options: [
+ {
+ result: "S",
+ value: "喜欢有结构和常规",
+ key: "A",
+ },
+ {
+ result: "N",
+ value: "喜欢自由和灵活性",
+ key: "B",
+ },
+ ],
+ title: "对于日常安排",
+ },
+ {
+ options: [
+ {
+ result: "P",
+ value: "首先考虑可能性",
+ key: "A",
+ },
+ {
+ result: "J",
+ value: "首先考虑后果",
+ key: "B",
+ },
+ ],
+ title: "当遇到问题时",
+ },
+ {
+ options: [
+ {
+ result: "T",
+ value: "时间是一种宝贵的资源",
+ key: "A",
+ },
+ {
+ result: "F",
+ value: "时间是相对灵活的概念",
+ key: "B",
+ },
+ ],
+ title: "你如何看待时间",
+ },
+ ];
+ const question_results = [
+ {
+ resultProp: ["I", "S", "T", "J"],
+ resultDesc: "忠诚可靠,被公认为务实,注重细节。",
+ resultPicture: "icon_url_istj",
+ resultName: "ISTJ(物流师)",
+ },
+ {
+ resultProp: ["I", "S", "F", "J"],
+ resultDesc: "善良贴心,以同情心和责任为特点。",
+ resultPicture: "icon_url_isfj",
+ resultName: "ISFJ(守护者)",
+ },
+ ];
+
+ console.log(getBestQuestionResult(answerList, questions, question_results));
\ No newline at end of file