You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 line
3.1 KiB

  1. const app = getApp()
  2. const config = require("../../config/config")
  3. const Http = require("../../utils/HttpBasics.js")
  4. const navigationBarHeight = (getApp().statusBarHeight + 44) + "px"
  5. Page({
  6. data: {
  7. navigationBarHeight,
  8. imgHttps: app.globalData.imgHttps,
  9. userData: "",
  10. },
  11. onLoad: function () {
  12. console.log(123);
  13. let _this = this
  14. tt.login({
  15. success(_res) {
  16. let {code} = _res
  17. Http.post({
  18. url:config.api.login,
  19. data:{
  20. code:code,
  21. appId:'tt8183f73e1ebb053701'
  22. }
  23. }).then(res=>{
  24. Http.setToken(res.data.token);
  25. app.globalData.token = res.data.token
  26. tt.getUserInfo({// 获取用户信息
  27. withCredentials: true,
  28. // withRealNameAuthenticationInfo: true,
  29. success(res) {
  30. console.log(res);
  31. _this.setData({
  32. userData: res.userInfo
  33. })
  34. Http.get({
  35. url: config.api.checkUserInfo
  36. }).then(res => {
  37. }).catch(err=>{
  38. console.log("我没提交授权",err.code);
  39. if(err.code == 11004){
  40. Http.post({
  41. url:config.api.userInfo,
  42. data:{
  43. iv:res.iv,
  44. encryptedData:res.encryptedData
  45. }
  46. }).then(res=>{
  47. console.log(res);
  48. })
  49. }
  50. })
  51. },
  52. fail(res) {
  53. tt.navigateTo({
  54. url: 'pages/index/index' // 指定页面的url
  55. });
  56. },
  57. });
  58. }).catch(err=>{
  59. console.log(err);
  60. tt.showModal({
  61. title: '提示',
  62. showCancel: false,
  63. content: '登录失败,请重新尝试',
  64. success: (res) => {
  65. if (res.cancel) {
  66. //点击取消,默认隐藏弹框
  67. } else {
  68. //点击确定
  69. wx.reLaunch({
  70. url: '/pages/index/index',
  71. })
  72. }
  73. }
  74. });
  75. })
  76. },
  77. });
  78. }
  79. })