index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import $ from './../../utils/Tool';
  2. const app = getApp();
  3. const AUTH = require('../../utils/auth');
  4. import {userSave,getuserPhone} from "../../requests/api";
  5. import router from '../../utils/router';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. phonePop:false,
  12. wxqcode:'',
  13. },
  14. getUserInfoFn(res){
  15. if(res.detail.errMsg==='getUserInfo:ok'){
  16. $.store.set('userInfo',res.detail.userInfo)
  17. }
  18. this.setData({phonePop:true});
  19. },
  20. bindGetPhoneNumber(e){
  21. if (e.detail.errMsg == "getPhoneNumber:ok"){
  22. let isLogined = AUTH.checkHasLogined();
  23. if(isLogined){
  24. var data={};
  25. data.encryptedData=e.detail.encryptedData;
  26. data.iv=e.detail.iv;
  27. data.openid=wx.getStorageSync('openId') || app.globalData.openId;
  28. getuserPhone(data).then(async result=>{
  29. if(result.result==="success"){
  30. $.store.set('phoneNumber',result.phoneNumber);
  31. await this.creatUser();
  32. this.goHome();
  33. }
  34. })
  35. }
  36. }else{
  37. this.goHome();
  38. }
  39. },
  40. goHome(){
  41. // let pages = getCurrentPages();
  42. // let prevPage = pages[ pages.length - 2 ];
  43. // prevPage.setData({
  44. // formAuth:true,
  45. // })
  46. router.reLaunch();
  47. },
  48. onClose(event){
  49. if(event.detail==="cancel"){
  50. this.setData({phonePop:false});
  51. $.store.set('clickPhone',true)
  52. this.goHome();
  53. }
  54. },
  55. // 创建用户
  56. async creatUser(){
  57. const data={};
  58. data.phone = $.store.get('phoneNumber');
  59. data.openId =$.store.get('openId') ||$.storage.get('openId');
  60. // console.log($.store.get('openId') ,$.storage.get('openId'),"$.storage.get('openId')")
  61. const {nickName} = $.store.get('userInfo')
  62. data.nickname=nickName;
  63. // data.userName=app.globalData.userInfo.nickName;
  64. console.log(data);
  65. let res = await userSave(data);
  66. if(res.result==="success"){
  67. $.store.set('userId',res.id);
  68. $.storage.set('userId', res.id);
  69. // $.store.set('userId',data.openId);
  70. // $.storage.set('userId', data.openId);
  71. $.storage.set('logined',true);
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function (options) {
  78. },
  79. onshow(){
  80. },
  81. })