业务交流通
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

login.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/login/login.js
  2. const app = getApp()
  3. const $request = require('../../utils/request.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: {},
  10. // 是否获取到了用户信息
  11. hasUserInfo: false,
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. },
  18. // 获取手机号授权
  19. getPhoneNumber(e) {
  20. console.log(e);
  21. if (!!e.detail.iv && !!e.detail.encryptedData) {
  22. const iv = e.detail.iv
  23. const encryptedData = e.detail.encryptedData
  24. this.appletLogin(iv, encryptedData)
  25. } else {
  26. wx.showToast({
  27. title: '请允许授权',
  28. icon: "none",
  29. duration: 3000
  30. })
  31. }
  32. },
  33. // 保存用户信息
  34. appletLogin(iv, encryptedData) {
  35. let { nickName, gender, country, city, province, avatarUrl } = this.data.userInfo;
  36. $request.get('/com/appletLogin.action', {
  37. // openid: app.globalData.openid,
  38. iv: iv,
  39. encryptedData: encryptedData,
  40. sessionKey: app.globalData.sessionKey,
  41. loginState: "业务交流通",
  42. avatarUrl,
  43. gender,
  44. nickName,
  45. country,
  46. province,
  47. city
  48. }).then(res => {
  49. // console.log(res,'保存用户信息返回的Res')
  50. this.getUserSession()
  51. }).catch(error => {
  52. console.log(error, 'error appletLogin')
  53. })
  54. },
  55. // 获取用户信息弹框
  56. onCheckboxChange() {
  57. if (!this.data.hasUserInfo) {
  58. this.getUserProfile()
  59. } else {
  60. this.setData({
  61. userInfo: {},
  62. hasUserInfo: false
  63. })
  64. }
  65. },
  66. // 获取用户信息
  67. getUserProfile(e) {
  68. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  69. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  70. wx.getUserProfile({
  71. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  72. success: (res) => {
  73. this.setData({
  74. userInfo: res.userInfo,
  75. hasUserInfo: true
  76. })
  77. },
  78. fail: () => {
  79. wx.showToast({
  80. title: '请允许授权',
  81. icon: "none",
  82. duration: 3000
  83. })
  84. }
  85. })
  86. },
  87. // 保存个人信息后拿到新数据
  88. getUserSession() {
  89. let that = this
  90. wx.showLoading({
  91. title: '加载中',
  92. mask: true
  93. })
  94. $request.post('/script/getSession.action', {}).then(res => {
  95. console.log(res,'getUserSession---res')
  96. wx.hideLoading()
  97. app.globalData.customerId = res.data.customer.customerId
  98. // wx.navigateTo({
  99. // url: "/pages/mine/mine", //跳转页面的路径,可带参数 ?隔开,不同参数用 & 分隔;相对路径,不需要.wxml后缀
  100. // success: function () {}, //成功后的回调;
  101. // fail: function () {}, //失败后的回调;
  102. // complete: function () {} //结束后的回调(成功,失败都会执行)
  103. // })
  104. }).catch(error => {
  105. console.log(error, "获取error")
  106. })
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. }
  113. })