Page({ /** * 页面的初始数据 */ data: { studentId : '', name: '', password: '' }, addScore1: function() { this.addScore(-0.5); this.call_the_name(); }, addScore2: function() { this.call_the_name(); }, addScore3: function() { this.addScore(0.5); this.call_the_name(); }, addScore4: function() { this.call_the_name(); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.call_the_name(); }, call_the_name: function() { const kind = wx.getStorageSync('call_kind'); const that = this; var url = ''; if (kind == '1') { url = 'http://10.133.15.50:8888/admin/randomRollCall?courseId=' + wx.getStorageSync('courseId'); } else if (kind == '2') { url = 'http://10.133.15.50:8888/admin/callByLastNum?courseId=' + wx.getStorageSync('courseId') + '&lastNum=' + wx.getStorageSync('lastNum'); } else if (kind == '3') { url = 'http://10.133.15.50:8888/admin/callByFirstname?courseId=' + wx.getStorageSync('courseId') + '&firstname=' + wx.getStorageSync('firstname'); } wx.request({ url: url, method: 'POST', header: { 'admin_token': wx.getStorageSync('token') // 携带token }, success(res) { if (res.statusCode === 200) { console.log(res.data.data); that.setData({ studentId: res.data.data.studentId, name: res.data.data.name, password: res.data.data.password }); } }, fail(error) { console.error(error); } }); }, addScore: function(score) { const that = this; wx.request({ url: 'http://10.133.15.50:8888/admin/addScore?score=' + score, method: 'PUT', header: { 'admin_token': wx.getStorageSync('token') // 携带token }, data: { student: { studentId: that.data.studentId, name: that.data.name, password: that.data.password }, course: { courseId: wx.getStorageSync('courseId'), description: wx.getStorageSync('description') } }, success(res) { if (res.statusCode === 200) { console.log("right op"); } }, fail(error) { console.error(error); } }); } })