QuestionsItem.vue 6.1 KB

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