| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <html lang="zh">
- <head>
- <title></title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <script src="/static/vue.js"></script>
- <script src="/static/jquery.min.js"></script>
- <style>
- p {
- white-space: pre-line;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <p v-show="!ajaxFinish">{{msg}}</p>
- <!--<input v-show="ajaxFinish" type="checkbox" v-model="showAnswer" /><span v-show="ajaxFinish">显示答案</span>-->
- <p id="tools" v-show="ajaxFinish"><input type="checkbox" v-model="showAnswer"/><span>显示答案</span><input type="button" @click="print" value="打印"/></p>
- <div v-show="ajaxFinish" v-for="data in datas">
- <div v-if="data!=null">
- <!--data-->
- <h1>{{data.title}}</h1>
- <div v-for="group in data.groups">
- <h2>{{group.title}}</h2>
- <p v-if="group.memo!=''" v-html="group.memo"></p>
- <div v-for="question,index in group.questions">
- <p style="font-weight:bold;" v-html="(index+1)+ '. ' + question.title"></p>
- <ul>
- <li v-for="option in question.options" v-html="option.value + '. '+option.text"></li>
- </ul>
- <p v-show="showAnswer" v-html="'<b>答案:</b>'+question.answer.join(';')"></p>
- <p v-if="question.explanation" v-show="showAnswer" v-html="'<b>题解:</b>'+question.explanation"></p>
- <hr>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- var URL_PREFIX = "";
- var app = new Vue({
- el: '#app',
- data: {
- courses: [],
- datas: [],
- msg: "loading...",
- showAnswer: true,
- finishCount: 0,
- ajaxFinish: false
- },
- methods: {
- print() {
- var tools = document.getElementById("tools");
- tools.style.display = "none";
- print();
- tools.style.display = "";
- },
- getCourse() {
- var url = location.href.split('?')[0].split('/');
- var self = this;
- $.ajax({
- url: URL_PREFIX + "/get/question/list/" + url[url.length - 1],
- type: "GET",
- success: function(data) {
- if (data["success"]) {
- if (data["data"] && data["data"]["results"]) {
- var res = data["data"]["results"];
- for (var i = 0, j = res.length; i < j; i++) {
- self.courses.push(res[i]["id"]);
- }
- self.getContentLoop();
- }
- if (document.title === "") {
- document.title = "百日题库-" + data["data"]["title"];
- }
- }
- else {
- self.msg = "获取失败";
- }
- }
- });
- },
- getContentLoop() {
- for (var i = 0, j = this.courses.length; i < j; i++) {
- this.getContentById(this.courses[i], i);
- }
- },
- getContentById(id, pos) {
- var self = this;
- $.ajax({
- url: URL_PREFIX + "/get/question/content_object/" + id,
- type: "GET",
- success: function(data) {
- self.finishCount++;
- if (data["success"]) {
- self.$set(self.datas, pos, data["data"]);
- //self.datas[pos] = data["data"];
- }
- else {
- self.msg = "获取失败";
- }
- console.log(self.finishCount, self.courses.length);
- if (self.finishCount == self.courses.length) {
- self.ajaxFinish = true;
- }
- }
- })
- }
- },
- mounted() {
- var search = location.search.substr(1).split('&');
- var courseName = "";
- for (var i = 0, j = search.length; i < j; i++) {
- var s = search[i].split('=');
- switch (s[0]) {
- case "course_name":
- courseName = s[1];
- break;
- }
- }
- if (courseName !== "") {
- document.title = "百日题库-" + decodeURI(courseName);
- }
- this.getCourse();
- }
- });
- </script>
- </body>
- </html>
|