修补了页面分享的bug

smart_class
educoder_weapp 5 years ago
parent 7bbbe466c9
commit 98dc49ab77

@ -20,6 +20,7 @@ AV.init({
App({ App({
towxml: new Towxml(), towxml: new Towxml(),
client: new Client(), client: new Client(),
logining: false,
string_format_init: function(){ string_format_init: function(){
//使String类实现format方法 //使String类实现format方法
//@todo: 待测试 //@todo: 待测试
@ -29,26 +30,31 @@ App({
}); });
}; };
}, },
enter_login: function(){ require_login(){
if (!this.logining) {
this.logining = true;
wx.navigateTo({ wx.navigateTo({
url: "/pages/login/login" url: "/pages/login/login"
}); });
}
}, },
onLaunch: function () { onLaunch: function () {
console.log("onLauch"); this.client.onRequireLogin(() => {
console.log(this.client.get_user_info({ this.require_login();
success: res=>{ });
console.log("app.js: userinfo get success"); console.log("onLauch");
console.log(res); this.client.get_user_info({
if(res.data.user_id == 2){ success: res=>{
this.enter_login(); console.log("app.js: userinfo get success");
} console.log(res);
}, if(res.data.user_id == 2){
fail:error=>{ this.client.callback.require_login();
console.warn("app.js: get user info fail"); }
this.enter_login(); },
} fail:error=>{
})); console.warn("app.js: get user info fail");
}
});
login(); login();
} }
}); });

@ -1,7 +1,8 @@
{ {
"pages": [ "pages": [
"pages/my_courses/my_courses", "pages/my_courses/my_courses",
"pages/exercises/exercises",
"pages/courses/courses", "pages/courses/courses",
"pages/exercise/exercise", "pages/exercise/exercise",
"pages/setting/setting", "pages/setting/setting",
@ -17,8 +18,8 @@
"pages/test/test", "pages/test/test",
"pages/course_detail/course_detail", "pages/course_detail/course_detail",
"pages/files/files", "pages/files/files",
"pages/exercises/exercises",
"pages/mark_detail/mark_detail" "pages/mark_detail/mark_detail"
], ],
"window": { "window": {

@ -16,6 +16,7 @@ export class Client{
} }
this.load_cached_cookies(); this.load_cached_cookies();
this.current_user = {}; this.current_user = {};
this.callback={require_login: ()=>{}};
this.load_current_user(); this.load_current_user();
} }
load_current_user(){ load_current_user(){
@ -59,6 +60,9 @@ export class Client{
cookie.save(); cookie.save();
} }
} }
onRequireLogin(cd){
this.callback.require_login = cd;
}
require_login(){ require_login(){
wx.redirectTo({ wx.redirectTo({
url: "../pages/login/login" url: "../pages/login/login"
@ -146,6 +150,7 @@ export class Client{
this.save_current_user(); this.save_current_user();
}, },
fail: error=>{ fail: error=>{
this.callback.require_login();
if(typeof fail == "function"){ if(typeof fail == "function"){
fail(error); fail(error);
} }

@ -199,13 +199,28 @@ export class Course{
} }
export class Exercise{ 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}; let data = {page:page, limit:limit};
return session.request({ return session.request({
url: api_base_url + "/courses/"+course_id+"/exercises.json", url: api_base_url + "/courses/"+course_id+"/exercises.json",
method: "GET", method: "GET",
data: data, 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, fail:fail,
complete: complete complete: complete
}) })
@ -216,22 +231,22 @@ export class Exercise{
url: api_base_url + "/exercises/" + exercise_id + "/start_answer.json", url: api_base_url + "/exercises/" + exercise_id + "/start_answer.json",
method: "GET", method: "GET",
data: data, data: data,
success: res=>{ success(res) {
if("status" in res.data){ if ("status" in res.data ) {
if(res.data.status<0){ if (res.data.status < 0){
fail(new Error(res.data.message)); fail(new Error(res.data.message));
return; return;
} }
/*switch (res.data.status) { switch(res.data.status){
case -1: case 409:
fail(new Error("???")); fail(new Error(res.data.message));
return; return;
}*/ }
} }
if(typeof success == "function") { if (typeof success == "function") {
success(res); success(res);
} }
}, },
fail: fail, fail: fail,
complete: complete complete: complete
}) })

@ -15,7 +15,16 @@ Page({
.then(res=>{ .then(res=>{
console.log("pull questions"); console.log("pull questions");
console.log(res); 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; let questions = res.data.exercise_questions;
for(var i=0;i<questions.length;i++){ for(var i=0;i<questions.length;i++){
if (questions[i]["question_type"]==3){ if (questions[i]["question_type"]==3){
@ -30,9 +39,16 @@ Page({
console.log(questions); console.log(questions);
} }
} }
this.setData({ exercise_questions: questions}); this.setData({ exercise_questions: questions, loading: false});
console.log(this.data); console.log(this.data);
}).catch(console.error) }).catch(error => {
console.error(error);
wx.showToast({
title: error.toString(),
icon: "none",
duration: 5000
})
});
}, },
answer_null_question: function ({ detail: { value }, currentTarget: { dataset } }){ answer_null_question: function ({ detail: { value }, currentTarget: { dataset } }){
console.log("answer_main_question"); console.log("answer_main_question");
@ -124,6 +140,7 @@ Page({
*/ */
onLoad: function (options) { onLoad: function (options) {
this.exercise_id = options.exercise_id; this.exercise_id = options.exercise_id;
this.course_name = options.exercise_name;//todo finish
this.pull_questions(); this.pull_questions();
}, },
@ -138,7 +155,9 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
if(this.data.loading){
this.pull_questions();
}
}, },
onError: function(e){ onError: function(e){
@ -148,14 +167,14 @@ Page({
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function () {
this.save_exercise({ show_loading: false });
}, },
/** /**
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function () { onUnload: function () {
this.save_exercise({show_loading: false});
}, },
/** /**

@ -4,8 +4,8 @@
<view class="question"> <view class="question">
<text class="hint">第{{question.q_position}}题</text> <text class="hint">第{{question.q_position}}题</text>
<text class="question-title">{{question.question_title}}</text> <text class="question-title">{{question.question_title}}</text>
<view wx:if="{{question.question_type==0}}"> <view wx:if="{{question.question_type==0 || question.question_type==2}}">
<radio-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}"> <radio-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}">
<radio disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" class="choice" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}"> <radio disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" class="choice" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}">
<text class="choice-text">{{choice.choice_text}}</text> <text class="choice-text">{{choice.choice_text}}</text>
<text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text> <text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text>
@ -14,20 +14,21 @@
</view> </view>
<view wx:elif="{{question.question_type==1}}"> <view wx:elif="{{question.question_type==1}}">
<checkbox-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}"> <checkbox-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}">
<checkbox disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" class="choice" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}">
<checkbox class="choice" disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}">
<text class="choice-text">{{choice.choice_text}}</text> <text class="choice-text">{{choice.choice_text}}</text>
<text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text> <text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text>
</checkbox> </checkbox>
</checkbox-group> </checkbox-group>
</view> </view>
<view wx:elif="{{question.question_type==2}}"> <!--view wx:elif="{{question.question_type==2}}">
<radio-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}"> <radio-group class="choices" bindchange="answer_choice_question" data-question_id="{{question.question_id}}">
<radio disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" class="choice" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}"> <radio class="choice" disabled="{{exercise.user_exercise_status==1 || exercise.user_exercise_status==4}}" wx:for="{{question.question_choices}}" wx:for-item="choice" wx:key="choice_id" checked="{{choice.user_answer_boolean}}" value="{{choice.choice_id}}">
<text class="choice-text">{{choice.choice_text}}</text> <text class="choice-text">{{choice.choice_text}}</text>
<text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text> <text wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text>
</radio> </radio>
</radio-group> </radio-group>
</view> </view-->
<view wx:elif="{{question.question_type==3}}"> <view wx:elif="{{question.question_type==3}}">
<block wx:for="{{question.null_inputs}}" wx:for-item="null_input"> <block wx:for="{{question.null_inputs}}" wx:for-item="null_input">
<view class="null-input flex-wrap"> <view class="null-input flex-wrap">
@ -44,7 +45,7 @@
<view wx:if="{{question.standard_answer}}" class="standard-null-inputs"> <view wx:if="{{question.standard_answer}}" class="standard-null-inputs">
<view class="standard-null-input flex-wrap" wx:for="{{question.standard_answer}}" wx:for-item="answer"> <view class="standard-null-input flex-wrap" wx:for="{{question.standard_answer}}" wx:for-item="answer">
<text class="hint">第{{answer.choice_id}}空答案:</text> <text class="hint">第{{answer.choice_id}}空答案:</text>
<text class="error" style="padding-top: 6rpx;">{{answer.answer_text}}</text> <text class="error" style="padding-top: 12rpx;">{{answer.answer_text}}</text>
</view> </view>
</view> </view>
</view> </view>
@ -67,7 +68,7 @@
</block> </block>
</view> </view>
</view> </view>
<cover-view wx:if="{{exercise.user_exercise_status!=1 && exercise.user_exercise_status!=4}}" class="foot flex-wrap" > <cover-view wx:if="{{exercise.user_exercise_status!=1 && exercise.user_exercise_status!=4}}" hidden="{{loading}}" class="foot flex-wrap" >
<button bindtap="save_exercise">保存</button> <button class="save operation" catchtap="save_exercise">保存</button>
<button bindtap="commit_exercise">交卷</button> <button class="commit operation" catchtap="commit_exercise">交卷</button>
</cover-view> </cover-view>

@ -3,18 +3,28 @@
width: 100%; width: 100%;
align-items: center; align-items: center;
background: white; background: white;
padding-top: 1px;
border-top: 1rpx solid gray;
bottom: 0; bottom: 0;
z-index: 2; z-index: 9;
} }
.operation{
color: white;
width: 50%;
}
.save{
background-color: #4797f8;
}
.commit{
background-color: orangered;
}
.container{ .container{
padding-bottom: 40px; padding-bottom: 40px;
} }
.question{ .question{
background: white; background: white;
margin: 20rpx -6rpx; margin: 20rpx -6rpx;
padding: 4rpx 20rpx 20rpx 20rpx; padding: 4rpx 20rpx 22rpx 22rpx;
border-radius: 18rpx;
} }
.question-title{ .question-title{
@ -37,8 +47,8 @@
height: 120rpx; height: 120rpx;
margin: 18rpx 0 4rpx 18rpx; margin: 18rpx 0 4rpx 18rpx;
border: 1rpx solid lightgray; border: 1rpx solid lightgray;
border-radius: 8rpx; border-radius: 12rpx;
padding-left: 12rpx; padding: 12rpx 10rpx;
} }
view.null-input{ view.null-input{
@ -47,9 +57,9 @@ view.null-input{
input.null-input{ input.null-input{
border: 1rpx solid lightgray; border: 1rpx solid lightgray;
padding: 14rpx 5rpx; padding: 12rpx 6rpx;
margin-left: 8rpx; margin: 6rpx 10rpx;
border-radius: 6rpx; border-radius: 10rpx;
} }
.standard-choice{ .standard-choice{

@ -51,10 +51,29 @@ Page({
.then(); .then();
/**@todo */ /**@todo */
}, },
pull_courses: function(){ pull_exercise: function(){
app.client.search_exercises({ course_id: this.course_id }) 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)}) .then(res => {
.catch(console.error); 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 } }){ see_exercise: function ({ currentTarget: { dataset } }){
wx.navigateTo({ wx.navigateTo({
@ -79,7 +98,7 @@ Page({
this.course_id = options.id; this.course_id = options.id;
}, },
onShow: function(){ onShow: function(){
this.pull_courses(); this.pull_exercise();
}, },
switchNav(event) { switchNav(event) {
var cur = event.currentTarget.dataset.current; var cur = event.currentTarget.dataset.current;
@ -106,6 +125,9 @@ Page({
}); });
}, },
onPullDownRefresh: function(){ onPullDownRefresh: function(){
this.pull_courses(); this.pull_exercise();
},
onShareAppMessage:function(){
} }
}) })

@ -1,4 +1,5 @@
{ {
"usingComponents": {}, "usingComponents": {},
"enablePullDownRefresh": true "enablePullDownRefresh": true,
"navigationBarTitleText": "试卷列表"
} }

@ -44,8 +44,9 @@ text.start-answer{
} }
.exercise{ .exercise{
background: white; background: white;
padding: 17rpx 12rpx; padding: 17rpx 14rpx;
margin: 14rpx 0rpx; margin: 14rpx 0rpx;
border-radius: 12rpx;
} }
.exercise-info{ .exercise-info{
margin-top: 4rpx; margin-top: 4rpx;
@ -59,6 +60,7 @@ text.start-answer{
border-radius: 14rpx; border-radius: 14rpx;
padding: 4rpx 16rpx; padding: 4rpx 16rpx;
margin-left: 18rpx; margin-left: 18rpx;
text-align: center;
} }
view.no-content{ view.no-content{

@ -54,7 +54,6 @@ Page({
onLoad: function (options) { onLoad: function (options) {
this.course_id = options.id; this.course_id = options.id;
console.log(this.course_id); console.log(this.course_id);
this.pull_files();
}, },
/** /**
@ -68,7 +67,7 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
this.pull_files();
}, },
/** /**

@ -43,7 +43,8 @@ Page({
this.save_input(); this.save_input();
wx.navigateBack({ wx.navigateBack({
delta: 1 delta: 1
}) });
app.logining = false;
console.log("login_successful!!!!"); console.log("login_successful!!!!");
}, },
fail(error){ fail(error){
@ -86,7 +87,7 @@ Page({
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function () { onUnload: function () {
app.logining = false;
}, },
/** /**

@ -75,6 +75,10 @@ Page({
this.setData({ avatar_url: "https://www.educoder.net/images/" + app.client.current_user.image_url }) this.setData({ avatar_url: "https://www.educoder.net/images/" + app.client.current_user.image_url })
} }
}) })
},
onShareAppMessage: function(){
} }
// enter_usersetting: function(event){ // enter_usersetting: function(event){

Loading…
Cancel
Save