作者 吴亚瑞

个人信息

// pages/14/14.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
imageUrl: app.globalData.baseUrl,
show: false,
wordshow: false,
popshow: false,
nickname: '',
oldpassword: '',
password1: '',
password2: '',
img: '', //头像
meData: ''
},
onLoad: function (options) {
},
onShow: function () {
this.getMe()
},
//获取用户个人信息
getMe() {
var that = this;
app.post("my/UserInfo", {}).then(res => {
if (res.code == 1) {
that.setData({
meData: res.data,
img: res.data.avatar
})
}
}).catch(err => {
wx.showToast({
title: err.msg,
icon: 'none'
})
})
},
// 头像
// 上传头像
changeMsg() {
var that = this
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
console.log(res)
wx.showLoading({
title: '正在上传..',
})
wx.uploadFile({
url: that.data.imageUrl + 'common/upload',
filePath: res.tempFilePaths[0],
name: 'file',
header: {
"token": wx.getStorageSync('token') || '',
'content-type': 'application/json;'
},
success: function (res) {
console.log(res, '2222')
wx.hideLoading();
let imgUrl = JSON.parse(res.data).data.fullurl
that.setData({
img: imgUrl,
});
app.post('my/UpdateAvatar', {
avatar: imgUrl,
}).then(r => {
console.log(r)
if (r.code == 1) {
wx.showToast({
title: '修改成功',
icon: 'none',
})
}
})
},
});
}
})
},
// 打开
gopop(e) {
console.log(e, '4444')
let id = e.currentTarget.dataset.id
... ... @@ -20,14 +99,17 @@ Page({
popshow: true
})
} else {
this.setData({
wordshow: true,
popshow: true
})
}
},
// 关闭
goclose(e) {
let id = e.currentTarget.dataset.id
if (id == 1) {
... ... @@ -42,55 +124,124 @@ Page({
})
}
},
// 昵称
bindname() {
this.getnickname()
this.getMe()
gotoday() {
wx.showToast({
title: '保存成功',
mask: true,
})
setTimeout(() => {
wx.navigateBack({
delta: 0
})
}, 1000)
},
getnickname() {
var that = this;
if (this.data.nickname == '') {
wx.showToast({
title: '请输入昵称',
icon: 'none'
})
} else {
app.post("my/UpdateNickname", {
nickname: this.data.nickname
}).then(res => {
if (res.code == 1) {
wx.showToast({
title: '修改成功',
icon: 'none'
})
this.setData({
show: false,
popshow: false
})
}
}).catch(err => {
wx.showToast({
title: err.msg,
icon: 'none'
})
})
}
},
// 密码
bindword() {
this.getpassword()
},
getpassword() {
var that = this;
if (this.data.oldpassword == '') {
wx.showToast({
title: '请输入旧密码',
icon: 'none'
})
} else if (this.data.password1 != this.data.password2) {
wx.showToast({
title: '两次的密码不一致',
icon: 'none'
})
} else {
app.post("my/UpdatePassword", {
old_password: this.data.oldpassword,
new_password: this.data.password1
}).then(res => {
if (res.code == 1) {
wx.showToast({
title: '修改成功',
icon: 'none'
})
this.setData({
wordshow: false,
popshow: false
})
}
}).catch(err => {
wx.showToast({
title: err.msg,
icon: 'none'
})
})
}
onLoad: function (options) {
},
// 退出
goOut() {
wx.showModal({
content: '确认退出该账号?',
confirmText: '退出登录',
confirmColor: '#F44D36',
success(res) {
if (res.confirm) {
wx.clearStorageSync()
wx.navigateBack({
delta: 0
})
app.post('login/GetOutLogin', {
}).then(r => {
console.log(r)
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
console.log(2)
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log(3)
},
/**
* 生命周期函数--监听页面隐藏
*/
... ...
<view class="my_m_box" style="border-bottom: 1rpx solid #eeeeee;">
<view class="my_mb_text">头像</view>
<view class="flex">
<image class="my_mb_img" src="/img/ic_head@2x.png">
<image class="my_mb_img" src="{{img?img:'/img/ic_head@2x.png'}}" bindtap="changeMsg">
</image>
<image class="my_mb_next" src="/img/ic_arrow@2x.png"></image>
</view>
... ... @@ -9,26 +9,26 @@
<view class="my_m_box" bindtap="gopop" data-id="{{1}}">
<view class="my_mb_text">昵称</view>
<view class="flex fs28">
<view>昵称</view>
<view>{{meData.nickname}}</view>
<image class="my_mb_next" src="/img/ic_arrow@2x.png"></image>
</view>
</view>
<view class="my_m_box">
<view class="my_mb_text">所属班级</view>
<view class="flex fs28">
<view>所属班级</view>
<view>{{meData.classroom}}</view>
<!-- <image class="my_mb_next" src="/img/ic_arrow@2x.png"></image> -->
</view>
</view>
<view class="my_m_box" bindtap="gopop">
<view class="my_mb_text">修改密码</view>
<view class="flex fs28">
<view>昵称</view>
<view></view>
<image class="my_mb_next" src="/img/ic_arrow@2x.png"></image>
</view>
</view>
<view class="my_m_box">
<view class="my_mb_text cy">退出登录</view>
<view class="my_mb_text cy" bindtap="goOut">退出登录</view>
</view>
<!-- 昵称框 -->
<page-container show="{{popshow}}"></page-container>
... ... @@ -38,9 +38,9 @@
</view>
<text>修改昵称</text>
<view class="input">
<input type="text" placeholder="请输入昵称" />
<input type="text" placeholder="请输入昵称" model:value="{{nickname}}" />
</view>
<view class="button" bindtap="gotoday">确定</view>
<view class="button" bindtap="bindname">确定</view>
</view>
<!-- 密码框 -->
<view class="denglu" wx:if="{{wordshow}}">
... ... @@ -49,13 +49,13 @@
</view>
<text>修改密码</text>
<view class="input">
<input type="text" placeholder="请输入旧密码" />
<input type="text" placeholder="请输入旧密码" model:value="{{oldpassword}}"/>
</view>
<view class="input">
<input type="text" placeholder="请输入新密码" />
<input type="text" placeholder="请输入新密码" model:value="{{password1}}"/>
</view>
<view class="input">
<input type="text" placeholder="请再次确认密码" />
<input type="text" placeholder="请再次确认密码" model:value="{{password2}}"/>
</view>
<view class="button" bindtap="gotoday">保存</view>
<view class="button" bindtap="bindword">保存</view>
</view>
\ No newline at end of file
... ...
... ... @@ -27,6 +27,12 @@ Page({
login: false,
meData:{}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onShow() {
let token = wx.getStorageSync('token')
if (token == '') {
... ... @@ -71,12 +77,7 @@ Page({
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getMe()
},
//获取用户个人信息
getMe(){
var that = this;
... ... @@ -102,13 +103,6 @@ Page({
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
... ...