answer.vue 12 KB

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