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

60 行
1.4 KiB

  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 登录
  5. wx.login({
  6. success: res => {
  7. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  8. console.log("login", res);
  9. }
  10. })
  11. // 获取用户信息
  12. wx.getSetting({
  13. success: res => {
  14. if (res.authSetting['scope.userInfo']) {
  15. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  16. wx.getUserInfo({
  17. success: res => {
  18. // 可以将 res 发送给后台解码出 unionId
  19. this.globalData.userInfo = res.userInfo
  20. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  21. // 所以此处加入 callback 以防止这种情况
  22. if (this.userInfoReadyCallback) {
  23. this.userInfoReadyCallback(res)
  24. }
  25. }
  26. })
  27. }
  28. }
  29. })
  30. this.getLocation()
  31. // setTimeout(() => {
  32. // this.globalData.market={
  33. // name:"陕西大悦城"
  34. // }
  35. // }, 1000);
  36. },
  37. /**
  38. * 获取地址位置信息
  39. */
  40. getLocation:function (){
  41. wx.getLocation({
  42. type: 'wgs84',
  43. success: function (res) {
  44. console.log("getLocation", res);
  45. },
  46. fail:error=>{
  47. console.log(error);
  48. }
  49. })
  50. },
  51. globalData: {
  52. // 当前用户信息
  53. userInfo: null,
  54. // 当前商场信息
  55. market:{
  56. name:"陕西大悦城"
  57. }
  58. }
  59. })