layuiadmin 前端token驗證


//驗證token
    $(function () {
      var authorization = localStorage.getItem('layuiAdmin');
      var resmsg = ['invalid','blacklist','expired'];
      //設置請求頭
      if(typeof JSON.parse(authorization).authorization == 'undefined'){
        var header = {'authorization':''};
      } else {
        var header = {'authorization': 'bearer '+ JSON.parse(authorization).authorization};
      }
      //接口驗證
      $.ajax({
        url:'http://myblog.cn:8080/api/jump',//接口
        type:'get',
        headers:header,
        success:function (res) {
          if (resmsg.includes(res.msg)) {
            layer.msg(res.content, {
              icon: 5,
            }, function () {
              localStorage.removeItem('layuiAdmin');
              location.reload();
            });
          } else {
            switch (res.msg) {
              case "refresh":
                layui.data(setter.tableName, {
                  key: setter.request.tokenName
                  ,value: res.content
                });
                break;
              case "ok":
                // location.href = '/home.html';
                break;
            }
          }
        }
      });
    });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM