/**
 * 登录
 * @param {object} {token}
 * return Pomise
 */
 import { getWatchLoginInfo } from '../API/apiAll';
 import store from '@/store/index'
 // import Layer from '@/plugins/Layer/index'; //登陆成功
 import Cookie from 'js-cookie'
 import { getQueryVariable } from '../Utils/index'
 
 export const login = async function({token} = {token: ''}) {
  Cookie.set('token', token, { expires: 10 });
  const { id, uin, liveNowStatus } = store().getters['channelInfo']
  const res = await getWatchLoginInfo({
    id, uin
  });
  if (res.code === 200 && res.errorCode === 0) {
    const info = res.data.watchUserInfo;
    store().commit('set_userInfo', info)
    const referer = {refererId: getQueryVariable('refererId')}
    // 邀请统计
    if (referer.refererId && info.id) {
      store().dispatch('invitation', referer)
    }
    // 数据统计相关 
    store().dispatch('PostInfo')
    // 用户行为
    const Inkmarks = require('@gdyfe/ink-marks');
    Inkmarks.setUser({
      id: Number(info.id) || 0,
      username: info.userNick || '游客'
    });
    const websocketHeartbeat = require('../websocketHeartbeat').default;
    websocketHeartbeat().useIt('userInfo', {
      "userId": info.id || 0,
      //  "token": this.token,
      "id": id,
      "type":"live",
      "uin": uin,
      "liveNowStatus": liveNowStatus
    })
  }
   return this
 }