// pages/user/user.js import { http } from '../../utils/util' Page({ /** * 页面的初始数据 */ data: { user_avatar: '/images/img_tx_ydl@2x.png', user_name: '点击登录', user_tip: '登录获得更多信息', balance: 0, user_data: [{ name: '我的收藏夹', img: '/images/ic_scscj@3x.png', url: '/pages/user/subpage/newest/newest' }, { name: '我的任务', img: '/images/ic_wdrw@3x.png', url: '/pages/user/subpage/quest/quest' }, { name: '通用教程', img: '/images/ic_tyjc@3x.png', url: '/pages/user/subpage/tutorial/tutorial' }], skills: [{ name: "账号关联", image: '/images/ic_zhgl@3x.png', url: '/pages/user/subpage/relation/relation' }, { name: "系统消息", image: '/images/ic_xtxx@3x.png', url: '/pages/user/subpage/system/system' }, { name: "线索收集", image: '/images/ic_xxsj@3x.png', url: '/pages/user/subpage/colllection/colllection' }, { name: "设置", image: '/images/ic_sz@3x.png', url: '/pages/user/subpage/setup/setup' }, ], userInfo: {}, canIUse: wx.canIUse('button.open-type.getUserInfo'), canIUseGetUserProfile: false, canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), phone: false }, to(e) { wx.navigateTo({ url: e.currentTarget.dataset.url, }) }, userlogin() { wx.login({ success: res => { this.setData({ code: res.code }) http("/user/login", "post", { code: res.code }).then(res => { if (res.msg === "未注册!") { this.getUserProfile() } else { getApp().globalData.token = res.data.token this.setData({ user_avatar:res.data.user.avatar, user_name:res.data.user.name, user_tip:'欢迎来到星途~' }) wx.setStorage({ key: 'user', data: res.data.user }) wx.setStorage({ key: 'token', data: res.data.token }) wx.getStorage({ key: 'token', success (res) { } }) } }) } }) }, getUserProfile(e) { let that = this // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.login({ success: loginRes => { wx.showModal({ title: '温馨提示', content: '进一步获取用户信息', success() { wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (userRes) => { that.setData({ iv: userRes.iv, encryptedData: userRes.encryptedData, code: loginRes.code, phone: true }) } }) } }) } }) }, getPhoneNumber(e) { this.setData({ phone: false }) let that = this let param = { userinfo: { iv: this.data.iv, encryptedData: this.data.encryptedData }, phone: { iv: e.detail.iv, encryptedData: e.detail.encryptedData }, code: this.data.code } http("/user/register", "post", param).then(res => { wx.showToast({ title: '注册成功,请再次点击头像登录', icon: 'none', duration: 2000 }) }) }, colse () { this.data({ phone: false }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.setNavigationBarTitle({ title: '', success: function (res) {} }) if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })