NONGJINGQUANXIAOCHENGXU/pages/person-info/index.js

87 lines
1.9 KiB
JavaScript

// pages/user/user.js
const app = getApp();
const $ = require('../../utils/util.js')
const { $Toast } = require('../../dist/base/index');
Page({
/**
* 页面的初始数据
*/
data: {
userInfo: ''
},
onClickCell({ currentTarget }) {
console.log(currentTarget)
return
const { dataset } = currentTarget;
switch (dataset.type) {
case 'avatarUrl':
this.toModifyAvatar();
break;
default: {
break;
}
}
},
async toModifyAvatar() {
try {
const tempFilePath = await new Promise((resolve, reject) => {
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
const { path, size } = res.tempFiles[0];
if (size <= 10485760) {
resolve(path);
} else {
reject({ errMsg: '图片大小超出限制,请重新上传' });
}
},
fail: (err) => reject(err),
});
});
const tempUrlArr = tempFilePath.split('/');
const tempFileName = tempUrlArr[tempUrlArr.length - 1];
$Toast({
context: this,
selector: '#t-toast',
message: `已选择图片-${tempFileName}`,
theme: 'success',
});
} catch (error) {
if (error.errMsg === 'chooseImage:fail cancel') return;
$Toast({
context: this,
selector: '#t-toast',
message: error.errMsg || error.msg || '修改头像出错了',
theme: 'fail',
});
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
var that = this;
that.setData({
userInfo: getApp().globalData.userInfo
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
})