From ecc2a42f691d0058d74e77ae0cd687ca65da62ea Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sun, 17 Nov 2019 08:05:16 +0800 Subject: [PATCH] fix a bug --- README.md | 2 +- app.js | 12 ++++++------ data/eduapi.js | 12 ++++++++++-- data/requests.js | 2 -- lib/live-query-binding.js | 2 ++ pages/about/about.js | 2 +- pages/classroom/classroom.js | 12 ++++++------ pages/classroom/classroom.wxml | 4 ++-- pages/course_invite/course_invite.js | 3 +-- pages/course_invite/course_invite.wxml | 4 ++-- pages/exercise/exercise.wxml | 8 -------- pages/exercise_result/exercise_result.js | 1 - pages/findmore/findmore.wxss | 2 +- pages/login/login.js | 21 ++++++++++++++++++++- pages/login/login.wxml | 11 +++++++++-- 15 files changed, 61 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index b27212c..f135a8e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ educoder微信小程序,帮助使用[educoder平台](https://www.educoder.net) [https://github/jinke18/smart_class](https://github.com/jinke18/smart_class) ## 小程序码 -![小程序码](/images/weapp_code.png) +![小程序码](/images/weapp_code_smart_class.png) # 功能介绍 diff --git a/app.js b/app.js index eba7a07..fa60ed7 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,6 @@ const AV = require('./lib/av-live-query-weapp-min'); const Towxml = require('/towxml/main'); const login = require("./model/user"); -//初始化 AV.init({ appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI', appKey: 'waM3bwf1ftpsMLjRBqqVyJIQ', @@ -53,11 +52,12 @@ App({ console.warn("app.js: get user info fail"); } }).then(()=>{ - login().then(user=>{ - user.addUnique("edu_account_real_names", this.client.current_user.real_name); - user.addUnique("edu_account_names", this.client.current_user.name); - user.addUnique("edu_account_logins", this.client.current_user.login); - user.save(); + login().then(localuser=>{ + //save for autologin + localuser.addUnique("edu_account_real_names", this.client.current_user.real_name); + localuser.addUnique("edu_account_names", this.client.current_user.name); + localuser.addUnique("edu_account_logins", this.client.current_user.login); + localuser.set("cookies", this.client.session.cookies).save(); }); }); } diff --git a/data/eduapi.js b/data/eduapi.js index 428e71f..5442540 100644 --- a/data/eduapi.js +++ b/data/eduapi.js @@ -228,13 +228,21 @@ export class Course{ method:"POST", data: data, success: res=>{ - if("status" in res.data && res.data.status<0){ - fail(new Error(res.data.message)); + if ("status" in res.data) { + switch(res.data.status) { + case 402: + fail(new Error(res.data.message || "请完善个人信息后重试")); return; + default: + if (res.data.status < 0) { + fail(new Error(res.data.message)); + return; + } } if(typeof success == "function"){ success(res); } + } }, fail: fail, complete: complete diff --git a/data/requests.js b/data/requests.js index 6c3e5a7..1fcc2e2 100644 --- a/data/requests.js +++ b/data/requests.js @@ -11,7 +11,6 @@ import {Cookie} from "./cookie"; export class Session { cookies = {} constructor(){ - } set_cookie(cookie){ this.cookies[cookie.key] = cookie; @@ -23,7 +22,6 @@ export class Session { request({url, data, header, method, dataType, responseType, success, fail, complete}) { console.log("request data and headers: "); console.log({url: url, data: data, header: {...header, "Cookie": this.cookie_str}, method: method, dataType: dataType, responseType: responseType}) - return wx.request({ url: url, data: data, diff --git a/lib/live-query-binding.js b/lib/live-query-binding.js index 2dba462..7a1c46b 100644 --- a/lib/live-query-binding.js +++ b/lib/live-query-binding.js @@ -2,10 +2,12 @@ module.exports = (subscription, initialStats, onChange) => { console.log("query_bingding"); let stats = [...initialStats] const remove = value => { + console.log("remove"); stats = stats.filter(target => target.id !== value.id) return onChange(stats) } const upsert = value => { + console.log("upsert"); let existed = false; stats = stats.map(target => (target.id === value.id ? ((existed = true), value) : target)) if (!existed) stats = [...stats,value] diff --git a/pages/about/about.js b/pages/about/about.js index 4bbfd63..7d8d5f0 100644 --- a/pages/about/about.js +++ b/pages/about/about.js @@ -6,7 +6,7 @@ Page({ /** * 页面的初始数据 */ - md: '# 简介\neducoder微信小程序,帮助使用[educoder平台](https://www.educoder.net)的应用,方便在手机上使用。利用educoder网站的API搭建\n\n## 源码\n[https://github/jinke18/smart_class](https://github.com/jinke18/smart_class)\n\n## 小程序码\n![小程序码](/images/weapp_code.png)\n\n# 功能介绍\n\n## 教室\n- 学员可以输入邀请码进入课堂\n\n- 进入教室界面会显示在位,头像为彩色,若退出课堂界面则会显示灰色头像\n\n- 教员在教室界面中可以直观地看到学员在位情况,可以选择学员让其起立回答问题,并且对学员可以进行加分、减分操作\n\n- 在分数列表中可以看到加减分记录(数据在后台可以导出)\n\n- 学员可以收到教员让其起立提问、回答的提示,还可以点击“我要提问、回答”\n\n- 教室内有讨论区,可以交流\n\n## 课程资源\n\n- 在课程界面进入“资源”可以查看本课堂的课程文件资源\n\n- 支持打开ppt doc xls pdf文件\n\n## 试卷作答\n\n- 学员在课程内可以看到老师发布的试卷,并且回答\n\n- 试卷截止后并且老师选择了公开答案,学生可以看到公布的答案\n\n- 老师可以创建试卷,发布试卷,查看学员作答分数(developing)\n\n## 其他\n账号的注册、登陆、找回密码、头像更改等\n\n# 实现\n## educoder平台接入\n使用HTTP与平台的api接口交互\n\n接口列表如下\n- 搜索课堂https://www.educoder.net/api/courses.json\n\n- 查询用户的课堂https://www.educoder.net/api/users//courses.json\n\n- 查询学校https://www.educoder.net/api/schools/school_list.json\n\n- 新建课堂https://www.educoder.net/api/courses.json\n\n- 加入课堂https://www.educoder.net/api/courses/apply_to_join_course.json\n\n- 新建试卷https://www.educoder.net/api/courses//exercises/new.json\n\n- 查询试卷https://www.educoder.net/api/courses//exercises.json\n\n- 班级文件资源https://www.educoder.net/api/files.json\n\n# 教室学员在位情况及分数的同步实现\n使用了[leancloud](https://www.leancloud.cn/)提供的javascript开发包实现数据同步功能, 如学员在位情况、分数的同步, 其底部技术为websocket' + md: '# 简介\n## 源码\n[https://github/jinke18/smart_class](https://github.com/jinke18/smart_class)\n\n## 小程序码\n![小程序码](/images/weapp_code_smart_class.jpg)\n\n# 功能介绍\n\n## 教室\n- 学员可以输入邀请码进入课堂\n\n- 进入教室界面会显示在位,头像为彩色,若退出课堂界面则会显示灰色头像\n\n- 教员在教室界面中可以直观地看到学员在位情况,可以选择学员让其起立回答问题,并且对学员可以进行加分、减分操作\n\n- 在分数列表中可以看到加减分记录(数据在后台可以导出)\n\n- 学员可以收到教员让其起立提问、回答的提示,还可以点击“我要提问、回答”\n\n- 教室内有讨论区,可以交流\n\n## 课程资源\n\n- 在课程界面进入“资源”可以查看本课堂的课程文件资源\n\n- 支持打开ppt doc xls pdf文件\n\n## 试卷作答\n\n- 学员在课程内可以看到老师发布的试卷,并且回答\n\n- 试卷截止后并且老师选择了公开答案,学生可以看到公布的答案\n\n- 老师可以创建试卷,发布试卷,查看学员作答分数\n\n## 其他\n账号的注册、登陆、找回密码、头像更改等\n\n# 实现\n## educoder平台接入\n使用HTTP与平台的api接口交互\n\n接口列表如下\n- 搜索课堂https://www.educoder.net/api/courses.json\n\n- 查询用户的课堂https://www.educoder.net/api/users//courses.json\n\n- 查询学校https://www.educoder.net/api/schools/school_list.json\n\n- 新建课堂https://www.educoder.net/api/courses.json\n\n- 加入课堂https://www.educoder.net/api/courses/apply_to_join_course.json\n\n- 新建试卷https://www.educoder.net/api/courses//exercises/new.json\n\n- 查询试卷https://www.educoder.net/api/courses//exercises.json\n\n- 班级文件资源https://www.educoder.net/api/files.json\n\n# 教室学员在位情况及分数的同步实现\n使用了[leancloud](https://www.leancloud.cn/)提供的javascript开发包实现数据同步功能, 如学员在位情况、分数的同步, 其底部技术为websocket' , data: { diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index 75ec089..8eab97d 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -18,7 +18,7 @@ Page({ select_stu_login:"", message_text: "", messages: [], - show_conversation: true + show_conversation: false }, enter_mark_detail({currentTarget:{dataset}}){ wx.navigateTo({ @@ -67,6 +67,7 @@ Page({ console.log("close conversation"); console.log(event); this.setData({show_conversation: false}); + console.log(this.data); this.messageSubscription.unsubscribe(); this.messageUnbind(); }, @@ -233,8 +234,7 @@ Page({ }) }); }); - - this.pull_messages(); + //this.pull_messages(); }, /** @@ -271,8 +271,8 @@ Page({ console.log("onUnload"); this.presenceSubscription.unsubscribe(); this.presenceUnbind(); - this.messageSubscription.unsubscribe(); - this.messageUnbind(); + //this.messageSubscription.unsubscribe(); + //this.messageUnbind(); }, /** @@ -303,7 +303,7 @@ Page({ }) }); }); - this.pull_messages(); + //this.pull_messages(); }, /** diff --git a/pages/classroom/classroom.wxml b/pages/classroom/classroom.wxml index 2ec72bb..882e569 100644 --- a/pages/classroom/classroom.wxml +++ b/pages/classroom/classroom.wxml @@ -1,8 +1,8 @@ - - + + {{message.sender_name}}:{{message.text}} diff --git a/pages/course_invite/course_invite.js b/pages/course_invite/course_invite.js index b77baea..1fb5c2a 100644 --- a/pages/course_invite/course_invite.js +++ b/pages/course_invite/course_invite.js @@ -31,7 +31,7 @@ Page({ wx.showToast({ title: res.data.message }) - wx.navigateTo({ + wx.redirectTo({ url: "../course/course?course_id=" + res.data.course_id }); }) @@ -42,7 +42,6 @@ Page({ }); console.warn(error); }) - }, /** diff --git a/pages/course_invite/course_invite.wxml b/pages/course_invite/course_invite.wxml index d4b8c42..1d4462a 100644 --- a/pages/course_invite/course_invite.wxml +++ b/pages/course_invite/course_invite.wxml @@ -6,8 +6,8 @@ {{course_name}}\n - - 该邀请链接已失效 + 该邀请链接已失效 diff --git a/pages/exercise/exercise.wxml b/pages/exercise/exercise.wxml index 1e4f6e4..4d035b0 100644 --- a/pages/exercise/exercise.wxml +++ b/pages/exercise/exercise.wxml @@ -28,14 +28,6 @@ - diff --git a/pages/exercise_result/exercise_result.js b/pages/exercise_result/exercise_result.js index 7b6fcd1..02db148 100644 --- a/pages/exercise_result/exercise_result.js +++ b/pages/exercise_result/exercise_result.js @@ -16,7 +16,6 @@ Page({ */ onLoad: function (options) { this.exercise_id = options.exercise_id; - this.exercise_id = 2996; }, /** diff --git a/pages/findmore/findmore.wxss b/pages/findmore/findmore.wxss index db61ecd..6447a72 100644 --- a/pages/findmore/findmore.wxss +++ b/pages/findmore/findmore.wxss @@ -65,4 +65,4 @@ text.name{ text-align:center; padding: 12px 0; } -/**动画*/ + diff --git a/pages/login/login.js b/pages/login/login.js index ee6000a..296cb2c 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -1,4 +1,6 @@ // pages/login/login.js +const AV = require('../../lib/av-live-query-weapp-min'); +const {jsonify} = require('../../utils/leancloudutils'); const app = getApp(); Page({ @@ -63,6 +65,23 @@ Page({ } }) }, + login_test_account({currentTarget:{dataset}}){ + console.log(dataset); + const {login, password} = dataset; + this.setData({login,password}); + this.login(); + }, + pull_test: function(){ + let query = new AV.Query("MetaData"); + query.find().then(metadatas=>{ + this.setData({metadata: metadatas[0].toJSON()}) + }); + let test_query = new AV.Query("TestAccount") + test_query.find() + .then(accounts=>{ + this.setData(jsonify({accounts})); + }) + }, /** * 生命周期函数--监听页面加载 */ @@ -91,7 +110,7 @@ Page({ * 生命周期函数--监听页面显示 */ onShow: function () { - + this.pull_test(); }, /** diff --git a/pages/login/login.wxml b/pages/login/login.wxml index 9599937..3f70fc6 100644 --- a/pages/login/login.wxml +++ b/pages/login/login.wxml @@ -26,6 +26,13 @@ - 注册 - 忘记密码 + + 注册 + 忘记密码 + + + + + +