random.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <view class="content">
  3. <view class="top-box">
  4. <view class="icon"></view>
  5. <selectSwitch class='btn' @change="changeSwitch" :switchList="['科一题目','科四题目']" checked_bj_color='#E31818' />
  6. <van-icon class='set' name="/static/img/答题/设置@2x.png" size='20' @click='show=true' />
  7. </view>
  8. <van-popup :show="show" @close="show=false" position="bottom">
  9. <van-cell title="背题模式" clickable :data-index="index" @click="answerflag=!answerflag">
  10. <van-switch slot="right-icon" :checked="answerflag" size="24px" active-color="#16CC16" />
  11. <!-- <selectSwitch slot="right-icon" @change="changeSwitch" :switchList="['答题模式','背题模式']" checked_bj_color='#E31818' /> -->
  12. </van-cell>
  13. <van-cell title="答对跳转下一题 " clickable :data-index="index" @click="answerjump=!answerjump">
  14. <van-switch slot="right-icon" :checked="answerjump" size="24px" active-color="#16CC16" />
  15. </van-cell>
  16. <!-- <van-cell title="答错展示题目解析" clickable :data-index="index" @click="checked=!checked">
  17. <van-switch slot="right-icon" :checked="checked" size="24px" active-color="#16CC16" />
  18. </van-cell> -->
  19. <van-cell title="错误震动提醒" clickable :data-index="index" @click="checked=!checked">
  20. <van-switch slot="right-icon" :checked="checked" size="24px" active-color="#16CC16" />
  21. </van-cell>
  22. <!-- <van-cell title="主题选择" clickable :data-index="index" @click="checked=!checked">
  23. <van-switch slot="right-icon" :checked="checked" size="24px" active-color="#16CC16" />
  24. </van-cell>
  25. <van-cell title="字体选择" clickable :data-index="index" @click="checked=!checked">
  26. <van-switch slot="right-icon" :checked="checked" size="24px" active-color="#16CC16" />
  27. </van-cell> -->
  28. </van-popup>
  29. <van-skeleton class='skeleton' avatar row="6" :row-width="['100%','40%','70%','70%','70%','70%']" avatar-shape='square'
  30. :loading="loading">
  31. <swiper class="swiper-box" :current="swiperIndex" @change="swiperChange" circular>
  32. <swiper-item v-for="(itembox,indexbox) in questionList" :key='indexbox'>
  33. <view class="swiper-item">
  34. <view class="topic-box">
  35. <view class="topic-right">
  36. <view class="topic-top">
  37. <view class="topic-left">
  38. <text class="topic-type">{{questionType(itembox.type)}}</text>
  39. <van-icon name="star-o" size='20' />
  40. </view>
  41. <!-- <rich-text class="topic-tit" :nodes="itembox.id+'、'+itembox.question"></rich-text> -->
  42. <view class="topic-tit" v-html="itembox.id+'、'+itembox.question"></view>
  43. </view>
  44. <video v-if="itembox.videoUrl" class="topic-img" :muted='true' :loop='true' :autoplay='true' :controls='false'
  45. :src="encodeURI(itembox.mediaUrl)"></video>
  46. <image v-if="itembox.sinaimg" class="topic-img" :src="itembox.mediaUrl" mode="aspectFit"></image>
  47. <view class="topic-opt" v-if='itembox.type==2'>
  48. <van-radio-group :value="userAnswer[itembox.id]">
  49. <van-cell-group>
  50. <van-cell :class='{answer:(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))}'
  51. v-for="(item,index) in choiceList" :key="index" :title="itembox[item]" v-show='itembox[item]' clickable
  52. :data-index="index+1" @click="singleToggle($event,itembox)">
  53. <van-icon v-if="(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))" slot="icon"
  54. name="/static/img/答题/对@2x.png" size='20' />
  55. <van-radio slot="right-icon" :ref="`checkboxes${itembox.id}`" checked-color="#1464cc" :name="index+1" />
  56. </van-cell>
  57. </van-cell-group>
  58. </van-radio-group>
  59. <!-- <button @click="submit(itembox)" class="submit" type="default" v-show="!(answerflag || completeAnswer[itembox.id])">提交答案</button> -->
  60. </view>
  61. <view class="topic-opt" v-if='itembox.type==1'>
  62. <van-radio-group :value="userAnswer[itembox.id]">
  63. <van-cell-group>
  64. <van-cell :class='{answer:(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))}'
  65. v-for="(item,index) in 2" :key="index" :title="index?'错误':'正确'" clickable :data-index="index+1" @click="singleToggle($event,itembox)">
  66. <van-icon v-if="(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))" slot="icon"
  67. name="/static/img/答题/对@2x.png" size='20' />
  68. <van-radio slot="right-icon" :ref="`checkboxes${itembox.id}`" checked-color="#1464cc" :name="index+1" />
  69. </van-cell>
  70. </van-cell-group>
  71. </van-radio-group>
  72. <!-- <button @click="submit(itembox)" class="submit" type="default" v-show="!(answerflag || completeAnswer[itembox.id])">提交答案</button> -->
  73. </view>
  74. <view class="topic-opt" v-else-if='itembox.type==3'>
  75. <van-checkbox-group :value="userAnswer[itembox.id]" @change="onChange($event,itembox)">
  76. <van-cell-group>
  77. <van-cell :class='{answer:(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))}'
  78. v-for="(item,index) in choiceList" :key="index" :title="itembox[item]" v-show='itembox[item]' clickable
  79. @click='toggle($event,itembox)' :data-index="index">
  80. <van-icon v-if="(itembox.answerTrue.includes(index+1) && (answerflag || completeAnswer[itembox.id]))" slot="icon"
  81. name="/static/img/答题/对@2x.png" size='20' />
  82. <van-checkbox shape="square" catch:tap="noop" slot="right-icon" :ref="`checkboxes${itembox.id}`"
  83. checked-color="#1464cc" :name="index+1" />
  84. </van-cell>
  85. </van-cell-group>
  86. </van-checkbox-group>
  87. <button @click="submit(itembox)" class="submit" type="default" v-show="!(answerflag || completeAnswer[itembox.id])">提交答案</button>
  88. </view>
  89. </view>
  90. </view>
  91. <view v-show="answerflag || completeAnswer[itembox.id]">
  92. <view class="flag">
  93. <text v-if="itembox.type==2" class="result">正确答案: {{itembox[choiceList[itembox.answerTrue-1]]}}</text>
  94. <text v-else-if="itembox.type==1" class="result">正确答案: {{itembox.answerTrue==1?'正确':'错误'}}</text>
  95. <text v-else-if="itembox.type==3" class="result">正确答案: {{itembox.answerTrue.split('').map((key)=>{
  96. return itembox[choiceList[key-1]]
  97. })}}</text>
  98. </view>
  99. <view class="parsing">
  100. <view class="item-titBox">
  101. <text class="item-tit">题目解析</text>
  102. </view>
  103. <view class="parsing-text">
  104. <text class="item-tit">{{itembox.explain1 ? itembox.explain1 : "无"}}</text>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </swiper-item>
  110. </swiper>
  111. </van-skeleton>
  112. </view>
  113. </template>
  114. <script>
  115. import selectSwitch from "@/components/xuan-switch/xuan-switch.vue";
  116. import {
  117. questionListRandom
  118. } from "@/api/answer.js"
  119. export default {
  120. components: {
  121. selectSwitch
  122. },
  123. data() {
  124. return {
  125. loading: true,
  126. answerflag: false,
  127. answerjump: true,
  128. kemu: 1,
  129. completeAnswer: {},
  130. show: false,
  131. checked: true,
  132. radio: null,
  133. result: [],
  134. userAnswer: {},
  135. questionList: {},
  136. choiceList: ['an1', 'an2', 'an3', 'an4', 'an5', 'an6', 'an7'],
  137. swiperIndex: 0,
  138. shakeIndex: 0,
  139. pageNum: 1,
  140. shake: 0,
  141. }
  142. },
  143. mounted() {
  144. this.listInit()
  145. },
  146. methods: {
  147. async listInit() {
  148. await questionListRandom({
  149. num: 20,
  150. kemu: this.kemu
  151. }).then((res) => {
  152. this.questionList = res.rows
  153. this.$nextTick(() => {
  154. this.loading = false
  155. })
  156. })
  157. },
  158. questionType(index) {
  159. switch (index) {
  160. case 1:
  161. return '判断';
  162. case 2:
  163. return '单选';
  164. case 3:
  165. return '多选';
  166. }
  167. },
  168. swiperChange(e) {
  169. console.log(e)
  170. let aShake = e.detail.current - this.shakeIndex
  171. this.shake += aShake ** 2 != 1 ? -aShake / Math.abs(aShake) : aShake;
  172. this.swiperIndex = e.detail.current
  173. this.shakeIndex = e.detail.current
  174. if (e.detail.current % 10 == 0) {
  175. if (Math.abs(this.shake) < 10) {
  176. this.shake = 0
  177. return
  178. }
  179. this.pageNum += 1;
  180. questionListRandom({
  181. num: 10,
  182. kemu: this.kemu
  183. }).then((res) => {
  184. this.shake = 0
  185. if (e.detail.current == 20) {
  186. this.questionList = res.rows.concat(this.questionList.slice(10))
  187. }
  188. if (e.detail.current == 10) {
  189. this.questionList = this.questionList.slice(0, 20).concat(res.rows)
  190. }
  191. if (e.detail.current == 0) {
  192. this.questionList = this.questionList.slice(0, 10).concat(res.rows).concat(this.questionList.slice(20))
  193. }
  194. })
  195. }
  196. },
  197. onChange(event, itembox) {
  198. if (this.completeAnswer[itembox.id] || this.answerflag) {
  199. return
  200. }
  201. this.$set(this.userAnswer, itembox.id, event.detail)
  202. },
  203. singleToggle(event, itembox) {
  204. if (this.completeAnswer[itembox.id] || this.answerflag) {
  205. return
  206. }
  207. const {
  208. index
  209. } = event.currentTarget.dataset;
  210. this.$set(this.userAnswer, itembox.id, index)
  211. setTimeout(() => {
  212. this.submit(itembox)
  213. }, 0)
  214. },
  215. toggle(event, itembox) {
  216. const {
  217. index
  218. } = event.currentTarget.dataset;
  219. const checkbox = this.$refs[`checkboxes${itembox.id}`][index];
  220. checkbox.toggle();
  221. },
  222. noop() {},
  223. submit(itembox) {
  224. this.$set(this.completeAnswer, itembox.id, true)
  225. let flag = (this.userAnswer[itembox.id] + '').split(',').sort().join('') == itembox.answerTrue.split('').sort().join(
  226. '')
  227. if (flag) {
  228. wx.vibrateShort();
  229. if (this.answerjump) {
  230. let index = this.swiperIndex
  231. this.swiperIndex = ++index % 30
  232. }
  233. } else {
  234. wx.vibrateLong();
  235. }
  236. }
  237. }
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. /deep/ .answer .van-cell {
  242. background-color: #16CC16 !important;
  243. color: #ffffff;
  244. }
  245. /deep/ .van-cell {
  246. // background-color: #16CC16 !important;
  247. margin: 10rpx;
  248. border-radius: 20rpx;
  249. }
  250. .content {
  251. width: 100%;
  252. height: 100vh;
  253. background-color: #FFFFFF;
  254. }
  255. .skeleton {
  256. // margin: 0rpx 20rpx;
  257. }
  258. .swiper-box {
  259. height: calc(100vh - 120rpx);
  260. margin: 0rpx 20rpx;
  261. swiper-item {
  262. overflow: auto;
  263. }
  264. }
  265. .top-box {
  266. height: 60rpx;
  267. padding: 30rpx;
  268. display: flex;
  269. justify-content: space-between;
  270. align-items: center;
  271. .icon {
  272. width: 60rpx;
  273. }
  274. .btn {}
  275. .set {
  276. color: red;
  277. }
  278. }
  279. .topic-box {
  280. // padding: 20rpx;
  281. display: flex;
  282. justify-content: center;
  283. // border: 2px solid red;
  284. .topic-top {
  285. display: flex;
  286. // border: 2px solid red;
  287. padding: 10rpx;
  288. .topic-left {
  289. display: flex;
  290. flex-direction: column;
  291. .topic-type {
  292. background: #E31818;
  293. border-radius: 10rpx;
  294. // border: 2px solid red;
  295. color: #FFFFFF;
  296. width: 66rpx;
  297. height: 30rpx;
  298. display: flex;
  299. justify-content: center;
  300. align-items: center;
  301. border-radius: 15px 15px 0px 15px;
  302. padding: 10rpx;
  303. margin-bottom: 18rpx;
  304. }
  305. }
  306. .topic-tit {
  307. padding: 10rpx;
  308. }
  309. }
  310. .topic-right {
  311. flex: 1;
  312. display: flex;
  313. flex-direction: column;
  314. padding: 0 10rpx;
  315. .topic-img {
  316. padding: 10rpx;
  317. margin: auto;
  318. width: 500rpx;
  319. height: 250rpx;
  320. // border: 2px solid red;
  321. }
  322. .topic-opt {
  323. // border: 2px solid red;
  324. padding: 30rpx 5rpx;
  325. .submit {
  326. margin: auto;
  327. margin-top: 150rpx;
  328. height: 80rpx;
  329. background: linear-gradient(90deg, #E31818, #ED3E24, #ED4F24);
  330. border-radius: 35rpx;
  331. display: flex;
  332. justify-content: center;
  333. align-items: center;
  334. color: #FFFFFF;
  335. }
  336. }
  337. }
  338. }
  339. .flag {
  340. // border: 2px solid red;
  341. padding: 30rpx 5rpx;
  342. display: flex;
  343. justify-content: center;
  344. .result {
  345. display: inline-block;
  346. background-color: #16CC16;
  347. // border: 2px solid red;
  348. width: 690rpx;
  349. // height: 70rpx;
  350. padding: 20rpx;
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. border-radius: 20rpx;
  355. color: #ffffff;
  356. }
  357. }
  358. .item-titBox {
  359. display: flex;
  360. justify-content: space-between;
  361. align-items: center;
  362. padding: 20rpx;
  363. border-bottom: 1rpx solid #e8e8e8;
  364. .item-tit {
  365. border-left: 8rpx solid #E31818;
  366. font-size: 30rpx;
  367. // line-height: 38rpx;
  368. padding: 0 11rpx;
  369. }
  370. }
  371. .parsing-text {
  372. padding: 30rpx;
  373. // border: 2px solid red;
  374. }
  375. </style>