import {
  wxLogin
} from '../api/permission'

var token = ''

export function isLogin() {
  if (token == '') {
    return new Promise((resolve, reject) => {
      wx.login({
        success(res) {
          if (res.code) {
            //发起网络请求
            const respose = wxLogin({
              code: res.code
            })
            respose.then(function (data) {
              console.log(respose);
              token = respose.content.token
              console.log(token);
              resolve(true);
            })
          } else {
            console.log('登录失败！' + res.errMsg)
            reject(false);
          }
        }
      })
    })
  } else {
    return true;
  }
}

export function getToken() {
  console.log(token);
  return token;
}