// pages/setName/setName.js import httpRequestApi from '../../utils/APIRequest'; Page({ /** * 页面的初始数据 */ data: { phone: '', name: '', headImg: '' }, //获取输入名字 getName: function ({detail}) { this.setData({ name: detail.value, }) }, //获取输入手机号 getPhone: function ({detail}) { this.setData({ phone: detail.value, }) }, //保存修改 Savemodification: function () { //console.log(this.data.name,this.data.phone); const name = this.data.name; const phone = this.data.phone; const reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/; if(phone !== '') { if(phone.length !== 11 || !reg.test(phone)){ wx.showModal({ title: '提示', content: '请输入正确手机号' }) return; } } httpRequestApi.setUserInfo({ "mobileNo": phone, "nickName": name, "avatar": "" }).success(res => { if(res.data.success) { wx.navigateBack(); } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //初始化获取个人信息 httpRequestApi.getUserInfo().success(res => { const user = res.data.data; this.setData({ name: user.nickName, phone: user.mobileNo, headImg: user.avatar }) }); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })