index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <view class="comQuestion">
  3. <view class="title">{{ titleConfig.title }}</view>
  4. <view class="subTitle">{{ titleConfig.subTitle }}</view>
  5. <!-- 题号题型 -->
  6. <view class="tip">
  7. <view class="type">
  8. 单选题(10分)
  9. </view>
  10. <view class="number">
  11. 1/10
  12. </view>
  13. </view>
  14. <!-- 题目主体 -->
  15. <view class="question">
  16. <view class="descripiton">
  17. 如果一个或多个地区货币对外贬值,一般导致如果一个或多个地区货币对外贬值,一般导致
  18. </view>
  19. <view class="option" v-for="item in optionList" :key="item.code" @click="handleClick(item)">
  20. <view
  21. :class="['number', selectedOption.includes(item.code) ? 'active':'', isTrue ? '': 'falseResult', isResult ? 'trueResult':'']">
  22. {{item.code}}
  23. </view>
  24. <view :class="['content', isTrue ? '': 'falseOption', isResult ? 'trueOption':'']">
  25. {{item.optVal}}
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 如果题型是多选的话展示提交按钮且未答题时 -->
  30. <view class="submitBtn">
  31. <u-button color="#f8572c" shape="circle" text="提交答案" @click="handleSubmit"></u-button>
  32. </view>
  33. <!-- 答案 -->
  34. <view class="answerBox" v-if="isAnswer">
  35. <view class="resultBox">
  36. <view :class="['sign', isTrue ? '': 'falseSign']">{{isTrue ? '✓':'x'}}</view>
  37. <view :class="['result', isTrue ? '': 'falseResult']">{{isTrue ? '回答正确':'回答错误'}}</view>
  38. </view>
  39. <view class="detailBox">
  40. <view class="true_result">
  41. <view class="sign">正确答案</view>
  42. <view class="result">B</view>
  43. </view>
  44. <view class="user_result">
  45. <view class="sign">您的答案</view>
  46. <view :class="['result', isTrue ? '': 'falseResult']">{{selectVal}}</view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 问题解析 -->
  51. <view class="analysis" v-if="isAnswer">
  52. <view class="analysis_title">
  53. 解析
  54. </view>
  55. <view class="analysis_content">
  56. 本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加本国进口增加
  57. </view>
  58. </view>
  59. <!-- 底部题卡-->
  60. <QuestionTabbar />
  61. </view>
  62. </template>
  63. <script>
  64. import QuestionTabbar from "../tabbar/index.vue";
  65. export default {
  66. components: {
  67. QuestionTabbar
  68. },
  69. props: {
  70. titleConfig: {
  71. type: Object,
  72. default: () => ({
  73. title: "",
  74. subTitle: "",
  75. })
  76. }
  77. },
  78. data() {
  79. return {
  80. // 记录用户的回答是否正确
  81. isTrue: true,
  82. // 正确选项
  83. isResult: false,
  84. // 是否答题
  85. isAnswer: false,
  86. // 存储多选时选中的选项
  87. selectedOption: [],
  88. // 存储用户选中的选项
  89. selectVal: "",
  90. // 选项列表(模拟数据)
  91. optionList: [{
  92. code: 'A',
  93. optVal: "本国出口减少"
  94. },
  95. {
  96. code: 'B',
  97. optVal: "本国出口增加"
  98. },
  99. {
  100. code: 'C',
  101. optVal: "本国进口增加"
  102. },
  103. {
  104. code: 'D',
  105. optVal: "本国旅游收入减少"
  106. }, {
  107. code: 'E',
  108. optVal: "本国旅游收入减少"
  109. }, {
  110. code: 'F',
  111. optVal: "本国旅游收入减少"
  112. }, {
  113. code: 'G',
  114. optVal: "本国旅游收入减少"
  115. },
  116. ]
  117. };
  118. },
  119. methods: {
  120. // 数组的值按照英文字母排序
  121. sortEn(arr) {
  122. arr.sort(function(a, b) {
  123. return a.charCodeAt(0).toString(16) - b.charCodeAt(0).toString(16);
  124. });
  125. return arr;
  126. },
  127. // 点击选项时
  128. handleClick(val) {
  129. console.log('val-00----------',val)
  130. // 如果是单选直接请求接口,并存储用户选中的选项
  131. this.selectVal = val.code
  132. // 如果是多选,记录当前点击的选项(取反,选中的再次点击要取消选中)
  133. if (this.selectedOption.includes(val.code)) {
  134. this.selectedOption = this.selectedOption.filter(t => t !== val.code)
  135. } else {
  136. this.selectedOption.push(val.code)
  137. }
  138. this.selectVal = this.sortEn(this.selectedOption).join(",")
  139. },
  140. // 点击提交按钮 (多选题)
  141. handleSubmit() {
  142. // 直接请求接口
  143. }
  144. },
  145. }
  146. </script>
  147. <style lang="scss">
  148. page {
  149. background-color: #f9f9f9;
  150. height: 100%;
  151. }
  152. .comQuestion {
  153. padding: 40rpx;
  154. color: #000;
  155. .title {
  156. font-size: 60rpx;
  157. font-weight: 900;
  158. }
  159. .subTitle {
  160. margin: 20rpx 0;
  161. color: #666;
  162. }
  163. .tip {
  164. width: 100%;
  165. height: 100rpx;
  166. background-color: #eeecec;
  167. border-radius: 20rpx;
  168. display: flex;
  169. justify-content: space-between;
  170. align-items: center;
  171. padding: 0 20rpx;
  172. margin: 50rpx 0;
  173. }
  174. .question {
  175. .option {
  176. display: flex;
  177. align-items: center;
  178. margin: 30rpx 0;
  179. .number {
  180. margin-right: 20rpx;
  181. width: 40rpx;
  182. height: 40rpx;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. font-weight: 600;
  187. border: 1px solid #f8572c;
  188. border-radius: 50%;
  189. color: #f8572c;
  190. }
  191. .active {
  192. // border: 1px solid #f8572c;
  193. background-color: #f8572c;
  194. color: #fff;
  195. }
  196. .trueResult {
  197. border: 1px solid #22c134;
  198. background-color: #22c134;
  199. color: #fff;
  200. }
  201. .trueOption {
  202. color: #22c134;
  203. }
  204. .falseResult {
  205. border: 1px solid #ff4d4f;
  206. background-color: #ff4d4f;
  207. color: #fff;
  208. }
  209. .falseOption {
  210. color: #ff4d4f;
  211. }
  212. }
  213. }
  214. .submitBtn {
  215. width: 200rpx;
  216. margin: 80rpx auto;
  217. margin-bottom: 160rpx;
  218. }
  219. .answerBox {
  220. width: 100%;
  221. height: 200rpx;
  222. background-color: #fff;
  223. border-radius: 20rpx;
  224. overflow: hidden;
  225. box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
  226. .resultBox {
  227. display: flex;
  228. align-items: center;
  229. height: 40%;
  230. // background-color: red;
  231. padding: 0 20rpx;
  232. .sign {
  233. width: 30rpx;
  234. height: 30rpx;
  235. color: #fff;
  236. display: flex;
  237. justify-content: center;
  238. align-items: center;
  239. margin-right: 20rpx;
  240. border-radius: 50%;
  241. background-color: #22c134;
  242. }
  243. .result {
  244. color: #22c134;
  245. font-weight: 600;
  246. }
  247. .falseSign {
  248. background-color: #ff4d4f;
  249. }
  250. .falseResult {
  251. color: #ff4d4f;
  252. }
  253. }
  254. .detailBox {
  255. height: 60%;
  256. display: flex;
  257. // background-color: yellow;
  258. box-sizing: border-box;
  259. border-top: 4rpx solid #f9f9f9;
  260. .true_result,
  261. .user_result {
  262. width: 50%;
  263. box-sizing: border-box;
  264. display: flex;
  265. flex-direction: column;
  266. justify-content: space-around;
  267. align-items: center;
  268. .result {
  269. font-weight: 600;
  270. color: #22c134;
  271. }
  272. .falseResult {
  273. color: #ff4d4f;
  274. }
  275. }
  276. .true_result {
  277. border-right: 4rpx solid #f9f9f9;
  278. }
  279. }
  280. }
  281. .analysis {
  282. background-color: #fff;
  283. border-radius: 20rpx;
  284. box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
  285. margin-top: 20rpx;
  286. margin-bottom: 160rpx;
  287. padding: 20rpx 12rpx;
  288. .analysis_title {
  289. margin-bottom: 20rpx;
  290. font-size: 32rpx;
  291. font-weight: 600;
  292. color: #333;
  293. }
  294. }
  295. }
  296. </style>