app.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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
  30. }
  31. this.globalData.userInfo = res.result.data
  32. return wx.cloud.callFunction({
  33. name: 'listPublishers',
  34. data: {
  35. manager: true,
  36. page_token: 0,
  37. page_size: 20
  38. }
  39. })
  40. }).then(res => {
  41. if (res.result.status !== 'OK') {
  42. this.globalData.hasUserInfo = false
  43. this.globalData.userNotFound = true
  44. if (this.onUserInfoChange) {
  45. this.onUserInfoChange()
  46. }
  47. return
  48. }
  49. this.globalData.pubInfo = res.result.list
  50. this.globalData.hasUserInfo = true
  51. this.globalData.userNotFound = false
  52. if (this.onUserInfoChange) {
  53. this.onUserInfoChange()
  54. }
  55. })
  56. }
  57. },
  58. globalData: {
  59. userInfo: {},
  60. pubInfo: [],
  61. pubIndex: 0,
  62. hasUserInfo: false,
  63. userNotFound: false,
  64. openId: null,
  65. notiForm: 0
  66. }
  67. })