// pages/course_detail/course_detail.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { showModalStatus: false, studentId: "", name: "", description: "" }, studentId: function(e) { this.setData({ studentId: e.detail.value }); console.log("studentId:", e.detail.value); }, name: function(e) { this.setData({ name: e.detail.value }); console.log("name:", e.detail.value); }, cancel: function (e) { var currentStatu = e.currentTarget.dataset.statu; this.util(currentStatu) }, update: function (e) { var currentStatu = e.currentTarget.dataset.statu; this.util(currentStatu) /* 下面补充确定后向后端传输数据*/ const that = this; wx.request({ url: 'http://10.133.15.50:8888/admin/addStudent2Course', 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("yes"); } }, fail(error) { console.error(error); } }); }, util: function (currentStatu) { /* 动画部分 */ // 第1步:创建动画实例 var animation = wx.createAnimation({ duration: 200, //动画时长 timingFunction: "linear", //线性 delay: 0 //0则不延迟 }); // 第2步:这个动画实例赋给当前的动画实例 this.animation = animation; // 第3步:执行第一组动画 animation.opacity(0).rotateX(-100).step(); // 第4步:导出动画对象赋给数据对象储存 this.setData({ animationData: animation.export() }) // 第5步:设置定时器到指定时候后,执行第二组动画 setTimeout(function () { // 执行第二组动画 animation.opacity(1).rotateX(0).step(); // 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象 this.setData({ animationData: animation }) //关闭 if (currentStatu == "close") { this.setData({ showModalStatus: false }); } }.bind(this), 200) // 显示 if (currentStatu == "open") { this.setData({ showModalStatus: true }); } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData ({ description: wx.getStorageSync("description") }); }, chooseMessageFile: function (event) { var that = this; wx.chooseMessageFile({ count: 1, type: 'all', success(res) { var filename = res.tempFiles[0].name that.setData({filename:filename}); console.info(filename); console.log(res.tempFiles[0].path); wx.uploadFile({ url: 'http://10.133.15.50:8888/admin/batchAddStudents?courseId=' + wx.getStorageSync('courseId') + '&file=' + res.tempFiles[0].path, header: { admin_token: wx.getStorageSync('token') // 携带token }, name: filename, method: 'POST', success(res) { var data = JSON.parse(res.data) if (data.code == 200) { console.log('上传成功'); } else{ console.log('上传失败'); wx.showToast({ title: res.message, icon: 'none' }) } } }) } }); } })