From 98dc49ab77dba671f3aa5eea56683fc2cc55434c Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sun, 3 Nov 2019 23:58:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=A1=A5=E4=BA=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 38 ++++++++++++++----------- app.json | 7 +++-- data/client.js | 5 ++++ data/eduapi.js | 51 ++++++++++++++++++++++------------ pages/exercise/exercise.js | 31 +++++++++++++++++---- pages/exercise/exercise.wxml | 23 +++++++-------- pages/exercise/exercise.wxss | 28 +++++++++++++------ pages/exercises/exercises.js | 32 +++++++++++++++++---- pages/exercises/exercises.json | 3 +- pages/exercises/exercises.wxss | 4 ++- pages/files/files.js | 3 +- pages/login/login.js | 5 ++-- pages/setting/setting.js | 4 +++ 13 files changed, 160 insertions(+), 74 deletions(-) diff --git a/app.js b/app.js index f65e7c9..1fd4262 100644 --- a/app.js +++ b/app.js @@ -20,6 +20,7 @@ AV.init({ App({ towxml: new Towxml(), client: new Client(), + logining: false, string_format_init: function(){ //使String类实现format方法 //@todo: 待测试 @@ -29,26 +30,31 @@ App({ }); }; }, - enter_login: function(){ + require_login(){ + if (!this.logining) { + this.logining = true; wx.navigateTo({ - url: "/pages/login/login" + url: "/pages/login/login" }); + } }, onLaunch: function () { - console.log("onLauch"); - console.log(this.client.get_user_info({ - success: res=>{ - console.log("app.js: userinfo get success"); - console.log(res); - if(res.data.user_id == 2){ - this.enter_login(); - } - }, - fail:error=>{ - console.warn("app.js: get user info fail"); - this.enter_login(); - } - })); + this.client.onRequireLogin(() => { + this.require_login(); + }); + console.log("onLauch"); + this.client.get_user_info({ + success: res=>{ + console.log("app.js: userinfo get success"); + console.log(res); + if(res.data.user_id == 2){ + this.client.callback.require_login(); + } + }, + fail:error=>{ + console.warn("app.js: get user info fail"); + } + }); login(); } }); \ No newline at end of file diff --git a/app.json b/app.json index 46c76eb..054ac0c 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,8 @@ { "pages": [ - + "pages/my_courses/my_courses", + "pages/exercises/exercises", "pages/courses/courses", "pages/exercise/exercise", "pages/setting/setting", @@ -17,8 +18,8 @@ "pages/test/test", "pages/course_detail/course_detail", "pages/files/files", - "pages/exercises/exercises", - "pages/mark_detail/mark_detail" + + "pages/mark_detail/mark_detail" ], "window": { diff --git a/data/client.js b/data/client.js index ed1ed6b..897ebec 100644 --- a/data/client.js +++ b/data/client.js @@ -16,6 +16,7 @@ export class Client{ } this.load_cached_cookies(); this.current_user = {}; + this.callback={require_login: ()=>{}}; this.load_current_user(); } load_current_user(){ @@ -59,6 +60,9 @@ export class Client{ cookie.save(); } } + onRequireLogin(cd){ + this.callback.require_login = cd; + } require_login(){ wx.redirectTo({ url: "../pages/login/login" @@ -146,6 +150,7 @@ export class Client{ this.save_current_user(); }, fail: error=>{ + this.callback.require_login(); if(typeof fail == "function"){ fail(error); } diff --git a/data/eduapi.js b/data/eduapi.js index 33bae61..16f1349 100644 --- a/data/eduapi.js +++ b/data/eduapi.js @@ -199,13 +199,28 @@ export class Course{ } export class Exercise{ - static search({session,course_id,page=1, limit=15, success, fail, complete}){ + static search({session,course_id, page=1, limit=15, success, fail, complete}){ let data = {page:page, limit:limit}; return session.request({ url: api_base_url + "/courses/"+course_id+"/exercises.json", method: "GET", data: data, - success: success, + success(res) { + if ("status" in res.data ) { + if (res.data.status < 0){ + fail(new Error(res.data.message)); + return; + } + switch(res.data.status){ + case 409: + fail(new Error(res.data.message)); + return; + } + } + if (typeof success == "function") { + success(res); + } + }, fail:fail, complete: complete }) @@ -216,22 +231,22 @@ export class Exercise{ url: api_base_url + "/exercises/" + exercise_id + "/start_answer.json", method: "GET", data: data, - success: res=>{ - if("status" in res.data){ - if(res.data.status<0){ - fail(new Error(res.data.message)); - return; - } - /*switch (res.data.status) { - case -1: - fail(new Error("???")); - return; - }*/ - } - if(typeof success == "function") { - success(res); - } - }, + success(res) { + if ("status" in res.data ) { + if (res.data.status < 0){ + fail(new Error(res.data.message)); + return; + } + switch(res.data.status){ + case 409: + fail(new Error(res.data.message)); + return; + } + } + if (typeof success == "function") { + success(res); + } + }, fail: fail, complete: complete }) diff --git a/pages/exercise/exercise.js b/pages/exercise/exercise.js index 3f3e53e..f77120f 100644 --- a/pages/exercise/exercise.js +++ b/pages/exercise/exercise.js @@ -15,7 +15,16 @@ Page({ .then(res=>{ console.log("pull questions"); console.log(res); - this.setData({ exercise: res.data.exercise}); + this.setData({exercise: res.data.exercise}); + if (!res.data.exercise_questions){ + if(res.data.status==401) + wx.showToast({ + title: '请登陆后重试', + icon: "none" + }) + //console.log("require_login"); + return; + } let questions = res.data.exercise_questions; for(var i=0;i { + console.error(error); + wx.showToast({ + title: error.toString(), + icon: "none", + duration: 5000 + }) + }); }, answer_null_question: function ({ detail: { value }, currentTarget: { dataset } }){ console.log("answer_main_question"); @@ -124,6 +140,7 @@ Page({ */ onLoad: function (options) { this.exercise_id = options.exercise_id; + this.course_name = options.exercise_name;//todo finish this.pull_questions(); }, @@ -138,7 +155,9 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - + if(this.data.loading){ + this.pull_questions(); + } }, onError: function(e){ @@ -148,14 +167,14 @@ Page({ * 生命周期函数--监听页面隐藏 */ onHide: function () { - + this.save_exercise({ show_loading: false }); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { - this.save_exercise({show_loading: false}); + }, /** diff --git a/pages/exercise/exercise.wxml b/pages/exercise/exercise.wxml index 3e5eb75..f0a8e54 100644 --- a/pages/exercise/exercise.wxml +++ b/pages/exercise/exercise.wxml @@ -4,8 +4,8 @@ 第{{question.q_position}}题 {{question.question_title}} - - + + {{choice.choice_text}} 正确答案 @@ -14,20 +14,21 @@ - + + {{choice.choice_text}} 正确答案 - - - + @@ -44,7 +45,7 @@ 第{{answer.choice_id}}空答案: - {{answer.answer_text}} + {{answer.answer_text}} @@ -67,7 +68,7 @@ - - - + \ No newline at end of file diff --git a/pages/exercise/exercise.wxss b/pages/exercise/exercise.wxss index 0a12e41..1845b4e 100644 --- a/pages/exercise/exercise.wxss +++ b/pages/exercise/exercise.wxss @@ -3,18 +3,28 @@ width: 100%; align-items: center; background: white; - padding-top: 1px; - border-top: 1rpx solid gray; bottom: 0; - z-index: 2; + z-index: 9; } +.operation{ + color: white; + width: 50%; +} +.save{ + background-color: #4797f8; +} +.commit{ + background-color: orangered; +} + .container{ padding-bottom: 40px; } .question{ background: white; margin: 20rpx -6rpx; - padding: 4rpx 20rpx 20rpx 20rpx; + padding: 4rpx 20rpx 22rpx 22rpx; + border-radius: 18rpx; } .question-title{ @@ -37,8 +47,8 @@ height: 120rpx; margin: 18rpx 0 4rpx 18rpx; border: 1rpx solid lightgray; - border-radius: 8rpx; - padding-left: 12rpx; + border-radius: 12rpx; + padding: 12rpx 10rpx; } view.null-input{ @@ -47,9 +57,9 @@ view.null-input{ input.null-input{ border: 1rpx solid lightgray; - padding: 14rpx 5rpx; - margin-left: 8rpx; - border-radius: 6rpx; + padding: 12rpx 6rpx; + margin: 6rpx 10rpx; + border-radius: 10rpx; } .standard-choice{ diff --git a/pages/exercises/exercises.js b/pages/exercises/exercises.js index 31b91e6..72497d8 100644 --- a/pages/exercises/exercises.js +++ b/pages/exercises/exercises.js @@ -51,10 +51,29 @@ Page({ .then(); /**@todo */ }, - pull_courses: function(){ + pull_exercise: function(){ app.client.search_exercises({ course_id: this.course_id }) - .then(res => {console.log("pull_courses");console.log(res); this.setData({ exercises: res.data.exercises, loading: false});console.log(this.data)}) - .catch(console.error); + .then(res => { + console.log("pull_exercise"); + console.log(res); + if(res.data.exercises){ + this.setData({exercises: res.data.exercises, loading: false}); + }else if(res.data.status==401){ + wx.showToast({ + title: '请登陆后重试', + icon: "none" + }); + } + console.log(this.data) + }) + .catch(error=>{ + console.error(error); + wx.showToast({ + title: error.toString(), + icon: "none", + duration: 5000 + }) + }); }, see_exercise: function ({ currentTarget: { dataset } }){ wx.navigateTo({ @@ -79,7 +98,7 @@ Page({ this.course_id = options.id; }, onShow: function(){ - this.pull_courses(); + this.pull_exercise(); }, switchNav(event) { var cur = event.currentTarget.dataset.current; @@ -106,6 +125,9 @@ Page({ }); }, onPullDownRefresh: function(){ - this.pull_courses(); + this.pull_exercise(); + }, + onShareAppMessage:function(){ + } }) \ No newline at end of file diff --git a/pages/exercises/exercises.json b/pages/exercises/exercises.json index 7360326..3279e41 100644 --- a/pages/exercises/exercises.json +++ b/pages/exercises/exercises.json @@ -1,4 +1,5 @@ { "usingComponents": {}, - "enablePullDownRefresh": true + "enablePullDownRefresh": true, + "navigationBarTitleText": "试卷列表" } \ No newline at end of file diff --git a/pages/exercises/exercises.wxss b/pages/exercises/exercises.wxss index beff893..22b8fac 100644 --- a/pages/exercises/exercises.wxss +++ b/pages/exercises/exercises.wxss @@ -44,8 +44,9 @@ text.start-answer{ } .exercise{ background: white; - padding: 17rpx 12rpx; + padding: 17rpx 14rpx; margin: 14rpx 0rpx; + border-radius: 12rpx; } .exercise-info{ margin-top: 4rpx; @@ -59,6 +60,7 @@ text.start-answer{ border-radius: 14rpx; padding: 4rpx 16rpx; margin-left: 18rpx; + text-align: center; } view.no-content{ diff --git a/pages/files/files.js b/pages/files/files.js index 6bc6de3..29973cb 100644 --- a/pages/files/files.js +++ b/pages/files/files.js @@ -54,7 +54,6 @@ Page({ onLoad: function (options) { this.course_id = options.id; console.log(this.course_id); - this.pull_files(); }, /** @@ -68,7 +67,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - + this.pull_files(); }, /** diff --git a/pages/login/login.js b/pages/login/login.js index 3bc037c..82cbf60 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -43,7 +43,8 @@ Page({ this.save_input(); wx.navigateBack({ delta: 1 - }) + }); + app.logining = false; console.log("login_successful!!!!"); }, fail(error){ @@ -86,7 +87,7 @@ Page({ * 生命周期函数--监听页面卸载 */ onUnload: function () { - + app.logining = false; }, /** diff --git a/pages/setting/setting.js b/pages/setting/setting.js index 27f1246..4274371 100644 --- a/pages/setting/setting.js +++ b/pages/setting/setting.js @@ -75,6 +75,10 @@ Page({ this.setData({ avatar_url: "https://www.educoder.net/images/" + app.client.current_user.image_url }) } }) + }, + + onShareAppMessage: function(){ + } // enter_usersetting: function(event){