业务交流通
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

login.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: null,
  10. // 是否获取到了用户信息
  11. hasUserInfo: false,
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. const userInfo = wx.getStorageSync('userInfo') || null;
  18. if (app.globalData.userInfo || userInfo) {
  19. this.setData({
  20. userInfo
  21. })
  22. }
  23. },
  24. onShow(){
  25. this.setData({
  26. currentIndex: 2
  27. })
  28. },
  29. // 获取手机号授权
  30. getPhoneNumber(e) {
  31. console.log(e);
  32. if (!!e.detail.iv && !!e.detail.encryptedData) {
  33. const iv = e.detail.iv
  34. const encryptedData = e.detail.encryptedData
  35. this.appletLogin(iv, encryptedData)
  36. } else {
  37. wx.showToast({
  38. title: '请允许授权',
  39. icon: "none",
  40. duration: 3000
  41. })
  42. }
  43. },
  44. // 保存用户信息
  45. appletLogin(iv, encryptedData) {
  46. wx.showLoading({
  47. title: '登录中...',
  48. mask: true
  49. })
  50. let { nickName, gender, country, city, province, avatarUrl } = this.data.userInfo;
  51. $request.get('/com/appletLogin.action', {
  52. // openid: app.globalData.openid,
  53. iv: iv,
  54. encryptedData: encryptedData,
  55. sessionKey: app.globalData.sessionKey,
  56. loginState: "需求对对碰",
  57. avatarUrl,
  58. gender,
  59. nickName,
  60. country,
  61. province,
  62. city
  63. }).then(res => {
  64. console.log(res, '保存用户信息返回的Res')
  65. this.getUserSession()
  66. }).catch(error => {
  67. console.log(error, 'error appletLogin')
  68. })
  69. },
  70. // 获取用户信息弹框
  71. onCheckboxChange() {
  72. if (!this.data.hasUserInfo) {
  73. if (!this.data.userInfo) {
  74. this.getUserProfile()
  75. } else {
  76. this.setData({
  77. hasUserInfo: true
  78. })
  79. }
  80. } else {
  81. this.setData({
  82. hasUserInfo: false
  83. })
  84. }
  85. },
  86. // 获取用户信息
  87. getUserProfile(e) {
  88. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  89. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  90. wx.getUserProfile({
  91. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  92. lang:"zh_CN",
  93. success: (res) => {
  94. this.setData({
  95. userInfo: res.userInfo,
  96. hasUserInfo: true
  97. })
  98. wx.setStorageSync('userInfo', res.userInfo)
  99. },
  100. fail: () => {
  101. wx.showToast({
  102. title: '请允许授权',
  103. icon: "none",
  104. duration: 3000
  105. })
  106. }
  107. })
  108. },
  109. // 保存个人信息后拿到新数据
  110. getUserSession() {
  111. let that = this
  112. $request.post('/script/getSession.action', {}).then(res => {
  113. wx.hideLoading()
  114. console.log(res, '返回的res')
  115. let businessCommunicationCustomer = res.data.businessCommunicationCustomer;
  116. app.globalData.customerId = businessCommunicationCustomer.customerId;
  117. app.globalData.customer = res.data.customer;
  118. app.globalData.businessCommunicationCustomer = businessCommunicationCustomer;
  119. wx.setStorageSync('businessCommunicationCustomer', businessCommunicationCustomer)
  120. let pages = getCurrentPages();
  121. let Page = pages[pages.length - 1];//当前页
  122. let prevPage = pages[pages.length - 2]; //上一个页面
  123. let info = prevPage.data //取上页data里的数据也可以修改
  124. // 如果是上一页是我的页面
  125. if (prevPage.route == "pages/myModule/index") {
  126. if (res.data.customer.paidByMonth) {
  127. businessCommunicationCustomer.nickName = res.data.customer.nickName;
  128. businessCommunicationCustomer.isPartner = true;
  129. } else {
  130. businessCommunicationCustomer.isPartner = false;
  131. }
  132. prevPage.setData({
  133. user: businessCommunicationCustomer,
  134. isLogin:true
  135. })
  136. wx.navigateBack()
  137. } else {
  138. wx.navigateBack()
  139. }
  140. // let tempListData = info.listData;
  141. // tempListData.forEach(el => {
  142. // if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  143. // el.info = Page.data.detailValue
  144. // }
  145. // })
  146. // prevPage.setData({ listData: tempListData })//设置数据
  147. // wx.navigateBack()
  148. }).catch(error => {
  149. console.log(error, "获取error")
  150. })
  151. },
  152. })