// pages/center/center.js var app = getApp() Page({ /** * 页面的初始数据 */ data: { userAvatar: '', token: '' }, changeAvatar: function () { var self = this wx.showActionSheet({ itemList: ['从相册中选择','拍照'], success: function (res) { if (!res.cancel) { if (res.tapIndex == 0) { self.chooseAvatar('album') } else { self.chooseAvatar('camera') } } } }) }, chooseAvatar: function (type) { var self = this wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: [type], success: function (res) { var avatar = res.tempFilePaths[0]; console.log(avatar) app.restAjax.post(app.restAjax.path('{usercenterUrl}/app/file/uploadimage', [app.usercenterUrl]), { image: avatar }, { headers: { token: self.data.token } }, function (code, data) { console.log(data); }, function (code, data) { console.log(data) }) self.setData({ userAvatar: avatar }) } }) }, getToken: function () { var self = this wx.getStorage({ key: 'token', success: function(res) { self.setData({ token: res.data }) }, }) }, /** * 跳转到我的志愿团队页面 */ toMyTeam: function() { wx.navigateTo({ url: '../myVlounteerTeam/myVlounteerTeam', }) }, /** * 跳转到我的志愿活动页面 */ toMyVolunteerActivity: function() { wx.navigateTo({ url: '../myVolunteerActivity/myVolunteerActivity', }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getToken() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })