ResultView.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <script setup lang="ts">
  2. import {
  3. ref,
  4. reactive,
  5. toRefs,
  6. onMounted,
  7. watch,
  8. computed,
  9. onBeforeUnmount,
  10. } from "vue";
  11. import NavBarPage from "../components/NavBarPage.vue";
  12. import randarPage from "./result/randarPage.vue";
  13. import { useRoute } from "vue-router";
  14. import { fetchTaskScore } from "./utils/api";
  15. import { Toast } from "vant";
  16. const route = useRoute();
  17. const score = ref(0);
  18. const data = ref(null);
  19. const scoresList = ref(null);
  20. const taskId = computed(() => route.query.conversationId); // 会话ID "2c64eb8b69be432ca0bb9ae55bc78def"
  21. const randarlist = ref([0, 0, 0, 0]);
  22. const nameMapping = {
  23. introduction_profession: "自我介绍专业性",
  24. demand_accuracy: "挖掘需求准确性",
  25. product_advantages: "清晰表达产品优势",
  26. attract_interest: "吸引客户兴趣",
  27. penalty_points: "扣分项",
  28. };
  29. const handleResult = async () => {
  30. let res;
  31. let shouldContinue = true; // 控制是否继续调用接口的标志
  32. while (shouldContinue) {
  33. res = await fetchTaskScore(taskId.value);
  34. if (res.code !== 200) {
  35. // 当返回错误时,停止调用接口
  36. shouldContinue = false;
  37. } else if (res.body && Object.keys(res.body).length !== 0) {
  38. // 当res.body有值时,停止调用接口
  39. data.value = res.body;
  40. shouldContinue = false;
  41. } else {
  42. await new Promise((resolve) => setTimeout(resolve, 3000));
  43. }
  44. }
  45. if (res && res.code === 200 && res.body) {
  46. const scores = extractScores(res.body);
  47. score.value = scores.reduce((sum, score) => sum + score, 0);
  48. scoresList.value = Object.keys(res.body).reduce((acc, key) => {
  49. // if (key !== "penalty_points") {
  50. acc[key] = {
  51. ...res.body[key],
  52. name: nameMapping[key], // 添加 name 字段
  53. };
  54. // }
  55. return acc;
  56. }, {});
  57. const obj = extractScores(scoresList.value);
  58. randarlist.value = Object.values(obj);
  59. }
  60. };
  61. // 处理“分”字
  62. const extractScores = (data) => {
  63. return Object.values(data).map((item) => {
  64. // 去除可能的"分"字,然后转换为整数
  65. return parseInt(item.score.replace("分", ""), 10);
  66. });
  67. };
  68. onMounted(() => {
  69. handleResult();
  70. window.addEventListener("popstate", function (event) {
  71. // 执行一些操作,例如关闭当前页面或跳转到其他页面
  72. window.location.href = "/#/home";
  73. });
  74. });
  75. onBeforeUnmount(() => {
  76. window.removeEventListener("popstate", function (event) {
  77. // 执行一些操作,例如关闭当前页面或跳转到其他页面
  78. window.location.href = "/#/home";
  79. });
  80. });
  81. </script>
  82. <template>
  83. <div class="result" style="overflow: hidden">
  84. <NavBarPage title="考试" type="home" />
  85. <div style="height: 46px"></div>
  86. <div class="score">
  87. <span>最终得分</span>
  88. <p class="score-num">
  89. <span>{{ score }}</span
  90. >分
  91. </p>
  92. </div>
  93. <div style="height: 9.06rem; visibility: hidden"></div>
  94. <div class="content">
  95. <div style="width: 100vw; height: 19.06rem">
  96. <randarPage :randarList="randarlist" />
  97. </div>
  98. <div class="standard">
  99. <div class="standard-title">
  100. <img src="../assets/robot.jpg" alt="" />
  101. <span>评分标准</span>
  102. </div>
  103. <div
  104. class="standard-content"
  105. v-for="(item, key) in scoresList"
  106. :key="key"
  107. >
  108. <div class="standard-subtitle">
  109. <span class="pro"
  110. >{{
  111. item.name == "扣分项" ? item.name : `${item.name}(50分)`
  112. }}:</span
  113. >
  114. <span>{{ item.score }}</span>
  115. </div>
  116. <p>
  117. <span>得分原因:</span>
  118. <span>{{ item.reason }}</span>
  119. </p>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </template>
  125. <style scoped lang="less">
  126. html,
  127. body {
  128. margin: 0;
  129. padding: 0;
  130. height: 100vh;
  131. overflow: hidden;
  132. /* 禁止页面整体滚动 */
  133. }
  134. .result {
  135. width: 100%;
  136. height: 100%;
  137. /* height: 100vh; */
  138. overflow: hidden;
  139. }
  140. .score {
  141. position: fixed;
  142. z-index: 999;
  143. width: 100%;
  144. height: 9.06rem;
  145. background-color: rgba(243, 249, 255, 1);
  146. display: flex;
  147. flex-direction: column;
  148. align-items: center;
  149. justify-content: center;
  150. span {
  151. display: flex;
  152. width: 5.06rem;
  153. height: 2.88rem;
  154. font-weight: bold;
  155. line-height: 2.88rem;
  156. color: rgba(64, 149, 229, 1);
  157. font-size: 1rem;
  158. text-align: center;
  159. font-family: Times New Roman-regular;
  160. }
  161. .score-num {
  162. display: flex;
  163. align-items: last baseline;
  164. color: rgba(64, 149, 229, 1);
  165. font-size: 1rem;
  166. span {
  167. display: block;
  168. width: 5.06rem;
  169. height: 3.31rem;
  170. line-height: 4.25rem;
  171. font-size: 3rem;
  172. text-align: center;
  173. font-family: Times New Roman-regular;
  174. }
  175. }
  176. }
  177. .content {
  178. width: 100%;
  179. height: 100%;
  180. overflow: scroll;
  181. }
  182. .standard-title {
  183. display: flex;
  184. align-items: center;
  185. padding: 0 0.94rem;
  186. margin-bottom: 0.63rem;
  187. img {
  188. width: 1.5rem;
  189. height: 1.5rem;
  190. }
  191. span {
  192. display: inline-block;
  193. width: 4rem;
  194. height: 1.44rem;
  195. line-height: 1.44rem;
  196. margin-left: 0.33rem;
  197. color: rgba(64, 149, 229, 1);
  198. font-size: 1rem;
  199. text-align: center;
  200. font-family: Times New Roman-regular;
  201. }
  202. }
  203. .standard-subtitle {
  204. padding: 0.56rem 1rem;
  205. height: 1.06rem;
  206. font-size: 0.88rem;
  207. font-family: Times New Roman-regular;
  208. span {
  209. color: rgba(64, 149, 229, 1);
  210. font-weight: 600;
  211. }
  212. .pro {
  213. display: inline-block;
  214. height: 1.06rem;
  215. line-height: 1.06rem;
  216. padding: 0 0.3rem;
  217. font-weight: normal;
  218. color: rgba(102, 102, 102, 1);
  219. border-left: 0.3rem solid rgba(64, 149, 229, 1);
  220. }
  221. }
  222. .standard-content p {
  223. padding: 0 1.63rem;
  224. margin-bottom: 0.31rem;
  225. line-height: 1.25rem;
  226. color: rgba(102, 102, 102, 1);
  227. font-size: 0.88rem;
  228. text-align: left;
  229. font-family: SourceHanSansSC-bold;
  230. }
  231. .standard-content p span:nth-child(1) {
  232. font-weight: 600;
  233. }
  234. </style>