xz_mini/pages/center/center.js

135 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-06-23 19:14:44 +08:00
// pages/center/center.js
2020-06-26 15:00:36 +08:00
var app = getApp()
2020-06-23 19:14:44 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
2020-06-26 15:00:36 +08:00
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)
2020-06-26 15:19:04 +08:00
app.restAjax.post(app.restAjax.path('{usercenterUrl}/app/file/uploadimage', [app.usercenterUrl]), avatar, 'image', {
2020-06-26 15:00:36 +08:00
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
})
},
})
2020-06-23 19:14:44 +08:00
},
2020-06-26 14:06:35 +08:00
/**
* 跳转到我的志愿团队页面
*/
toMyTeam: function() {
wx.navigateTo({
url: '../myVlounteerTeam/myVlounteerTeam',
})
},
/**
* 跳转到我的志愿活动页面
*/
toMyVolunteerActivity: function() {
wx.navigateTo({
url: '../myVolunteerActivity/myVolunteerActivity',
})
},
2020-06-23 19:14:44 +08:00
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
2020-06-26 15:00:36 +08:00
this.getToken()
2020-06-23 19:14:44 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})