app.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if (!wx.cloud) {
  15. console.error('请使用 2.2.3 或以上的基础库以使用云能力')
  16. } else {
  17. wx.cloud.init({
  18. // env 参数说明:
  19. // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
  20. // 此处请填入环境 ID, 环境 ID 可打开云控制台查看
  21. // 如不填则使用默认环境(第一个创建的环境)
  22. env: "msg-push-9ga0xxc9c4aa5242",
  23. traceUser: true,
  24. })
  25. wx.cloud.callFunction({
  26. name: 'getUser'
  27. }).then(res => {
  28. if (res.result.data !== undefined) {
  29. this.globalData.userInfo = res.result.data
  30. return wx.cloud.callFunction({
  31. name: 'listPublishers',
  32. data: {
  33. type: 'manage'
  34. }
  35. })
  36. }
  37. }).then(res => {
  38. if (res.result.list !== undefined) {
  39. this.globalData.pubInfo = res.result.list
  40. this.globalData.hasUserInfo = true
  41. if (this.onUserInfoReady) {
  42. this.onUserInfoReady()
  43. }
  44. }
  45. })
  46. }
  47. },
  48. globalData: {
  49. userInfo: null,
  50. hasUserInfo: false,
  51. openId: null,
  52. publisherId: null,
  53. noticeIndex: null,
  54. vibrate: null
  55. }
  56. })