app.js 1.96 KB
import { getYHStorageSync } from './utils/util';
import {WeToast} from './vendors/toast/wetoast';
import { ttLogin, addLoginListenner } from './login/utils/login/login';
import { Event } from './login/utils/index';

global.event = new Event();

App({
  globalData: {
    selectedChannel: 'boy',
    userInfo: {},
    systemInfo: null,
    WXThird_session: '',
    WXUnion_ID: '',
    openID: '',
    verifyKey: '',
    sessionkey: '',
    sid: '',
    udid: '',
    cid: '1',
    mobileRegisterState: '',
    hasReportAwakeAction: 'false',
    defraudurl: 'https://activity.yoho.cn/feature/45.html?title=防诈骗提醒',
    union_type: '', // 渠道号,大数据上传用
    union_type_time: '',
    ch: '',
    networkType: '0',
    deviceInfo: {},
    currentScene: 1001,
    user_union_type: '', // 用户相关unionType 要与union_type区分开
    user_union_type_imageUrl: '', // 联盟图片
    user_nounion_type_imageUrl: '', // 非联盟用户分享banner图片
    shareId: '',
    shareInfo: {},
    open_id: ''
},
  onLaunch: function () {
    let res = tt.getSystemInfoSync();
    if (!res.screenHeight) {
      res.screenHeight = res.windowHeight;
    }
    if (!res.screenWidth) {
      res.screenWidth = res.windowWidth;
    }

    this.globalData.systemInfo = res;
    ttLogin();
    addLoginListenner();
  },

  getUserInfo() {
    let userInfo = getYHStorageSync('userInfo', 'app');
    this.globalData.userInfo = userInfo || {};
  },

  isLogin: function () {
    return this.globalData.userInfo.uid > 0 ? true : false
  },
  getUid: function() {
    let uid = this.globalData.userInfo.uid || 0;
    
    if (!uid || uid === 0) {
        this.getUserInfo();
        uid = this.globalData.userInfo.uid || 0;
    }
    return uid;
  },
  clearUserSession() {},
  getSessionkey: function() {
      let sessionKey = getYHStorageSync('sessionkey', 'app');
      if (sessionKey) {
          this.globalData.sessionkey = sessionKey;
      }
      return sessionKey || '';
  },
  WeToast
})