ResultView.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 defectsList = ref(null);
  21. const taskId = computed(() => route.query.conversationId); // 会话ID "2c64eb8b69be432ca0bb9ae55bc78def"
  22. const randarlist = ref([0, 0, 0, 0]);
  23. const loading = ref(false);
  24. const nameMapping = {
  25. introduction_profession: "自我介绍专业性",
  26. basic_information: "客户画像采集",
  27. purchase_intent: "需求挖掘能力",
  28. invitation_results: "沟通转化效果",
  29. penalty_points: "扣分项",
  30. defects: "评分详解"
  31. };
  32. const handleResult = async () => {
  33. let res;
  34. let shouldContinue = true; // 控制是否继续调用接口的标志
  35. loading.value = true;
  36. while (shouldContinue) {
  37. res = await fetchTaskScore(taskId.value);
  38. if (res.code !== 200) {
  39. // 当返回错误时,停止调用接口
  40. loading.value = false
  41. shouldContinue = false;
  42. } else if (res.body && Object.keys(res.body).length !== 0) {
  43. // 当res.body有值时,停止调用接口
  44. data.value = res.body;
  45. shouldContinue = false;
  46. } else {
  47. await new Promise((resolve) => setTimeout(resolve, 3000));
  48. }
  49. }
  50. if (res && res.code === 200 && res.body) {
  51. loading.value = false;
  52. const scores = extractScores(res.body);
  53. score.value = scores.reduce((sum, score) => sum + score, 0);
  54. scoresList.value = Object.keys(res.body).reduce((acc, key) => {
  55. if (key !== "defects") {
  56. acc[key] = {
  57. ...res.body[key],
  58. name: nameMapping[key], // 添加 name 字段
  59. };
  60. }
  61. return acc;
  62. }, {});
  63. defectsList.value = res.body.defects;
  64. console.log(defectsList.value, '000000000');
  65. const obj = extractScores(scoresList.value);
  66. randarlist.value = Object.values(obj);
  67. }
  68. };
  69. // 处理“分”字
  70. const extractScores = (data) => {
  71. return Object.values(data).map((item) => {
  72. // 确保 score 是一个字符串,并且去除可能的 "分" 字
  73. let scoreStr = String(item.score).replace("分", "");
  74. // 将 score 转换为整数,如果转换失败则返回 0
  75. const score = parseInt(scoreStr, 10);
  76. return isNaN(score) ? 0 : score;
  77. });
  78. };
  79. onMounted(() => {
  80. handleResult();
  81. window.addEventListener("popstate", function (event) {
  82. // 执行一些操作,例如关闭当前页面或跳转到其他页面
  83. window.location.href = "/#/home";
  84. });
  85. });
  86. onBeforeUnmount(() => {
  87. window.removeEventListener("popstate", function (event) {
  88. // 执行一些操作,例如关闭当前页面或跳转到其他页面
  89. window.location.href = "/#/home";
  90. });
  91. });
  92. </script>
  93. <template>
  94. <div class="result" style="overflow: hidden">
  95. <NavBarPage title="考试" type="home" />
  96. <div style="height: 46px"></div>
  97. <div class="score">
  98. <span>最终得分</span>
  99. <p class="score-num">
  100. <span style="margin-right: 0.2rem;">{{ score }}</span>分
  101. </p>
  102. </div>
  103. <div style="height: 9.06rem; visibility: hidden"></div>
  104. <div class="content">
  105. <div style="width: 100vw; height: 19.06rem">
  106. <randarPage :randarList="randarlist" />
  107. </div>
  108. <div class="loading" v-show="loading">
  109. <van-loading color="#0094ff" size="26px" vertical>加载中...</van-loading>
  110. </div>
  111. <div class="standard">
  112. <div class="standard-title">
  113. <img src="../assets/robot.jpg" alt="" />
  114. <span>评分标准</span>
  115. </div>
  116. <div class="standard-content" v-for="(item, key) in scoresList" :key="key">
  117. <div class="standard-subtitle">
  118. <span class="pro">{{ item.name == "扣分项" ? item.name : `${item.name}(25分)` }}:</span>
  119. <span>{{ item.score }}</span>
  120. </div>
  121. <p>
  122. <span>得分原因:</span>
  123. <span>{{ item.reason }}</span>
  124. </p>
  125. </div>
  126. <div class="standard-content" style="margin-top: 1.5rem;">
  127. <div class="standard-title">
  128. <img src="../assets/robot.jpg" alt="" />
  129. <span>评分详解</span>
  130. </div>
  131. <div class="standard-content" v-for="(item, index) in defectsList" :key="index">
  132. <div class="standard-subtitle">
  133. <span class="pro">轮次{{item.rounds}}:</span>
  134. </div>
  135. <p>
  136. <span>原句:</span>
  137. <span>{{ item.original_sentence }}</span>
  138. </p>
  139. <p>
  140. <span>不足:</span>
  141. <span>{{ item.defect }}</span>
  142. </p>
  143. <p>
  144. <span>建议:</span>
  145. <span>{{ item.example }}</span>
  146. </p>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </template>
  153. <style scoped lang="less">
  154. html,
  155. body {
  156. margin: 0;
  157. padding: 0;
  158. height: 100vh;
  159. overflow: hidden;
  160. /* 禁止页面整体滚动 */
  161. }
  162. .result {
  163. width: 100%;
  164. height: 100%;
  165. /* height: 100vh; */
  166. overflow: hidden;
  167. }
  168. .score {
  169. position: fixed;
  170. z-index: 999;
  171. width: 100%;
  172. height: 9.06rem;
  173. background-color: rgba(243, 249, 255, 1);
  174. display: flex;
  175. flex-direction: column;
  176. align-items: center;
  177. justify-content: center;
  178. span {
  179. display: flex;
  180. width: 5.06rem;
  181. height: 2.88rem;
  182. font-weight: bold;
  183. line-height: 2.88rem;
  184. color: rgba(64, 149, 229, 1);
  185. font-size: 1rem;
  186. text-align: center;
  187. font-family: Times New Roman-regular;
  188. }
  189. .score-num {
  190. display: flex;
  191. align-items: last baseline;
  192. color: rgba(64, 149, 229, 1);
  193. font-size: 1rem;
  194. span {
  195. display: block;
  196. width: 5.06rem;
  197. height: 3.31rem;
  198. line-height: 4.25rem;
  199. font-size: 3rem;
  200. text-align: center;
  201. font-family: Times New Roman-regular;
  202. }
  203. }
  204. }
  205. .content {
  206. width: 100%;
  207. height: 100%;
  208. overflow: scroll;
  209. }
  210. .standard-title {
  211. display: flex;
  212. align-items: center;
  213. padding: 0 0.94rem;
  214. margin-bottom: 0.63rem;
  215. img {
  216. width: 1.5rem;
  217. height: 1.5rem;
  218. }
  219. span {
  220. display: inline-block;
  221. width: 4rem;
  222. height: 1.44rem;
  223. line-height: 1.44rem;
  224. margin-left: 0.33rem;
  225. color: rgba(64, 149, 229, 1);
  226. font-size: 1rem;
  227. text-align: center;
  228. font-family: Times New Roman-regular;
  229. }
  230. }
  231. .standard-subtitle {
  232. padding: 0.56rem 1rem;
  233. height: 1.06rem;
  234. font-size: 0.88rem;
  235. font-family: Times New Roman-regular;
  236. span {
  237. color: rgba(64, 149, 229, 1);
  238. font-weight: 600;
  239. }
  240. .pro {
  241. display: inline-block;
  242. height: 1.06rem;
  243. line-height: 1.06rem;
  244. padding: 0 0.3rem;
  245. font-weight: normal;
  246. color: rgba(102, 102, 102, 1);
  247. border-left: 0.3rem solid rgba(64, 149, 229, 1);
  248. }
  249. }
  250. .standard-content p {
  251. padding: 0 1.63rem;
  252. margin-bottom: 0.31rem;
  253. line-height: 1.25rem;
  254. color: rgba(102, 102, 102, 1);
  255. font-size: 0.88rem;
  256. text-align: left;
  257. font-family: SourceHanSansSC-bold;
  258. }
  259. .standard-content p span:nth-child(1) {
  260. font-weight: 600;
  261. }
  262. .loading {
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. width: 100%;
  267. height: 100%;
  268. background-color: rgba(0, 0, 0, 0.5);
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. z-index: 9999;
  273. }
  274. </style>