123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import {
- userLogin,
- getMyInfo
- } from '~/api/user'
- import {
- createStoreBindings
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- let storeBindings
- App({
- onLaunch() {
- this.checkIsIos()
- this.getNavbarInfo()
- },
- async onShow(options) {
- this.storeBindings = createStoreBindings(this, {
- store,
- actions: ['setUser']
- })
- let shareUid = options.query.uid
- let uid = wx.getStorageSync('uid')
- if (uid) {
- let userInfo = await getMyInfo()
- this.setUser(userInfo.user)
- if (getApp().callBack) {
- getApp().callBack();
- }
- } else {
- this.login(shareUid)
- }
- },
- login(shareUid) {
- wx.login({
- success: async (res) => {
- if (res.code) {
-
- let data = {
- code: res.code,
- shareUid
- }
- let userRes = await userLogin(data)
- this.setUser(userRes.data)
- wx.setStorageSync('uid', userRes.data.uid)
- wx.setStorageSync('user', userRes.data)
- this.globalData.userInfo = userRes.data
- if (getApp().callBack) {
- getApp().callBack(userRes);
- }
- }
- }
- })
- },
- checkIsIos: function () {
- wx.getSystemInfo({
- success: (res) => {
- if (res.system.search('iOS') != -1) {
- this.globalData.isIOS = true
- }
- }
- })
- },
- getNavbarInfo() {
-
- const systemInfo = wx.getSystemInfoSync();
-
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect();
-
- this.globalData.navBarHeight = systemInfo.statusBarHeight + 44;
- this.globalData.menuRight = systemInfo.screenWidth - menuButtonInfo.right;
- this.globalData.menuTop = menuButtonInfo.top;
- this.globalData.menuHeight = menuButtonInfo.height;
- },
- globalData: {
- userInfo: null,
- isIOS: false,
- navBarHeight: 0,
- menuRight: 0,
- menuTop: 0,
- menuHeight: 0,
- }
- })
|