<blockquote id="shwb3"><ruby id="shwb3"></ruby></blockquote>
  • <small id="shwb3"><strong id="shwb3"></strong></small>

      1. <big id="shwb3"></big>
        1. 首页 > 其他 > 详细

          0326

          时间:2019-03-26 22:24:14      阅读:27      评论:0      收藏:0      [点我收藏+]

          标签:color   eof   creat   split   iss   innerhtml   权限   rmi   arr   

          /**
           * 为按钮添加权限
           * @author hpf
           * @since 2019-03-25
           */
          var Ajax={
              get: function(url, fn) {
                  // XMLHttpRequest对象用于在后台与服务器交换数据   
                  var xhr = new XMLHttpRequest();            
                  xhr.open(‘GET‘, url, true);
                  xhr.onreadystatechange = function() {
                      // readyState == 4说明请求已完成
                      if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) { 
                          // 从服务器获得数据 
                          fn.call(this, xhr.responseText);  
                      }
                  };
                  xhr.send();
              },
              // datat应为‘a=a1&b=b1‘这种字符串格式,在jq里如果data为对象会自动将对象转成这种字符串格式
              post: function (url, data, fn) {
                  var xhr = new XMLHttpRequest();
                  xhr.open("POST", url, true);
                  // 添加http头,发送信息至服务器时内容编码类型
                  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");  
                  xhr.onreadystatechange = function() {
                      if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 304)) {
                          fn.call(this, xhr.responseText);
                      }
                  };
                  xhr.send(data);
              }
          }
          function linksFactory(apilist, fn) {
              var links = {};
              linkNum = 0;
              if (!(apilist instanceof Array)) { return ‘../‘ }
              apilist.map(function (v, i, a) {
                  var _arr = v.url.split(‘/‘);
                  var _name = _arr[_arr.length - 1];
                  _name = _name.split(‘?‘)[0];
                  if (links[_name] !== undefined) {
                      _name = _name + linkNum++;
                  }
                  links[_name] = {
                      url: function () {
                          var me =this;
                          if (me.res_power=="true") {
                              creatStyle(me.param);
                              return me.api;
                          } else {
                              if (typeof fn === ‘function‘) {
                                  fn(me);
                              }
                              return ‘../‘;
                          }
                      },
                      api: v.url,
                      param: v.param,
                      res_power: true
                  }
              });
          
          
              for (var k in links) {
                  (function (key) {
                      Ajax.get(‘/sys/buttonAssign/isPermission/‘+links[key].param,function(_res){
                          var res=JSON.parse(_res);
                          links[key].res_power=res.result;
                          if(links[key].api==‘button‘){
                              links[key].url();
                          }
                      })
                  })(k);
              }
              return links;
          }
          
          function creatStyle(p){
              var style=‘<style>[assign-url="‘+p+‘"]{display:initial;}</style>‘;
              var ele=document.createElement(‘div‘);
              ele.innerHTML=style;
              document.getElementsByTagName(‘head‘)[0].appendChild(ele.firstElementChild)
          }

           

           

           

          $.post(requestPower.getAssignList.url(),param, function(data){
                            var menuDetail= $.parseJSON(data.menuList);
                            $.fn.zTree.init($("#menuTree"), setting, menuDetail);
                            var userDetail= $.parseJSON(data.userList);
                            userDetail.forEach(function(item){
                                if(item.flag == ‘1‘ && item.pId != "DROOT"){
                                    item.iconSkin = "sec";
                                }
                                else if(item.flag == ‘2‘){
                                    item.iconSkin = "user";
                                }
                            });
                            $.fn.zTree.init($("#userTree"), setting, userDetail);
                            processHeight();
                        });

           

           

           

              var requestPower=linksFactory(
                  [
                      //{url:path+"/sys/roleAssign/assignMenu",param:"roleAssign:permission:arrange"},
                      //{url:"assignMenu",param:"roleAssign:permission:buttonArrange"},
                      {url:path+"/sys/roleAssign/assignMenu",param:"roleAssign:permission:arrange"},
                      {url:"getAssignList",param:"roleAssign:permission:buttonArrange"},
                  ],function(me){
                      console.log(me);
                      alert("没有权限");
                  }
              )
              requestPower.assignMenu.url()
              requestPower.getAssignList.url()

           

          0326

          标签:color   eof   creat   split   iss   innerhtml   权限   rmi   arr   

          原文:https://www.cnblogs.com/pengfei25/p/10604146.html

          (0)
          (0)
             
          举报
          评论 一句话评论(0
          0条  
          登录后才能评论!
          ? 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
          打开技术之扣,分享程序人生!
                       

          鲁公网安备 37021202000002号

          t6娱乐平台官方
          <blockquote id="shwb3"><ruby id="shwb3"></ruby></blockquote>
        2. <small id="shwb3"><strong id="shwb3"></strong></small>

            1. <big id="shwb3"></big>
              1. <blockquote id="shwb3"><ruby id="shwb3"></ruby></blockquote>
              2. <small id="shwb3"><strong id="shwb3"></strong></small>

                  1. <big id="shwb3"></big>