From 1929fc9c7dab1ac1cfd70a60b663a60c76de8328 Mon Sep 17 00:00:00 2001 From: chenbo <623659388@qq.com> Date: Tue, 20 Apr 2021 14:54:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E5=AE=98=E6=96=B9=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wx-mini-program/pages/auth/login/login.js | 33 ++++++++++++++++++++- wx-mini-program/pages/auth/login/login.wxml | 3 +- wx-mini-program/project.config.json | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/wx-mini-program/pages/auth/login/login.js b/wx-mini-program/pages/auth/login/login.js index 5a6677c..196c4d0 100644 --- a/wx-mini-program/pages/auth/login/login.js +++ b/wx-mini-program/pages/auth/login/login.js @@ -4,10 +4,17 @@ var user = require('../../../utils/user.js'); var app = getApp(); Page({ + data: { + canIUseGetUserProfile: false, // 用于向前兼容 + }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 // 页面渲染完成 - + if (wx.getUserProfile) { + this.setData({ + canIUseGetUserProfile: true + }) + } }, onReady: function() { @@ -23,6 +30,30 @@ Page({ // 页面关闭 }, + getUserProfile(e) { + // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 + // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 + wx.getUserProfile({ + desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 + success: (res) => { + user.checkLogin().catch(() => { + user.loginByWeixin(res.userInfo).then(res => { + app.globalData.hasLogin = true; + wx.navigateBack({ + delta: 1 + }) + }).catch((err) => { + app.globalData.hasLogin = false; + util.showErrorToast('微信登录失败'); + }); + }); + }, + fail: (res) => { + app.globalData.hasLogin = false; + util.showErrorToast('微信登录失败'); + } + }); + }, wxLogin: function(e) { if (e.detail.userInfo == undefined) { app.globalData.hasLogin = false; diff --git a/wx-mini-program/pages/auth/login/login.wxml b/wx-mini-program/pages/auth/login/login.wxml index c2b604b..6541f71 100644 --- a/wx-mini-program/pages/auth/login/login.wxml +++ b/wx-mini-program/pages/auth/login/login.wxml @@ -1,6 +1,7 @@ - + + \ No newline at end of file diff --git a/wx-mini-program/project.config.json b/wx-mini-program/project.config.json index d3b359c..7558867 100644 --- a/wx-mini-program/project.config.json +++ b/wx-mini-program/project.config.json @@ -19,7 +19,7 @@ } }, "compileType": "miniprogram", - "libVersion": "2.9.4", + "libVersion": "2.16.0", "appid": "wx4901b319ace4f88a", "projectname": "dts-shop", "simulatorType": "wechat",