mini/pages/my/setting/index.js
2025-04-15 20:23:27 +08:00

114 lines
1.8 KiB
JavaScript

import userAPI from "../../../api/user";
import commonAPI from '../../../api/common';
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
userInfo:{},
uploading:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
chooseAvatar(event){
wx.cropImage({
cropScale: '1:1',
src: event.detail.avatarUrl,
success:()=>{
this.setData({
uploading:true
})
commonAPI.upload({tempFilePath:event.detail.avatarUrl}).then((data)=>{
return userAPI.updateInfo({avatar:data.url})
}).then(()=>{
wx.showToast({
icon:'none',
title: '头像更新成功',
})
return app.forceGetUserInfo();
}).then((data)=>{
this.setData({userInfo:data})
}).finally(()=>{
this.setData({
uploading:false
})
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
app.forceGetUserInfo().then((data)=>{
this.setData({
userInfo:data
})
})
},
logout(){
wx.removeStorage({
key: 'token',
success(){
app.globalData.accessToken = '';
app.globalData.userInfo = {};
wx.reLaunch({
url: '/pages/my/login/index',
})
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})