From 946a2e57a7d7c519a4eed0d3a7b22f3bfc0c1ce6 Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 16 May 2020 00:01:12 +0800 Subject: [PATCH] =?UTF-8?q?F=20=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E5=96=84=E6=97=B6=E5=8A=A0=E5=85=A5=E8=AF=BE?= =?UTF-8?q?=E5=A0=82bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 3 + cloudfunctions/cloudapi/index.js | 98 ++++++++++++++++++- cloudfunctions/login/index.js | 2 +- cloudfunctions/trigger/config.json | 5 + cloudfunctions/trigger/index.js | 56 +++++++++-- miniprogram/account/pages/profile/profile.js | 4 +- miniprogram/app.js | 6 +- .../modal/join-course/join-course.js | 91 ++++++++++++----- .../modal/join-course/join-course.wxml | 4 +- miniprogram/config.js | 2 +- miniprogram/course/pages/course/course.wxml | 2 +- .../pages/course_invite/course_invite.wxml | 2 +- .../pages/course_setting/course_setting.js | 3 + miniprogram/markdown/path/path/path.js | 8 +- miniprogram/markdown/path/path/path.wxml | 2 +- miniprogram/markdown/shixun/shixun/shixun.js | 14 +-- .../main/my_course/course-item/course-item.js | 12 +-- miniprogram/pages/main/my_course/my_course.js | 4 - .../pages/main/my_course/my_course.wxml | 2 +- project.config.json | 7 ++ 20 files changed, 261 insertions(+), 66 deletions(-) diff --git a/changelog.md b/changelog.md index 10bbf29..429ba91 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## v0.16.7 + * F 用户信息未完善时加入课堂bug + ## v0.16.6 * A 支持选用微信头像 * F 兼容Promise.finally diff --git a/cloudfunctions/cloudapi/index.js b/cloudfunctions/cloudapi/index.js index 0d4fa9f..cb2864b 100644 --- a/cloudfunctions/cloudapi/index.js +++ b/cloudfunctions/cloudapi/index.js @@ -1,10 +1,101 @@ const cloud = require('wx-server-sdk') +const sceneDescMap = { + [void 0]: "未知", + 1000: "其他", + 1001: "发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表)", + 1005: "微信首页顶部搜索框的搜索结果页", + 1006: "发现栏小程序主入口搜索框的搜索结果页", + 1007: "单人聊天会话中的小程序消息卡片", + 1008: "群聊会话中的小程序消息卡片", + 1011: "扫描二维码", + 1012: "长按图片识别二维码", + 1013: "扫描手机相册中选取的二维码", + 1014: "小程序模板消息", + 1017: "前往小程序体验版的入口页", + 1019: "微信钱包(微信客户端7.0.0版本改为支付入口)", + 1020: "公众号profile 页相关小程序列表(已废弃)", + 1022: "聊天顶部置顶小程序入口(微信客户端6.6.1版本起废弃)", + 1023: "安卓系统桌面图标", + 1024: "小程序profile页", + 1025: "扫描一维码", + 1026: "发现栏小程序主入口,「附近的小程序」列表", + 1027: "微信首页顶部搜索框搜索结果页「使用过的小程序」列表", + 1028: "我的卡包", + 1029: "小程序中的卡券详情页", + 1030: "自动化测试下打开小程序", + 1031: "长按图片识别一维码", + 1032: "扫描手机相册中选取的一维码", + 1034: "微信支付完成页", + 1035: "公众号自定义菜单", + 1036: "App分享消息卡片", + 1037: "小程序打开小程序", + 1038: "从另一个小程序返回", + 1039: "摇电视", + 1042: "添加好友搜索框的搜索结果页", + 1043: "公众号模板消息", + 1044: "带shareTicket的小程序消息卡片", + 1045: "朋友圈广告", + 1046: "朋友圈广告详情页", + 1047: "扫描小程序码", + 1048: "长按图片识别小程序码", + 1049: "扫描手机相册中选取的小程序码", + 1052: "卡券的适用门店列表", + 1053: "搜一搜的结果页", + 1054: "顶部搜索框小程序快捷入口(微信客户端版本6.7.4起废弃)", + 1056: "聊天顶部音乐播放器右上角菜单", + 1057: "钱包中的银行卡详情页", + 1058: "公众号文章", + 1059: "体验版小程序绑定邀请页", + 1064: "微信首页连Wi-Fi状态栏", + 1067: "公众号文章广告", + 1068: "附近小程序列表广告(已废弃)", + 1069: "移动应用", + 1071: "钱包中的银行卡列表页", + 1072: "二维码收款页面", + 1073: "客服消息列表下发的小程序消息卡片", + 1074: "公众号会话下发的小程序消息卡片", + 1077: "摇周边", + 1078: "微信连Wi-Fi成功提示页", + 1079: "微信游戏中心", + 1081: "客服消息下发的文字链", + 1082: "公众号会话下发的文字链", + 1084: "朋友圈广告原生页", + 1088: "会话中系统消息,打开小程序", + 1089: "微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏)", + 1090: "长按小程序右上角菜单唤出最近使用历史", + 1091: "公众号文章商品卡片", + 1092: "城市服务入口", + 1095: "小程序广告组件", + 1096: "聊天记录,打开小程序", + 1097: "微信支付签约原生页,打开小程序", + 1099: "页面内嵌插件", + 1102: "公众号profile 页服务预览", + 1103: "发现栏小程序主入口,「我的小程序」列表(基础库2.2.4版本起废弃)", + 1104: "微信聊天主界面下拉,「我的小程序」栏(基础库2.2.4版本起废弃)", + 1106: "聊天主界面下拉,从顶部搜索结果页,打开小程序", + 1107: "订阅消息,打开小程序", + 1113: "安卓手机负一屏,打开小程序(三星)", + 1114: "安卓手机侧边栏,打开小程序(三星)", + 1124: "扫“一物一码”打开小程序", + 1125: "长按图片识别“一物一码”", + 1126: "扫描手机相册中选取的“一物一码”", + 1129: "微信爬虫访问", + 1131: "浮窗打开小程序", + 1135: "小程序资料页打开小程序", + 1146: "地理位置信息打开出行类小程序", + 1148: "卡包-交通卡,打开小程序", + 1150: "扫一扫商品条码结果页打开小程序", + 1153: '“识物”结果页打开小程序' +} -cloud.init() +cloud.init({ + env: cloud.DYNAMIC_CURRENT_ENV +}); exports.main = async (event, context) => { let {name, data} = event; + console.log(event); const wxContext = cloud.getWXContext(); let db = cloud.database(); switch (name) { @@ -20,9 +111,12 @@ exports.main = async (event, context) => { } } case "reportPageHistory":{ - db.collection("pageHistory").add({ + console.log("reportPageHistory"); + return db.collection("pageHistory").add({ data:{ ...data, + isCrawl: data.scene==1129, + sceneDesc: sceneDescMap[data.scene], time: new Date(), timestamp: Date.now(), openid: wxContext.OPENID diff --git a/cloudfunctions/login/index.js b/cloudfunctions/login/index.js index 43f1594..c7bc018 100644 --- a/cloudfunctions/login/index.js +++ b/cloudfunctions/login/index.js @@ -7,7 +7,7 @@ cloud.init({ }) -exports.main = (event, context) => { +exports.main = async (event, context) => { diff --git a/cloudfunctions/trigger/config.json b/cloudfunctions/trigger/config.json index bcfb085..127b1bd 100644 --- a/cloudfunctions/trigger/config.json +++ b/cloudfunctions/trigger/config.json @@ -10,6 +10,11 @@ "name": "submitPages", "type": "timer", "config": "0 0 2 * * * *" + }, + { + "name": "clearPageHistory", + "type":"timer", + "config":"0 0 3 1 * * *" } ] } \ No newline at end of file diff --git a/cloudfunctions/trigger/index.js b/cloudfunctions/trigger/index.js index 75cd3e6..7c68329 100644 --- a/cloudfunctions/trigger/index.js +++ b/cloudfunctions/trigger/index.js @@ -1,17 +1,36 @@ +const cloud = require('wx-server-sdk'); +cloud.init({ + env: cloud.DYNAMIC_CURRENT_ENV +}) -const cloud = require('wx-server-sdk') +const config = { + submitPagesGapDay: 1, + clearPageHistoryGapDay: 30 +}; -cloud.init() +const milliSecondsPerDay = 24*60*60*1000; + +const collectionNameMap = { + pageHistory: "pageHistory" +} + +const PagePathMap = { + shixun:"markdown/shixun/shixun/shixun", + path:"markdown/path/path/path" +} exports.main = async (event, context) => { - const wxContext = cloud.getWXContext() + const wxContext = cloud.getWXContext(); console.log(event); let {TriggerName, Time} = event; switch(TriggerName){ case "submitPages":{ return submitPages({Time}); } + case "clearPageHistory":{ + return clearPageHistory({Time}); + } } } @@ -19,22 +38,24 @@ async function submitPages({Time}){ console.log("start submitPages"); const db = cloud.database(); const _ = db.command; - const pageHistoryCollection = db.collection("pageHistory"); + const pageHistoryCollection = db.collection(collectionNameMap.pageHistory); - let shixunPath = "markdown/shixun/shixun/shixun"; - let pathPath = "markdown/path/path/path"; + let shixunPath = PagePathMap.shixun; + let pathPath = PagePathMap.path; let timeEnd = new Date(Time); - let timeStart = new Date(timeEnd.getTime()-24*60*60*1000); + let timeStart = new Date(timeEnd.getTime() - config.submitPagesGapDay*milliSecondsPerDay); let shixunResult = await pageHistoryCollection.where({ page: shixunPath, status: 200, + isCrawl: false, time: _.lt(timeEnd).and(_.gte(timeStart)) }).get(); let pathResult = await pageHistoryCollection.where({ page: pathPath, - status:200, + status: 200, + isCrawl: false, time:_.lt(timeEnd).and(_.gte(timeStart)) }).get(); @@ -81,4 +102,23 @@ async function submitPages({Time}){ }else{ console.warn("no path history"); } + return {code:0, message:"success"}; +} + +async function clearPageHistory({Time}){ + console.log("clearPageHistory", Time); + + let now = new Date(Time); + let timeEnd = new Date(now.getTime() - config.clearPageHistoryGapDay*milliSecondsPerDay); + + const db = cloud.database(); + const _ = cloud.command; + const pageHistoryCollection = db.collection(collectionNameMap.pageHistory); + + let res = await pageHistoryCollection.where({ + time: _lt(timeEnd) + }).remove(); + + console.log("remove page History result: ", res); + return {code: 0, message:"success", data:res}; } \ No newline at end of file diff --git a/miniprogram/account/pages/profile/profile.js b/miniprogram/account/pages/profile/profile.js index c740882..39ba715 100644 --- a/miniprogram/account/pages/profile/profile.js +++ b/miniprogram/account/pages/profile/profile.js @@ -155,7 +155,7 @@ Page({ this.refresh(); }, onShow: function () { - if(this.secondShow){ + if(this.secondShow){ //更新头像 app.api("users.accounts")() .then(res=>{ let {avatar_url} = res; @@ -246,7 +246,7 @@ Page({ }else{ app.api("users.accounts", { method: "PUT" })(value) .then(res => { - app.syncUser({refresh:1}); + app.syncUser({refresh:1});//更新用户信息 res.message = "更新成功"; wx.hideLoading(); app.showMsg(res); diff --git a/miniprogram/app.js b/miniprogram/app.js index b7a6d7a..5d5c3f6 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -66,7 +66,7 @@ App({ let account = { ...res, ...global.accountManager.testAccount}; global.accountManager.setCurrentAccount(account); }); - /* 爬虫访问时运行没有用 + /* 爬虫访问时运行这些没有用 wx.reportMonitor('1', 1); global.realTimeLog.info("爬虫访问", options); global.realTimeLog.setFilterMsg("mpcrawl"); @@ -93,6 +93,8 @@ App({ } }) } + /** + * 系统升级提醒 this.api("users.system_update")().then(res => { if (res.system_update) { let { subject = "升级服务通知", system_score} = res; @@ -112,7 +114,7 @@ App({ }) } }).catch(e=>{}); - + */ }, onShow() { diff --git a/miniprogram/components/modal/join-course/join-course.js b/miniprogram/components/modal/join-course/join-course.js index 3de95f0..110bc0d 100644 --- a/miniprogram/components/modal/join-course/join-course.js +++ b/miniprogram/components/modal/join-course/join-course.js @@ -2,22 +2,10 @@ const app = getApp(); Component({ properties: { - hidden:{ + show:{ type:Boolean, - value: true, - observer:function(hidden){ - if(!hidden){ - wx.getClipboardData({ - success:res=>{ - if(!res.data||res.data==this.clipboardData) return; - this.clipboardData = res.data; - var match = res.data.match(/(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Z]{5,6}/); - if(match) - this.setData({invite_code: match[0]}); - } - }) - } - } + value: false, + observer: "onShowChange" }, show_code:{ type:Number, @@ -36,23 +24,75 @@ Component({ data: { identities:[], - hidden:true, + showDialog: false, buttons:[ {text:"取消"}, {text:"提交"} ] }, methods: { + onShowChange(value){ + if(value){ + if(!this.checkLogin()||!this.checkProfile()){ + value = false; + this.setData({show: false}); + } + wx.getClipboardData({ + success:res=>{ + if(!res.data||res.data==this.clipboardData) return; + this.clipboardData = res.data; + var match = res.data.match(/(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Z]{5,6}/); + if(match) + this.setData({invite_code: match[0]}); + } + }) + this.setData({showDialog: value}); + }else{ + this.setData({showDialog: value}); + } + }, + checkLogin(){ + if(app.user().user_id==2){ + wx.showModal({ + title:"提示", + content:"您需要登录后才能加入课堂", + confirmText:"现在登录", + success: res=>{ + if(res.confirm) + app.navigateTo({url:"{account}"}); + } + }) + return false; + } + return true; + }, + checkProfile(){ + if(app.user().profile_completed) + return true; + else{ + wx.showModal({ + title:"提示", + content:"您需要完善您的个人资料,才能加入课堂", + confirmText:"立即完善", + success:res=>{ + if(res.confirm){ + app.navigateTo({ + url:"{profile}" + }); + } + } + }) + return false; + } + }, scan(){ wx.scanCode({ success:res=>{ - ; var fail = false; if(res.scanType=="QR_CODE") this.setData({invite_code: res.result}); else if(res.scanType=="WX_CODE"&&res.path){ var match = res.path.match(/course_invite\?(.*)$/) - ; if(match){ var options = {} match[1].split("&").map(i=>{ @@ -60,7 +100,6 @@ Component({ var k = i.slice(0, index); var v = i.slice(index + 1); options[k]=v}) - ; if(options.scene){ var scene = {}; for (var i of decodeURIComponent(options.scene).split("&")) { @@ -69,12 +108,10 @@ Component({ var v = i.slice(index+1); scene[k] = v; } - ; if(scene.course_id){ var {course_id} = scene; app.api("weapps.courses.basic_info")({ course_id }) .then(({ course:{invite_code=""}}) => { - ; this.setData({invite_code}); }).catch(app.showError); }else @@ -93,7 +130,7 @@ Component({ }) }, onCancel() { - this.setData({ hidden: true,invite_code:'', professor:"", student:"", assistant_professor:"" }); + this.setData({ show: false, invite_code:'', professor:"", student:"", assistant_professor:"" }); }, onTapButton({detail:{index}}){ if(index==0) @@ -129,8 +166,14 @@ Component({ this.onCancel(); }) .catch(e=>{ - e.message =e.message||'未知错误'; - app.showError(e); + if(e.code==402){ //一般是信息没完善 + if(this.checkProfile()){ //信息已完善还是出错 + wx.showToast({ title: '发生未知错误',icon:"none"}) + global.realTimeLog.error("join course", e); + } + } + else + app.showError(e); }) } } diff --git a/miniprogram/components/modal/join-course/join-course.wxml b/miniprogram/components/modal/join-course/join-course.wxml index 1d6c4af..090e95a 100644 --- a/miniprogram/components/modal/join-course/join-course.wxml +++ b/miniprogram/components/modal/join-course/join-course.wxml @@ -1,5 +1,5 @@ - - + + diff --git a/miniprogram/config.js b/miniprogram/config.js index 9a93971..8105eff 100644 --- a/miniprogram/config.js +++ b/miniprogram/config.js @@ -1,6 +1,6 @@ const cloudDir = "cloud://educoder.6564-educoder-1300855313/"; -let _version = "0.16.6"; +let _version = "0.16.7"; /** */ let { miniProgram:{ envVersion="release", version=_version}={}} = wx.getAccountInfoSync(); diff --git a/miniprogram/course/pages/course/course.wxml b/miniprogram/course/pages/course/course.wxml index b9403b4..21a3f3e 100644 --- a/miniprogram/course/pages/course/course.wxml +++ b/miniprogram/course/pages/course/course.wxml @@ -62,7 +62,7 @@ -