diff --git a/.gitignore b/.gitignore
index edccf46..18cb9a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,6 +13,8 @@ project.config.json
app.js
towxml
+we-cropper
+
.idea
api_docs
diff --git a/app.json b/app.json
index 9e518da..9e39ef7 100644
--- a/app.json
+++ b/app.json
@@ -2,6 +2,7 @@
"pages": [
"pages/findmore/findmore",
"pages/my_courses/my_courses",
+ "pages/login/login",
"pages/course_setting/course_setting",
"pages/exercises/exercises",
"pages/courses/courses",
@@ -9,13 +10,13 @@
"pages/setting/setting",
"pages/classroom/classroom",
"pages/about/about",
- "pages/login/login",
+
"pages/test/test",
"pages/course/course",
"pages/files/files",
"pages/mark_detail/mark_detail",
- "pages/reset_password/reset_password"
-
+ "pages/reset_password/reset_password",
+ "pages/image_crop/image_crop"
],
"window": {
"backgroundTextStyle": "dark",
diff --git a/data/client.js b/data/client.js
index 7124c71..48bf5bd 100644
--- a/data/client.js
+++ b/data/client.js
@@ -224,6 +224,29 @@ export class Client{
});
})
}
+ upload_avatar({avatar_path, success, fail, complete}){
+ console.log("upload_avatar");
+ return new Promise((resolve, reject) => {
+ Account.upload_avatar({
+ session: this.session,
+ avatar_path: avatar_path,
+ login: this.current_user.login,
+ complete: complete,
+ success: res => {
+ if (typeof success == "function") {
+ success(res);
+ }
+ resolve(res);
+ },
+ fail: error => {
+ if (typeof fail == "function") {
+ fail(error);
+ }
+ reject(error);
+ }
+ })
+ });
+ }
search_courses({limit=20, page=1, order="all", search="", success, fail, complete}={}){
return new Promise((resolve, reject) => {
@@ -271,7 +294,7 @@ export class Client{
session: this.session,
page: page,
per_page: per_page,
- user: this.current_user.login,
+ login: this.current_user.login,
complete: complete,
success: res=>{
if(typeof success == "function"){
diff --git a/data/eduapi.js b/data/eduapi.js
index a2bfa5a..14e908c 100644
--- a/data/eduapi.js
+++ b/data/eduapi.js
@@ -90,10 +90,10 @@ export class Account{
complete: complete
})
}
- static get_user_courses({session,user,category="",status="",sort_by="",sort_direction="",page=1, per_page=16, success, fail, complete}){
+ static get_user_courses({session,login,category="",status="",sort_by="",sort_direction="",page=1, per_page=16, success, fail, complete}){
let data = {page: page, per_page: per_page, category:category, status: status, sort_by: sort_by, sort_direction: sort_direction};
return session.request({
- url: api_base_url + "/users/"+user +"/courses.json",
+ url: api_base_url + "/users/"+login +"/courses.json",
method: "GET",
data: data,
success: success,
@@ -125,6 +125,33 @@ export class Account{
}
static set_password({}){
+ }
+ static upload_avatar({session, login, avatar_path, success, fail, complete}){
+ var avatar_data=null;
+ wx.getFileSystemManager().readFile({
+ filePath: avatar_path,
+ encoding: "base64",
+ success:res=> {
+ console.log("in success");
+ console.log(res);
+ avatar_data ="data:image/jpeg;base64,"+res.data;
+ console.log("upload_avatar");
+ console.info(avatar_data);
+ session.request({
+ url: "https://www.educoder.net/api/users/accounts/"+login+"/avatar.json",
+ method: "PUT",
+ data: {image: avatar_data},
+ success: success,
+ fail: fail,
+ complete: complete
+ })
+ },
+ fail: error=>{
+ console.error(error);
+ }
+ });
+
+
}
}
diff --git a/data/requests.js b/data/requests.js
index 406c6bf..a15575b 100644
--- a/data/requests.js
+++ b/data/requests.js
@@ -49,11 +49,18 @@ export class Session {
}
uploadFile({url, filePath, name, header, formData, success, fail, complete}){
+ console.log("uploadFile");
+ console.log({
+ url: url,
+ filePath: filePath,
+ name: name,
+ header: {"content-type": "multipart/form-data", "Cookie": this.cookie_str, ...header},
+ formData: formData});
return wx.uploadFile({
url: url,
filePath: filePath,
name: name,
- header: {...header, "content-type": "multipart/form-data", "Cookie": this.cookie_str},
+ header: {"content-type": "multipart/form-data", "Cookie": this.cookie_str, ...header},
formData: formData,
success: success,
fail: fail,
diff --git a/pages/findmore/findmore.js b/pages/findmore/findmore.js
index 7b33557..38e7c6a 100644
--- a/pages/findmore/findmore.js
+++ b/pages/findmore/findmore.js
@@ -16,20 +16,20 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
-
+ app.client.get_home_page()
+ .then(res => {
+ console.info(res);
+ this.setData({ page_info: res.data, page_status: 1 });
+ }).catch(error => {
+ this.setData({ page_status: 2 });
+ })
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
- app.client.get_home_page()
- .then(res=>{
- console.info(res);
- this.setData({page_info: res.data, page_status: 1});
- }).catch(error=>{
- this.setData({page_status: 2});
- })
+
},
/**
@@ -57,7 +57,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
-
+ this.onLoad();
},
/**
diff --git a/pages/findmore/findmore.json b/pages/findmore/findmore.json
index 8835af0..7360326 100644
--- a/pages/findmore/findmore.json
+++ b/pages/findmore/findmore.json
@@ -1,3 +1,4 @@
{
- "usingComponents": {}
+ "usingComponents": {},
+ "enablePullDownRefresh": true
}
\ No newline at end of file
diff --git a/pages/image_crop/image_crop.js b/pages/image_crop/image_crop.js
new file mode 100644
index 0000000..9016fe5
--- /dev/null
+++ b/pages/image_crop/image_crop.js
@@ -0,0 +1,106 @@
+import WeCropper from '../../we-cropper/dist/we-cropper.min.js'
+
+
+const device = wx.getSystemInfoSync()
+const width = device.windowWidth
+const height = device.windowHeight - 30
+const app = getApp();
+
+Page({
+ data: {
+ cropperOpt: {
+ id: 'cropper',
+ width,
+ height,
+ scale: 2.5,
+ zoom: 8,
+ cut: {
+ x: (width - 300) / 2,
+ y: (height - 300) / 2,
+ width: 300,
+ height: 300
+ }
+ }
+ },
+
+ touchStart(e) {
+ console.log(e);
+ this.mycropper.touchStart(e)
+ },
+
+ touchMove(e) {
+ console.log(e);
+ this.mycropper.touchMove(e)
+ },
+
+ touchEnd(e) {
+ console.log(e);
+ this.mycropper.touchEnd(e)
+ },
+
+ getCropperImage() {
+ console.warn("ontap: getCropImage")
+ this.mycropper.getCropperImage((avatar) => {
+ console.log(avatar);
+ if (avatar) {
+ console.info("avatar");
+ console.log(avatar);
+ app.client.upload_avatar({
+ avatar_path: avatar,
+ success: res=>{
+ console.log("upload avatar success");
+ console.log(res);
+ },
+ fail: error=>{
+ console.error(error);
+ }
+ });
+ } else {
+ console.error('获取图片失败')
+ }
+ })
+ },
+
+ uploadTap() {
+ const self = this
+
+ wx.chooseImage({
+ count: 1,
+ success(res) {
+ const src = res.tempFilePaths[0]
+ self.mycropper.pushOrign(src)
+ }
+ })
+ },
+
+ onLoad(option) {
+ const {cropperOpt} = this.data
+ const {src} = option
+
+ if (src) {
+ Object.assign(cropperOpt, {src})
+ this.mycropper = new WeCropper(cropperOpt);
+ this.mycropper
+ .on('ready', function (ctx) {
+ console.info("ready");
+ console.info(ctx);
+ })
+ .on('beforeImageLoad', (ctx) => {
+ console.info("beforeImageLoad");
+ wx.showToast({
+ title: '上传中',
+ icon: 'loading',
+ duration: 3000
+ })
+ })
+ .on('imageLoad', (ctx) => {
+ console.info("imageLoad")
+ wx.hideToast()
+ })
+ .on('beforeDraw', (ctx, instance) => {
+ console.log(`before canvas draw,i can do something`)
+ console.log(`current canvas context:`, ctx)
+ })
+ }
+ }
+})
\ No newline at end of file
diff --git a/pages/image_crop/image_crop.json b/pages/image_crop/image_crop.json
new file mode 100644
index 0000000..a2f054a
--- /dev/null
+++ b/pages/image_crop/image_crop.json
@@ -0,0 +1,4 @@
+{
+ "usingComponents": {},
+ "navigationBarTitleText": "设置头像"
+}
\ No newline at end of file
diff --git a/pages/image_crop/image_crop.wxml b/pages/image_crop/image_crop.wxml
new file mode 100644
index 0000000..91d5c35
--- /dev/null
+++ b/pages/image_crop/image_crop.wxml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
diff --git a/pages/image_crop/image_crop.wxss b/pages/image_crop/image_crop.wxss
new file mode 100644
index 0000000..568a8a1
--- /dev/null
+++ b/pages/image_crop/image_crop.wxss
@@ -0,0 +1,21 @@
+page{
+height: 100%
+}
+.cropper{
+position: absolute;
+top: 0;
+left: 0;
+}
+
+.operation{
+ position: fixed;
+ bottom: 0;
+ width: 100%;
+ align-items: center
+}
+
+.operation button{
+ width: 49%;
+}
+
+
diff --git a/pages/setting/setting.js b/pages/setting/setting.js
index 5d3079b..5bd8e1f 100644
--- a/pages/setting/setting.js
+++ b/pages/setting/setting.js
@@ -7,6 +7,37 @@ Page({
show_join_course_modal: false,
invite_code: ""
},
+ /**on tap */
+ onTapAvatar: function({currentTarget:{dataset}}){
+ wx.showActionSheet({
+ itemList: ["查看图片","更改头像"],
+ success:res=>{
+ switch(res.tapIndex){
+ case 0:
+ wx.previewImage({
+ urls: [dataset.src],
+ });
+ break;
+ case 1:
+ console.log("点击更改头像");
+ wx.chooseImage({
+ count:1,
+ success: function(res) {
+ console.log("choose image")
+ console.log(res);
+ const src = res.tempFilePaths[0]
+ wx.navigateTo({
+ url: '../image_crop/image_crop?src='+src,
+ })
+ },
+ })
+ break;
+ }
+ }
+ })
+
+ },
+
logout: function(){
app.client.logout({
success:res=>{
@@ -73,6 +104,8 @@ Page({
this.setData({current_user: app.client.current_user})
if ("image_url" in app.client.current_user && app.client.current_user.image_url) {
this.setData({ avatar_url: "https://www.educoder.net/images/" + app.client.current_user.image_url })
+ }else{
+ this.setData({ avatar_url: "" });
}
})
},
diff --git a/pages/setting/setting.wxml b/pages/setting/setting.wxml
index 18bc2ff..6d0424c 100644
--- a/pages/setting/setting.wxml
+++ b/pages/setting/setting.wxml
@@ -1,7 +1,7 @@
-
+
{{current_user.real_name}} | {{current_user.username}}