common.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. let filterData = (arr1, arr2) => {
  2. let map = {};
  3. for (let i = 0; i < arr1.length; i++) {
  4. if (arr1[i]) {
  5. map[arr1[i].question_id] = arr1[i].answer
  6. }
  7. }
  8. return arr2.map((item) => {
  9. for (let i = 0; i < item.answer.length; i++) {
  10. const value = item.answer[i];
  11. const va = map[item.id]
  12. // console.log(va)
  13. if (va) {
  14. // const maparr = map[item.question_id]
  15. for (let j = 0; j < va.length; j++) {
  16. if (va[j].key == value.key) {
  17. value.checked = 1;
  18. }
  19. }
  20. }
  21. }
  22. return item
  23. })
  24. }
  25. let examDjsFn = (examSurplusTime) => {
  26. let timer = null;
  27. let time = examSurplusTime * 1000
  28. timer = setInterval(() => {
  29. let m, s
  30. if (time >= 0) {
  31. m = Math.floor(time / 1000 / 60 % 60);
  32. s = Math.floor(time / 1000 % 60);
  33. m = m < 10 ? ('0' + m) : m;
  34. s = s < 10 ? ('0' + s) : s;
  35. let duration = m + ':' + s;
  36. console.log(duration)
  37. // that.setData({
  38. // duration: duration
  39. // })
  40. time = time - 1000
  41. return duration
  42. } else {
  43. clearInterval(timer);
  44. return '00:00'
  45. }
  46. }, 1000);
  47. }
  48. export default {
  49. filterData,
  50. examDjsFn
  51. };