export default {

  setLoginInfo: function (loginInfo) {
    var _self = this;

    _self.clearLocalStorage();

    _self.setLocalStorage(loginInfo);

  },


  //  设置localStorage
  setLocalStorage: function (loginInfo) {
    localStorage.setItem('#LoginInfo', JSON.stringify(loginInfo));
    localStorage.setItem('#token', loginInfo.token);
    localStorage.setItem('#accountId', loginInfo.accountId);
  },

  clearLocalStorage: function () {
    // 清理localStorage时需要保留的参数列表
    var reserveParams = ['hostPageBaseURL', 'workShopId', 'resourceInstanceId',
      'resourceInstanceName', 'apsBaseUrl', 'cameraBaseURL', '#rememberPassword', '#userName', '#password', '#languageSelected'];
    //存放的信息
    var reserveParamValues = [];

    //获取参数信息 
    var len = reserveParams.length;
    for (let i = 0; i < len; i++) {
      var reserveParam = reserveParams[i];
      var reserveParamValue = '';
      if (localStorage.getItem(reserveParam) != undefined) {
        reserveParamValue = localStorage.getItem(reserveParam);
      }
      reserveParamValues.push(reserveParamValue);
    }

    //清理localStorage
    window.localStorage.clear();

    //还原参数信息
    for (let i = 0; i < len; i++) {
      localStorage.setItem(reserveParams[i], reserveParamValues[i]);
    }
  },

};