app.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 展示本地存储能力
  5. var logs = wx.getStorageSync('logs') || []
  6. logs.unshift(Date.now())
  7. wx.setStorageSync('logs', logs)
  8. // // 登录
  9. // wx.login({
  10. // success: res => {
  11. // // 发送 res.code 到后台换取 openId, sessionKey, unionId
  12. // }
  13. // })
  14. // // 获取用户信息
  15. // wx.getSetting({
  16. // success: res => {
  17. // if (res.authSetting['scope.userInfo']) {
  18. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  19. // wx.getUserInfo({
  20. // success: res => {
  21. // // 可以将 res 发送给后台解码出 unionId
  22. // this.globalData.userInfo = res.userInfo
  23. // console.log(this.globalData.userInfo)
  24. // const db = wx.cloud.database()
  25. // db.collection("userInfoData").get({
  26. // success: function (user) {
  27. // if (user.data.length == 0) {
  28. // db.collection("userInfoData").add({
  29. // data: {
  30. // publisherId: []
  31. // },
  32. // success: function () {
  33. // this.globalData.publisherId = []
  34. // if (this.userInfoReadyCallback) {
  35. // this.userInfoReadyCallback(res)
  36. // }
  37. // }.bind(this)
  38. // })
  39. // } else {
  40. // this.globalData.publisherId = user.data[0].publisherId
  41. // if (this.userInfoReadyCallback) {
  42. // this.userInfoReadyCallback(res)
  43. // }
  44. // }
  45. // }.bind(this)
  46. // })
  47. // }
  48. // })
  49. // }
  50. // }
  51. // })
  52. if (!wx.cloud) {
  53. console.error('请使用 2.2.3 或以上的基础库以使用云能力')
  54. } else {
  55. wx.cloud.init({
  56. // env 参数说明:
  57. // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
  58. // 此处请填入环境 ID, 环境 ID 可打开云控制台查看
  59. // 如不填则使用默认环境(第一个创建的环境)
  60. env: "msg-push-9ga0xxc9c4aa5242",
  61. traceUser: true,
  62. })
  63. wx.cloud.callFunction({
  64. name: 'getUser'
  65. }).then(res => {
  66. if (res.result.data !== undefined) {
  67. this.globalData.userInfo = res.result.data
  68. return wx.cloud.callFunction({
  69. name: 'listPublishers',
  70. data: {
  71. type: 'manage'
  72. }
  73. })
  74. }
  75. }).then(res => {
  76. if (res.result.list !== undefined) {
  77. this.globalData.pubInfo = res.result.list
  78. this.globalData.hasUserInfo = true
  79. if (this.onUserInfoReady) {
  80. this.onUserInfoReady()
  81. }
  82. }
  83. })
  84. }
  85. },
  86. globalData: {
  87. userInfo: null,
  88. hasUserInfo: false,
  89. openId: null,
  90. publisherId: null,
  91. noticeIndex: null,
  92. vibrate: null
  93. }
  94. })