You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB
JavaScript

2 years ago
// pages/changeName/index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
lifePhoto: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
that.data.lifePhoto = options.lifePhoto;
if (options.lifePhoto == null || options.lifePhoto == 'null') {
that.data.lifePhoto = '';
}
that.setData({
lifePhoto: that.data.lifePhoto
});
},
chooseImage: function(e) {
var that = this;
// var type = e.currentTarget.dataset.type;
var type = 21;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
app.load("上传中");
// 返回选定照片的本地文件路径列表tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
var formData = {'type' : type};
wx.uploadFile({
url: app.globalData.ip + '/user/auth/uploadImage',
filePath: res.tempFilePaths[0],
name: 'uploadFile',
header: app.globalData.header2, // 设置请求的 header
formData: formData, // HTTP 请求中其他额外的 form data
success: function (res1) {
console.log(res1);
if (res1.statusCode == 200) {
var result = JSON.parse(res1.data)
if (result.status == 200) {
if (type == 21) {
that.data.lifePhoto = result.data.url;
}
that.setData({
lifePhoto: that.data.lifePhoto
});
} else {
app.showTips(that, result.msg);
}
}
wx.hideLoading();
},
fail: function (res2) {
wx.hideLoading();
}
})
}
})
},
})