matchanswer.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <template>
  2. <view class="wrap">
  3. <u-navbar title="开始答题" :placeholder="true" bgColor="rgba(255,255,255,0.3)" leftText="返回" :autoBack="true" titleStyle="font-weight:bold;color:#7a5831"></u-navbar>
  4. <view class="main" v-if="hasLoad">
  5. <view class="process">
  6. <view class="b-state">
  7. <view class="b-count">
  8. <view class="s-tit1">答题进度</view>
  9. <view class="s-num">{{ state.session_seq }}</view>
  10. <view class="s-tit2">/{{ state.total_count }}</view>
  11. </view>
  12. <view class="b-time" v-if="state.session_expired != -1">
  13. <view class="s-tit">剩余时间</view>
  14. <view class="s-time">{{ costTime(state.session_expired, 'countdown') }}</view>
  15. </view>
  16. </view>
  17. <view class="b-bar">
  18. <view class="s-percent" :style="barPercent"></view>
  19. </view>
  20. </view>
  21. <view class="answer">
  22. <view class="b-head">
  23. <view class="s-type">{{ state.type_text }}</view>
  24. <view class="s-time"></view>
  25. </view>
  26. <view class="b-title">
  27. <view class="s-num">{{ state.session_seq }}.</view>
  28. <text class="s-title">
  29. {{ state.title }}
  30. <text class="s-score">({{ state.score }}分)</text>
  31. </text>
  32. </view>
  33. <view class="b-options">
  34. <view class="b-item" v-for="(item, index) in state.optionList" :key="index" @click="onChoose(index)" :class="[optionState(index)]">
  35. <view class="s-num">{{ optionNum(index) }}.</view>
  36. <view class="s-cont">{{ item.label }}</view>
  37. <view class="s-state iconfont" :class="[optionIcon(index)]"></view>
  38. </view>
  39. </view>
  40. <!-- <view class="b-result" :class="resultIcon" v-if="state.state == 2">
  41. <view class="b-right">
  42. <view class="s-tit">正确答案:</view>
  43. <view class="s-cont">{{trueAnswer}}</view>
  44. </view>
  45. <view class="b-mine">
  46. <view class="s-tit">已选答案:</view>
  47. <view class="s-cont">{{userAnswer}}</view>
  48. </view>
  49. </view> -->
  50. <!-- <view class="b-explain" v-if="state.state == 2 && state.explain">
  51. <text>解析:{{state.explain}}</text>
  52. </view> -->
  53. <view class="b-action">
  54. <view class="b-next" @click="onFinish" v-if="state.session_status == 2">查看成绩</view>
  55. <view class="b-next" @click="onFinish" v-else-if="state.session_status == 3">超时结束</view>
  56. <view class="b-submit" :class="btnState" @click="onSubmitAnswer" v-else-if="state.state == 1">提交答案</view>
  57. <view class="b-next" :class="btnState" @click="onGetNew" v-else-if="state.state == 2">进入下一题</view>
  58. <view class="b-home" @click="onHome">稍后再答</view>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 加载中 -->
  63. <load-more :loadingType="loadingType" :loadingText="loadingText" color="#ffffff" :top="500"></load-more>
  64. </view>
  65. </template>
  66. <script>
  67. import { getNew, getResult, submitAnswer } from '@/service/api/examine.js';
  68. import mixinsCommon from '@/mixins/common.js';
  69. import mixinsAuth from '../../mixins/auth.js';
  70. export default {
  71. mixins: [mixinsCommon, mixinsAuth],
  72. data() {
  73. return {
  74. hasLoad: false,
  75. session_id: 0,
  76. state: {
  77. optionList: [],
  78. trueAnswer: [],
  79. userAnswer: []
  80. },
  81. disable: {
  82. submit: false
  83. },
  84. loadingType: 1,
  85. loadingText: ''
  86. };
  87. },
  88. onLoad(options) {
  89. console.log('onLoad', options);
  90. this.session_id = options.session_id;
  91. this.onGetNew();
  92. // 倒计时
  93. if (this.state.session_expired != -1) {
  94. setInterval(() => {
  95. if (this.state.session_expired > 0) {
  96. this.state.session_expired--;
  97. }
  98. }, 1000);
  99. }
  100. },
  101. computed: {
  102. barPercent() {
  103. return 'width: ' + (this.state.session_seq * 100) / this.state.total_count + '%';
  104. },
  105. optionNum() {
  106. return (index) => {
  107. return String.fromCharCode(64 + (index + 1));
  108. };
  109. },
  110. optionState() {
  111. return (index) => {
  112. console.log('optionState', index);
  113. let optionRight = false;
  114. let optionWrong = false;
  115. if (this.state.state == 2) {
  116. if (this.state.type === 'radio' || this.state.type === 'yesorno') {
  117. if (this.state.trueAnswer.includes(index)) {
  118. optionRight = true;
  119. } else if (this.state.userAnswer.includes(index)) {
  120. optionWrong = true;
  121. }
  122. } else {
  123. if (this.state.trueAnswer.includes(index)) {
  124. optionRight = true;
  125. } else if (
  126. (this.state.userAnswer.includes(index) && !this.state.trueAnswer.includes(index)) ||
  127. (this.state.trueAnswer.includes(index) && !this.state.userAnswer.includes(index))
  128. ) {
  129. optionWrong = true;
  130. }
  131. }
  132. }
  133. let ret = '';
  134. ret = this.state.userAnswer.includes(index) ? 'f-select' : '';
  135. ret += optionRight ? ' f-right' : '';
  136. ret += optionWrong ? ' f-wrong' : '';
  137. return ret;
  138. // return {
  139. // 'f-select': this.state.userAnswer.includes(index),
  140. // 'f-right': optionRight,
  141. // 'f-wrong': optionWrong
  142. // }
  143. };
  144. },
  145. optionIcon() {
  146. return (index) => {
  147. console.log('optionIcon', index);
  148. return {
  149. 'icon-roundcheck': this.state.userAnswer.includes(index)
  150. // 'icon-roundcheckfill': this.state.trueAnswer.includes(index),
  151. };
  152. };
  153. },
  154. resultIcon() {
  155. let ret = '';
  156. ret += this.state.result == 2 ? ' f-right' : '';
  157. ret += this.state.result == 3 ? ' f-wrong' : '';
  158. ret += this.state.result == 4 ? ' f-timeout' : '';
  159. ret += this.state.result == 5 ? ' f-timeout-end' : '';
  160. return ret;
  161. // return {
  162. // 'f-right': this.state.result == 2,
  163. // 'f-wrong': this.state.result == 3,
  164. // 'f-timeout': this.state.result == 4,
  165. // 'f-timeout-end': this.state.result == 5,
  166. // }
  167. },
  168. trueAnswer() {
  169. console.log('1', this.state.trueAnswer);
  170. if (!this.state.trueAnswer) this.state.trueAnswer = [];
  171. let options = this.state.trueAnswer.map((item) => {
  172. return String.fromCharCode(64 + (parseInt(item) + 1));
  173. });
  174. return options.join('、');
  175. },
  176. userAnswer() {
  177. console.log('2', this.state.trueAnswer);
  178. if (!this.state.trueAnswer) this.state.trueAnswer = [];
  179. let options = this.state.userAnswer.map((item) => {
  180. return String.fromCharCode(64 + (parseInt(item) + 1));
  181. });
  182. return options.join('、');
  183. },
  184. btnState() {
  185. return this.disable.submit === true || this.state.userAnswer.length === 0 ? 'disable' : '';
  186. // return {
  187. // 'disable': this.disable.submit === true || this.state.userAnswer.length === 0
  188. // }
  189. }
  190. },
  191. methods: {
  192. onChoose(index) {
  193. if (this.state.state != 1) {
  194. return;
  195. }
  196. let valueIndex = this.state.userAnswer.indexOf(index);
  197. if (valueIndex !== -1) {
  198. this.state.userAnswer.splice(valueIndex, 1);
  199. } else {
  200. if (this.state.type === 'checkbox') {
  201. this.state.userAnswer.push(index);
  202. } else {
  203. this.state.userAnswer = [index];
  204. }
  205. }
  206. if (this.state.userAnswer.length === 0) {
  207. this.disable.submit = true;
  208. } else {
  209. this.disable.submit = false;
  210. }
  211. },
  212. onGetNew() {
  213. getNew(this.session_id).then(([err, res]) => {
  214. console.log('getNew', err, res);
  215. if (!err) {
  216. this.hasLoad = true;
  217. this.loadingType = -1;
  218. this.state = res;
  219. this.state.userAnswer = []; // 初始化提交的答案
  220. } else {
  221. if (err.data.code == 502) {
  222. // 超时结束
  223. this.onFinish();
  224. } else {
  225. if (!this.hasLoad) {
  226. this.loadingType = 3;
  227. this.loadingText = err.data.msg || '加载失败';
  228. }
  229. }
  230. }
  231. });
  232. },
  233. onSubmitAnswer() {
  234. if (this.disable.submit) {
  235. return;
  236. }
  237. if (this.state.userAnswer.length === 0) {
  238. return this.$logic.showToast('还未选择答案');
  239. }
  240. this.disable.submit = true;
  241. submitAnswer(this.state.id, this.state.userAnswer.join(',')).then(([err, res]) => {
  242. console.log('submitAnswer', err, res);
  243. this.disable.submit = false;
  244. if (!err) {
  245. this.state = res;
  246. if (this.state.session_status == 3) {
  247. this.$logic.showToast('答题会话已超时结束');
  248. }
  249. }
  250. });
  251. },
  252. onFinish() {
  253. uni.reLaunch({
  254. url: '/answer_pages/examine/summary?session_id=' + this.session_id
  255. });
  256. },
  257. onHome() {
  258. uni.reLaunch({
  259. url: '/answer_pages/home/index'
  260. });
  261. }
  262. }
  263. };
  264. </script>
  265. <style lang="scss">
  266. // page {
  267. // padding-bottom: env(safe-area-inset-bottom);
  268. // background: #da5650;
  269. // }
  270. .wrap {
  271. background: #da5650;
  272. }
  273. .main {
  274. padding: 40upx;
  275. }
  276. .process {
  277. display: flex;
  278. flex-direction: column;
  279. .b-state {
  280. display: flex;
  281. align-items: center;
  282. justify-content: space-between;
  283. color: #fff;
  284. .b-count {
  285. display: flex;
  286. align-items: center;
  287. .s-tit1,
  288. .s-tit2 {
  289. font-size: 24upx;
  290. }
  291. .s-num {
  292. margin: 0 10upx;
  293. font-size: 32upx;
  294. }
  295. }
  296. .b-time {
  297. display: flex;
  298. align-items: center;
  299. .s-tit {
  300. font-size: 24upx;
  301. }
  302. .s-time {
  303. margin-left: 10upx;
  304. font-size: 28upx;
  305. }
  306. }
  307. }
  308. .b-bar {
  309. margin-top: 10upx;
  310. background: rgba(255, 255, 255, 0.5);
  311. width: 100%;
  312. height: 24upx;
  313. position: relative;
  314. .s-percent {
  315. position: absolute;
  316. left: 0;
  317. bottom: 0;
  318. width: 30%;
  319. height: 24upx;
  320. display: inline-block;
  321. background: #fff;
  322. }
  323. }
  324. }
  325. .answer {
  326. margin-top: 50upx;
  327. padding: 40upx;
  328. background: #fff;
  329. border-radius: 20upx;
  330. overflow: hidden;
  331. display: flex;
  332. flex-direction: column;
  333. .b-head {
  334. display: flex;
  335. align-items: center;
  336. // justify-content: space-around;
  337. .s-type {
  338. width: fit-content;
  339. background: #da5650;
  340. padding: 0 20upx;
  341. font-size: 28upx;
  342. color: #fff;
  343. height: 50upx;
  344. line-height: 50upx;
  345. }
  346. .s-time {
  347. /* 题目剩余时间 */
  348. }
  349. }
  350. .b-title {
  351. margin-top: 20upx;
  352. font-size: 30upx;
  353. display: flex;
  354. .s-num {
  355. font-weight: bold;
  356. }
  357. .s-title {
  358. margin-left: 10upx;
  359. flex: 1;
  360. }
  361. .s-score {
  362. margin-left: 20upx;
  363. color: #666;
  364. }
  365. }
  366. .b-options {
  367. margin-top: 40upx;
  368. .b-item {
  369. margin-bottom: 20upx;
  370. padding: 20upx;
  371. font-size: 28upx;
  372. display: flex;
  373. // align-items: center;
  374. background: #f7f7f7;
  375. &:last-child {
  376. margin-bottom: 0;
  377. }
  378. &.f-select {
  379. background: #ecf3fe;
  380. color: #338ada;
  381. }
  382. &.f-right {
  383. background: #ecf6f0;
  384. color: #1eab69;
  385. }
  386. &.f-wrong {
  387. background: #ffebeb;
  388. color: #d13b42;
  389. }
  390. .s-num {
  391. font-weight: bold;
  392. }
  393. .s-cont {
  394. margin-left: 10upx;
  395. flex: 1;
  396. }
  397. .s-state {
  398. margin-top: 2upx;
  399. margin-left: 10upx;
  400. font-size: 32upx;
  401. }
  402. }
  403. }
  404. .b-result {
  405. padding: 80upx 0;
  406. display: flex;
  407. align-items: center;
  408. justify-content: space-between;
  409. background-repeat: no-repeat;
  410. background-size: 180upx auto;
  411. background-position: center center;
  412. &.f-right {
  413. background-image: url(https://huli-app.wenlvti.net/app_static/wuyuan/static/wenwu/answer/imgs/result_right.png);
  414. }
  415. &.f-wrong {
  416. background-image: url(https://huli-app.wenlvti.net/app_static/wuyuan/static/wenwu/answer/imgs/result_wrong.png);
  417. }
  418. &.f-timeout {
  419. background-image: url(https://huli-app.wenlvti.net/app_static/wuyuan/static/wenwu/answer/imgs/result_timeout.png);
  420. }
  421. &.f-timeout-end {
  422. background-image: url(https://huli-app.wenlvti.net/app_static/wuyuan/static/wenwu/answer/imgs/result_timeout_end.png);
  423. }
  424. .b-right,
  425. .b-mine {
  426. display: flex;
  427. align-items: center;
  428. .s-tit {
  429. font-size: 26upx;
  430. color: #333;
  431. }
  432. .s-cont {
  433. margin-left: 10upx;
  434. font-weight: bold;
  435. color: #da5650;
  436. font-size: 36upx;
  437. }
  438. }
  439. }
  440. .b-explain {
  441. font-size: 28upx;
  442. color: #808080;
  443. }
  444. .b-action {
  445. margin-top: 50upx;
  446. display: flex;
  447. flex-direction: column;
  448. .b-submit {
  449. height: 100upx;
  450. line-height: 100upx;
  451. text-align: center;
  452. color: #fff;
  453. font-size: 32upx;
  454. background: #da5650;
  455. border-radius: 50upx;
  456. letter-spacing: 10upx;
  457. &.disable {
  458. background: rgba($color: #da5650, $alpha: 0.7);
  459. }
  460. }
  461. .b-next {
  462. height: 100upx;
  463. line-height: 100upx;
  464. text-align: center;
  465. color: #fff;
  466. font-size: 32upx;
  467. background: #ff8d1a;
  468. border-radius: 50upx;
  469. letter-spacing: 10upx;
  470. &.disable {
  471. background: rgba($color: #ff8d1a, $alpha: 0.2);
  472. }
  473. }
  474. .b-home {
  475. margin-top: 40upx;
  476. text-align: center;
  477. color: #808080;
  478. font-size: 28upx;
  479. }
  480. }
  481. }
  482. </style>