提交头像

This commit is contained in:
dong_bo0602 2020-06-26 15:00:36 +08:00
parent 5eb282a80f
commit ec45edf43f
5 changed files with 64 additions and 9 deletions

View File

@ -1,5 +1,6 @@
{
"pages": [
"pages/center/center",
"pages/index/index",
"pages/volunteerRegister/volunteerRegister",
"pages/volunteer/volunteer",
@ -13,7 +14,6 @@
"pages/newTeam/newTeam",
"pages/volunteerTeam/volunteerTeam",
"pages/venue/venue",
"pages/center/center",
"pages/cultureDetail/cultureDetail",
"pages/activitySign/activitySign",
"pages/activityDetail/activityDetail",

View File

@ -1,18 +1,72 @@
// 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
})
},
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getToken()
},
/**

View File

@ -3,8 +3,8 @@
</view>
<view class="page-container">
<view class="person">
<view class="user-avatar">
<image src="../../images/user-avatar.png"></image>
<view class="user-avatar" bindtap="changeAvatar">
<image src="{{userAvatar}}"></image>
</view>
<view class="user-name">杜若无心</view>
</view>

View File

@ -6,16 +6,16 @@
"setting": {
"urlCheck": false,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": true,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"coverView": true,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"enhance": false,
"nodeModules": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,

View File

@ -223,4 +223,5 @@ module.exports.put = putJson;
module.exports.get = getForm;
module.exports.params = getParamsArg;
module.exports.path = buildPath;
module.exports.escape = escape;
module.exports.escape = escape;
module.exports.file = postFile;