index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. define([
  2. 'require',
  3. 'api/topic',
  4. 'text!./index.html',
  5. 'css!./index.css'
  6. ], function (require, topicApi, html) {
  7. return {
  8. props: {
  9. activeName: {
  10. type: String,
  11. default: ''
  12. }
  13. },
  14. data: function () {
  15. return {
  16. type: '1',
  17. page: 1,
  18. limit: 16,
  19. total: 0,
  20. paperList: [],
  21. finished: false
  22. };
  23. },
  24. watch: {
  25. activeName: {
  26. handler: function (value) {
  27. if (value === 'question') {
  28. this.getPaper();
  29. }
  30. },
  31. immediate: true
  32. },
  33. type: function () {
  34. this.paperList = [];
  35. this.page = 1;
  36. this.total = 0;
  37. this.finished = false;
  38. this.getPaper();
  39. }
  40. },
  41. methods: {
  42. getPaper: function () {
  43. var vm = this;
  44. topicApi.myTestPaper({
  45. page: this.page,
  46. limit: this.limit,
  47. type: this.type
  48. }).then(function (res) {
  49. vm.total = res.data.total;
  50. vm.paperList = res.data.data;
  51. vm.finished = vm.limit > vm.paperList.length;
  52. });
  53. },
  54. handleCurrentChange: function () {
  55. this.getPaper();
  56. },
  57. answer: function (id) {
  58. if (this.type == 1) {
  59. window.location.assign(this.$router.problem_index + '?id=' + id);
  60. } else {
  61. window.location.assign(this.$router.question_index + '?id=' + id);
  62. }
  63. },
  64. goProblemResult: function (problem) {
  65. window.location.assign(this.$router.problem_result + '?test_id=' + problem.test_id);
  66. },
  67. goQuestionResult: function (question) {
  68. window.location.assign(this.$router.question_result + '?test_id=' + question.test_id);
  69. }
  70. },
  71. template: html
  72. };
  73. });