| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //app.js
- App({
- onLaunch: function () {
- // 展示本地存储能力
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now())
- wx.setStorageSync('logs', logs)
- // // 登录
- // wx.login({
- // success: res => {
- // // 发送 res.code 到后台换取 openId, sessionKey, unionId
- // }
- // })
- if (!wx.cloud) {
- console.error('请使用 2.2.3 或以上的基础库以使用云能力')
- } else {
- wx.cloud.init({
- // env 参数说明:
- // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
- // 此处请填入环境 ID, 环境 ID 可打开云控制台查看
- // 如不填则使用默认环境(第一个创建的环境)
- env: "msg-push-9ga0xxc9c4aa5242",
- traceUser: true,
- })
- wx.cloud.callFunction({
- name: 'getUser'
- }).then(res => {
- if (res.result.data !== undefined) {
- this.globalData.userInfo = res.result.data
- return wx.cloud.callFunction({
- name: 'listPublishers',
- data: {
- user_id: this.globalData.userInfo._id,
- page_token: 0,
- page_size: 25
- }
- })
- } else {
- return {
- result: {
- errMsg: 'please login first'
- }
- }
- }
- }).then(res => {
- if (res.result.list !== undefined) {
- this.globalData.pubInfo = res.result.list
- this.globalData.hasUserInfo = true
- if (this.onUserInfoReady) {
- this.onUserInfoReady()
- }
- }
- })
- }
- },
- globalData: {
- userInfo: null,
- hasUserInfo: false,
- openId: null,
- publisherId: null,
- noticeIndex: null,
- vibrate: null
- }
- })
|