// index.js // 获取应用实例 const app = getApp() Page({ data: { motto: '欢迎进入', userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo'), canIUseGetUserProfile: false, canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false isSelected:0 }, // 事件处理函数 bindViewTap() { wx.navigateTo({ url: '../logs/logs' }) }, bindmaiViewTap() { wx.switchTab({ url: '../main/main' }) }, // bindhisViewTap(){ // wx.redirectTo({ // url: '../history/history' // }) // }, // bindrecViewTap(){ // wx.switchTab({ // url: '../recommend/recommend' // }) // }, // bindmacViewTap(){ // wx.redirectTo({ // url: '../match/match' // }) // }, onLoad() { if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) }, getUserInfo(e) { // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 console.log(e) this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }, // handleImageTap: function(e) { // const index = e.currentTarget.dataset.index; // 获取当前点击的图片的位置 // const isSelected = this.data['isSelected' + index]; // 获取当前点击的图片的选中状态 // let newData = {}; // 定义一个新的数据对象 // if (isSelected) { // newData['isSelected' + index] = false; // 如果当前图片已经被选中,就将它的选中状态设置为 false // } else { // for (let i = 1; i <= 3; i++) { // if (i !== index && this.data['isSelected' + i]) { // 如果有其他图片被选中,则将它的选中状态还原 // newData['isSelected' + i] = false; // // wx.navigateTo({ // // url: '../match/match' // // }) // } // } // newData['isSelected' + index] = true; // 将当前点击的图片的选中状态设置为 true // } // this.setData(newData); // 使用 setData 方法更新页面数据 // // wx.navigateTo({ // // url: '../match/match' // // }) // }, onLoad(options) { this.setData({ imageUrl1: '../images/main.jpg', selectedImageUrl1: '../images/main.jpg', imageUrl2: '../images/match.jpg', selectedImageUrl2: '../images/match.jpg', imageUrl3: '../images/history.jpg', selectedImageUrl3: '../images/history.jpg', imageUrl4: '../images/recom.jpg', selectedImageUrl4: '../images/recom.jpg', }) } })