学生评教系统中,会有评教和个人页面两大管理。在个人页面中,需显示个人的基本信息,比如:学号,姓名,班级,邮箱等。
一,获取微信头像和昵称:使用<open-data></open-data>来自动获取头像和昵称。
<view class='logo'>
<open-data type="userAvatarUrl"></open-data>
</view>
<view class='name'>
<open-data type="userNickName"></open-data>
</view>
二,获取基本信息:
<view class='contain'>
<view class='item'>
<text class='item-left'>学号</text>
<text class='item-right'>{{student.no}}</text>
</view>
<view class='item'>
<text class='item-left'> 姓名</text>
<text class='item-right' >{{student.name}}</text>
</view>
<view class='item'>
<text class='item-left'> 班级</text>
<text class='item-right' >{{student.classname}}</text>
</view>
<view class='item'>
<text class='item-left'> 系部</text>
<text class='item-right' >{{student.departmentname}}</text>
</view>
<view class='item' bindtap="setemail">
<text class='item-left'>邮箱</text>
<text class='item-right' >
<text wx:if="{{student.email=='' || student.email== null}}">未绑定</text><text wx:else>{{student.email}}</text>
</text>
</view>
<view class='item' bindtap="resetpwd">
<text class='item-left'>密码</text>
<text class='item-right' >重置</text>
</view>
<view class='item'>
<text class='item-left'>退出</text>
<text class='item-right' bindtap="exit">>></text>
</view>
</view>
(1)在页面中,获取学生的姓名,学号,班级,系部是通过读取student缓存来获取的:
//读取缓存
var student = wx.getStorageSync('student');
// console.log(student);
this.setData({
student:student
});
(2)密码重置时,相应的跳转之后,跳转到密码重置页,实现输入旧密码-输入新密码-再次确认新密码三个过程,然后对密码进行非空验证:
formSubmit: function (e) {
// console.log(e);
var oldpwd = e.detail.value.oldpwd;
var newpwd = e.detail.value.newpwd;
var newpwd2 = e.detail.value.newpwd2;
var no = wx.getStorageSync('student').no;
// console.log(no);
if (oldpwd == '' || newpwd == '' || newpwd2 == '') {
wx.showToast({
title: '密码不能为空',
icon: 'none',
duration: 1000
})
} else if (newpwd != newpwd2) {
wx.showToast({
title: '两次输入不一致',
icon: 'none',
duration: 1000
})
} else {
var url = app.globalData.url.setpassword;
wx.request({
url: url, //仅为示例,并非真实的接口地址
method: 'POST',
data: {
no: no,
oldpwd: oldpwd,
newpwd: newpwd
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: (res) => {
console.log(res.data);
if (res.data.error) {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
} else {
wx.showToast({
title: res.data.msg,
icon: 'success',
duration: 2000,
success: function () {
setTimeout(function () {
wx.navigateBack({ belta: 1 })
}, 2000)
}
})
}
}
})
}
},
(3)点击退出时,弹出是否退出的提示并进行页面跳转
exit:function(e){
wx.showModal({
title: '提示',
content: '确认是否要退出',
success: function (res) {
if (res.confirm) {
//清除缓存
wx.removeStorageSync('student')
//页面跳转
wx.redirectTo({
url: '../login/login'
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},