// pages/personSet/personSet.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { personInfo: {}, isAuth: false, imgHeader: '/images/heard.png' }, getUser() { wx.request({ url: `https://puyue.yhupai.com/prod-api/system/user/profile`, method: 'GET', header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, dataType: 'json', success: (res, header) => { // console.log(res); if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); } else { let data=res.data.data this.setData({ personInfo: data, }) if(this.data.personInfo.avatar){ this.setData({ imgHeader:'https://puyue.yhupai.com/prod-api/'+this.data.personInfo.avatar }) } } }, }); }, goChangePSW() { wx.navigateTo({ url: '/pages/changePsw/changePSW', }) }, chooseimage() { var that = this; // 将当前页面的上下文赋值给 that 变量 // 在某个事件处理函数中调用以下代码 wx.chooseImage({ count: 1, // 最多可以选择的图片数量,这里设为1 sourceType: ['album'], // 从相册选择 success: function (res) { // 选择成功后,res.tempFilePaths 是选定的图片的本地文件路径列表 const tempFilePath = res.tempFilePaths; wx.compressImage({ src: tempFilePath[0], quality: 80, // 设置压缩质量,范围为 0-100 success: function (res) { const compressedFilePath = res.tempFilePath; console.log(compressedFilePath, 'compressedFilePath'); // 压缩后的图片路径进行的后续操作 try { // const userinfo = wx.getStorageSync('userinfo') let data = compressedFilePath wx.uploadFile({ // 上传接口路径 url: `https://puyue.yhupai.com/prod-api/system/user/profile/avatar`, filePath: data, name: 'avatarfile', // 上传文件对应的 key 名称 method: 'post', header: { 'content-type': 'application/form-data', "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, // data: data success: function (res) { that.getUser() // // 上传成功后的处理逻辑 // that.setData({ // imageSrc: JSON.parse(res.data).msg // 将选择的图片路径设置为页面数据的某个属性 // }); }, fail: function (res) { // 上传失败后的处理逻辑 console.log(res, '上传失败后的处理逻辑'); } }) } catch (e) { } }, fail: function (err) { // 压缩失败的处理 console.error(err); } }); } }); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getUser() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })