app.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.status !== 'OK') {
  29. return res.result
  30. }
  31. this.globalData.userInfo = res.result.data
  32. return wx.cloud.callFunction({
  33. name: 'listPublishers',
  34. data: {
  35. user_id: this.globalData.userInfo._id,
  36. page_token: 0,
  37. page_size: 20
  38. }
  39. })
  40. }).then(res => {
  41. if (res.result.status !== 'OK') {
  42. return
  43. }
  44. this.globalData.pubInfo = res.result.list
  45. this.globalData.hasUserInfo = true
  46. if (this.onUserInfoReady) {
  47. this.onUserInfoReady()
  48. }
  49. })
  50. }
  51. },
  52. globalData: {
  53. userInfo: {},
  54. pubInfo: [],
  55. hasUserInfo: false,
  56. openId: null,
  57. noticeIndex: null,
  58. vibrate: null
  59. }
  60. })