A 支持选取微信头像

master
educoder_weapp 5 years ago
parent 9d1cbbeee4
commit 26ddc8d992

@ -1,3 +1,11 @@
## v0.16.5
* A 头像安全检查
* U 信息安全检查速度
## v0.16.4
* A 试卷答题时网络不好情况处理
* A 课堂界面兼容iphone X
## v0.16.3 ## v0.16.3
* U 优化项目结构,主包压缩一半 * U 优化项目结构,主包压缩一半

@ -0,0 +1,6 @@
{
"permissions": {
"openapi": [
]
}
}

@ -0,0 +1,18 @@
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
let {name, data} = event;
const wxContext = cloud.getWXContext()
switch (name) {
case 'getOpenData': {
return cloud.getOpenData(data);
}
default: {
return
}
}
}

@ -0,0 +1,14 @@
{
"name": "cloudapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~2.0.2"
}
}

@ -14,8 +14,6 @@ exports.main = (event, context) => {
const wxContext = cloud.getWXContext() const wxContext = cloud.getWXContext()
return { return {
event,
context,
openid: wxContext.OPENID, openid: wxContext.OPENID,
appid: wxContext.APPID, appid: wxContext.APPID,
unionid: wxContext.UNIONID, unionid: wxContext.UNIONID,

@ -4,7 +4,9 @@
"wxacode.get", "wxacode.get",
"wxacode.getUnlimited", "wxacode.getUnlimited",
"security.msgSecCheck", "security.msgSecCheck",
"security.imgSecCheck" "security.imgSecCheck",
"search.siteSearch",
"search.submitPages"
] ]
} }
} }

@ -49,7 +49,10 @@ exports.main = async (event, context) => {
} }
} }
case 'getOpenData': { case 'getOpenData': {
return getOpenData(event) return cloud.getOpenData(data);
}
case "search.siteSearch":{
return cloud.openapi.search.siteSearch(data);
} }
default: { default: {
return return
@ -87,8 +90,3 @@ async function getWXACode(data) {
}); });
} }
async function getOpenData(event) {
return cloud.getOpenData({
list: event.openData.list,
})
}

@ -1,6 +1,7 @@
const app = getApp(); const app = getApp();
import {throttle} from "../../../../js/utils"; import {throttle} from "../../../../js/utils";
const risk_message = "检测到内容含有敏感词汇"; const risk_message = "检测到内容含有敏感词汇";
function msgSecCheck({name="", remarks=""}){ function msgSecCheck({name="", remarks=""}){
let content = name+","+ remarks; let content = name+","+ remarks;
console.log("msgsecCheck", content); console.log("msgsecCheck", content);
@ -11,7 +12,7 @@ function msgSecCheck({name="", remarks=""}){
this.tmp_promise.then(res=>{ this.tmp_promise.then(res=>{
if(res.errCode==87014){ if(res.errCode==87014){
wx.showToast({ wx.showToast({
title: risk_message,icon:"none",duration:4000 title: risk_message,icon:"none",duration:2600
}) })
} }
}) })

@ -13,7 +13,7 @@ function msgSecCheck({name, nickname}){
this.tmp_promise.then(res=>{ this.tmp_promise.then(res=>{
if(res.errCode==87014){ if(res.errCode==87014){
wx.showToast({ wx.showToast({
title: risk_message,icon:"none",duration:4000 title: risk_message,icon:"none",duration:2600
}) })
} }
}) })
@ -52,6 +52,9 @@ Page({
this.setData({name: value}); this.setData({name: value});
this.throttledMsgSecCheck(this.data); this.throttledMsgSecCheck(this.data);
}, },
onGetUserInfo(e){
console.log(e);
},
setInfo(res){ setInfo(res){
let locations = Object.keys(locationData); let locations = Object.keys(locationData);
let location_index = locations.indexOf(res.location); let location_index = locations.indexOf(res.location);
@ -230,9 +233,13 @@ Page({
}, },
saveInfo(value){ saveInfo(value){
wx.showLoading({
title: '提交中'
});
value.gender = parseInt(value.gender); value.gender = parseInt(value.gender);
this.msgSecCheck(value).then(res=>{ this.msgSecCheck(value).then(res=>{
if(res.errCode==87014){ if(res.errCode==87014){
wx.hideLoading();
wx.showModal({ wx.showModal({
content: risk_message,showCancel:false content: risk_message,showCancel:false
}) })
@ -241,6 +248,7 @@ Page({
.then(res => { .then(res => {
app.syncUser({refresh:1}); app.syncUser({refresh:1});
res.message = "更新成功"; res.message = "更新成功";
wx.hideLoading();
app.showMsg(res); app.showMsg(res);
setTimeout(() => { setTimeout(() => {
wx.navigateBack({ wx.navigateBack({
@ -248,10 +256,12 @@ Page({
}) })
}, 420); }, 420);
}).catch(e => { }).catch(e => {
wx.hideLoading();
this.showError(e); this.showError(e);
}) })
} }
}).catch(e=>{ }).catch(e=>{
wx.hideLoading();
wx.showToast({ wx.showToast({
title: '出错了\n︿',icon:"none" title: '出错了\n︿',icon:"none"
}); });
@ -260,7 +270,6 @@ Page({
}, },
onTap(e){ onTap(e){
;
let { target: { id } } = e; let { target: { id } } = e;
if (id) { if (id) {
if ((id == 'name' || id == "gender") && this.data.authen) if ((id == 'name' || id == "gender") && this.data.authen)

@ -67,4 +67,5 @@
<text>*我们确保您所提供的信息均处于严格保密状态,不会泄露</text> <text>*我们确保您所提供的信息均处于严格保密状态,不会泄露</text>
</view> </view>
</view> </view>
<button wx:if="{{false}}" open-type="getUserInfo" bindgetuserinfo="onGetUserInfo" lang="zh_CN" type="secondary">使用微信信息</button>
<add-department bindsuccess="refreshDepartments" school_id="{{school_id}}" school_name="{{school_name}}" show="{{showAddDepartment}}"/> <add-department bindsuccess="refreshDepartments" school_id="{{school_id}}" school_name="{{school_name}}" show="{{showAddDepartment}}"/>

@ -9,18 +9,31 @@ wx.cloud.init({
App({ App({
globalData: { globalData: {
versionCode: config.versionCode, versionCode: config.versionCode,
debug: config.debug debug: config.debug,
openid:wx.getStorageSync('openid')
}, },
client, client,
openapi(name){ openapi(name){
return ({success, fail, complete, ...data})=>{ return ({success, fail, complete, ...data}={})=>{
return this.callOpenapi({name, data, success,fail, complete}); return this.callOpenapi({name, data, success,fail, complete});
} }
}, },
cloudapi(name){
return ({success, fail, complete, ...data})=>{
return this.callCloudfunction({
name:"cloudapi", data:{name, data}, success, fail, complete
});
}
},
callOpenapi({name, data, success, fail, complete}){ callOpenapi({name, data, success, fail, complete}){
return this.callCloudapi({name:"openapi", data:{name, data}, success, fail, complete}); return this.callCloudfunction({name:"openapi", data:{name, data}, success, fail, complete});
},
cloudfunction(name){
return ({success, fail, complete, ...data}={})=>{
return this.callCloudfunction({name, data, success, fail, complete});
}
}, },
callCloudapi({name, data, success, fail, complete}){ callCloudfunction({name, data, success, fail, complete}){
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
return wx.cloud.callFunction({name, data, return wx.cloud.callFunction({name, data,
success:res=>{ success:res=>{
@ -42,15 +55,15 @@ App({
syncUser(options) { return client.syncUser(options) }, syncUser(options) { return client.syncUser(options) },
updateUserInfo(info){return client.updateUserInfo(info)}, updateUserInfo(info){return client.updateUserInfo(info)},
onLaunch: function (options) { onLaunch: function (options) {
if(options.scene==1129){ if(options.scene==1129||options["user-agent"]=="mpcrawler"){
this.api("accounts.login")(global.accountManager.testAccount) this.api("accounts.login")(global.accountManager.testAccount)
.then(res=>{ .then(res=>{
let account = { ...res, ...global.accountManager.testAccount}; let account = { ...res, ...global.accountManager.testAccount};
global.accountManager.setCurrentAccount(account); global.accountManager.setCurrentAccount(account);
}); });
wx.reportMonitor('1', 1); wx.reportMonitor('1', 1);
global.realTimeLog.info("爬虫访问"); global.realTimeLog.info("爬虫访问", options);
global.realTimeLog.setFilterMsg("wxcrawl"); global.realTimeLog.setFilterMsg("mpcrawl");
} }
if (options.referrerInfo && options.referrerInfo.appId) { if (options.referrerInfo && options.referrerInfo.appId) {
var db = wx.cloud.database(); var db = wx.cloud.database();
@ -83,6 +96,16 @@ App({
}) })
} }
}).catch(e=>{}); }).catch(e=>{});
if(!this.globalData.openid){
this.cloudfunction("login")()
.then(res=>{
this.globalData.openid = res.openid;
wx.setStorage({
data: res.openid,
key: 'openid',
})
})
}
}, },
onShow() { onShow() {
@ -156,3 +179,4 @@ function toAbsPath(current, path) {
return path; return path;
} }
*/ */

@ -106,10 +106,8 @@ Component({
}, },
update_identities: function ({ detail: { value } }) { update_identities: function ({ detail: { value } }) {
var data = {assistant_professor:"", professor:"",student:""} var data = {assistant_professor:"", professor:"",student:""}
;
for(var identity of value) for(var identity of value)
data[identity] = 1 data[identity] = 1
;
this.setData(data) this.setData(data)
}, },
join_course () { join_course () {
@ -130,8 +128,10 @@ Component({
this.triggerEvent("success"); this.triggerEvent("success");
this.onCancel(); this.onCancel();
}) })
.catch(app.showError) .catch(e=>{
e.message =e.message||'未知错误';
app.showError(e);
})
} }
} }
}) })

@ -16,7 +16,7 @@ Component({
} }
}, },
attached(){ attached(){
this.refresh().finally(()=>{ this.refresh().then(()=>{
this.loaded = true; this.loaded = true;
}) })
}, },

@ -5,11 +5,9 @@ const developUrl = "https://test-newweb.educoder.net";
const trialUrl = "https://pre-newweb.educoder.net"; const trialUrl = "https://pre-newweb.educoder.net";
const releaseUrl = "https://www.educoder.net"; const releaseUrl = "https://www.educoder.net";
let _version = "0.16.4"; let _version = "0.16.5";
var eduUrl = releaseUrl; var eduUrl = releaseUrl;
/** /**
* A 试卷答题时网络不好情况处理
* A 课堂界面兼容iphone X
*/ */
export function switchEnv(env) { export function switchEnv(env) {

@ -26,10 +26,8 @@ Component({
methods: { methods: {
onChoose(e){ onChoose(e){
;
}, },
onChange(e){ onChange(e){
;
let {detail:{value}} = e; let {detail:{value}} = e;
this.sort_type = value?'id':''; this.sort_type = value?'id':'';
this.refresh(); this.refresh();
@ -39,7 +37,6 @@ Component({
let {sort_type=''} = this; let {sort_type=''} = this;
if(sort_type!='id') if(sort_type!='id')
app.api("weapps.courses.students")({course_id, limit:1000}).then(res=>{ app.api("weapps.courses.students")({course_id, limit:1000}).then(res=>{
;
var {students,students_count} = res; var {students,students_count} = res;
this.setData({students,students_count}); this.setData({students,students_count});
if(!this.imageMap) if(!this.imageMap)
@ -53,17 +50,19 @@ Component({
else else
app.api("courses.students")({course_id, limit:10000}) app.api("courses.students")({course_id, limit:10000})
.then(res=>{ .then(res=>{
;
var students; var students;
if(this.imageMap) if(this.imageMap)
students = res.students.map(i=>{ students = res.students.map(i=>{
i.image_url = this.imageMap.get(i.user_id); i.image_url = this.imageMap.get(i.user_id);
return i; return i;
}) })
if(res.students.length>0)
students = [{letter:"#", items:res.students}]; students = [{letter:"#", items:res.students}];
else
students = [];
var {students_count} = res; var {students_count} = res;
this.setData({ students, students_count}); this.setData({ students, students_count});
}) });
let ext = {course_id, course_identity}; let ext = {course_id, course_identity};
this.setData({ext}); this.setData({ext});
} }

@ -7,7 +7,7 @@
<view class="switch-wrp"> <view class="switch-wrp">
<switch color="#00b0f0" bindchange="onChange">按学号排序</switch> <switch color="#00b0f0" bindchange="onChange">按学号排序</switch>
</view> </view>
<navigator wx:if="{{course_identity&&course_identity<5}}" class='invite' hover-class="none" url="/course/pages/course_invite/course_invite?course_id={{course_id}}"><button class="invite-button" size="mini" type="main">邀请学生</button></navigator> <navigator wx:if="{{course_identity&&course_identity<5}}" class='invite' hover-class="none" url="/course/pages/course_invite/course_invite?course_id={{course_id}}"><button class="invite-button" size="mini" type="secondary">邀请学生</button></navigator>
</view> </view>
</mp-index-list> </mp-index-list>

@ -4,8 +4,8 @@
<text>教师人数:</text> <text>教师人数:</text>
<text class="count">{{teacher_list_size}}</text> <text class="count">{{teacher_list_size}}</text>
</view> </view>
<navigator hover-class="none" url="/course/pages/teacher_apply/teacher_apply?course_id={{course_id}}" wx:if="{{course_identity&&course_identity<=2}}"> <navigator hover-class="none" url="/course/pages/teacher_apply/teacher_apply?course_id={{course_id}}" wx:if="{{course_identity&&course_identity<=2&&apply_size>0}}">
<mp-badge wx:if="{{apply_size>0}}"/> <mp-badge />
<text class="apply-text">待审批({{apply_size}})</text> <text class="apply-text">待审批({{apply_size}})</text>
</navigator> </navigator>
</view> </view>

@ -37,6 +37,7 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
line-height: 22px;
} }
.tips{ .tips{
display: flex; display: flex;

@ -176,10 +176,14 @@ Page({
attendance({ show = 1 }) { attendance({ show = 1 }) {
app.api("users.attendance")() app.api("users.attendance")()
.then(res => { .then(res => {
this.refresh();
res.message = "签到成功"; res.message = "签到成功";
if (show) if (show)
app.showMsg(res); app.showMsg(res);
}).catch(e=>{
if(show)
app.showError(e);
}).finally(()=>{
this.refresh();
}) })
}, },
enterUserinfo(){ enterUserinfo(){

@ -4,7 +4,7 @@
"add-tips": "/components/add-tips/add-tips", "add-tips": "/components/add-tips/add-tips",
"my-course":"./my_course/my_course", "my-course":"./my_course/my_course",
"my-shixun":"./my_shixun/my_shixun", "my-shixun":"./my_shixun/my_shixun",
"my-path":"../my_path/my_path" "my-path":"./my_path/my_path"
}, },
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",
"navigationBarTitleText": "我的", "navigationBarTitleText": "我的",

@ -64,7 +64,7 @@ Component({
addCourse() { addCourse() {
if(app.user().user_id==2) if(app.user().user_id==2)
return wx.showToast({ return wx.showToast({
title: '请先登录' title: '请先登录',icon:"none"
}); });
return this.setData({ showModal: 1 }); return this.setData({ showModal: 1 });
/* /*

@ -14,7 +14,7 @@
</form> </form>
<nav-bar list="{{list}}" current="{{current}}" bindchange="onTapNav"/> <nav-bar list="{{list}}" current="{{current}}" bindchange="onTapNav"/>
<scroll-view class="body" scroll-y="1" lower-threshold="160" bindscrolltolower="_onReachBottom" scroll-top="{{scrollTop}}"> <scroll-view class="body" scroll-y="1" lower-threshold="160" bindscrolltolower="_onReachBottom" scroll-top="{{scrollTop}}">
<view wx:for="{{results}}" class="search-item-wrap"> <view wx:for="{{results}}" class="search-item-wrap" wx:key="id">
<search-item data="{{item}}"/> <search-item data="{{item}}"/>
</view> </view>
</scroll-view> </scroll-view>

@ -8,21 +8,34 @@ Page({
}, },
touchStart(e) { touchStart(e) {
if(!this.mycropper)
return wx.showToast({
title: '请先选取图片',icon:"none"
})
this.mycropper.touchStart(e) this.mycropper.touchStart(e)
}, },
touchMove(e) { touchMove(e) {
this.mycropper.touchMove(e) this.mycropper.touchMove(e)
}, },
touchEnd(e) { touchEnd(e) {
this.mycropper.touchEnd(e) this.mycropper.touchEnd(e)
}, },
onGetUserInfo(e){
console.log(e);
let {detail:{userInfo}} = e;
if(userInfo.avatarUrl){
let path = userInfo.avatarUrl;
this.mycropper.pushOrign(path);
}else{
wx.showToast({
title: '微信头像获取失败',icon:"none"
})
}
},
async _checkImg({path}){ async _checkImg({path}){
let cloudPath = "images/avatars/"+ path.replace(/[\/\\:]/g, "_"); let match = path.match(/(\.[^\.]*?)$/)
if(match)
var ext = match[0];
else
var ext = ".jpg";
let cloudPath = "images/temp/"+ app.globalData.openid + "-" + Date.now() + ext;
let res = await wx.cloud.uploadFile({ let res = await wx.cloud.uploadFile({
cloudPath, cloudPath,
filePath: path filePath: path
@ -33,7 +46,6 @@ Page({
checkImg({path}){ checkImg({path}){
if(this.promise&&path==this.tmp_path) if(this.promise&&path==this.tmp_path)
return this.promise; return this.promise;
let buffer = wx.getFileSystemManager().readFileSync(path);
this.promise = this._checkImg({path}); this.promise = this._checkImg({path});
this.tmp_path = path; this.tmp_path = path;
this.promise.then(res=>{ this.promise.then(res=>{
@ -47,35 +59,49 @@ Page({
return this.promise; return this.promise;
}, },
onConfirm(){ onConfirm(){
this.setData({submitting:1});
if(!this.mycropper||!this.mycropper.src) if(!this.mycropper||!this.mycropper.src)
return wx.showToast({ return wx.showToast({
title: '请先选取图片',icon:"none" title: '请先选取图片',icon:"none"
}) })
let {src} = this.mycropper; let {croperTarget} = this.mycropper;
wx.showLoading({ wx.showLoading({
title: '检查图片中...', title: '检查图片中...',
}) })
this.checkImg({path: src}).then(res=>{ this.checkImg({path: croperTarget}).then(res=>{
if(res.errCode==0) if(res.errCode==0)
this.startUpload(); this.startUpload();
else if(res.errCode==87014){ else if(res.errCode==87014){
wx.hideLoading(); wx.hideLoading();
wx.showModal({ wx.showModal({
content:rich_message,showCancel: false content:rich_message,showCancel: false
}) });
this.setData({submitting:0});
}else{ }else{
wx.showToast({ wx.showToast({
title: '发生了未知错误',icon:"none" title: '发生了未知错误,请重试',icon:"none"
}); });
this.promise = null;
let {croperTarget} = this.mycropper;
this.checkImg({path:croperTarget});
this.setData({submitting:0});
wx.reportMonitor('2', 1); wx.reportMonitor('2', 1);
global.realTimeLog.error("未知错误 checkImg1"); global.realTimeLog.error("未知错误 checkImg1", res);
global.realTimeLog.setFilterMsg("unexpected"); global.realTimeLog.setFilterMsg("unexpected");
} }
}).catch(e=>{ }).catch(e=>{
wx.hideLoading(); wx.hideLoading();
app.showError(e); wx.showToast({
title: '请求超时,请重试',icon:"none"
});
this.promise = null;
let {croperTarget} = this.mycropper;
this.checkImg({path:croperTarget});
this.setData({submitting:0});
wx.reportMonitor('2', 1); wx.reportMonitor('2', 1);
global.realTimeLog.error("未知错误 checkImg2"); global.realTimeLog.error("未知错误 checkImg2", e);
global.realTimeLog.setFilterMsg("unexpected"); global.realTimeLog.setFilterMsg("unexpected");
}) })
}, },
@ -93,10 +119,11 @@ Page({
}); });
}, },
startUpload() { startUpload() {
this.setData({submitting:1});
this.mycropper.getCropperImage((avatar) => { this.mycropper.getCropperImage((avatar) => {
if (avatar) { if (avatar) {
wx.showLoading({ wx.showLoading({
title: '上传中', title: '上传头像中',
}); });
this.uploadAvartar(avatar) this.uploadAvartar(avatar)
.then(res => { .then(res => {
@ -104,6 +131,7 @@ Page({
wx.showToast({ wx.showToast({
title: '更改成功', title: '更改成功',
}); });
this.setData({submitting:0});
setTimeout(()=>{ setTimeout(()=>{
wx.navigateBack({ wx.navigateBack({
delta: 1 delta: 1
@ -115,12 +143,14 @@ Page({
icon: "none" icon: "none"
}); });
wx.hideLoading(); wx.hideLoading();
this.setData({submitting:0});
}); });
} else { } else {
wx.showToast({ wx.showToast({
title: '图片截取失败', title: '图片截取失败',
icon: "none" icon: "none"
}); });
this.setData({submitting:0});
} }
}) })
}, },
@ -165,11 +195,11 @@ Page({
this.mycropper = new WeCropper(cropperOpt); this.mycropper = new WeCropper(cropperOpt);
this.mycropper this.mycropper
.on('beforeImageLoad', (ctx) => { .on('beforeImageLoad', (ctx) => {
wx.showLoading({title: '上传中'}) wx.showLoading({title: '图片加载中'})
}) })
.on('imageLoad', (ctx) => { .on('imageLoad', (ctx) => {
let {src} = this.mycropper; let {croperTarget} = this.mycropper;
this.checkImg({path:src}); this.checkImg({path:croperTarget});
wx.hideLoading(); wx.hideLoading();
}) })
.updateCanvas(); .updateCanvas();

@ -8,8 +8,11 @@
<button class="upload" type="main" plain="1" bindtap="chooseImage"> <button class="upload" type="main" plain="1" bindtap="chooseImage">
重选图片 重选图片
</button> </button>
<button type="main" class="getCropperImage" bindtap="onConfirm"> <button type="main" disabled="{{submitting}}" class="getCropperImage" bindtap="onConfirm">
确认 确认
</button> </button>
<button type="main" plain open-type="getUserInfo" bindgetuserinfo="onGetUserInfo">
微信头像
</button>
</view> </view>
</block> </block>

@ -25,5 +25,9 @@ height: 100%
.operations>button{ .operations>button{
flex: auto; flex: auto;
border-radius: 0; border-radius: 0;
white-space: nowrap;
display: flex;
justify-content: center;
align-items: center;
} }

@ -3,7 +3,7 @@
"rules": [ "rules": [
{ {
"action":"allow", "action":"allow",
"page":"path/pages/path/path", "page":"markdown/path/path/path",
"params":[ "params":[
"subject_id" "subject_id"
], ],
@ -11,7 +11,7 @@
}, },
{ {
"action": "allow", "action": "allow",
"page": "shixun/pages/shixun/shixun", "page": "markdown/shixun/shixun/shixun",
"params": [ "params": [
"identifier" "identifier"
], ],
@ -23,12 +23,20 @@
}, },
{ {
"action":"disallow", "action":"disallow",
"page":"task/pages/task/task" "page":"markdown/task/task/task"
},
{
"action":"disallow",
"page":"account/pages/accounts/accounts"
}, },
{ {
"action":"disallow", "action":"disallow",
"page":"course/pages/course/course" "page":"course/pages/course/course"
}, },
{
"action":"disallow",
"page":"pages/my_courses/my_courses"
},
{ {
"action": "allow", "action": "allow",
"page": "*" "page": "*"

@ -6,7 +6,7 @@
"ignore": [] "ignore": []
}, },
"setting": { "setting": {
"urlCheck": true, "urlCheck": false,
"es6": true, "es6": true,
"enhance": true, "enhance": true,
"postcss": true, "postcss": true,

Loading…
Cancel
Save