123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // pages/login/login.js
- const app = getApp()
- const $request = require('../../utils/request.js');
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
-
- userInfo: {},
- // 是否获取到了用户信息
- hasUserInfo: false,
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
-
- // 获取手机号授权
- getPhoneNumber(e) {
- console.log(e);
- if (!!e.detail.iv && !!e.detail.encryptedData) {
- const iv = e.detail.iv
- const encryptedData = e.detail.encryptedData
- this.appletLogin(iv, encryptedData)
- } else {
- wx.showToast({
- title: '请允许授权',
- icon: "none",
- duration: 3000
- })
- }
- },
- // 保存用户信息
- appletLogin(iv, encryptedData) {
- let { nickName, gender, country, city, province, avatarUrl } = this.data.userInfo;
- $request.get('/com/appletLogin.action', {
- // openid: app.globalData.openid,
- iv: iv,
- encryptedData: encryptedData,
- sessionKey: app.globalData.sessionKey,
- loginState: "业务交流通",
- avatarUrl,
- gender,
- nickName,
- country,
- province,
- city
- }).then(res => {
- // console.log(res,'保存用户信息返回的Res')
- this.getUserSession()
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
- // 获取用户信息弹框
- onCheckboxChange() {
- if (!this.data.hasUserInfo) {
- this.getUserProfile()
- } else {
- this.setData({
- userInfo: {},
- hasUserInfo: false
- })
- }
- },
- // 获取用户信息
- getUserProfile(e) {
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
- // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- },
- fail: () => {
- wx.showToast({
- title: '请允许授权',
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- // 保存个人信息后拿到新数据
- getUserSession() {
- let that = this
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- $request.post('/script/getSession.action', {}).then(res => {
- console.log(res,'getUserSession---res')
- wx.hideLoading()
- app.globalData.customerId = res.data.customer.customerId
- // wx.navigateTo({
- // url: "/pages/mine/mine", //跳转页面的路径,可带参数 ?隔开,不同参数用 & 分隔;相对路径,不需要.wxml后缀
- // success: function () {}, //成功后的回调;
- // fail: function () {}, //失败后的回调;
- // complete: function () {} //结束后的回调(成功,失败都会执行)
- // })
-
- }).catch(error => {
- console.log(error, "获取error")
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|