iweb-tool
Version:
a build tool based gulp & webpack
2 lines • 35.7 kB
JavaScript
+function(e){"use strict";function t(e){return e.toString().length>1?e.toString():"0"+e.toString()}String.prototype.trim=function(){return this.replace(/^\s*(\b.*\b|)\s*$/,"$1")},String.prototype.replaceStr=function(e,t){var n=this.split(e);return new String(n.join(t))},String.prototype.lengthb=function(){var e=this.replace(/[^\x00-\xff]/g,"**");return e.length},String.prototype.replaceAll=function(e,t){var n=new RegExp(e,"g");return this.replace(n,t)},String.prototype.substrCH=function(e){for(var t=0,n=0;e>t&&n<this.length;){var r=this.charCodeAt(n);if(r>256&&t==e-1)break;t+=r>256?2:1,n+=1}return this.substr(0,n)},String.prototype.startWith=function(e){return 0==this.indexOf(e)},String.prototype.endWith=function(e){var t=this.indexOf(e);return-1==t?void 0:t==this.length-e.length},String.prototype.format=function(e){if(null!=e){var t=this;for(var n in e){var r=new RegExp("\\<\\#\\="+n+"\\#\\>","gi");t=t.replace(r,e[n]?"null"==e[n]?"":e[n]:"")}}return t},Date.prototype.format=function(e){var n=this.getFullYear(),r=this.getMonth()+1,s=this.getDate(),i=this.getHours(),a=this.getMinutes(),o=this.getSeconds();return e=e||"yyyy-MM-dd hh:mm:ss",e.replace(/yyyy/,n).replace(/yy/,n.toString().substr(2,2)).replace(/MM/,t(r)).replace(/M/,r).replace(/dd/,t(s)).replace(/d/,s).replace(/hh/,t(i)).replace(/h/,i).replace(/mm/,t(a)).replace(/m/,a).replace(/ss/,t(o)).replace(/s/,o)},Date.prototype.getAAAAMMJJ=function(){var e=this.getDate();10>e&&(e="0"+e);var t=this.getMonth()+1;10>t&&(t="0"+t);var n=this.getYear();return n+""+t+e},Date.prototype.getFomatDate=function(){var e=this.getFullYear(),t=this.getMonth()+1;10>t&&(t="0"+t);var n=this.getDate();return 10>n&&(n="0"+n),e+"-"+t+"-"+n},Date.prototype.getFomatDateTime=function(){var e=this.getFullYear(),t=this.getMonth()+1;10>t&&(t="0"+t);var n=this.getDate();10>n&&(n="0"+n);var r=this.getHours();10>r&&(r="0"+r);var s=this.getMinutes();10>s&&(s="0"+s);var i=this.getSeconds();return 10>i&&(i="0"+i),e+"-"+t+"-"+n+" "+r+":"+s+":"+i},Array.prototype.indexOf=function(e){for(var t=0;t<this.length;t++)if(this[t]==e)return t;return-1},Array.prototype.remove=function(e){return 0>e||e>this.length?void alert("index out of bound"):void this.splice(e,1)},Array.prototype.removeEle=function(e){for(var t=0,n=this.length;n>t;t++)if(this[t]==e)return void this.splice(t,1)},Math.UUID=function(){return((new Date).getTime()+"").substr(9)},String.UUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,n="x"==e?t:3&t|8;return n.toString(16)})},Array.prototype.insert=function(e,t){return 0>e||e>this.length?void alert("index out of bound"):void this.splice(e,0,t)},Array.prototype.values=function(e){if(null==e)return null;for(var t=new Array,n=0;n<e.length;n++)t.push(this[e[n]]);return t},Array.prototype.clear=function(){this.splice(0,this.length)},window.getRequest=function(e){e||(e=document.location.search);var t=new Object;if(-1!=e.indexOf("?"))for(var n=e.substring(e.indexOf("?")+1),r=n.split("&"),s=0;s<r.length;s++)t[r[s].split("=")[0]]=unescape(r[s].split("=")[1]);return t},window.setCookie=function(e,t,n,r,s,i){var a=e+"="+encodeURIComponent(t);n&&(a+="; expires="+n.toGMTString()),r&&(a+="; path="+r),s&&(a+="; domain="+s),i&&(a+="; secure="+i),document.cookie=a},window.getCookie=function(e){var t="(?:; )?"+e+"=([^;]*);?",n=new RegExp(t);return n.test(document.cookie)?decodeURIComponent(RegExp.$1):null},window.deleteCookie=function(e,t,n){setCookie(e,"",new Date(0),t,n)},window.execIgnoreError=function(e,t,n){try{e.call(t,n)}catch(r){}},window.encodeBase64=function(e){for(var t,n,r,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,a=e.length,o="";a>i;){if(t=255&e[i++],i==a){o+=s.charAt(t>>2),o+=s.charAt((3&t)<<4),o+="==";break}if(n=e[i++],i==a){o+=s.charAt(t>>2),o+=s.charAt((3&t)<<4|(240&n)>>4),o+=s.charAt((15&n)<<2),o+="=";break}r=e[i++],o+=s.charAt(t>>2),o+=s.charAt((3&t)<<4|(240&n)>>4),o+=s.charAt((15&n)<<2|(192&r)>>6),o+=s.charAt(63&r)}return o},e.getFunction=function(t,n){if(!n||"function"==typeof n)return n;if("function"==typeof t[n])return t[n];if("function"==typeof window[n])return window[n];if(-1!=n.indexOf(".")){var r=e.getJSObject(t,n);if("function"==typeof r)return r;if(r=e.getJSObject(window,n),"function"==typeof r)return r}return n},e.getJSObject=function(e,t){if(t){if("object"==typeof t)return t;for(var n=t.split("."),r=e,s=0;s<n.length;s++)if(r=r[n[s]],!r)return null;return r}},window.getCurrentJsPath=function(){var e=document,t={},n=+new Date,r=/((?:http|https|file):\/\/.*?\/[^:]+)(?::\d+)?:\d+/,s=-1===(""+e.querySelector).indexOf("[native code]");if(e.currentScript)return e.currentScript.src;var i;try{t.b()}catch(a){i=a.fileName||a.sourceURL||a.stack||a.stacktrace}if(i){var o=r.exec(i)[1];if(o)return o}for(var u,h=e.scripts,c=h.length-1;u=h[c--];)if(u.className!==n&&"interactive"===u.readyState)return u.className=n,s?u.getAttribute("src",4):u.src}}($),+function(e){"use strict";var t="1.0.0",n="i_theme",r="i_locale",s="i_languages",i="usercode",a=-480,o="contextpath",u={version:t};window.getCookie||(window.getCookie=function(e){var t="(?:; )?"+e+"=([^;]*);?",n=new RegExp(t);return n.test(document.cookie)?decodeURIComponent(RegExp.$1):null}),window.createShellObject=function(e){var t=function(){};return t.prototype=e,new t},function(){var t={},h={},c={},l={"float":{precision:2},datetime:{format:"yyyy-MM-dd hh:mm:ss",metaType:"DateTimeFormatMeta",speratorSymbol:"-"},time:{format:"hh:mm:ss"},date:{format:"yyyy-MM-dd"},currency:{precision:2,curSymbol:"¥"}},f={};f.getEnvironment=function(){return createShellObject(t)},f.getClientAttributes=function(){return createShellObject(h)},f.setContextPath=function(e){return t[o]=e},f.getContextPath=function(e){return t[o]},f.setClientAttribute=function(e,t){h[e]=t},f.getSessionAttributes=function(){return createShellObject(c)},f.setSessionAttribute=function(e,t){c[e]=t,setCookie("ISES_"+e,t)},f.removeClientAttribute=function(e){h[e]=null,execIgnoreError(function(){delete h[e]})},f.getRootComponent=function(){return this.rootComponet},f.setRootComponent=function(e){this.rootComponet=e},f.getTheme=function(){return this.getEnvironment().theme},f.getLocale=function(){return this.getEnvironment().locale},f.getLanguages=function(){return this.getEnvironment().languages},f.collectEnvironment=function(){var e=this.getEnvironment(),t=this.getSessionAttributes();for(var n in h)t[n]=h[n];return e.clientAttributes=t,e},f.changeTheme=function(r){t.theme=r,setCookie(n,r),e(document).trigger("themeChange")},f.changeLocale=function(n){t.locale=n,setCookie(r,n),e(document).trigger("localeChange")},f.setMaskerMeta=function(e,t){if(l[e])if("object"!=typeof t)l[e]=t;else for(var n in t)l[e][n]=t[n];else l[e]=t},f.getMaskerMeta=function(t){return e.extend({},l[t])},f.registerSystemTimeZoneOffset=function(e){a=e},f.getSystemTimeZoneOffset=function(){return a},t.theme=getCookie(n),t.locale=getCookie(r),t.languages=getCookie(s)?getCookie(s).split(","):["ZH"],t.timezoneOffset=(new Date).getTimezoneOffset(),t.usercode=getCookie(i),document.cookie.replace(/ISES_(\w*)=([^;]*);?/gi,function(e,t,n){c[t]=n});var d=function(){};d.prototype=f,u.Core=new d}(),function(){var e,t=getCookie(i);if("undefined"!=typeof Log4js){e=new Log4js.Logger("iweb"),e.setLevel(Log4js.Level.ERROR);var n=new Log4js.ConsoleAppender(e,!0);e.addAppender(n)}else e={LEVEL_MAP:{OFF:Number.MAX_VALUE,ERROR:4e4,WARN:3e4,INFO:2e4,DEBUG:1e4,TRACE:5e3,ALL:1},level:4e4,setLevel:function(e){if(e){var t=this.LEVEL_MAP[e.toUpperCase()];t&&(this.level=t)}},isDebugEnabled:function(){return this.LEVEL_MAP.DEBUG>=this.level&&console},isTraceEnabled:function(){return this.LEVEL_MAP.TRACE>=this.level&&console},isInfoEnabled:function(){return this.LEVEL_MAP.INFO>=this.level&&console},isWarnEnabled:function(){return this.LEVEL_MAP.WARN>=this.level&&console},isErrorEnabled:function(){return this.LEVEL_MAP.ERROR>=this.level&&console},debug:function(){this.isDebugEnabled()&&console.debug.call(console,arguments)},warn:function(){this.isWarnEnabled()&&console.debug.call(console,arguments)},info:function(){this.isInfoEnabled()&&console.debug.call(console,arguments)},trace:function(){this.isTraceEnabled()&&console.debug.call(console,arguments)},error:function(){this.isErrorEnabled()&&console.debug.call(console,arguments)}};e.setLevel(t),u.log=e,u.debugMode=!1}(),u.browser={isIE:!1,isFF:!1,isOpera:!1,isChrome:!1,isSafari:!1,isWebkit:!1,isIE6:!1,isIE7:!1,isIE8:!1,isIE8_CORE:!1,isIE9:!1,isIE9_CORE:!1,isIE10:!1,isIE10_ABOVE:!1,isIE11:!1,isIOS:!1,isIphone:!1,isIPAD:!1,isStandard:!1,version:0},function(){var e,t,n=navigator.userAgent,r=/(msie\s|trident.*rv:)([\w.]+)/,s=/(firefox)\/([\w.]+)/,i=/(opera).+version\/([\w.]+)/,a=/(chrome)\/([\w.]+)/,o=/version\/([\w.]+).*(safari)/,h=n.toLowerCase(),c=null,l=r.exec(h);if(null!=l&&(c={browser:"IE",version:l[2]||"0"}),l=s.exec(h),null!=l&&(c={browser:l[1]||"",version:l[2]||"0"}),l=i.exec(h),null!=l&&(c={browser:l[1]||"",version:l[2]||"0"}),l=a.exec(h),null!=l&&(c={browser:l[1]||"",version:l[2]||"0"}),l=o.exec(h),null!=l&&(c={browser:l[2]||"",version:l[1]||"0"}),null!=l&&(c={browser:"",version:"0"}),(t=h.match(/opera.([\d.]+)/))?u.browser.isOpera=!0:"IE"==c.browser&&11==c.version?(u.browser.isIE11=!0,u.browser.isIE=!0):(t=h.match(/chrome\/([\d.]+)/))?(u.browser.isChrome=!0,u.browser.isStandard=!0):(t=h.match(/version\/([\d.]+).*safari/))?(u.browser.isSafari=!0,u.browser.isStandard=!0):(t=h.match(/gecko/))?(u.browser.isFF=!0,u.browser.isStandard=!0):(t=h.match(/msie ([\d.]+)/))?u.browser.isIE=!0:(t=h.match(/firefox\/([\d.]+)/))&&(u.browser.isFF=!0,u.browser.isStandard=!0),h.match(/webkit\/([\d.]+)/)&&(u.browser.isWebkit=!0),h.match(/ipad/i)&&(u.browser.isIOS=!0,u.browser.isIPAD=!0,u.browser.isStandard=!0),h.match(/iphone/i)&&(u.browser.isIOS=!0,u.browser.isIphone=!0),u.browser.version=e&&c.version?c.version:0,u.browser.isIE){var f=parseInt(u.browser.version),d=document.documentMode;null==d?6==f?u.browser.isIE6=!0:7==f&&(u.browser.isIE7=!0):(7==d?u.browser.isIE7=!0:8==d?u.browser.isIE8=!0:9==d?(u.browser.isIE9=!0,u.browser.isSTANDARD=!0):10==d?(u.browser.isIE10=!0,u.browser.isSTANDARD=!0,u.browser.isIE10_ABOVE=!0):u.browser.isSTANDARD=!0,8==f?u.browser.isIE8_CORE=!0:9==f?u.browser.isIE9_CORE=!0:11==c.version&&(u.browser.isIE11=!0))}}(),window.iweb=u}($),+function($,ko){function _updateDom(e,t){for(var n in t){var r=t[n];for(var s in r){var i=r[s];if("trigger"==s)e.trigger(i[0]);else if($.isArray(i))$.each(i,function(t,n){e[t](n)});else try{e[n](r)}catch(a){e[n](r[n])}}}}var App=function(){this.dataTables={}};App.fn=App.prototype,App.fn.init=function(e,t,n){var r=this;this.element=t||document.body,$(this.element).find("[u-meta]").each(function(){if(!($(this).data("u-meta")||$(this).parents("[u-meta]").length>0)){var t=JSON.parse($(this).attr("u-meta"));if(t&&t.type){r.adjustFunc&&r.adjustFunc.call(r,t);var n=$.compManager._createComp(this,t,e,r);n&&$(this).data("u-meta",n)}}}),$.hotkeys&&$.hotkeys.scan(this.element),_getDataTables(this,e);try{("undefined"==typeof n||1==n)&&ko.applyBindings(e,this.element)}catch(s){iweb.log.error(s)}},App.fn.setAdjustMetaFunc=function(e){this.adjustFunc=e},App.fn.addDataTable=function(e){return this.dataTables[e.id]=e,this},App.fn.getDataTable=function(e){return this.dataTables[e]},App.fn.getDataTables=function(){return this.dataTables},App.fn.getComp=function(e){var t=null;return $(this.element).find("[u-meta]").each(function(){if($(this).data("u-meta")){var n=$(this).data("u-meta");if(n.id==e)return t=n,!1}}),t},App.fn.getCompsByDataTable=function(e,t){for(var n=this.getComps(t),r=[],s=0;s<n.length;s++)(n[s].dataModel&&n[s].dataModel.id==e||n[s].dataTable&&n[s].dataTable.id==e)&&r.push(n[s]);return r},App.fn.getComps=function(e){e=e?e:this.element;var t=[];return $(e).find("[u-meta]").each(function(){if($(this).data("u-meta")){var e=$(this).data("u-meta");e&&t.push(e)}}),t},App.fn.compsValidate=function(e){for(var t=this.getComps(e),n=!0,r=0;r<t.length;r++)t[r].doValidate&&(n=t[r].doValidate(!0)&&n);return n},App.fn.getCompsByType=function(e,t){t=t?t:this.element;var n=[];return $(t).find("[u-meta]").each(function(){if($(this).data("u-meta")){var t=$(this).data("u-meta");t&&t.type==e&&n.push(t)}}),n},App.fn.getEnvironment=function(){return window.iweb.Core.collectEnvironment()},App.fn.setClientAttribute=function(e,t){window.iweb.Core.setClientAttribute(e,t)},App.fn.getClientAttribute=function(e){window.iweb.Core.getClientAttributes()[e]},App.fn.serverEvent=function(){return new ServerEvent(this)},App.fn.ajax=function(e){e=this._wrapAjax(e),$.ajax(e)},App.fn._wrapAjax=function(e){var t=this,n=e.success,r=e.error,s=e.deferred;return s&&s.resolve||(s={resolve:function(){},reject:function(){}}),e.success=function(e,r,i){processXHRError(t,e,r,i)?(n.call(null,e),t._successFunc(e,s)):s.reject()},e.error=function(e,n,i){processXHRError(t,e,n,i)?(r.call(null,e),t._successFunc(e,s)):s.reject()},e.data?e.data.environment=ko.toJSON(window.iweb.Core.collectEnvironment()):e.data={environment:ko.toJSON(window.iweb.Core.collectEnvironment())},e},App.fn._successFunc=function(e,t){t.resolve()},window.processXHRError=function(rsl,state,xhr){return"string"==typeof rsl&&(rsl=JSON.parse(rsl)),xhr.getResponseHeader&&xhr.getResponseHeader("X-Error")?($.showMessageDialog({type:"info",title:"提示",msg:rsl.message,backdrop:!0}),rsl.operate&&eval(rsl.operate),!1):!0},App.fn.setUserCache=function(e,t){var n=this.getEnvironment().usercode;n&&localStorage.setItem(n+e,t)},App.fn.getUserCache=function(e){var t=this.getEnvironment().usercode;if(t)return localStorage.getItem(t+e)},App.fn.removeUserCache=function(e){var t=this.getEnvironment().usercode;t&&localStorage.removeItem(t+e)},App.fn.setCache=function(e,t){localStorage.setItem(e,t)},App.fn.getCache=function(e){return localStorage.getItem(e)},App.fn.removeCache=function(e){localStorage.removeItem(e)},App.fn.setSessionCache=function(e,t){sessionStorage.setItem(e,t)},App.fn.getSessionCache=function(e){return sessionStorage.getItem(e)},App.fn.removeSessionCache=function(e){sessionStorage.removeItem(e)},App.fn.setEnable=function(e){$(this.element).find("[u-meta]").each(function(){if($(this).data("u-meta")){var t=$(this).data("u-meta");t.setEnable&&t.setEnable(e)}})};var ServerEvent=function(e){this.app=e,this.datas={},this.params={},this.event=null,this.ent=window.iweb.Core.collectEnvironment(),window.pako&&0==iweb.debugMode&&(this.compression=!0)};ServerEvent.DEFAULT={async:!0,singleton:!0,url:(window.$ctx||"/iwebap")+"/evt/dispatch"},ServerEvent.fn=ServerEvent.prototype,ServerEvent.fn.addDataTable=function(e,t){var n=this.app.getDataTable(e);return this.datas[e]=n.getDataByRule(t),this},ServerEvent.fn.setCompression=function(e){window.pako||1!=e?this.compression=e:iweb.log.error("can't compression, please include pako!")},ServerEvent.fn.addDataTables=function(e){if(2==arguments.length)for(var t=0;t<e.length;t++){var n;"string"==typeof arguments[1]?n=arguments[1]:"array"==$.type(arguments[1])&&(n=arguments[1][t]),this.addDataTable(e[t],n)}else for(var t=0;t<e.length;t++){var r=e[t];if("string"==typeof r)this.addDataTable(r);else for(key in r)this.addDataTable(key,r[key])}return this},ServerEvent.fn.addAllDataTables=function(e){for(var t=this.app.dataTables,n=0;n<t.length;n++)this.addDataTable(t[n].id,e)},ServerEvent.fn.addParameter=function(e,t){return this.params[e]=t,this},ServerEvent.fn.setEvent=function(e){return this.event=e,this};var _formatEvent=function(e){return e};ServerEvent.fn.fire=function(e){var t=this,n=this.getData();n.parameters=ko.toJSON(this.params);var r={type:e.type||"POST",data:e.params||{},url:e.url||ServerEvent.DEFAULT.url,async:"undefined"==typeof e.async?ServerEvent.DEFAULT.async:e.async,singleton:e.singleton||ServerEvent.DEFAULT.singleton,success:e.success,error:e.error,dataType:"json"};r.data.ctrl=e.ctrl,r.data.method=e.method,this.event&&(r.data.event=ko.toJSON(this.event));var s=r.preSuccess||function(){},i=r.success||function(){},a=r.error;this.orignError=a;var o=r.deferred;o&&o.resolve||(o={resolve:function(){},reject:function(){}}),r.success=function(e,n,r){processXHRError(t,e,n,r)?(s.call(null,e),t._successFunc(e,o),i.call(null,e.custom),o.resolve()):o.reject()},r.error=function(e,n,r){processXHRError(t,e,n,r)?a&&a.call(null,e.custom):o.reject()},r.data=$.extend(r.data,n),$.ajax(r)},ServerEvent.fn.getData=function(){var e=ko.toJSON(this.app.getEnvironment()),t=ko.toJSON(this.datas),n="";return this.compression&&(window.isSwfCompressReady()?(e=window.swfCompress(e),t=window.swfCompress(t),n="deflate"):(e=encodeBase64(window.pako.gzip(e)),t=encodeBase64(window.pako.gzip(t)),n="gzip")),{environment:e,dataTables:t,compression:this.compression,compressType:n}},ServerEvent.fn._successFunc=function(e,t){var n=e.dataTables,r=e.dom;r&&this.updateDom(JSON.parse(r)),n&&this.updateDataTables(n,t)},ServerEvent.fn.updateDataTables=function(e,t){for(var n in e){var r=this.app.getDataTable(n);r&&(r.setData(e[n]),r.updateMeta(e[n].meta))}},ServerEvent.fn.setSuccessFunc=function(e){this._successFunc=e},ServerEvent.fn.updateDom=function(){$.each(dom,function(e,t){var n=t.two,r=$(t.one);_updateDom(r,n)})};var processXHRError=function(self,rsl,state,xhr){if("string"==typeof rsl&&(rsl=JSON.parse(rsl)),xhr.getResponseHeader&&xhr.getResponseHeader("X-Error")){if(!self.orignError)return $.showMessageDialog?$.showMessageDialog({type:"info",title:"提示",msg:rsl.message,backdrop:!0}):alert(rsl.message),rsl.operate&&eval(rsl.operate),!1;self.orignError.call(self,rsl,state,xhr)}return!0};$.createApp=function(){var e=new App;return e};var _getDataTables=function(e,t){for(var n in t)t[n]instanceof $.DataTable&&(t[n].id=n,t[n].parent=t,e.addDataTable(t[n]))}}($,ko),+function(e){"use strict";var t=function(){};t.fn=t.prototype,t.fn.on=function(e,t){e=e.toLowerCase(),this._events||(this._events={});var n=this._events[e]||(this._events[e]=[]);return n.push({callback:t}),this},t.fn.trigger=function(e){if(e=e.toLowerCase(),!this._events||!this._events[e])return this;for(var t=Array.prototype.slice.call(arguments,1),n=this._events[e],r=0,s=n.length;s>r;r++)n[r].callback.apply(this,t);return this},t.fn.getEvent=function(e){return e=e.toLowerCase(),this._events||(this._events={}),this._events[e]};var n=function(e){this.id=e.id,this.meta=n.createMetaItems(e.meta),this.enable=e.enable||n.DEFAULTS.enable,this.pageSize=ko.observable(e.pageSize||n.DEFAULTS.pageSize),this.pageIndex=ko.observable(e.pageIndex||n.DEFAULTS.pageIndex),this.totalPages=ko.observable(e.totalPages||n.DEFAULTS.totalPages),this.totalRow=ko.observable(),this.pageCache=void 0===e.pageCache?n.DEFAULTS.pageCache:e.pageCache,this.rows=ko.observableArray([]),this.selectedIndices=ko.observableArray([]),this.focusIndex=-1,this.cachedPages=[],this.createDefaultEvents(),this.metaChange=ko.observable(1),this.valueChange=ko.observable(1),this.enableChange=ko.observable(1),this.params=e.params||{},this.master=e.master||""};n.fn=n.prototype=new t,n.DEFAULTS={pageSize:20,pageIndex:0,totalPages:20,pageCache:!1,enable:!0},n.META_DEFAULTS={enable:!0,required:!1,descs:{}},n.createMetaItems=function(t){var r={};for(var s in t){var i=t[s];"string"==typeof i&&(i={}),r[s]=e.extend({},n.META_DEFAULTS,i)}return r},n.ON_ROW_SELECT="select",n.ON_ROW_UNSELECT="unSelect",n.ON_ROW_ALLSELECT="allSelect",n.ON_ROW_ALLUNSELECT="allUnselect",n.ON_VALUE_CHANGE="valueChange",n.ON_INSERT="insert",n.ON_UPDATE="update",n.ON_DELETE="delete",n.ON_DELETE_ALL="deleteAll",n.ON_ROW_FOCUS="focus",n.ON_ROW_UNFOCUS="unFocus",n.ON_LOAD="load",n.ON_ENABLE_CHANGE="enableChange",n.ON_META_CHANGE="metaChange",n.ON_ROW_META_CHANGE="rowMetaChange",n.SUBMIT={current:"current",focus:"focus",all:"all",select:"select",change:"change",empty:"empty"},n.fn.createDefaultEvents=function(){},n.fn.addParam=function(e,t){this.params[e]=t},n.fn.addParams=function(e){for(var t in e)this.params[t]=e[t]},n.fn.getParam=function(e){return this.params[e]},n.fn.getMeta=function(e,t){return 0==arguments.length?this.meta:this.meta[e][t]},n.fn.setMeta=function(e,t,r){var s=this.meta[e][t];this.meta[e][t]=r,this.metaChange(-this.metaChange()),"enable"==t&&this.enableChange(-this.enableChange()),this.trigger(n.ON_META_CHANGE,{eventType:"dataTableEvent",dataTable:this.id,field:e,meta:t,oldValue:s,newValue:r})},n.fn.setCurrentPage=function(e){this.pageIndex(e);var t=this.cachedPages[this.pageIndex()];t&&(this.removeAllRows(),this.setRows(t.rows),this.setRowsSelect(t.selectedIndcies))},n.fn.isChanged=function(){for(var e=this.getAllRows(),t=0;t<e.length;t++)if(e[t].status!=r.STATUS.NORMAL)return!0;return!1},n.fn.updateMeta=function(e){if(e){for(var t in e)for(var n in e[t])"default"===n?(this.meta[t]["default"]||(this.meta[t]["default"]={}),this.meta[t]["default"].value=e[t][n]):"display"===n?(this.meta[t]["default"]||(this.meta[t]["default"]={}),this.meta[t]["default"].display=e[t][n]):this.meta[t][n]=e[t][n];this.metaChange(-this.metaChange())}},n.fn.setData=function(e){var t=e.pageIndex,n=e.pageSize||this.pageSize(),r=e.totalPages||this.totalPages(),s=e.totalRow;e.type;this.setRows(e.rows),this.pageIndex(t),this.pageSize(n),this.totalPages(r),this.totalRow(s),this.updateSelectedIndices(),e.select&&e.select.length>0&&this.rows().length>0&&this.setRowsSelect(e.select),e.focus&&this.setRowFocus(e.focus)},n.fn.setRows=function(t){for(var s=[],i=0;i<t.length;i++){var a=t[i];if(a.id||(a.id=r.getRandomRowId()),a.status==r.STATUS.DELETE)this.removeRowByRowId(a.id);else{var o=this.getRowByRowId(a.id);o?(o.updateRow(a),e.isEmptyObject(a.data)||(this.trigger(n.ON_UPDATE,{index:i,rows:[o]}),o==this.getCurrentRow()?(this.valueChange(-this.valueChange()),o.valueChange(-o.valueChange())):o.valueChange(-o.valueChange()))):(o=new r({parent:this,id:a.id}),o.setData(t[i]),s.push(o))}}s.length>0&&this.addRows(s)},n.fn.clearCache=function(){this.cachedPages=[]},n.fn.cacheCurrentPage=function(){this.pageCache&&(this.cachedPages[this.pageIndex()]={rows:this.rows().slice(),selectedIndcies:this.selectedIndices().slice(),pageSize:this.pageSize()})},n.fn.hasPage=function(e){return this.pageCache&&this.cachedPages[e]&&this.cachedPages[e].pageSize==this.pageSize()?!0:!1},n.fn.copyRow=function(e,t){var n=new r({parent:this});t&&n.setData(t.getData()),this.insertRows(void 0===e?this.rows().length:e,[n])},n.fn.addRow=function(e){this.insertRow(this.rows().length,e)},n.fn.addRows=function(e){this.insertRows(this.rows().length,e)},n.fn.insertRow=function(e,t){t||(t=new r({parent:this})),this.insertRows(e,[t])},n.fn.insertRows=function(e,t){for(var r=0;r<t.length;r++)this.rows.splice(e+r,0,t[r]),this.updateSelectedIndices(e+r,"+"),this.updateFocusIndex(e,"+");this.trigger(n.ON_INSERT,{index:e,rows:t})},n.fn.createEmptyRow=function(){var e=new r({parent:this});return this.addRow(e),e},n.fn.removeRowByRowId=function(e){var t=this.getIndexByRowId(e);-1!=t&&this.removeRow(t)},n.fn.removeRow=function(e){e instanceof r&&(e=this.getIndexByRowId(e.rowId)),this.removeRows([e])},n.fn.removeAllRows=function(){this.rows([]),this.selectedIndices([]),this.focusIndex=-1,this.trigger(n.ON_DELETE_ALL)},n.fn.removeRows=function(e){e=this._formatToIndicesArray(e),e=e.sort();for(var t=[],r=this.rows(),s=[],i=e.length-1;i>=0;i--){var a=e[i],o=r[a];if(null!=o){t.push(o.rowId);var u=r.splice(a,1);s.push(u[0]),this.updateSelectedIndices(a,"-"),this.updateFocusIndex(a,"-")}}this.rows(r),this.deleteRows=s,this.trigger(n.ON_DELETE,{indices:e,rowIds:t,deleteRows:s})},n.fn.setRowDelete=function(e){e instanceof r&&(e=this.getIndexByRowId(e.rowId)),this.setRowDelete([e])},n.fn.setAllRowsDelete=function(){for(var e=new Array(this.rows().length),t=0;t<e.length;t++)e[t]=t;this.setRowsDelete(e)},n.fn.setRowsDelete=function(e){e=this._formatToIndicesArray(e);for(var t=0;t<e.length;t++){var s=this.getRow(e[t]);s.status==r.STATUS.NEW?(this.rows(this.rows().splice(e[t],1)),this.updateSelectedIndices(e[t],"-"),this.updateFocusIndex(index,"-")):s.status=r.STATUS.FALSE_DELETE}var i=this.getRowIdsByIndices(e);this.trigger(n.ON_ROW_DELETE,{falseDelete:!0,indices:e,rowIds:i})},n.fn.setAllRowsSelect=function(){for(var e=new Array(this.rows().length),t=0;t<e.length;t++)e[t]=t;this.setRowsSelect(e),this.trigger(n.ON_ROW_ALLSELECT,{})},n.fn.setRowSelect=function(e){e instanceof r&&(e=this.getIndexByRowId(e.rowId)),this.setRowsSelect([e]),this.setRowFocus(this.getSelectedIndex())},n.fn.setRowsSelect=function(t){t=this._formatToIndicesArray(t);var r=this.selectedIndices();if("array"!=e.type(t)||"array"!=e.type(r)||t.join()!=r.join()){this.setAllRowsUnSelect({quiet:!0}),this.selectedIndices(t);var s=this.getRowIdsByIndices(t);this.valueChange(-this.valueChange()),this.trigger(n.ON_ROW_SELECT,{indices:t,rowIds:s})}},n.fn.addRowsSelect=function(e){e=this._formatToIndicesArray(e);for(var t=this.selectedIndices().slice(),r=0;r<e.length;r++){for(var s=e[r],i=!0,a=0;a<t.length;a++)t[a]==s&&(i=!1);i&&t.push(e[r])}this.selectedIndices(t);var o=this.getRowIdsByIndices(e);this.trigger(n.ON_ROW_SELECT,{indices:e,rowIds:o})},n.fn.getRowIdsByIndices=function(e){for(var t=[],n=0;n<e.length;n++)t.push(this.getRow(e[n]).rowId);return t},n.fn.setAllRowsUnSelect=function(e){this.selectedIndices([]),e&&e.quiet||this.trigger(n.ON_ROW_ALLUNSELECT)},n.fn.setRowUnSelect=function(e){this.setRowsUnSelect([e])},n.fn.setRowsUnSelect=function(e){e=this._formatToIndicesArray(e);var t=this.selectedIndices().slice();if(-1!=t.indexOf(e[0])){for(var r=0;r<e.length;r++){var s=e[r],i=t.indexOf(s);-1!=i&&t.splice(i,1)}this.selectedIndices(t);var a=this.getRowIdsByIndices(e);this.trigger(n.ON_ROW_UNSELECT,{indices:e,rowIds:a})}},n.fn.updateSelectedIndices=function(e,t){var n=this.selectedIndices().slice();if(null!=n&&0!=n.length){for(var r=0,s=n.length;s>r;r++)"+"==t?n[r]>=e&&(n[r]=parseInt(n[r])+1):"-"==t&&(n[r]==e?n.splice(r,1):n[r]>e&&(n[r]=n[r]-1));this.selectedIndices(n)}},n.fn.updateFocusIndex=function(e,t){e<=this.focusIndex&&-1!=this.focusIndex&&("+"===t?this.focusIndex++:"-"===t&&(this.focusIndex===this.opIndex?this.focusIndex=-1:this.focusIndex--))},n.fn.getSelectedIndex=function(){var e=this.selectedIndices();return null==e||0==e.length?-1:e[0]},n.fn.getSelectedIndexs=function(){var e=this.selectedIndices();return null==e||0==e.length?[]:e},n.fn.getFocusIndex=function(){return this.focusIndex},n.fn.getIndexByRowId=function(e){for(var t=0,n=this.rows().length;n>t;t++)if(this.rows()[t].rowId==e)return t;return-1},n.fn.getAllDatas=function(){for(var e=this.getAllRows(),t=[],n=0,r=e.length;r>n;n++)e[n]&&t.push(e[n].getData());return t},n.fn.getData=function(){for(var e=[],t=0;t<this.rows().length;t++)e.push(this.rows()[t].getData());return e},n.fn.getDataByRule=function(e){var t={},r=null;if(t.meta=this.meta,t.params=this.params,e=e||n.SUBMIT.current,e==n.SUBMIT.current){var s=this.focusIndex;-1==s&&(s=this.getSelectedIndex()),r=[];for(var i=0,a=this.rows().length;a>i;i++)i==s?r.push(this.rows()[i].getData()):r.push(this.rows()[i].getEmptyData())}else if(e==n.SUBMIT.focus){r=[];for(var i=0,a=this.rows().length;a>i;i++)i==this.focusIndex?r.push(this.rows()[i].getData()):r.push(this.rows()[i].getEmptyData())}else e==n.SUBMIT.all?r=this.getData():e==n.SUBMIT.select?r=this.getSelectedDatas(!0):e==n.SUBMIT.change?r=this.getChangedDatas():e===n.SUBMIT.empty&&(r=[]);return t.rows=r,t.select=this.getSelectedIndexs(),t.focus=this.getFocusIndex(),t.pageSize=this.pageSize(),t.pageIndex=this.pageIndex(),t.isChanged=this.isChanged(),t.master=this.master,t},n.fn.getSelectedDatas=function(e){for(var t=this.selectedIndices(),n=[],r=[],s=0,i=t.length;i>s;s++)r.push(t[s]);for(var s=0,i=this.rows().length;i>s;s++)-1!=r.indexOf(s)?n.push(this.rows()[s].getData()):1==e&&n.push(this.rows()[s].getEmptyData());return n},n.fn.refSelectedRows=function(){return ko.pureComputed({read:function(){for(var e=this.selectedIndices()||[],t=this.rows(),n=[],r=0;r<e.length;r++)n.push(t[r]);return n},owner:this})},n.fn.ref=function(e){return ko.pureComputed({read:function(){this.valueChange();var t=this.getCurrentRow();return t?t.getValue(e):""},write:function(t){var n=this.getCurrentRow();n&&n.setValue(e,t)},owner:this})},n.fn.refMeta=function(e,t){return ko.pureComputed({read:function(){return this.metaChange(),this.getMeta(e,t)},write:function(n){this.setMeta(e,t,n)},owner:this})},n.fn.refRowMeta=function(e,t){return ko.pureComputed({read:function(){this.metaChange();var n=this.getCurrentRow();return n?n.getMeta(e,t):this.getMeta(e,t)},write:function(t){var n=this.getCurrentRow();n&&n.setMeta(e,t)},owner:this})},n.fn.refEnable=function(e){return ko.pureComputed({read:function(){if(this.enableChange(),!e)return this.enable;var t=this.getMeta(e,"enable");return("undefined"==typeof t||null==t)&&(t=!0),t&&this.enable},owner:this})},n.fn.isEnable=function(e){var t=this.getMeta(e,"enable");return("undefined"==typeof t||null==t)&&(t=!0),t&&this.enable},n.fn.getValue=function(e,t){return t=t||this.getCurrentRow(),t?t.getValue(e):""},n.fn.setValue=function(e,t,n,r){n=n?n:this.getCurrentRow(),n&&n.setValue(e,t,r)},n.fn.setEnable=function(e){this.enable!=e&&(this.enable=e,this.enableChange(-this.enableChange()),this.trigger(n.ON_ENABLE_CHANGE,{enable:this.enable}))},n.fn.getCurrentRow=function(){if(-1!=this.focusIndex)return this.getFocusRow();var e=this.getSelectedIndex();return-1==e?null:this.getRow(e)},n.fn.getFocusRow=function(){return-1!=this.focusIndex?this.getRow(this.focusIndex):null},n.fn.setRowFocus=function(e,t,s){var i=null;e instanceof r&&(e=this.getIndexByRowId(e.rowId),i=e.rowId),-1===e||e===this.focusIndex&&!s||(this.focusIndex=e,t||(this.valueChange(-this.valueChange()),i||(i=this.getRow(e).rowId),this.trigger(n.ON_ROW_FOCUS,{index:e,rowId:i})))},n.fn.setRowUnFocus=function(){this.valueChange(-this.valueChange());var e=this.focusIndex,t=null;-1!==e&&(t=this.getRow(e).rowId),this.trigger(n.ON_ROW_UNFOCUS,{index:e,rowId:t}),this.focusIndex=-1},n.fn.getRow=function(e){return this.rows()[e]},n.fn.getAllRows=function(){return this.rows()},n.fn.getRowByRowId=function(e){for(var t=0,n=this.rows().length;n>t;t++)if(this.rows()[t].rowId==e)return this.rows()[t];return null},n.fn.getChangedDatas=function(e){for(var t=[],n=0,s=this.rows().length;s>n;n++)this.rows()[n]&&this.rows()[n].status!=r.STATUS.NORMAL?t.push(this.rows()[n].getData()):1==e&&t.push(this.rows()[n].getEmptyData());return t},n.fn._formatToIndicesArray=function(t){if("string"==typeof t||"number"==typeof t)t=[t];else if(t instanceof r)t=this.getIndexByRowId(t.rowId);else if("array"===e.type(t)&&t.length>0&&t[0]instanceof r)for(var n=0;n<t.length;n++)t[n]=this.getIndexByRowId(t[n].rowId);return t};var r=function(e){this.rowId=e.id||r.getRandomRowId(),this.status=r.STATUS.NEW,this.parent=e.parent,this.initValue=null,this.data={},this.metaChange=ko.observable(1),this.valueChange=ko.observable(1),this.init()};r.STATUS={NORMAL:"nrm",UPDATE:"upd",NEW:"new",DELETE:"del",FALSE_DELETE:"fdel"},r.fn=r.prototype=new t,r.fn.init=function(){var e=this.parent.meta;for(var t in e)if(this.data[t]={},e[t]["default"]){var n=e[t]["default"];for(var r in n)"value"==r?this.data[t].value=n[r]:(this.data[t].meta=this.data[t].meta||{},this.data[t].meta[r]=n[r])}},r.fn.ref=function(e){return ko.pureComputed({read:function(){return this.valueChange(),this._getField(e).value},write:function(t){this.setValue(e,t)},owner:this})},r.fn.refMeta=function(e,t){return ko.pureComputed({read:function(){return this.metaChange(),this.getMeta(e,t)},write:function(n){this.setMeta(e,t,n)},owner:this})},r.fn.refCombo=function(t,n){return ko.pureComputed({read:function(){this.valueChange();var r=e.getJSObject(this.parent.parent,n);if(void 0===this._getField(t).value||""===this._getField(t).value)return"";for(var s=this._getField(t).value,i="string"==typeof s?s.split(","):[s],a=[],o=0,u=r.length;u>o;o++)for(var h=0;h<i.length;h++)r[o].pk==i[h]&&a.push(r[o].name);return a.toString()},write:function(e){this.setValue(t,e)},owner:this})},r.fn.refDate=function(e,t){return ko.pureComputed({read:function(){
if(this.valueChange(),!this._getField(e).value)return"";var n=this._getField(e).value;return n?n=moment(n).format(t):""},write:function(t){this.setValue(e,t)},owner:this})},r.fn.getValue=function(e){return this._getField(e).value},r.fn.setValue=function(e,t,s,i){var a=this.getValue(e)||"";a!=(t||"")&&(this._getField(e).value=t,this._getField(e).changed=!0,this.status!=r.STATUS.NEW&&(this.status=r.STATUS.UPDATE),this.valueChange(-this.valueChange()),this.parent.getCurrentRow()==this&&this.parent.valueChange(-this.parent.valueChange()),this.parent.trigger(n.ON_VALUE_CHANGE,{eventType:"dataTableEvent",dataTable:this.parent.id,rowId:this.rowId,field:e,oldValue:a,newValue:t,ctx:s||""}),this.parent.trigger(e+"."+n.ON_VALUE_CHANGE,{eventType:"dataTableEvent",dataTable:this.parent.id,rowId:this.rowId,field:e,oldValue:a,newValue:t,ctx:s||""}))},r.fn.getMeta=function(e,t){if(0==arguments.length){var n={};for(var r in this.data)n[r]=this.data[r].meta?this.data[r].meta:{};return n}var s=this._getField(e).meta;return s&&s[t]?s[t]:this.parent.getMeta(e,t)},r.fn.setMeta=function(e,t,r){var s=this._getField(e).meta;s||(s=this._getField(e).meta={});var i=s[t];s[t]=r,this.metaChange(-this.metaChange()),"enable"==t&&this.parent.enableChange(-this.parent.enableChange()),this.parent.getCurrentRow()==this&&this.parent.metaChange(-this.parent.metaChange()),this.parent.trigger(n.ON_ROW_META_CHANGE,{eventType:"dataTableEvent",dataTable:this.parent.id,field:e,meta:t,oldValue:i,newValue:r,row:this})},r.fn.setData=function(t){this.status=t.status;for(var n in t.data)if(this.data[n]){var r=t.data[n];if("string"==typeof r||"number"==typeof r||null===r)this.data[n].value=this.formatValue(n,r);else if(r.error)e.showMessageDialog({title:"警告",msg:r.error,backdrop:!0});else{this.data[n].value=this.formatValue(n,r.value);for(var s in r.meta)this.setMeta(n,s,r.meta[s])}}},r.fn.formatValue=function(e,t){var n=this.parent.getMeta(e,"type");return n&&("date"==n||"datetime"==n)?s(t):t},r.fn.updateRow=function(e){this.setData(e)},r.fn.getData=function(){var e=ko.toJS(this.data),t=this.parent.getMeta();for(var n in t)t[n]&&t[n].type&&("date"==t[n].type||"datetime"==t[n].type)&&(e[n].value=i(e[n].value));return{id:this.rowId,status:this.status,data:e}},r.fn.getEmptyData=function(){return{id:this.rowId,status:this.status,data:{}}},r.fn._getField=function(e){if(!this.data[e])throw new Error("field:"+e+" not exist in dataTable:"+this.parent.id+"!");return this.data[e]},r.getRandomRowId=function(){return setTimeout(function(){})};var s=function(e){if(!e)return e;var t=new Date;t.setTime(e);var n=t.getFullYear(),r=t.getMonth()+1;parseInt(r)<10&&(r="0"+r);var s=t.getDate();parseInt(s)<10&&(s="0"+s);var i=t.getHours();parseInt(i)<10&&(i="0"+i);var a=t.getMinutes();parseInt(a)<10&&(a="0"+a);var o=t.getSeconds();parseInt(o)<10&&(o="0"+o);var u=n+"-"+r+"-"+s+" "+i+":"+a+":"+o;return u},i=function(e){if(!e)return"";e.indexOf("-")>-1&&(e=e.replace(/\-/g,"/"));var t=Date.parse(e);return isNaN(t)?"":t};e.Row=r,e.DataTable=n}($),+function(e,t){"use strict";var n={plugs:{},apply:function(r,s){s=s||document.body,e(s).find("[u-meta]").each(function(){if(!(e(this).data("u-meta")||e(this).parent("[u-meta]").length>0)){var t=JSON.parse(e(this).attr("u-meta"));if(t&&t.type){var s=n._createComp(this,t,r,app);s&&e(this).data("u-meta",s)}}}),t.applyBindings(r,s)},addPlug:function(e){var t=e.getName();if(this.plugs||(this.plugs={}),this.plugs[t])throw new Error("plug has exist:"+t);this.plugs[t]=e},_createComp:function(e,t,n,r){var s=t.type,i=this.plugs[s];if(!i)return null;var a=new i(e,t,n,r);return a.type=s,a}};e.compManager=n}($,ko);