index - 副本.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view class="dayQuestion">
  3. <view class="title">每日答题</view>
  4. <view class="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) ? '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. data() {
  70. return {
  71. // 记录用户的回答是否正确
  72. isTrue: true,
  73. // 正确选项
  74. isResult: false,
  75. // 是否答题
  76. isAnswer: false,
  77. // 存储多选时选中的选项
  78. selectedOption: [],
  79. // 存储用户选中的选项
  80. selectVal: "",
  81. // 选项列表(模拟数据)
  82. optionList: [{
  83. code: 'A',
  84. optVal: "本国出口减少"
  85. },
  86. {
  87. code: 'B',
  88. optVal: "本国出口增加"
  89. },
  90. {
  91. code: 'C',
  92. optVal: "本国进口增加"
  93. },
  94. {
  95. code: 'D',
  96. optVal: "本国旅游收入减少"
  97. },{
  98. code: 'E',
  99. optVal: "本国旅游收入减少"
  100. },{
  101. code: 'F',
  102. optVal: "本国旅游收入减少"
  103. },{
  104. code: 'G',
  105. optVal: "本国旅游收入减少"
  106. },
  107. ]
  108. };
  109. },
  110. methods: {
  111. // 数组的值按照英文字母排序
  112. sortEn(arr) {
  113. arr.sort(function(a, b) {
  114. return a.charCodeAt(0).toString(16) - b.charCodeAt(0).toString(16);
  115. });
  116. return arr;
  117. },
  118. // 点击选项时
  119. handleClick(val) {
  120. // 如果是单选直接请求接口,并存储用户选中的选项
  121. this.selectVal = val.code
  122. // 如果是多选,记录当前点击的选项(取反,选中的再次点击要取消选中)
  123. if (this.selectedOption.includes(val.code)) {
  124. this.selectedOption = this.selectedOption.filter(t => t !== val.code)
  125. } else {
  126. this.selectedOption.push(val.code)
  127. }
  128. this.selectVal = this.sortEn(this.selectedOption).join(",")
  129. },
  130. // 点击提交按钮 (多选题)
  131. handleSubmit() {
  132. // 直接请求接口
  133. }
  134. },
  135. }
  136. </script>
  137. <style lang="scss">
  138. page {
  139. background-color: #f9f9f9;
  140. height: 100%;
  141. }
  142. .dayQuestion {
  143. padding: 40rpx;
  144. color: #000;
  145. .title {
  146. font-size: 60rpx;
  147. font-weight: 900;
  148. }
  149. .subTitle {
  150. margin: 20rpx 0;
  151. color: #666;
  152. }
  153. .tip {
  154. width: 100%;
  155. height: 100rpx;
  156. background-color: #eeecec;
  157. border-radius: 20rpx;
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. padding: 0 20rpx;
  162. margin: 50rpx 0;
  163. }
  164. .question {
  165. .option {
  166. display: flex;
  167. align-items: center;
  168. margin: 30rpx 0;
  169. .number {
  170. margin-right: 20rpx;
  171. width: 40rpx;
  172. height: 40rpx;
  173. display: flex;
  174. justify-content: center;
  175. align-items: center;
  176. font-weight: 600;
  177. border: 1px solid #f8572c;
  178. border-radius: 50%;
  179. color: #f8572c;
  180. }
  181. .active {
  182. // border: 1px solid #f8572c;
  183. background-color: #f8572c;
  184. color: #fff;
  185. }
  186. .trueResult {
  187. border: 1px solid #22c134;
  188. background-color: #22c134;
  189. color: #fff;
  190. }
  191. .trueOption {
  192. color: #22c134;
  193. }
  194. .falseResult {
  195. border: 1px solid #ff4d4f;
  196. background-color: #ff4d4f;
  197. color: #fff;
  198. }
  199. .falseOption {
  200. color: #ff4d4f;
  201. }
  202. }
  203. }
  204. .submitBtn {
  205. width: 200rpx;
  206. margin: 80rpx auto;
  207. margin-bottom: 160rpx;
  208. }
  209. .answerBox {
  210. width: 100%;
  211. height: 200rpx;
  212. background-color: #fff;
  213. border-radius: 20rpx;
  214. overflow: hidden;
  215. box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
  216. .resultBox {
  217. display: flex;
  218. align-items: center;
  219. height: 40%;
  220. // background-color: red;
  221. padding: 0 20rpx;
  222. .sign {
  223. width: 30rpx;
  224. height: 30rpx;
  225. color: #fff;
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. margin-right: 20rpx;
  230. border-radius: 50%;
  231. background-color: #22c134;
  232. }
  233. .result {
  234. color: #22c134;
  235. font-weight: 600;
  236. }
  237. .falseSign {
  238. background-color: #ff4d4f;
  239. }
  240. .falseResult {
  241. color: #ff4d4f;
  242. }
  243. }
  244. .detailBox {
  245. height: 60%;
  246. display: flex;
  247. // background-color: yellow;
  248. box-sizing: border-box;
  249. border-top: 4rpx solid #f9f9f9;
  250. .true_result,
  251. .user_result {
  252. width: 50%;
  253. box-sizing: border-box;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-around;
  257. align-items: center;
  258. .result {
  259. font-weight: 600;
  260. color: #22c134;
  261. }
  262. .falseResult {
  263. color: #ff4d4f;
  264. }
  265. }
  266. .true_result {
  267. border-right: 4rpx solid #f9f9f9;
  268. }
  269. }
  270. }
  271. .analysis {
  272. background-color: #fff;
  273. border-radius: 20rpx;
  274. box-shadow: 0 0 12px 2px rgba(0, 0, 0, 0.2);
  275. margin-top: 20rpx;
  276. margin-bottom: 160rpx;
  277. padding: 20rpx 12rpx;
  278. .analysis_title {
  279. margin-bottom: 20rpx;
  280. font-size: 32rpx;
  281. font-weight: 600;
  282. color: #333;
  283. }
  284. }
  285. }
  286. </style>