C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

82 lignes
2.0 KiB

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