C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

88 行
2.1 KiB

  1. //app.js
  2. App({
  3. data: {
  4. appId: ''
  5. },
  6. onLaunch: function() {
  7. // 登录
  8. wx.login({
  9. success: res => {
  10. wx.request({
  11. url: 'https://ciformall.youlane.cn/C/api/user/login',
  12. header: {
  13. "content-type": "application/json;charset=UTF-8"
  14. },
  15. data: {
  16. appId: "wx649b3be73c1afe47",
  17. code: res.code
  18. },
  19. method: 'POST',
  20. success: (result)=>{
  21. console.log(result)
  22. this.globalData.openId = result.data.data.openId
  23. }
  24. })
  25. // Http.postResquest('/api/user/login', '登录中', {
  26. // appId: "wx649b3be73c1afe47",
  27. // code: result.code
  28. // }, (res) => {
  29. // console.log(res)
  30. // })
  31. }
  32. })
  33. // 获取用户信息
  34. wx.getSetting({
  35. success: res => {
  36. if (res.authSetting['scope.userInfo']) {
  37. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  38. wx.getUserInfo({
  39. success: res => {
  40. // 可以将 res 发送给后台解码出 unionId
  41. this.globalData.userInfo = res.userInfo
  42. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  43. // 所以此处加入 callback 以防止这种情况
  44. if (this.userInfoReadyCallback) {
  45. this.userInfoReadyCallback(res)
  46. }
  47. }
  48. })
  49. }
  50. }
  51. })
  52. this.getLocation()
  53. // setTimeout(() => {
  54. // this.globalData.market={
  55. // name:"陕西大悦城"
  56. // }
  57. // }, 1000);
  58. },
  59. /**
  60. * 获取地址位置信息
  61. */
  62. getLocation: function() {
  63. wx.getLocation({
  64. type: 'wgs84',
  65. success: function(res) {
  66. console.log("getLocation", res);
  67. },
  68. fail: error => {
  69. console.log(error);
  70. }
  71. })
  72. },
  73. globalData: {
  74. // 当前用户信息
  75. userInfo: null,
  76. openId:null,
  77. // 当前商场信息
  78. market: {
  79. name: "陕西大悦城"
  80. }
  81. },
  82. getAppid() {
  83. let appId = "wx649b3be73c1afe47"
  84. return appId
  85. }
  86. })