修改页面,完成单页模式新增首页返回上一页按钮
This commit is contained in:
@@ -0,0 +1 @@
|
||||
layui.define(["jquery","form"],function(v){var o="selectN",l=layui.jquery,d=layui.form,u=function(c){this.selected=[],this.values=[],this.names=[],this.lastValue="",this.lastName="",this.isSelected=!1,this.config={elem:"",data:[],selected:[],tips:"请选择",search:!1,width:null,last:!1,verify:"",filter:"",name:"",delimiter:",",field:{idName:"id",titleName:"name",statusName:"status",childName:"children"},formFilter:null},this.config=l.extend(this.config,c),this.setTips=function(){var e=this,t=e.config;if(Object.prototype.toString.call(t.tips)!="[object Array]")return t.tips;var a=l(t.elem).find("select").length;return t.tips.hasOwnProperty(a)?t.tips[a]:"请选择"},this.setSearch=function(){var e=this,t=e.config;if(Object.prototype.toString.call(t.search)!="[object Array]")return t.search===!0?"lay-search ":" ";var a=l(t.elem).find("select").length;return t.search.hasOwnProperty(a)&&t.search[a]===!0?"lay-search ":" "},this.setWidth=function(){var e=this,t=e.config;if(Object.prototype.toString.call(t.width)!="[object Array]")return/^\d+$/.test(t.width)?'style="width:'+t.width+'px;" ':" ";var a=l(t.elem).find("select").length;if(t.width.hasOwnProperty(a))return/^\d+$/.test(t.width[a])?'style="width:'+t.width[a]+'px;" ':" "},this.createSelect=function(e){var t=this,a=t.config,i=a.field,r="";r+='<div class="layui-input-inline" '+t.setWidth()+">",r+=" <select "+t.setSearch()+'lay-filter="'+a.filter+'">',r+=' <option value="">'+t.setTips()+"</option>";for(var n=0;n<e.length;n++){var s=e[n][i.statusName]==0?'disabled="" ':"";r+=" <option "+s+'value="'+e[n][i.idName]+'">'+e[n][i.titleName]+"</option>"}return r+=" </select>",r+="</div>",r},this.getOptionData=function(e,t){for(var a=this.config.field,i=e,r=0;r<t.length;r++)if(typeof i[t[r]]=="undefined"){i=null;break}else if(typeof i[t[r]][a.childName]=="undefined"){i=null;break}else i=i[t[r]][a.childName];return i},this.set=function(e){var t=this,a=t.config;$E=l(a.elem);var i=a.verify==""?"":'lay-verify="'+a.verify+'" ',r='<div style="height:0px;width:0px;overflow:hidden"><input '+i+'name="'+a.name+'"></div>';r+=t.createSelect(a.data),$E.html(r),e=typeof e=="undefined"?a.selected:e;for(var n=[],s=0;s<e.length;s++){$E.find("select:last").val(e[s]);var h=$E.find("select:last").get(0).selectedIndex-1;n.push(h);var f=t.getOptionData(a.data,n);if(f){var r=t.createSelect(f);$E.append(r)}}d.render("select",a.formFilter),t.getSelected()},this.change=function(e){var t=this,a=t.config,i=e.parent();i.nextAll("div.layui-input-inline").remove();var r=[];i.parent().find("select").each(function(){r.push(l(this).get(0).selectedIndex-1)});var n=t.getOptionData(a.data,r);if(n){var s=t.createSelect(n);i.after(s),d.render("select",a.formFilter)}t.getSelected()},this.getSelected=function(){var e=this,t=e.config,a=[],i=[],r=[];$E=l(t.elem),$E.find("select").each(function(){var s={},h=l(this).val(),f=l(this).find("option:selected").text();s.value=h,s.name=f,a.push(h),i.push(f),r.push(s)}),e.selected=r,e.values=a,e.names=i,e.lastValue=$E.find("select:last").val(),e.lastName=$E.find("option:selected:last").text(),e.isSelected=e.lastValue!="";var n=t.last===!0?e.lastValue:e.values.join(t.delimiter);$E.find('input[name="'+t.name+'"]').val(n)},this.getData=function(e){var t;return l.ajax({url:e,dataType:"json",async:!1,success:function(a){t=a},error:function(){console.error(o+" hint:候选数据ajax请求错误 "),t=!1}}),t}};u.prototype.render=function(){var c=this,e=c.config;if($E=l(e.elem),$E.length==0)return console.error(o+" hint:找不到容器 "+e.elem),!1;if(Object.prototype.toString.call(e.data)!="[object Array]"){var t=c.getData(e.data);if(t===!1)return console.error(o+" hint:缺少分类数据"),!1;c.config.data=t}e.filter=e.filter==""?e.elem.replace("#","").replace(".",""):e.filter,e.name=e.name==""?e.elem.replace("#","").replace(".",""):e.name,c.config=e,c.set(),d.on("select("+e.filter+")",function(a){c.change(l(a.elem))}),$E.find('input[name="'+e.name+'"]').focus(function(){var a=l(e.elem).offset().top;l("html,body").scrollTop(a-200),l(e.elem).find("select:last").addClass("layui-form-danger"),setTimeout(function(){l(e.elem).find("select:last").removeClass("layui-form-danger")},3e3)})},v(o,function(c){var e=new u(c);return e.render(),e})});
|
||||
Reference in New Issue
Block a user