jtable bate

一些想法

1.需要保存获取数据接口和搜索接口
2.单元格区分 展示值和实际数值

如何调用

    ftable=new jtable();
    var f_post={
        "Json":{
            "alipay_name":$("#list_alipay_name :selected").text(),
            "alipay_name_id":$("#list_alipay_name :selected").attr("index_row"),
        }
    }
    ftable.post(u.file.list,f_post,function(ret){

        ftable.create({
            "ret":ret,
            "frame":{
                trans:[
                    ["t_id","ID","text"],
                ],
        }
    });


    })

css部分

/*sql_window*/
.sql_window_bg{
  position: absolute;
  width: 100%;
  height:100%;
  top:0;
  left: 0;
  z-index: 11;
}
.sql_window_con{
  position: absolute;
  width: 200px;
  height:300px;
  z-index: 12;
  background: #fff;
  border: 1px solid #ddd;
  border-width: 0 1px 4px 1px;
  padding:10px;
}

/*table补全*/
.table td{
  padding: 0 2px !important;
}
.table-bordered th,
 .table-bordered td {
   border: 1px solid #ddd !important;
 }
 .table-bordered th,
 .table-bordered td {
   border: 1px solid #ddd !important;
 }

.table-page-con{
  text-align: center !important;
  height:75px;
}
.table-page-con a{
  cursor:pointer;
}
.table-mubu{
  top:0;
  left:0;
  position: absolute;
  z-index: 99;
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,.6);

}
.table td .input-group{
  max-width: 220px !important;
  min-width: 120px !important;
}
.table th {
  white-space: nowrap;
  padding:4px 3px !important;
}

插件定义部分




*/
//创建table
function jtable(){
    var that = this;
    this.url;//请求地址
    var post_data;//抛出数据
    this.trs=[];//全部tr
    this.th=[];//表头数据
    this.table=document.createElement("table");//表格
    this.css="table";
    this.table.className=this.css;
    this.sqlkey={};
    var callback;
    var ret;
    this.target=$(".maintable");//注入目标
    this.post=function(){
        this.loading();
        this.url=arguments[0];
        post_data=arguments[1];
        callback=(typeof(arguments[2])=="undefined")?callback:arguments[2];
        ajax(this.url,post_data,callback);
    }

    var frame={
        "trans":undefined,
        "hide":undefined,
        "fixed":undefined,
        "post_page_num":undefined,
        "search":undefined,
    }
    this.create=function(){
        this.loadend();
        this.target.empty();
        this.trs=[];//全部tr
        this.th=[];//表头数据
        this.table.innerHTML="";
        ret=arguments[0].ret;
        frame=(typeof(arguments[0].frame)=="undefined")?frame:arguments[0].frame;
        if(typeof(ret.data[0])=="undefined"){console.log("数据为空");return;}
        if(!(ret.data instanceof Array)){console.log("传入非数组");return;}
        //存在 页码字段
        if(!!ret.countnum&&!!ret.pagemax&&ret.pagemax>1){
            this.createpage(ret);
        }
        //不存在 sql_key 字段
        if(!post_data.Json.sql_key){
            that.sqlkey={};
        }
        for(var i =0 , len = ret.data.length; i= '"+keyvalue+"'",
                        sqlkey_field:type,
                    }
                    break;
                case "less":
                    that.sqlkey[sqlkey_field]={
                        "value":keyvalue,
                        "sqltext":sqlkey_field+" <= '"+keyvalue+"'",
                        sqlkey_field:type,
                    }
                    break;
            }
            var post_sql=[];

            // for(var sql_i in that.sqlkey){
            //  post_sql.push(that.sqlkey[sql_i].sqltext)
            // }
            post_data.Json.sql_key=that.sqlkey;
            console.table(that.sqlkey);
            console.log(post_data.Json.sql_key);

            // post_data.Json.sql_key
            that.post(that.url,post_data,callback)
            sql_w.close()
            }
        sql_w.init();


    }
}
function sql_window(){
    this.top=0;
    this.left=0;
    this.width=250;
    this.height="auto";
    this.father;
    this.result;
    this.ret;
    var that=this;
    this.init=function(){
        that.father.style.position="relative";
        var sql_bg=document.createElement("div");
        sql_bg.className="sql_window_bg";
        sql_bg.addEventListener("click",that.close);
        document.body.appendChild(sql_bg);

        var sql_w=document.createElement("div");
        sql_w.className="sql_window_con";
        sql_w.style.top=that.top +22+"px";
        var fatherLeft=that.father.offsetLeft;
        var winWidth=window.innerWidth;

        sql_w.style.left=that.left-((fatherLeft>(winWidth/2))?that.width:0)+"px";
        sql_w.style.width=this.width+"px";
        sql_w.style.height=this.height;
        this.father.appendChild(sql_w)
        //top
        var sql_w_top=document.createElement("div");
        sql_w_top.className=" sql_window_top";
        sql_w.appendChild(sql_w_top);
        //-close按钮
        var sql_close_btn=document.createElement("span");
        sql_close_btn.className="glyphicon glyphicon-remove pull-right";
        sql_close_btn.addEventListener("click",that.close);
        sql_w_top.appendChild(sql_close_btn);
        //-全选按钮
        var sql_allselect_btn = document.createElement("input");
        sql_allselect_btn.setAttribute("type","checkbox");
        sql_allselect_btn.checked=(!!this.ret&&this.ret.value!="")?false:true;
        sql_allselect_btn.addEventListener("click",that.selectAll)
        sql_w_top.appendChild(sql_allselect_btn);
        var sql_allselect_zh=document.createElement("span");
        sql_allselect_zh.innerHTML="全选";
        sql_w_top.appendChild(sql_allselect_zh);

        //选项窗口
        this.sql_w_mid=document.createElement("div");
        this.sql_w_mid.className="sql_window_mid";
        sql_w.appendChild(this.sql_w_mid)
        //-输入框
        var sql_input = document.createElement("input");
        sql_input.className="form-control keyvalue";
        sql_input.setAttribute("placeholder","搜索关键字");
        sql_input.value=(!!that.ret&&that.ret.value!="")?that.ret.value:"";
        this.sql_w_mid.appendChild(sql_input);
        //-按钮
        var sql_btn = document.createElement("button");
        sql_btn.className="btn-xs btn-primary";

        //-模糊搜索
        var mohu_btn=sql_btn.cloneNode(true);
        mohu_btn.innerHTML="模糊搜索";
        mohu_btn.addEventListener("click",function(){that.finish("like")})
        this.sql_w_mid.appendChild(mohu_btn)
        //-精确搜索
        var acc_btn=sql_btn.cloneNode(true);
        acc_btn.innerHTML="精确搜索";
        acc_btn.addEventListener("click",function(){that.finish("accuracy")})
        this.sql_w_mid.appendChild(acc_btn)
        //-大于搜索
        var more_btn=sql_btn.cloneNode(true);
        more_btn.innerHTML="大于此值";
        more_btn.addEventListener("click",function(){that.finish("more")})
        this.sql_w_mid.appendChild(more_btn)
        //-小于搜索
        var less_btn=sql_btn.cloneNode(true);
        less_btn.innerHTML="小于此值";
        less_btn.addEventListener("click",function(){that.finish("less")})
        this.sql_w_mid.appendChild(less_btn)
    }
    this.selectAll=function(){
        // console.dir(this);
        if(this.checked){
            that.finish("all");
        }

    }
    this.finish;
    this.close=function(){
        // alert(1);
        $(".sql_window_bg").remove();
        $(".sql_window_con").remove();

        // $(that.father).find("")
    }

}
function jt_child(){
    this.type="td";
    this.css;
    this.row=undefined;
    this.obj;
    this.create=function(){
        this.type=arguments[0];
        this.css=arguments[1];
        this.row=arguments[2];
        this.obj=document.createElement(this.type);
        this.obj.className=this.css;
        if(typeof(this.row)!="undefined"){
            this.obj.setAttribute("row",this.row)
        }

    }
}
//上传过滤
function post_filter(arr){
    var post_arr_type = typeof(arr);
    switch (post_arr_type) {
        case "string":
            if(arr == ""){
                return false;
            }
            break;
        case "undefined":
            console.log("输入的资料未定义")
            return false;
            break;
        case "object":
            for(var key in arr){
                var value = post_filter(arr[key]);
                if(!value){
                    return false;
                }
            }
    }
    return arr;
}
//呼叫提醒
function arm (str){
    str=(!str)?"数据为空":str;
    if(!debug){alert(str)};
    console.log(str)
}
//去除空格---函数法
//删除左右两端的空格
function trim(str){
       return str.replace(/(^\s*)|(\s*$)/g, "");
   }
//删除左边的空格
function ltrim(str){
    return str.replace(/(^\s*)/g,"");
}
//删除右边的空格
function rtrim(str){
    return str.replace(/(\s*$)/g,"");
}

js ES5 定义函数属性(property)的特性(attribute)

来源:hongdada

var foo = {};

      Object.defineProperty(foo, "x", {
          value: 10,
          writable: true, // 即{ReadOnly} = false
          enumerable: false, // 即{DontEnum} = true
          configurable: true // 即{DontDelete} = false
      });

      console.log(foo.x); // 10
      console.dir(foo.x);

      // 通过descriptor获取特性集attributes
      var desc = Object.getOwnPropertyDescriptor(foo, "x");
      console.dir(desc);
            
            

jq 插件化 自消失消息提示

js

//arm信息提示模块
function arm(str,type,addition){
  var type=(typeof(type)=="undefined")?"":type;
  var life;
  switch (type) {
    case "warning":
      life=10000;
      break;
    case "danger":
      life="long"
      break;
    case "info":
      life=10000;
      break;
    default:
      type="default";
      life=10000;
  }
  ac=new armContant();
  ac.create(str,type,life,addition)
}
var armcount=0;
function armContant(){
  this.armid=++armcount;
  var that = this;

  this.color;
  this.life;
  this.text;
  this.addition;
  this.content;
  this.closebtn=function(){
    var span =document.createElement("span");
    span.innerHTML="X";
    span.className="arm_btn_close";
    span.addEventListener("click",that.close);
    return span;
  }
  this.colorArr={
    "warning":["#F2753F","#FFFC66"],
    "danger":["#D53627","#F5F6EB"],
    "info":["#57D2F7","#666"],
    "default":["#00C4AB","#fff"],
  };
  this.create=function(){
    that.text=arguments[0];
    that.color=that.colorArr[arguments[1]];
    that.life=arguments[2]
    that.addition=arguments[3];
    //大容器
    that.content=document.createElement("div");
    that.content.className="arm_bigcon";
    that.content.style.background=that.color[0];
    that.content.style.color=that.color[1];
    that.content.setAttribute("armid",that.armid);

    // 图标容器
    var imgIcon = document.createElement("div");
    // imgIcon.className = "arm_icon_logo";
    imgIcon.className = "arm_icon_logo";
    imgIcon.innerHTML = "小冰军机处";
    that.content.appendChild(imgIcon);

    //-文字容器
    var strcon=document.createElement("div");
    strcon.className="arm_con";
    that.content.appendChild(strcon);

    //--文字
    var span=document.createElement("span");
    span.className="arm_str_main";
    span.innerHTML=that.text;
    strcon.appendChild(span)

    //--额外内容
    if(!!that.addition){
      strcon.appendChild(that.addition);
    }
    //--关闭按钮
    that.content.appendChild(that.closebtn());

    document.body.appendChild(that.content);
    if(that.life!="long"){
      setTimeout(that.close,that.life);
    }

  }
  this.close=function(){
    $("[armid="+that.armid+"]").remove();
  }
}

css

@charset "UTF-8";
/*arm*/
.arm_bigcon{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 99;
}
.arm_con{
  position: relative;
  margin: auto;
  left: 0;right: 0;
  top:0;
  padding:10px;
  width: 400px;
}
.arm_btn_close{
  position: absolute;
  margin: auto;
  top:0;bottom: 0;
  right:0;
  width: 20px;height:20px;
  cursor: pointer;
}
.arm_icon_logo{
  position: absolute;
  margin: auto;
  top:0;bottom: 0;
  left:0;
  line-height: 40px;
  height:40px;
  width:100px;
  padding:0 10px;
  /*background: url(../images/miniice.png) no-repeat;*/
  /*background-color: #fcfcfc;*/
  font-family: "microsoft yahei";
  background-position: center;
  background-size: 100% auto;

}

thinkphp3.2 批量上传文件

js

if(window.FileReader) {

            var FileController = u.file.upload;                    // 接收上传文件的后台地址
            // FormData 对象
            var form = new FormData();

            form.append("author", "hooyes");                        // 可以增加表单数据
            form.append("beginTime", data.beginTime);

            for(var i = 0 , len=data.file.length; i <len;i++){
                var fileObj = document.getElementById("file").files[i]; // 获取文件对象
                form.append("file"+i, fileObj);                           // 文件对象
            }
            // XMLHttpRequest 对象
            var xhr = new XMLHttpRequest();
            xhr.open("post", FileController, true);
            xhr.onreadystatechange = function () {
                if(xhr.readyState==4){
                    var ret =JSON.parse(this.response);
                        if(ret.code==1){
                            alert("成功")
                        }
                }
            };
            xhr.send(form);
    }
    else {
            alert("该浏览器不支持,请换Chrome内核浏览器");
    }

 

controller

 $upload = new \Think\Upload (); // 实例化上传类
            $upload->maxSize = 0; // 设置附件上传大小
            $upload->exts = array (
                    'csv'
            ); // 设置附件上传类型
            $upload->rootPath = './Public/uploadFile//'; // 设置附件上传根目录
            $upload->savePath = ''; // 设置附件上传(子)目录
            $now = $_SERVER['REQUEST_TIME'];
                        $upload->saveName = array('uniqid',$now);//防重名的保存规则
                        $info = $upload->upload (); // 上传文件

 

jq 插件化巨坑 loading 拷贝副本替换法

点哪个哪个显示加载

js

//调用
$(even).mini_load();//显示加载
$(even).mini_loaded();//回到原来的样子


$.fn.extend({
    mini_load:function(msg,color){
        var msg=(typeof(msg)=="undefined")?"操作中...":msg;
        var that=$(this);
        var that_copy=$(that).clone();
        var color=(typeof(color)=="undefined")?"white":"black";
        var img_load=document.createElement("span")
        img_load.className="span_loading";
        that_copy.attr("copy","loadingcopy");
        that_copy.html(msg);
        that_copy.prepend(img_load);
        $(that_copy).removeAttr("onclick");
        that.hide();
        that.after(that_copy);
    },
    mini_loaded:function(){
        var that=$(this);
        that.show();
        that.siblings("[copy='loadingcopy']").remove();
    }
})

css

.span_loading{
  background: url(../images/loading-white.gif);
  width:20px;
  height: 20px;
  display: inline-block;
  background-size: 100%;
  vertical-align:middle;
}