123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- const baseUrl = 'http://face3d.4dage.com:8102';
- var questionsData =[];
- var currData = [];
- var correctnum = 0;
- var currnum = 1;
- function getQuestionsData() {
- return new Promise (function(resolve,reject){
- $.ajax({
- url:baseUrl + '/api/web/list',
- type: 'POST',
- success: function(res) {
- resolve(res.data)
- },
- error: function(err) {
- console.log(err)
- }
- })
- })
-
- }
- function updateQuestion() {
- console.log(currData);
- var html = ` <p class="question fontLiSu colorc"><span class="num">${currnum}</span>.${currData?currData.title:''}</p>
- <div class="answer fontLiSu colorc">
- <ul id="options" >
- ${
- currData.answers.map(item => {
- return `<li class="li${currnum}" data-correct="${item.correct}">${item.content}</li>`
-
- }).join('')
- }
- </ul>
- </div>`;
- $(".topic").html(html);
- }
- $("#gui-modes-backIndex").click(function() {
- location.reload();
- })
- $("#gui-modes-quiz").click(function() {
- $("#game").show();
- })
- $("#closeGame").click(function() {
- currnum = 1;
- correctnum = 0;
- $(".process").hide();
- $(".start").show();
- $("#game").hide();
- })
- $("#start_btn").click(function() {
- currnum = 1;
- correctnum = 0;
- getQuestionsData().then(function(v) {
- console.log(v)
- questionsData = v.filter(function(item){return item.type=='1'}) ;
- currData= questionsData[currnum-1<0?0:currnum-1];
- console.log(currData)
- $("#start_page").hide();
- $("#process_page").show();
- updateQuestion();
- answer();
-
- })
-
- })
- $("#next_btn").click(function() {
-
- console.log(currnum,correctnum)
- if(currnum==10&&correctnum<7) {
- $("#process_page").hide();
- $(".again").show();
- }else if(currnum==10&&correctnum>=7) {
- $("#process_page").hide();
- $(".success").show();
- }else {
- currnum ++;
- currData= questionsData[currnum-1]
- updateQuestion();
- answer();
- }
-
-
- })
- var params = JSON.stringify({
- "pageNum": 1,
- "pageSize": 1,
- "searchKey": "",
- "type": 1
- })
- function answer () {
- $(".topic").one('click','li',function(item){
- flag= true;
- if($(this).attr("data-correct")==0){
- $(this).addClass("wrong");
- $("#options li").each(function(i,item) {
- if($(item).attr("data-correct")==1){
- setTimeout(function(){$(item).addClass("correct")},1000)
- }
- })
- }else {
- correctnum = correctnum + 1;
- $(this).addClass("correct");
- }
- if(currnum==10) {
- if(correctnum>=7) {
- $("#process_page").hide();
- $(".success").show();
- }else {
- $("#process_page").hide();
- $(".again").show();
- }
- }
- })
- }
- $(".again-btn").click(function() {
- initData();
- getQuestionsData().then(function(v) {
- console.log(v)
- questionsData = v ;
- currData= questionsData[currnum-1];
- $("#start_page").hide();
- $("#process_page").show();
- updateQuestion();
- answer();
-
- })
- })
- $(".over-btn").click(function() {
- initData()
- $("#game").hide();
-
- })
- function initData() {
- questionsData =[];
- currData = [];
- correctnum = 0;
- currnum = 1;
- $(".process").hide();
- $(".start").show();
- }
- $('html').click(function(){
- $("#guide").hide();
- })
-
|