12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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
- }
- let {
- scene
- } = wx.getLaunchOptionsSync()
-
- this.globalData.desktopTips = this.globalData.isIOS ? scene != 1104 : scene != 1023
- }
- })
- },
- 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,
- desktopTips: false,
- navBarHeight: 0,
- menuRight: 0,
- menuTop: 0,
- menuHeight: 0,
- }
- })
|