questionBankTest.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. <template>
  2. <view id="questionBank">
  3. <swiper class="swiper" :current="current" @change="swiperChange" :interval="interval">
  4. <swiper-item v-for="(bank,bankIndex) in questionList" :key="bankIndex">
  5. <view class="pageContent">
  6. <view class="pad_8 titBox">
  7. <view class="firstLetter">
  8. <view class="leftLetters">
  9. <view class="btnType">
  10. <text v-if="bank.type==1">单选</text>
  11. <text v-if="bank.type==2">多选</text>
  12. <text v-if="bank.type==3">判断</text>
  13. <text v-if="bank.type==4">简答题</text>
  14. <text v-if="bank.type==5">案例题</text>
  15. </view>
  16. <text>1/{{current}}</text>
  17. </view>
  18. <view style="color: #666;font-size: 28rpx;">03:25:06</view>
  19. <view class="leftLetters"></view>
  20. </view>
  21. <view class="titles">
  22. <rich-text :nodes="bank.content"></rich-text>
  23. </view>
  24. <view class="">
  25. <template v-if="bank.type == 1">
  26. <view v-if="!ques[bankIndex]">
  27. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="radioSelect" :data-index="index" :data-bindex="bankIndex" :data-optionsId="item.optionsId">
  28. <view class="activeTI">{{ ast[index] }}</view>
  29. {{ item.content }}
  30. </view>
  31. </view>
  32. <view v-if="ques[bankIndex]">
  33. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  34. <text :class="{right:(item.optionsId == ques[bankIndex]) || (item.optionsId == ans[bankIndex]),wrong:(item.optionsId == ques[bankIndex]) && (ques[bankIndex] != ans[bankIndex])}" class="activeTI">{{ ast[index] }}</text>
  35. {{ item.content }}
  36. </view>
  37. </view>
  38. <view v-if="ques[bankIndex]">
  39. <view class="pad_8 answer">
  40. <view>正确答案:{{ast[ans[bankIndex]-1]}}</view>
  41. <view>我的答案:{{ast[ques[bankIndex]-1]}}</view>
  42. </view>
  43. <view class="pad_8 answerInfos">
  44. <view class="answerTitle">答案解析</view>
  45. <view class="answerContent">
  46. <rich-text :nodes="bank.analysisContent"></rich-text>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <template v-if="bank.type == 2">
  52. <view v-if="!ques[bankIndex]">
  53. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty" @click="checkboxSelect" :data-index="index" :data-bindex="bankIndex" :data-optionsId="item.optionsId">
  54. <view :class="{checked:item.checked}" class="activeTI">{{ ast[index] }}</view>
  55. {{ item.content }}
  56. </view>
  57. </view>
  58. <view v-if="!ques[bankIndex]" class="submit_checkbox" @click="checkboxSubmit" :data-bindex="bankIndex">
  59. 确认答案
  60. </view>
  61. <view v-if="ques[bankIndex]">
  62. <view v-for="(item, index) in bank.jsonStr" :key="index" class="lisSty">
  63. <text :class="{right:(ques[bankIndex].indexOf(item.optionsId) != -1 ) || (ans[bankIndex].indexOf(item.optionsId) != -1),wrong:(ques[bankIndex].indexOf(item.optionsId) != -1 ) && (ans[bankIndex].indexOf(item.optionsId) == -1)}" class="activeTI">{{ ast[index] }}</text>
  64. {{ item.content }} {{ques[bankIndex].indexOf(item.optionsId) != -1 }} {{item.optionsId}} {{ans[bankIndex].indexOf(item.optionsId) != -1}}
  65. </view>
  66. </view>
  67. <view v-if="ques[bankIndex]">
  68. <view class="pad_8 answer">
  69. <view>正确答案:
  70. <text v-for="ansItem in ans[bankIndex]">{{ast[ansItem-1]}}</text>
  71. </view>
  72. <view>我的答案:
  73. <text v-for="quesItem in ques[bankIndex]">{{ast[quesItem-1]}}</text>
  74. </view>
  75. </view>
  76. <view class="pad_8 answerInfos">
  77. <view class="answerTitle">答案解析</view>
  78. <view class="answerContent">
  79. <rich-text :nodes="bank.analysisContent"></rich-text>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <template v-if="bank.type == 3">
  85. <view v-if="!ques[bankIndex]">
  86. <view v-for="(item, index) in judge" :key="index" class="lisSty" @click="judgeSelect" :data-index="index" :data-bindex="bankIndex" >
  87. <view class="activeTI">{{ ast[index] }}</view>
  88. {{ item }}
  89. </view>
  90. </view>
  91. <view v-if="ques[bankIndex]">
  92. <view v-for="(item, index) in judge" :key="index" class="lisSty">
  93. <text :class="{right:(index == ques[bankIndex]) || (index == ans[bankIndex]),wrong:(index == ques[bankIndex]) && (ques[bankIndex] != ans[bankIndex])}" class="activeTI">{{ ast[index] }}</text>
  94. {{ item }}
  95. </view>
  96. </view>
  97. <view v-if="ques[bankIndex]">
  98. <view class="pad_8 answer">
  99. <view>正确答案:{{ast[ans[bankIndex]]}}</view>
  100. <view>我的答案:{{ast[ques[bankIndex]]}}</view>
  101. </view>
  102. <view class="pad_8 answerInfos">
  103. <view class="answerTitle">答案解析</view>
  104. <view class="answerContent">
  105. <rich-text :nodes="bank.analysisContent"></rich-text>
  106. </view>
  107. </view>
  108. </view>
  109. </template>
  110. <template v-if="bank.type == 4">
  111. <view class="ans">
  112. <view class="ans_input" v-if="!ques[bankIndex]">
  113. <view class="top flex">
  114. <image :data-index="bankIndex" class="icon" :data-bindex="bankIndex" @click="chooseImg" src="/static/08-10_032.jpg" mode=""></image>
  115. <view class="progress">0/4</view>
  116. <view class="submit" @click="submitAns" :data-bindex="bankIndex" >确认答案</view>
  117. </view>
  118. <view class="textarea">
  119. <textarea v-model="bank.text" placeholder="在此输入答案"></textarea>
  120. </view>
  121. <view class="imgs">
  122. <view class="img" v-for="(img,imgIndex) in bank.imageList" >
  123. <text @click="deleteImg" :data-imgIndex="imgIndex" :data-bindex="bankIndex">x</text>
  124. <image :src="img"></image>
  125. </view>
  126. </view>
  127. </view>
  128. <view class="ans_submit answerInfos" v-if="ques[bankIndex]">
  129. <view class="answerTitle">答案我的</view>
  130. {{ques[bankIndex].text}}
  131. <view class="imgs">
  132. <image class="img" v-for="ques in ques[bankIndex].imageList" :src="ques"></image>
  133. </view>
  134. </view>
  135. </view>
  136. <view v-if="ques[bankIndex]">
  137. <view class="pad_8 answerInfos">
  138. <view class="answerTitle">答案解析</view>
  139. <view class="answerContent">
  140. 这是官方答案解析文本,卡片高度根据内容自动调整,我实在编不出来内容了,我实在编不出来内容了,我实在编不出来内容了,我实在编不出来内容了,就这样吧。
  141. </view>
  142. </view>
  143. </view>
  144. </template>
  145. <!-- <view v-if="ques[bankIndex] ">
  146. <view v-for="(item, index) in bank.jsonStr" :key="index"
  147. class="lisSty">
  148. <view :class="{right:(item.value == ques[bankIndex]) && (ques[bankIndex] == ans[bankIndex]),wrong:(item.value == ques[bankIndex]) && (ques[bankIndex] != ans[bankIndex])}" class="activeTI">{{ ast[index] }}</view>
  149. {{ item.label }}
  150. </view>
  151. </view>
  152. <view v-if="!ques[bankIndex]">
  153. <view v-for="(item, index) in bank.jsonStr" :key="index" @click="click" :data-value="item.value" class="lisSty">
  154. <text class="activeTI">{{ ast[index] }}</text>
  155. {{ item.label }}
  156. </view>
  157. </view> -->
  158. </view>
  159. </view>
  160. </view>
  161. </swiper-item>
  162. </swiper>
  163. <view class="footer_btn">
  164. <view @click="collect">收藏</view>
  165. <view @click="openFooterTab">答题卡</view>
  166. <view @click="submit">交卷</view>
  167. </view>
  168. <u-popup v-model="show" mode="bottom" border-radius="14" height="680rpx">
  169. <view class="popupView">
  170. <view class="popupTops">
  171. <view class="topIcon"></view>
  172. 点击编号即可跳转至对应题目
  173. </view>
  174. <view class="popupContent">
  175. <scroll-view scroll-y="true" style="height: 506rpx;">
  176. <view class="boxSty">
  177. <view v-for="(item, index) in questionList" :key="index" :data-index="index" @click="changeIndex" :class="{disabled:index>=5}" class="liListSty">{{ index + 1 }}</view>
  178. </view>
  179. </scroll-view>
  180. </view>
  181. </view>
  182. </u-popup>
  183. <view class="dialog" v-if="showDialog">
  184. <view class="text">左右滑动切换上下题</view>
  185. <view class="btn" @click="hideDialog">我知道了</view>
  186. </view>
  187. </view>
  188. </template>
  189. <script>
  190. export default {
  191. data() {
  192. return {
  193. id:'',
  194. current:0,
  195. questionList:[],
  196. ast: ['A', 'B', 'C', 'D','E','F','G'],
  197. judge:['错误','正确'],
  198. ans:[],
  199. ques:[],
  200. show: false,
  201. showDialog:true,
  202. bankList: []
  203. };
  204. },
  205. onLoad(option){
  206. this.id = option.id;
  207. this.goodsQuestionList()
  208. },
  209. methods: {
  210. goodsQuestionList() {
  211. this.$api.goodsQuestionList({
  212. examId:this.id
  213. }).then(res => {
  214. console.log(res)
  215. res.data.data.forEach((item,index) => {
  216. item.jsonStr = JSON.parse(item.jsonStr)
  217. if(item.type == 2) { //多选
  218. item.jsonStr.forEach(str => {
  219. str.optionsId = ''+str.optionsId;
  220. })
  221. let arr = item.answerQuestion.split(',');
  222. arr.forEach((a,i) => {
  223. arr[i] = ''+a;
  224. })
  225. this.$set(this.ans,index,arr);
  226. return;
  227. } else if(item.type == 4) {
  228. item.text = '';
  229. item.imageList = [];
  230. }
  231. this.$set(this.ans,index,item.answerQuestion);
  232. })
  233. this.questionList = res.data.data;
  234. })
  235. },
  236. /**
  237. * @param {Object} e单选点击
  238. */
  239. radioSelect(e) {
  240. let optionsId = e.currentTarget.dataset.optionsid;
  241. let bindex = e.currentTarget.dataset.bindex;
  242. if(this.ques[bindex]) return;
  243. this.$set(this.ques,bindex,optionsId)
  244. },
  245. /**
  246. * @param {Object} 多选点击
  247. */
  248. checkboxSelect(e) {
  249. let optionsId = e.currentTarget.dataset.optionsid;
  250. let bindex = e.currentTarget.dataset.bindex;
  251. let index = e.currentTarget.dataset.index;
  252. this.$set(this.questionList[bindex].jsonStr[index],'checked',!this.questionList[bindex].jsonStr[index].checked)
  253. },
  254. /**
  255. * @param {Object} 多选确认
  256. */
  257. checkboxSubmit(e) {
  258. let bindex = e.currentTarget.dataset.bindex;
  259. if(this.ques[bindex]) return;
  260. let arr = [];
  261. this.questionList[bindex].jsonStr.forEach(item => {
  262. console.log(item)
  263. if(item.checked) {
  264. arr.push(item.optionsId)
  265. }
  266. })
  267. this.$set(this.ques,bindex,arr)
  268. console.log(this.ques);
  269. console.log(this.ans)
  270. },
  271. judgeSelect(e) {
  272. let index = e.currentTarget.dataset.index;
  273. let bindex = e.currentTarget.dataset.bindex;
  274. if(this.ques[bindex]) return;
  275. this.$set(this.ques,bindex,index+'')
  276. },
  277. openFooterTab() {
  278. this.show = true;
  279. },
  280. hideDialog() {
  281. this.showDialog = false
  282. },
  283. changeIndex(e) {
  284. let index = e.currentTarget.dataset.index
  285. if(index >= 5) {
  286. uni.showToast({
  287. title: '返回详情购买后即可继续',
  288. duration: 2000,
  289. icon:'none'
  290. });
  291. return;
  292. }
  293. this.current = e.currentTarget.dataset.index
  294. },
  295. swiperChange(e) {
  296. this.current = e.detail.current;
  297. },
  298. submit() {
  299. uni.showToast({
  300. title: '不能试做返回详情购买后即可交卷~',
  301. duration: 2000,
  302. icon:'none'
  303. });
  304. return;
  305. },
  306. collect() {
  307. uni.showToast({
  308. title: '返回详情购买后即可收藏~',
  309. duration: 2000,
  310. icon:'none'
  311. });
  312. return;
  313. },
  314. click(e) {
  315. if(this.ques[this.current]) return;
  316. let value = e.currentTarget.dataset.value;
  317. this.ques[this.current] = value;
  318. this.ques = Object.assign({},this.ques)
  319. },
  320. deleteImg(e) {
  321. var imgIndex = e.currentTarget.dataset.imgindex;
  322. var bankIndex = e.currentTarget.dataset.bankindex;
  323. this.questionList[bankIndex].imageList.splice(imgIndex,1)
  324. },
  325. chooseImg(e) {
  326. console.log(e.currentTarget.dataset)
  327. let bankindex = e.currentTarget.dataset.bindex;
  328. uni.chooseImage({
  329. count: 1, //默认9
  330. sizeType: ['original', ], //可以指定是原图还是压缩图,默认二者都有
  331. sourceType: ['album','camera'], //从相册选择
  332. success: (res) => {
  333. // console.log(JSON.stringify(res.tempFilePaths));
  334. this.questionList[bankindex].imageList.push(res.tempFilePaths)
  335. }
  336. })
  337. },
  338. submitAns(e) {
  339. let type = e.currentTarget.dataset.type;
  340. let bankindex = e.currentTarget.dataset.bindex;
  341. console.log(this.questionList[bankindex])
  342. if(!this.questionList[bankindex].text && !this.questionList[bankindex].imageList.length) {
  343. uni.showToast({
  344. title: '请输入内容或上传图片',
  345. duration: 2000,
  346. icon:'none'
  347. });
  348. return
  349. }
  350. this.$set(this.ques,bankindex,{
  351. imageList:this.questionList[bankindex].imageList,
  352. text:this.questionList[bankindex].text,
  353. })
  354. }
  355. }
  356. };
  357. </script>
  358. <style lang="scss" scoped>
  359. .swiper {
  360. width:100%;
  361. height:100vh;
  362. }
  363. .lisSty {
  364. margin-bottom: 16rpx;
  365. }
  366. .activeTI {
  367. vertical-align: middle;
  368. display: inline-block;
  369. border: 1rpx solid #eee;
  370. border-radius: 50rpx;
  371. height: 48rpx;
  372. line-height: 46rpx;
  373. text-align: center;
  374. width: 48rpx;
  375. margin-right: 15rpx;
  376. color: #666;
  377. font-size: 30rpx;
  378. &.right {
  379. color:#fff;
  380. background:green;
  381. }
  382. &.wrong {
  383. color:#fff;
  384. background:red;
  385. }
  386. &.checked {
  387. color:#fff;
  388. background:blue;
  389. }
  390. }
  391. .submit_checkbox {
  392. margin:20rpx auto;
  393. width: 526rpx;
  394. height: 80rpx;
  395. background: rgba(0, 122, 255, 1);
  396. color:#fff;
  397. text-align: center;
  398. line-height: 80rpx;
  399. font-size: 30rpx;
  400. border-radius: 40rpx;
  401. }
  402. .titles {
  403. overflow: hidden;
  404. margin-bottom: 24rpx;
  405. }
  406. .titBox {
  407. padding: 41rpx 25rpx 24rpx 25rpx;
  408. }
  409. .ans {
  410. margin:8rpx 8rpx 8rpx;
  411. .ans_input {
  412. border-radius: 16rpx;
  413. background:#fff;
  414. .top {
  415. border-bottom:1rpx solid #EEEEEE;
  416. padding: 16rpx;
  417. display: flex;
  418. align-items: center;
  419. .icon {
  420. margin-right:20rpx;
  421. width: 40rpx;
  422. height: 38rpx;
  423. }
  424. .progress {
  425. flex:1;
  426. }
  427. .submit {
  428. width: 168rpx;
  429. height: 48rpx;
  430. line-height: 48rpx;
  431. text-align: center;
  432. color:#fff;
  433. font-size: 30rpx;
  434. background: #007AFF;
  435. border-radius: 24rpx;
  436. }
  437. }
  438. .textarea {
  439. textarea {
  440. width:100%;
  441. height:287rpx;
  442. padding:10rpx;
  443. }
  444. }
  445. .imgs {
  446. overflow: hidden;
  447. display: flex;
  448. width:100%;
  449. .img {
  450. width: 104rpx;
  451. height: 104rpx;
  452. border-radius: 8rpx;
  453. position:relative;
  454. margin:20rpx;
  455. text {
  456. position:absolute;
  457. right:-15rpx;
  458. top:-15rpx;
  459. width:30rpx;
  460. height:30rpx;
  461. text-align: center;
  462. line-height: 30rpx;
  463. color:#fff;
  464. background:red;
  465. border-radius:50%;
  466. }
  467. image {
  468. width:100%;
  469. height:100%;
  470. }
  471. }
  472. }
  473. }
  474. .ans_submit {
  475. padding:16rpx;
  476. border-radius: 16rpx;
  477. background:#fff;
  478. .imgs {
  479. overflow: hidden;
  480. display: flex;
  481. width:100%;
  482. .img {
  483. width: 104rpx;
  484. height: 104rpx;
  485. border-radius: 8rpx;
  486. position:relative;
  487. margin:20rpx;
  488. image {
  489. width:100%;
  490. height:100%;
  491. }
  492. }
  493. }
  494. }
  495. }
  496. .firstLetter {
  497. display: flex;
  498. justify-content: space-between;
  499. align-items: center;
  500. margin-bottom: 30rpx;
  501. .leftLetters {
  502. display: flex;
  503. align-items: center;
  504. width: 220rpx;
  505. .btnType {
  506. padding: 5rpx 10rpx;
  507. border: 1rpx solid #007aff;
  508. border-radius: 10rpx;
  509. background-color: rgba(0, 122, 255, 0.1);
  510. font-size: 28rpx;
  511. color: #007aff;
  512. margin-right: 15rpx;
  513. }
  514. }
  515. }
  516. .popupView {
  517. height: 100%;
  518. padding-bottom: 100rpx;
  519. .popupTops {
  520. height: 77rpx;
  521. border-bottom: 1rpx solid #eee;
  522. text-align: center;
  523. line-height: 77rpx;
  524. font-size: 24rpx;
  525. color: #999;
  526. position: relative;
  527. .topIcon {
  528. position: absolute;
  529. top: 10rpx;
  530. left: 50%;
  531. transform: translateX(-50%);
  532. width: 80rpx;
  533. height: 8rpx;
  534. background-color: #999;
  535. border-radius: 4rpx;
  536. }
  537. }
  538. .popupContent {
  539. }
  540. }
  541. .pageContent {
  542. background-color: #eaeef1;
  543. min-height: 100vh;
  544. padding-top: 8rpx;
  545. padding-bottom: 100rpx;
  546. }
  547. .pad_8 {
  548. background-color: #fff;
  549. margin: 0rpx 8rpx 8rpx;
  550. border-radius: 16rpx;
  551. }
  552. .answer {
  553. height: 80rpx;
  554. line-height: 80rpx;
  555. padding: 0rpx 24rpx;
  556. display: flex;
  557. align-items: center;
  558. justify-content: space-between;
  559. color: #666;
  560. font-size: 30rpx;
  561. }
  562. .footer_btn {
  563. background-color: #fff;
  564. z-index: 10078;
  565. position: fixed;
  566. bottom: 0rpx;
  567. display: flex;
  568. align-items: center;
  569. justify-content: space-between;
  570. width: 100%;
  571. height: 98rpx;
  572. padding: 0rpx 38rpx;
  573. border-top: 1rpx solid #eee;
  574. }
  575. .boxSty {
  576. padding: 44rpx 41rpx 0rpx;
  577. }
  578. .liListSty {
  579. width: 88rpx;
  580. height: 88rpx;
  581. border-radius: 32rpx;
  582. background-color: #ff3b30;
  583. text-align: center;
  584. line-height: 88rpx;
  585. color: #fff;
  586. font-size: 32rpx;
  587. float: left;
  588. margin: 20rpx 23rpx;
  589. &.disabled {
  590. border:1rpx solid #EEEEEE;
  591. color:#EEEEEE;
  592. background: none;
  593. }
  594. }
  595. .answerInfos {
  596. padding: 25rpx 25rpx 25rpx 23rpx;
  597. }
  598. .answerTitle {
  599. margin-bottom: 28rpx;
  600. color: #666;
  601. font-size: 30rpx;
  602. }
  603. .answerContent {
  604. font-size: 30rpx;
  605. color: #666;
  606. }
  607. .dialog {
  608. position: fixed;
  609. left:0;
  610. top:0;
  611. width:100%;
  612. height:100%;
  613. background-color: rgba(0,0,0,0.8);
  614. display: flex;
  615. flex-direction: column;
  616. align-items: center;
  617. justify-content: center;
  618. z-index: 20000;
  619. .text {
  620. font-size: 32rpx;
  621. color: #FFFFFF;
  622. text-align: center;
  623. }
  624. .btn {
  625. width: 242rpx;
  626. height: 82rpx;
  627. border: 2rpx solid #FFFFFF;
  628. border-radius: 16rpx;
  629. text-align: center;
  630. line-height: 82rpx;
  631. margin:41rpx auto;
  632. color:#fff;
  633. font-size: 32rpx;
  634. }
  635. }
  636. </style>