click_Jurisdiction.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const app = getApp();
  2. Page({
  3. data: {
  4. canIUse: wx.canIUse('button.open-type.getUserInfo')
  5. },
  6. onLoad() {
  7. setTimeout(function () {
  8. wx.hideLoading()
  9. })
  10. },
  11. bindGetUserInfo(e) {
  12. var that = this;
  13. app.showLoading();
  14. wx.login({
  15. success: function (res) {
  16. console.log(res.code)
  17. if (res.code) {
  18. wx.getUserInfo({
  19. withCredentials: true,
  20. success: function (res_user) {
  21. console.log(res_user);
  22. console.log(res_user.userInfo.avatarUrl);
  23. console.log(res_user.userInfo.city);
  24. console.log(res_user.userInfo.country);
  25. console.log(res_user.userInfo.gender);
  26. console.log(res_user.userInfo.language);
  27. console.log(res_user.userInfo.nickName);
  28. console.log(res_user.userInfo.province);
  29. let p_url = 'public/wxlogin';
  30. let p_data = {
  31. encryptedData: res_user.encryptedData,
  32. iv: res_user.iv,
  33. code: res.code,
  34. headimgurl: res_user.userInfo.avatarUrl,
  35. city: res_user.userInfo.city,
  36. country: res_user.userInfo.country,
  37. sex: res_user.userInfo.gender,
  38. language: res_user.userInfo.language,
  39. nickname: res_user.userInfo.nickName,
  40. province: res_user.userInfo.province,
  41. };
  42. app.postRequest(p_url, p_data, function (res) {
  43. console.log(res);
  44. if (res.code==201){
  45. app.cancelLoading();
  46. if (res.data.openid && res.data.wx_id){
  47. wx.navigateTo({
  48. url: '/pages/Landpage/Land/Land'
  49. })
  50. }
  51. }
  52. // console.log(res.data.openid);
  53. // that.setData({
  54. // selectArray: 123
  55. // })
  56. // 同步传参
  57. try {
  58. wx.setStorageSync('openid', res.data.openid)
  59. } catch (e) {
  60. }
  61. // 同步传参
  62. try {
  63. wx.setStorageSync('wx_id', res.data.wx_id)
  64. } catch (e) {
  65. }
  66. })
  67. }, fail: function () {
  68. wx.showToast({
  69. title: '您拒绝了,无法登陆,请重新授权',
  70. icon: 'none', // 不显示图标
  71. mask: true, // 是否显示透明蒙层,防止触摸穿透
  72. duration: 3000
  73. })
  74. // console.log('您拒绝了,无法登陆,请重新授权');
  75. }, complete: function (res) {
  76. }
  77. })
  78. }
  79. }
  80. })
  81. },
  82. }) // Page