
const ACCESS_TOKEN = 'LUMI_WEB_TOKEN';
const KEY_PAYMENT = "LUMI_WEB_SECRET_ID"

export default {
  /**
   * 获取登录令牌
   * @param {Boolean} again 内部调用
   */
  getToken(again) {
    if (again || getApp().globalData.TOKEN) {
      return getApp().globalData.TOKEN;
    }
    getApp().globalData.TOKEN = uni.getStorageSync(ACCESS_TOKEN);
    return this.getToken(true);
  },
  /**
   * 设置登录令牌
   * @param {String} token 令牌
   */
  setToken(token) {
    getApp().globalData.TOKEN = token;
    uni.setStorageSync(ACCESS_TOKEN, token);
  },
  /**
   * 获取支付ID
   */
  getPaymentId(again) {
    if (again || getApp().globalData.paymentId) {
      return getApp().globalData.paymentId;
    }
    getApp().globalData.paymentId = uni.getStorageSync(KEY_PAYMENT);
    return this.getPaymentId(true);
  },
  /**
   * 设置支付ID
   */
  setPaymentId(id) {
    getApp().globalData.paymentId = id;
    uni.setStorageSync(KEY_PAYMENT, id);
  },
  /**
   * 是否登录
   */
  isLogin() {
    const token = this.getToken();
    return token ? true : false;
  },
  /**
   * 注销登录
   */
  logout() {
    this.setToken('')
    this.setPaymentId('')
  }
}