修补了页面分享的bug

smart_class
educoder_weapp 5 years ago
parent 7bbbe466c9
commit 98dc49ab77

@ -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();
}
});

@ -2,6 +2,7 @@
"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": {

@ -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);
}

@ -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
})

@ -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<questions.length;i++){
if (questions[i]["question_type"]==3){
@ -30,9 +39,16 @@ Page({
console.log(questions);
}
}
this.setData({ exercise_questions: questions});
this.setData({ exercise_questions: questions, loading: false});
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 } }){
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});
},
/**

@ -4,7 +4,7 @@
<view class="question">
<text class="hint">第{{question.q_position}}题</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 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>
@ -14,20 +14,21 @@
</view>
<view wx:elif="{{question.question_type==1}}">
<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 wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text>
</checkbox>
</checkbox-group>
</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 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 wx:if="{{choice.standard_boolean}}" class="error standard-choice">正确答案</text>
</radio>
</radio-group>
</view>
</view-->
<view wx:elif="{{question.question_type==3}}">
<block wx:for="{{question.null_inputs}}" wx:for-item="null_input">
<view class="null-input flex-wrap">
@ -44,7 +45,7 @@
<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">
<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>
@ -67,7 +68,7 @@
</block>
</view>
</view>
<cover-view wx:if="{{exercise.user_exercise_status!=1 && exercise.user_exercise_status!=4}}" class="foot flex-wrap" >
<button bindtap="save_exercise">保存</button>
<button bindtap="commit_exercise">交卷</button>
<cover-view wx:if="{{exercise.user_exercise_status!=1 && exercise.user_exercise_status!=4}}" hidden="{{loading}}" class="foot flex-wrap" >
<button class="save operation" catchtap="save_exercise">保存</button>
<button class="commit operation" catchtap="commit_exercise">交卷</button>
</cover-view>

@ -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{

@ -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(){
}
})

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

@ -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{

@ -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();
},
/**

@ -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;
},
/**

@ -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){

Loading…
Cancel
Save