2025-04-22 14:39:59 +08:00

117 lines
1.9 KiB
JavaScript

import {
postUrl,
uploadFileUrl,
img_url
} from '../../../utils/util';
import { apiArr } from '../../../api/user';
Page({
/**
* 页面的初始数据
*/
data: {
picUrl: '',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
headerUploadClick() {
let _this = this;
wx.showLoading({
title: '加载中',
})
console.log('打开上传');
wx.chooseMedia({
count: 1,
mediaType: ['image'],
success(res) {
const tempFilePaths = res.tempFiles;
uploadFileUrl(tempFilePaths[0].tempFilePath, (ress) => {
let datas = JSON.parse(ress)
let url = img_url + datas.data.path;
_this.setData({
picUrl: url
})
postUrl(apiArr.avatar, {
avatar: datas.data.path
}, res => {
wx.hideLoading();
console.log('avataravataravataravatar', res);
wx.showToast({
title: '上传头像成功',
icon: 'success',
mask: true,
success() {
setTimeout(() => {
wx.navigateBack({
delta: 1
})
}, 1500)
}
})
})
})
},
fail(err) {
console.log('eeadasdad', err);
wx.hideLoading();
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})