QuestionsItem.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <script setup>
  2. import Questions from "./QuestionsItemSelect.vue";
  3. import uvParse from "@/uni_modules/uv-parse/components/uv-parse/uv-parse.vue";
  4. import { ref, watchEffect } from "vue";
  5. import { router } from "../../utils/router";
  6. const dataList = ref([]);
  7. const props = defineProps({
  8. data: {
  9. type: Array,
  10. default: () => [],
  11. },
  12. isRight: {
  13. type: Boolean,
  14. default: true,
  15. },
  16. onClick: {
  17. type: Function,
  18. },
  19. catalogue_id: {
  20. type: Number,
  21. default: 0,
  22. },
  23. });
  24. const TopicMapList = ["A", "B", "C", "D", "E"];
  25. watchEffect(() => {
  26. dataList.value = props.data.map((item, ind) => {
  27. let questions = [];
  28. const ans = item.correct_answer.split(",");
  29. const ansList = [];
  30. for (let i = 0; i < item.question_count; i++) {
  31. const current = TopicMapList[i];
  32. if (ans.includes(current)) {
  33. ansList.push({
  34. label: current,
  35. value: i,
  36. });
  37. }
  38. const v =
  39. item[`select_${current.toLowerCase()}`].replace(/<br\s*\/?>/g, "") ||
  40. "";
  41. questions.push({
  42. label: v,
  43. value: current,
  44. checked: false,
  45. index: i,
  46. });
  47. }
  48. return {
  49. ...item,
  50. questions, // 题目
  51. ansList, // 正确答案
  52. selectAns: !item.user_answer ? [] : item.user_answer.split(","), // 选择的答案
  53. isRight: !!item.is_correct, // 是否正确
  54. isImage: item.title.includes("<img"),
  55. ind,
  56. };
  57. });
  58. });
  59. const handleClick = (item) => {
  60. if (props.onClick) {
  61. props.onClick(item);
  62. return;
  63. }
  64. router.push({
  65. url: "/pages/learn/rightPractice",
  66. params: {
  67. catalogue_id: props.catalogue_id,
  68. isRight: props.isRight,
  69. },
  70. });
  71. console.log(item);
  72. };
  73. </script>
  74. <template>
  75. <!-- 问题内容 -->
  76. <view
  77. class="topic-content"
  78. v-for="(item, parindex) in dataList"
  79. :key="parindex"
  80. v-if="dataList.length"
  81. >
  82. <uvParse
  83. v-if="item.isImage"
  84. :content="item.title"
  85. class="question-text"
  86. ></uvParse>
  87. <rich-text v-else :nodes="item.title" class="question-text"></rich-text>
  88. <uvParse
  89. :content="item.questions_ex"
  90. v-if="item.style === 6 && item.isImage"
  91. class="question-text"
  92. ></uvParse>
  93. <rich-text
  94. v-else
  95. :nodes="item.questions_ex"
  96. class="question-text"
  97. :style="{
  98. lineHeight: 2,
  99. }"
  100. ></rich-text>
  101. <questions
  102. v-if="item.style !== 6"
  103. v-for="(question, index) in item.questions"
  104. :key="index"
  105. :answerList="item.ansList"
  106. :index="index"
  107. :styleCount="item.style"
  108. :question="question"
  109. :showResult="item.showResult"
  110. :parindex="parindex"
  111. />
  112. <view class="other" v-else>
  113. <questions
  114. v-for="(question, index) in item.questions"
  115. :key="index"
  116. :answerList="item.ansList"
  117. :index="index"
  118. :styleCount="item.style"
  119. :question="question"
  120. :showResult="item.showResult"
  121. :parindex="parindex"
  122. />
  123. </view>
  124. <div class="footer">
  125. <view v-if="isRight" class="c-primary" @click="handleClick(item)">{{
  126. onClick ? "答题" : "查看"
  127. }}</view>
  128. <view v-else class="c-error" @click="handleClick(item)">重做</view>
  129. </div>
  130. </view>
  131. </template>
  132. <style lang="scss" scoped>
  133. @import "@/uni.scss";
  134. .other {
  135. display: flex;
  136. gap: 12px;
  137. margin-top: 20rpx;
  138. }
  139. .footer {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. }
  144. .c-primary {
  145. padding: 2rpx 10rpx;
  146. border-radius: 4rpx;
  147. border: 1rpx solid $primary;
  148. color: $primary;
  149. font-size: 24rpx;
  150. }
  151. .c-error {
  152. padding: 2rpx 10rpx;
  153. border-radius: 4rpx;
  154. border: 1rpx solid $error;
  155. color: $error;
  156. font-size: 24rpx;
  157. }
  158. .content {
  159. font-family: PingFang SC, PingFang SC;
  160. font-weight: 500;
  161. font-size: 28rpx;
  162. color: #333333;
  163. display: flex;
  164. flex-direction: column;
  165. gap: 24rpx;
  166. padding: 0 30rpx;
  167. .ques-type {
  168. display: flex;
  169. gap: 16rpx;
  170. flex-direction: column;
  171. }
  172. }
  173. .grid {
  174. display: grid;
  175. grid-template-columns: repeat(5, 1fr);
  176. gap: 12px;
  177. }
  178. .bottom-modal {
  179. display: flex;
  180. flex-direction: column;
  181. gap: 20rpx;
  182. // padding: 20rpx;
  183. }
  184. .title {
  185. display: flex;
  186. justify-content: center;
  187. align-items: center;
  188. position: relative;
  189. .closeempty {
  190. position: absolute;
  191. right: 0;
  192. }
  193. }
  194. .parsing-text {
  195. height: 381rpx;
  196. white-space: normal;
  197. }
  198. .answer-content {
  199. display: flex;
  200. flex-direction: column;
  201. gap: 45rpx;
  202. font-family: PingFang SC, PingFang SC;
  203. font-weight: 500;
  204. font-size: 32rpx;
  205. color: #666666;
  206. }
  207. .topic-container {
  208. width: 100vw;
  209. overflow: hidden;
  210. position: relative;
  211. }
  212. .topic-item {
  213. display: flex;
  214. flex-direction: column;
  215. gap: 12px;
  216. position: relative;
  217. box-sizing: border-box;
  218. }
  219. .topic-header {
  220. display: flex;
  221. align-items: center;
  222. justify-content: space-between;
  223. }
  224. .topic-header-left {
  225. display: flex;
  226. gap: 8px;
  227. align-items: center;
  228. }
  229. .item {
  230. width: 72rpx;
  231. height: 72rpx;
  232. border-radius: 50%;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. border: 1rpx solid #dddddd;
  237. &.success {
  238. border-color: $primary;
  239. color: $primary;
  240. }
  241. }
  242. .topic-type {
  243. border: 1px solid $uni-primary;
  244. padding: 0 8px;
  245. border-radius: 6px;
  246. color: $uni-primary;
  247. font-weight: 600;
  248. font-size: 14px;
  249. }
  250. .topic-count {
  251. color: #333;
  252. font-size: 14px;
  253. }
  254. .topic-content {
  255. display: flex;
  256. flex-direction: column;
  257. gap: 8px;
  258. background-color: #fff;
  259. margin-top: 16rpx;
  260. padding: 24rpx;
  261. border-radius: 16rpx;
  262. }
  263. .question-text {
  264. font-weight: bold;
  265. font-size: 14px;
  266. white-space: normal;
  267. }
  268. .answer-section {
  269. border-radius: 16rpx;
  270. border: 1px solid #ddd;
  271. padding: 24rpx;
  272. display: flex;
  273. flex-direction: column;
  274. gap: 32rpx;
  275. }
  276. .answer-row {
  277. font-size: 14px;
  278. display: flex;
  279. align-items: center;
  280. gap: 12px;
  281. }
  282. .answer-item {
  283. display: flex;
  284. gap: 8px;
  285. align-items: center;
  286. padding-right: 12px;
  287. }
  288. .tip {
  289. margin-left: auto;
  290. }
  291. .border-r-primary {
  292. border-right: 2px solid $uni-primary;
  293. }
  294. .answer-text {
  295. color: $uni-primary;
  296. }
  297. .button-group {
  298. display: flex;
  299. gap: 8px;
  300. position: sticky;
  301. bottom: 0;
  302. margin-top: auto;
  303. }
  304. .prev-btn {
  305. flex: 1;
  306. background-color: $uni-primary-light;
  307. color: $uni-primary;
  308. }
  309. .next-btn {
  310. flex: 1;
  311. background-color: $uni-primary;
  312. color: #fff;
  313. }
  314. .star-icon {
  315. display: flex;
  316. flex-direction: column;
  317. align-items: center;
  318. font-weight: 500;
  319. font-size: 20rpx;
  320. color: #000000;
  321. }
  322. </style>