index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const app = getApp()
  2. const httpUtils = require('../../utils/http.js')
  3. const ui = require('../../utils/ui.js')
  4. Page({
  5. data: {
  6. tab: 1
  7. },
  8. onShow(){
  9. if(wx.getStorageSync('token')){
  10. this.setData({
  11. tab: 2
  12. })
  13. }else{
  14. this.setData({
  15. tab: 1
  16. })
  17. }
  18. },
  19. toOut(){
  20. wx.removeStorageSync('token')
  21. wx.removeStorageSync('phone')
  22. wx.removeStorageSync('openId')
  23. wx.removeStorageSync('code')
  24. this.setData({
  25. tab: 1
  26. })
  27. },
  28. toLogin(){
  29. wx.login({
  30. success (res) {
  31. if (res.code) {
  32. console.log("code",res)
  33. let code = res.code
  34. wx.setStorageSync('code', res.code)
  35. // 调userinfo接口
  36. let obj = {
  37. url: '/userInfo',
  38. data: {
  39. code: code
  40. }
  41. }
  42. httpUtils.request(obj).then(res1=>{
  43. console.log("userInfo",res1)
  44. wx.setStorageSync('openId', res1.data.data)
  45. wx.navigateTo({
  46. url: '/pages/submitPhone/index',
  47. })
  48. }).catch(err=>{
  49. console.log('ERROR',err)
  50. });
  51. }
  52. }
  53. })
  54. }
  55. })