123456789101112131415161718192021222324252627282930313233343536 |
- //app.js
- import { default as commonApi } from "./api/commonApi"
- import { default as userApi } from "./api/user"
- import { promisifyAll, promisify } from 'miniprogram-api-promise';
- const wxp = {}
- // promisify all wx's api
- promisifyAll(wx, wxp)
- App({
- onLaunch: async function () {
- // 展示本地存储能力
- if(!wx.getStorageSync('token')){
- const tokenData = await commonApi.getToken();
- if(tokenData.token){
- wx.setStorageSync('token', tokenData.token)
- }
- }
- // 登录
- const auth = await wxp.getSetting()
- if (!auth.authSetting['scope.userInfo']){
- console.log('您还没有授权');
- return
- }
- // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
- const info = await wxp.getUserInfo()
- this.globalData.userInfo = res.userInfo
- if (this.userInfoReadyCallback) {
- this.userInfoReadyCallback(res)
- }
- },
- globalData: {
- userInfo: null
- }
- })
|