forked from kidgrow-microservices-platform

zhaoxiaohao
2021-01-25 7b8704701a23e66960fc55818e3418b3bbba2f21
1
var Pandyle;(function(t){function e(e){return t._methods[e]}function r(t,e){var r=new RegExp("^\\w+"+e+"$");return r.test(t)}function n(e,n){$.isFunction(n)?r(e,"Filter")?t._filters[e]=n:r(e,"Converter")?t._converters[e]=n:t._methods[e]=n:t._variables[e]=n}function a(e){for(var r in e)t._config[r]=e[r]}t._variables={},t._methods={},t._filters={},t._converters={},t._pages={},t._config={},t.getMethod=e,t.hasSuffix=r,t.register=n,t.config=a})(Pandyle||(Pandyle={}));var Pandyle;(function(t){function e(e){return"undefined"!=typeof t._pages[e]}function r(e){t._pages[e.name]=e.html}function n(e){return t._pages[e]}function a(a){function i(t,e){t=t.replace(/<\s*script\s*>((?:.|\r|\n)*?)<\/script\s*>/g,function(t,e){return new Function(e)(),""}),t=t.replace(/<\s*style\s*>((?:.|\r|\n)*?)<\/style\s*>/g,function(t,e){var r="<style>"+e+"</style>";return $("head").append(r),""}),r({name:e,html:t}),$(a).html(t)}var o=$(a).attr("p-com");if(o=$.trim(o),e(o))$(a).html(n(o));else{var s="";if(/^@.*/.test(o))s=o;else{var p=o.split("."),c=t._config.comPath?t._config.comPath.Default||"./pages/{name}.html":"./pages/{name}.html";p.length>1?(c=t._config.comPath[p[0]],s=c.replace(/{.*}/g,p[1])):s=c.replace(/{.*}/g,o)}$.ajax({url:s,async:!1,success:function(t){i(t,o)}})}}t.hasComponent=e,t.addComponent=r,t.getComponent=n,t.loadComponent=a})(Pandyle||(Pandyle={})),function(t){t.fn.vm=function(t,e){void 0===e&&(e=!0);var r=this;if(r.data("vm"))return r.data("vm");var n=new Pandyle.VM(r,t,e);return r.data("vm",n),n},t.fn.inputs=function(){var t=this;if(t.data("inputs"))return t.data("inputs");var e=new Pandyle.Inputs(t);return t.data("inputs",e),e}}(jQuery);var Pandyle;(function(t){var e=function(){function t(t){this._data={},this._root=t,this.initData(),this.bindChange()}return t.prototype.data=function(){return $.extend({},this._data)},t.prototype.set=function(t){for(var e in t){this.setData(e,t[e]);var r=this._root.find('[name="'+e+'"]');this.updateDom(r,t[e]),r.trigger("modelChange",t[e])}},t.prototype.initData=function(){var t=this;this._root.find("input,textarea,select").each(function(e,r){var n=$(r),a=n.prop("tagName"),i=n.prop("name"),o=n.val()||"";switch(t.initName(i),a){case"INPUT":t.initData_input(n,i,o);break;case"TEXTAREA":t.initData_normal(n,i,o);break;case"SELECT":t.initData_select(n,i,o)}})},t.prototype.initData_input=function(t,e,r){var n=t.prop("type");switch(n){case"radio":this.initData_radio(t,e,r);break;case"checkbox":this.initData_check(t,e,r);break;default:this.initData_normal(t,e,r)}},t.prototype.initData_radio=function(t,e,r){$.isEmptyObject(this.getDataByName(e))&&this.setData(e,""),t.prop("checked")&&this.setData(e,r)},t.prototype.initData_check=function(t,e,r){$.isEmptyObject(this.getDataByName(e))&&this.setData(e,[]),t.prop("checked")&&this.getDataByName(e).push(r)},t.prototype.initData_normal=function(t,e,r){this.setData(e,r)},t.prototype.initData_select=function(t,e,r){this.setData(e,r)},t.prototype.bindChange=function(){var t=this;this._root.on("change viewChange","input,textarea,select",function(e){var r=$(e.currentTarget),n=r.prop("tagName"),a=r.prop("name"),i=r.val();switch(n){case"INPUT":t.onChange_input(r,a,i);break;case"TEXTAREA":t.onChange_normal(r,a,i);break;case"SELECT":t.onChange_select(r,a,i)}t.callBack&&t.callBack(a,i)})},t.prototype.onChange_normal=function(t,e,r){this.setData(e,r)},t.prototype.onChange_input=function(t,e,r){switch(t.prop("type")){case"radio":this.onChange_radio(t,e,r);break;case"checkbox":this.onChange_check(t,e,r);break;default:this.onChange_normal(t,e,r)}},t.prototype.onChange_radio=function(t,e,r){t.prop("checked")&&this.setData(e,r)},t.prototype.onChange_check=function(t,e,r){if(t.prop("checked"))this.getDataByName(e).push(r);else{var n=this.getDataByName(e).indexOf(r);this.getDataByName(e).splice(n,1)}},t.prototype.onChange_select=function(t,e,r){this.setData(e,r)},t.prototype.initName=function(t){t.split(".").reduce(function(t,e){return t[e]?t[e]:(t[e]={},t[e])},this._data)},t.prototype.getDataByName=function(t){return t.split(".").reduce(function(t,e){return t[e]},this._data)},t.prototype.setData=function(t,e){var r=t.split("."),n=r.pop(),a=r.reduce(function(t,e){return t[e]},this._data);a[n]=e},t.prototype.updateDom=function(t,e){var r=t.prop("tagName");switch(r){case"INPUT":this.updateDom_input(t,e);break;case"TEXTAREA":this.updateDom_normal(t,e);break;case"SELECT":this.updateDom_select(t,e);break;default:this.updateDom_normal(t,e)}},t.prototype.updateDom_input=function(t,e){var r=t.prop("type");switch(r){case"radio":this.updateDom_radio(t,e);break;case"checkbox":this.updateDom_check(t,e);break;default:this.updateDom_normal(t,e)}},t.prototype.updateDom_radio=function(t,e){t.each(function(t,r){var n=$(r);n.val()==e?n.prop("checked","checked"):n.prop("checked",!1)})},t.prototype.updateDom_check=function(t,e){t.each(function(t,r){var n=$(r);e.indexOf(n.val())>-1?n.prop("checked","checked"):n.prop("checked",!1)})},t.prototype.updateDom_normal=function(t,e){t.val(e)},t.prototype.updateDom_select=function(t,e){t.val(e)},t}();t.Inputs=e})(Pandyle||(Pandyle={})),Array.prototype.filter||(Array.prototype.filter=function(t){var e=this.length;if("function"!=typeof t)throw new TypeError;for(var r=new Array,n=arguments[1],a=0;a<e;a++)if(a in this){var i=this[a];t.call(n,i,a,this)&&r.push(i)}return r}),Array.prototype.forEach||(Array.prototype.forEach=function(t){var e=this.length;if("function"!=typeof t)throw new TypeError;for(var r=arguments[1],n=0;n<e;n++)n in this&&t.call(r,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(t){var e=this.length;if("function"!=typeof t)throw new TypeError;for(var r=new Array(e),n=arguments[1],a=0;a<e;a++)a in this&&(r[a]=t.call(n,this[a],a,this));return r}),Array.prototype.reduce||(Array.prototype.reduce=function(t,e){"use strict";if(null===this||"undefined"==typeof this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof t)throw new TypeError(t+" is not a function");var r,n,a=this.length>>>0,i=!1;for(1<arguments.length&&(n=e,i=!0),r=0;a>r;++r)this.hasOwnProperty(r)&&(i?n=t(n,this[r],r,this):(n=this[r],i=!0));if(!i)throw new TypeError("Reduce of empty array with no initial value");return n}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){for(var e=0,r=this.length;e<r;e++)if(this[e]===t)return e;return-1});var Pandyle;(function(t){var e=function(){function e(t,e,r){void 0===r&&(r=!0),this._data=$.extend({},e),this._root=t,this._relations=[],this._methods={},this._filters={},this._converters={},this._variables={},this._defaultAlias={root:{data:this._data,property:""},window:{data:window,property:"@window"}},r&&this.run()}return e.prototype.set=function(t){var e=this,r=function(r){var a=r.split(/[\[\]\.]/).filter(function(t){return""!=t}),i=a.pop(),o=n._data;if(a.length>0&&(o=a.reduce(function(t,e){return t[e]},n._data)),o[i]=t[r],$.isArray(o[i]))for(var s=n._relations.length-1;s>=0;s--)n.isChild(r,n._relations[s].property)&&n._relations.splice(s,1);var p=n._relations.filter(function(t){return e.isSelfOrChild(r,t.property)});p.length>0&&p[0].elements.forEach(function(t){e.render(t)})},n=this;for(var a in t)r(a)},e.prototype.get=function(t){var e=this;if(!t)return $.extend({},this._data);switch($.type(t)){case"array":return t.map(function(t){return e.get(t)});case"string":return this.getValue(this._root,t,this._data);case"object":var r={};for(var n in t)r[n]=this.getValue(this._root,t[n],this._data);return r;default:return null}},e.prototype.run=function(){this.render(this._root,this._data,"",this._defaultAlias)},e.prototype.render=function(t,e,r,n){var a=this;t.each(function(t,i){a.renderSingle(i,e,r,$.extend({},n))})},e.prototype.renderSingle=function(e,r,n,a){var i=$(e);i.data("context")||i.data("context",r),i.data("binding")||i.data("binding",{}),a&&!$.isEmptyObject(a)&&i.data("alias",a),r=i.data("context"),i.attr("p-for")?(this.setAlias(i,n,r),this.renderFor(i,r,n)):(this.bindAttr(e,n),this.bindIf(e,n),i.attr("p-com")&&t.loadComponent(e),i.attr("p-context")?this.renderContext(e,n):i.attr("p-each")?(this.setAlias(i,n,r),this.renderEach(i,r,n)):i.children().length>0?(this.setAlias(i,n,r),this.renderChild(e,r,n)):(this.setAlias(i,n,r),this.renderText(i,n)))},e.prototype.bindAttr=function(t,e){if($(t).attr("p-bind")){var r=$(t).attr("p-bind").split("^");r.forEach(function(e,r){var n=e.match(/^\s*([\w-]+)\s*:\s*(.*)$/),a=n[1],i=n[2].replace(/\s*$/,"");$(t).data("binding")[a]={pattern:i,related:!1}}),$(t).removeAttr("p-bind")}var n=$(t).data("binding"),a=$(t).data("context");for(var i in n)"text"!==i&&"if"!==i&&$(t).attr(i,this.convertFromPattern($(t),i,n[i].pattern,a,e))},e.prototype.bindIf=function(t,e){if($(t).attr("p-if")&&($(t).data("binding").If={pattern:$(t).attr("p-if"),related:!1},$(t).removeAttr("p-if")),$(t).data("binding").If){var r=$(t).data("binding").If.pattern,n=$(t).data("context"),a=this.convertFromPattern($(t),"If",r,n,e),i=new Function("return "+a);i()?$(t).show():$(t).hide()}},e.prototype.renderContext=function(t,e){var r=$(t);if(r.attr("p-context")){var n=r.data("context"),a=r.attr("p-context"),i=this.dividePipe(a),o=i.property,s=i.method,p=this.calcu(o,r,n);s&&(p=this.convert(s,$.extend({},p)));var c=o;""!==e&&(c=e+"."+o),this.setAlias(r,c,p),this.setRelation(o,$(t),e),this.renderChild(t,p,c)}},e.prototype.renderChild=function(t,e,r){var n=this,a=$(t);if(a.children().length>0){var i=a.data("alias");a.children().each(function(t,a){var o=$(a);o.data("context",e),n.renderSingle(o[0],e,r,$.extend({},i))})}},e.prototype.renderEach=function(t,e,r){var n=this;if(t.attr("p-each")){var a=t.attr("p-each").replace(/\s/g,""),i=this.dividePipe(a),o=i.property,s=i.method,p=this.calcu(o,t,e);s&&(p=this.filter(s,p)),t.data("pattern")||(t.data("pattern",t.html()),this.setRelation(o,t,r));var c=o;""!==r&&(c=r+"."+o);var u=t.data("alias"),d=t.data("pattern"),h=$("<div />").html(d).children();t.children().remove(),p.forEach(function(e,r){var a=h.clone(!0,!0);t.append(a),n.render(a,e,c.concat("[",r.toString(),"]"),$.extend(u,{index:{data:r,property:"@index"}}))})}},e.prototype.renderFor=function(t,r,n){var a=this;if(t.attr("p-for")){t.data("uid")||t.data("uid",e._uid++);var i=t.attr("p-for").replace(/\s/g,""),o=this.dividePipe(i),s=o.property,p=o.method,c=this.calcu(s,t,r);p&&(c=this.filter(p,c)),t.data("pattern")||t.data("pattern",t.prop("outerHTML"));var u=s;""!==n&&(u=n+"."+s);var d=t.data("alias"),h=t.data("pattern"),f=h.replace(/p-for=((".*?")|('.*?'))/g,""),l=$(f);t.siblings("[uid="+t.data("uid")+"]").remove();var y=function(e,o,p){if(0!==o.length){var c=l.clone(!0,!0);e.after(c),a.render(c,o.shift(),u.concat("[",p.toString(),"]"),$.extend(d,{index:{data:p,property:"@index"}})),0===p?(c.data("uid",t.data("uid")),c.data("pattern",h),c.attr("p-for",i),c.data("context",r),a.setRelation(s,c,n)):c.attr("uid",t.data("uid")),y(c,o,++p)}};y(t,c,0),t.remove()}},e.prototype.renderText=function(t,e){var r=t.data("context"),n=t.text();t.data("binding").text&&(n=t.data("binding").text.pattern);var a=this.convertFromPattern(t,"text",n,r,e);t.html(a)},e.prototype.convertFromPattern=function(t,e,r,n,a){var i=this,o=/{{\s*([\w\.\[\]\(\)\,\$@\{\}\d\+\-\*\/\s]*)\s*}}/g,s=!1;o.test(r)&&(t.data("binding")[e]||(t.data("binding")[e]={pattern:r,related:!1}),s=t.data("binding")[e].related);var p=r.replace(o,function(r,o){return s||(i.setRelation(o,t,a),t.data("binding")[e].related=!0),i.getValue(t,o,n)});return p},e.prototype.setRelation=function(t,e,r){var n=this;/^@.*/.test(t)?t=t.replace(/@(\w+)?/,function(t,r){return n.getAliasProperty(e,r)}):""!=r&&(t=r+"."+t),/^\./.test(t)&&(t=t.substr(1));var a=this._relations.filter(function(e){return e.property===t});0==a.length?this._relations.push({property:t,elements:[e]}):a[0].elements.indexOf(e)<0&&a[0].elements.push(e)},e.prototype.isSelfOrChild=function(t,e){t=t.replace(/[\[\]\(\)\.]/g,function(t){return"\\"+t});var r=new RegExp("^"+t+"$|^"+t+"[\\[\\.]\\w+");return r.test(e)},e.prototype.isChild=function(t,e){var r=new RegExp("^"+t+"[\\[\\.]\\w+");return r.test(e)},e.prototype.getValue=function(t,e,r){var n=this.calcu(e,t,r),a=$.type(n);return"string"===a||"number"===a||"boolean"===a?n:$.extend(this.toDefault(a),n)},e.prototype.calcu=function(e,r,n){var a=this,i=e.match(/[@\w]+((?:\(.*?\))*|(?:\[.*?\])*)/g);if(!i)return"";var o=i.reduce(function(e,i){var o,s=/^([@\w]+)([\(|\[].*)*/.exec(i),p=s[1];o=/^@.*/.test(p)?a.getAliasData(r,p.substr(1)):e[p];var c=s[2];if(c){var u=c.match(/\[\d+\]|\(.*\)/g);return u.reduce(function(e,i){if(/\[\d+\]/.test(i)){var o=parseInt(i.replace(/\[(\d+)\]/,"$1"));return e[o]}if(/\(.*\)/.test(i)){var s=i.replace(/\((.*)\)/,"$1").replace(/\s/,"").split(","),c=s.map(function(t){return/^[A-Za-z_\$\@].*$/.test(t)?a.calcu(t,r,n):(""===t&&(t='""'),new Function("return "+t)())}),u=e||a.getMethod(p)||t.getMethod(p)||window[p];return u.apply(a,c)}},o)}return o},n);return o},e.prototype.toDefault=function(t){switch(t){case"string":return"";case"number":return 0;case"boolean":return!1;case"array":return[];case"object":return{};case"function":return function(){};default:return null}},e.prototype.setAlias=function(t,e,r){var n=r||t.data("context");if(t.data("alias").self={data:n,property:e},t.attr("p-as")){var a=t.attr("p-as");t.data("alias")[a]={data:n,property:e}}},e.prototype.getAliasData=function(t,e){var r=t.data("alias");return r[e].data},e.prototype.getAliasProperty=function(t,e){var r=t.data("alias");return r[e].property},e.prototype.getMethod=function(t){return this._methods[t]},e.prototype.dividePipe=function(t){var e=t.split("|"),r=e[0].replace(/\s/g,""),n=e[1]?e[1].replace(/\s/g,""):null;return{property:r,method:n}},e.prototype.convert=function(e,r){if(/^{.*}$/.test(e)){var n=e.replace(/{|}/g,"").split(",");return n.reduce(function(t,e){var n=e.split(":");return/^[a-zA-z$_]+/.test(n[1])?t[n[0]]=n[1].split(".").reduce(function(t,e){return t[e]},r):t[n[0]]=new Function("return "+n[1])(),t},{})}return t.hasSuffix(e,"Converter")||(e+="Converter"),this._converters[e](r)},e.prototype.filter=function(e,r){return t.hasSuffix(e,"Filter")||(e+="Filter"),this._filters[e](r)},e.prototype.register=function(e,r){$.isFunction(r)?t.hasSuffix(e,"Filter")?this._filters[e]=r:t.hasSuffix(e,"Converter")?this._converters[e]=r:this._methods[e]=r:this._variables[e]=r},e}();e._uid=1,t.VM=e})(Pandyle||(Pandyle={}));