wrongTitle.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 title-width='500rpx' :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. questionList
  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 questionList({
  149. pageNum: this.pageNum,
  150. pageSize: 20,
  151. kemu: this.kemu
  152. }).then((res) => {
  153. this.questionList = res.rows
  154. this.$nextTick(() => {
  155. this.loading = false
  156. })
  157. })
  158. },
  159. questionType(index) {
  160. switch (index) {
  161. case 1:
  162. return '判断';
  163. case 2:
  164. return '单选';
  165. case 3:
  166. return '多选';
  167. }
  168. },
  169. swiperChange(e) {
  170. console.log(e)
  171. let aShake = e.detail.current - this.shakeIndex
  172. this.shake += aShake ** 2 != 1 ? -aShake / Math.abs(aShake) : aShake;
  173. this.swiperIndex = e.detail.current
  174. this.shakeIndex = e.detail.current
  175. if (e.detail.current % 10 == 0) {
  176. if (Math.abs(this.shake) < 10) {
  177. this.shake = 0
  178. return
  179. }
  180. this.pageNum += 1;
  181. questionList({
  182. pageNum: this.pageNum + 1,
  183. pageSize: 10,
  184. kemu: this.kemu
  185. }).then((res) => {
  186. this.shake = 0
  187. if (e.detail.current == 20) {
  188. this.questionList = res.rows.concat(this.questionList.slice(10))
  189. }
  190. if (e.detail.current == 10) {
  191. this.questionList = this.questionList.slice(0, 20).concat(res.rows)
  192. }
  193. if (e.detail.current == 0) {
  194. this.questionList = this.questionList.slice(0, 10).concat(res.rows).concat(this.questionList.slice(20))
  195. }
  196. })
  197. }
  198. },
  199. onChange(event, itembox) {
  200. if (this.completeAnswer[itembox.id] || this.answerflag) {
  201. return
  202. }
  203. this.$set(this.userAnswer, itembox.id, event.detail)
  204. },
  205. singleToggle(event, itembox) {
  206. if (this.completeAnswer[itembox.id] || this.answerflag) {
  207. return
  208. }
  209. const {
  210. index
  211. } = event.currentTarget.dataset;
  212. this.$set(this.userAnswer, itembox.id, index)
  213. setTimeout(() => {
  214. this.submit(itembox)
  215. }, 0)
  216. },
  217. toggle(event, itembox) {
  218. const {
  219. index
  220. } = event.currentTarget.dataset;
  221. const checkbox = this.$refs[`checkboxes${itembox.id}`][index];
  222. checkbox.toggle();
  223. },
  224. noop() {},
  225. submit(itembox) {
  226. this.$set(this.completeAnswer, itembox.id, true)
  227. let flag = (this.userAnswer[itembox.id] + '').split(',').sort().join('') == itembox.answerTrue.split('').sort().join(
  228. '')
  229. if (flag) {
  230. wx.vibrateShort();
  231. if (this.answerjump) {
  232. let index = this.swiperIndex
  233. this.swiperIndex = ++index % 30
  234. }
  235. } else {
  236. wx.vibrateLong();
  237. }
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. /deep/ .answer .van-cell {
  244. background-color: #16CC16 !important;
  245. color: #ffffff;
  246. }
  247. /deep/ .van-cell {
  248. // background-color: #16CC16 !important;
  249. margin: 10rpx;
  250. border-radius: 20rpx;
  251. }
  252. .content {
  253. width: 100%;
  254. height: 100vh;
  255. background-color: #FFFFFF;
  256. }
  257. .skeleton {
  258. // margin: 0rpx 20rpx;
  259. }
  260. .swiper-box {
  261. height: calc(100vh - 120rpx);
  262. margin: 0rpx 20rpx;
  263. swiper-item {
  264. overflow: auto;
  265. }
  266. }
  267. .top-box {
  268. height: 60rpx;
  269. padding: 30rpx;
  270. display: flex;
  271. justify-content: space-between;
  272. align-items: center;
  273. .icon {
  274. width: 60rpx;
  275. }
  276. .btn {}
  277. .set {
  278. color: red;
  279. }
  280. }
  281. .topic-box {
  282. // padding: 20rpx;
  283. display: flex;
  284. justify-content: center;
  285. // border: 2px solid red;
  286. .topic-top {
  287. display: flex;
  288. // border: 2px solid red;
  289. padding: 10rpx;
  290. .topic-left {
  291. display: flex;
  292. flex-direction: column;
  293. .topic-type {
  294. background: #E31818;
  295. border-radius: 10rpx;
  296. // border: 2px solid red;
  297. color: #FFFFFF;
  298. width: 66rpx;
  299. height: 30rpx;
  300. display: flex;
  301. justify-content: center;
  302. align-items: center;
  303. border-radius: 15px 15px 0px 15px;
  304. padding: 10rpx;
  305. margin-bottom: 18rpx;
  306. }
  307. }
  308. .topic-tit {
  309. padding: 10rpx;
  310. }
  311. }
  312. .topic-right {
  313. flex: 1;
  314. display: flex;
  315. flex-direction: column;
  316. padding: 0 10rpx;
  317. .topic-img {
  318. padding: 10rpx;
  319. margin: auto;
  320. width: 500rpx;
  321. height: 250rpx;
  322. // border: 2px solid red;
  323. }
  324. .topic-opt {
  325. // border: 2px solid red;
  326. padding: 30rpx 5rpx;
  327. .submit {
  328. margin: auto;
  329. margin-top: 150rpx;
  330. height: 80rpx;
  331. background: linear-gradient(90deg, #E31818, #ED3E24, #ED4F24);
  332. border-radius: 35rpx;
  333. display: flex;
  334. justify-content: center;
  335. align-items: center;
  336. color: #FFFFFF;
  337. }
  338. }
  339. }
  340. }
  341. .flag {
  342. // border: 2px solid red;
  343. padding: 30rpx 5rpx;
  344. display: flex;
  345. justify-content: center;
  346. .result {
  347. display: inline-block;
  348. background-color: #16CC16;
  349. // border: 2px solid red;
  350. width: 690rpx;
  351. // height: 70rpx;
  352. padding: 20rpx;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. border-radius: 20rpx;
  357. color: #ffffff;
  358. }
  359. }
  360. .item-titBox {
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. padding: 20rpx;
  365. border-bottom: 1rpx solid #e8e8e8;
  366. .item-tit {
  367. border-left: 8rpx solid #E31818;
  368. font-size: 30rpx;
  369. // line-height: 38rpx;
  370. padding: 0 11rpx;
  371. }
  372. }
  373. .parsing-text {
  374. padding: 30rpx;
  375. // border: 2px solid red;
  376. }
  377. </style>