From 8be373cd8be5ae0868706c23c6a6e8ebf3e71bf4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 24 Feb 2022 18:36:49 +0100 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Token=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + admin/admin.inc.php | 173 ++++++++++++++---- api/function_API.php | 14 +- api/index.php | 2 +- application/list.php | 2 +- config/api_key.php | 37 ++-- config/config.php | 4 +- .../zui/lib/datagrid/zui.datagrid.min.css | 6 + .../zui/lib/datagrid/zui.datagrid.min.js | 14 ++ 9 files changed, 197 insertions(+), 56 deletions(-) create mode 100755 public/static/zui/lib/datagrid/zui.datagrid.min.css create mode 100755 public/static/zui/lib/datagrid/zui.datagrid.min.js diff --git a/README.md b/README.md index d4587c0..7fc5186 100755 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ $HTTP["url"] =~ "^/(i|public)/" { * 2022-2-21 v2.5.4 Developing - 增加回收图片 +- 增加Token有效期 - 修复广场标题 * 2022-2-21 v2.5.3 diff --git a/admin/admin.inc.php b/admin/admin.inc.php index 29be4fe..ca1c495 100755 --- a/admin/admin.inc.php +++ b/admin/admin.inc.php @@ -38,6 +38,55 @@ if (isset($_POST['update'])) { '; header("refresh:1;"); } + +// 添加token +if (isset($_POST['add_token_id'])) { + // $_POST['add_token'] 生成的Token + // $_POST['add_token_id'] Token的ID + // $_POST['add_token_expired'] 过期时间 + $postArr = array( + $_POST['add_token'] => array( + 'id' => $_POST['add_token_id'], 'expired' => $_POST['add_token_expired'] * 86400 + time(), 'add_time' => time() + ) + ); + $new_config = array_replace($tokenList, $postArr); + $config_file = APP_ROOT . '/config/api_key.php'; + cache_write($config_file, $new_config, 'tokenList'); + echo ' + + '; + header("refresh:1;"); +} +// 禁用Token +if (isset($_GET['stop_token'])) { + + // unset($tokenList[$_GET['delete_token']]); + $stop_token = $_GET['stop_token']; + $postArr = array( + $stop_token => array( + 'id' => 0, 'expired' => time() + ) + ); + $new_config = array_replace($tokenList, $postArr); + $config_file = APP_ROOT . '/config/api_key.php'; + cache_write($config_file, $new_config, 'tokenList'); + echo ' + + '; + header("refresh:2;url=" . $config['domain'] . "/admin/admin.inc.php"); +} + + // 删除guset.config.php数组对 if (isset($_GET['delete_guest'])) { unset($guestConfig[$_GET['delete_guest']]); @@ -88,16 +137,7 @@ if (isset($_POST['delDir'])) { header("refresh:1;"); // 1s后刷新当前页面 } } -// 查找用户ID或者Token -if (isset($_POST['radio'])) { - if ($_POST['radio'] == 'id') { - $radio_value = '用户token: ' . getIDToken($_POST['radio-value']); - } elseif ($_POST['radio'] == 'token') { - $radio_value = '用户ID: ' . getID($_POST['radio-value']); - } else { - $radio_value = null; - } -} + // 恢复图片 if (isset($_GET['reimg'])) { $name = $_GET['reimg']; @@ -451,7 +491,7 @@ if (isset($_GET['reimg'])) {
-
外部KEY | 请根据需要申请并填写
+
外部KEY
@@ -469,31 +509,30 @@ if (isset($_GET['reimg'])) { " placeholder="隐藏的保存"> - 生成新的API upload Token -
-
- New Token - +
+
上传Token
+ +
+ - - - - - - - - - '; ?> - -
当前可用Token列表:
' . $value . '
-
+
+
+ +
- - -
-
- + +
+
+ + + +
+ +
@@ -841,7 +880,7 @@ if (isset($_GET['reimg'])) { - 删除 + 删除 @@ -855,7 +894,11 @@ if (isset($_GET['reimg'])) { + + + + diff --git a/api/function_API.php b/api/function_API.php index 4762bcb..cf4872f 100755 --- a/api/function_API.php +++ b/api/function_API.php @@ -58,8 +58,8 @@ function check_api($token) exit(json_encode($reJson, JSON_UNESCAPED_UNICODE)); } - if (!in_array($token, $tokenList)) { - // Token错误 Token错误 + if (!in_array($tokenList[$token], $tokenList)) { + // Token 是否存在 $reJson = array( "result" => 'failed', 'code' => 202, @@ -67,4 +67,14 @@ function check_api($token) ); exit(json_encode($reJson, JSON_UNESCAPED_UNICODE)); } + + if ($tokenList[$token]['expired'] < time()) { + // Token 是否过期 + $reJson = array( + "result" => 'failed', + 'code' => 203, + 'message' => 'Token Expired', + ); + exit(json_encode($reJson, JSON_UNESCAPED_UNICODE)); + } } diff --git a/api/index.php b/api/index.php index 882aac0..99a3602 100755 --- a/api/index.php +++ b/api/index.php @@ -28,7 +28,7 @@ if ($handle->uploaded) { // 允许上传的mime类型 $handle->allowed = array('image/*'); // 文件命名 - $handle->file_new_name_body = imgName($handle->file_src_name_body) . '_' . getID($token); + $handle->file_new_name_body = imgName($handle->file_src_name_body) . '_' . $tokenList[$token]['id']; // 最大上传限制 $handle->file_max_sizes = $config['maxSize']; // 最大宽度 diff --git a/application/list.php b/application/list.php index 16dbdee..21adc64 100755 --- a/application/list.php +++ b/application/list.php @@ -123,7 +123,7 @@
- + diff --git a/config/api_key.php b/config/api_key.php index 5cc2700..1b40482 100755 --- a/config/api_key.php +++ b/config/api_key.php @@ -1,17 +1,22 @@ Token(注意后边',') - */ - -$tokenList = array( - 0 => '8337effca0ddfcd9c5899f3509b23657', - 1 => '1c17b11693cb5ec63859b091c5b9c1b2', -); \ No newline at end of file +$tokenList=Array + ( + '8337effca0ddfcd9c5899f3509b23657'=>Array + ( + 'id'=>0, + 'expired'=>3373722730, + 'add_time'=>1645722730 + ), + '1c17b11693cb5ec63859b091c5b9c1b2'=>Array + ( + 'id'=>1, + 'expired'=>2509722743, + 'add_time'=>1645722743 + ), + '3e2246984b5047c25dcf08dc41c367b8'=>Array + ( + 'id'=>2, + 'expired'=>1645636354, + 'add_time'=>1645722754 + ) + ); \ No newline at end of file diff --git a/config/config.php b/config/config.php index c8677da..793d6a7 100755 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,7 @@ $config=Array 'user'=>'admin', 'password'=>'e6e061838856bf47e1de730719fb2609', 'mustLogin'=>0, - 'apiStatus'=>0, + 'apiStatus'=>1, 'path'=>'/i/', 'imgName'=>'default', 'maxSize'=>10485760, @@ -97,7 +97,7 @@ var _hmt = _hmt || []; ), 'language'=>0, 'version'=>'2.5.3', - 'update'=>'2022-02-24 00:42:23', + 'update'=>'2022-02-25 00:25:27', 'terms'=>'
diff --git a/public/static/zui/lib/datagrid/zui.datagrid.min.css b/public/static/zui/lib/datagrid/zui.datagrid.min.css new file mode 100755 index 0000000..c90ace4 --- /dev/null +++ b/public/static/zui/lib/datagrid/zui.datagrid.min.css @@ -0,0 +1,6 @@ +/*! + * ZUI: 数据表格② - v1.10.0 - 2021-11-04 + * http://openzui.com + * GitHub: https://github.com/easysoft/zui.git + * Copyright (c) 2021 cnezsoft.com; Licensed MIT + */.datagrid-container{position:relative;overflow:hidden;background-color:#f1f1f1;border:1px solid #ddd}.datagrid-cells{position:absolute;top:0;left:0;overflow:visible}.datagrid-cell{position:absolute;padding:8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background-color:#fff;border:1px solid #ddd;-webkit-transition:.4s cubic-bezier(.175,.885,.32,1);-o-transition:.4s cubic-bezier(.175,.885,.32,1);transition:.4s cubic-bezier(.175,.885,.32,1);-webkit-transition-property:background,outline;-o-transition-property:background,outline;transition-property:background,outline}.datagrid-cell.datagrid-cell-index{font-family:Monaco,Menlo,Consolas,"Courier New",monospace;color:grey;text-align:right;background-color:#f1f1f1}.datagrid-cell.datagrid-cell-head{background-color:#f1f1f1}.datagrid-cell-span{z-index:10}.datagrid-row{position:absolute;width:100%;background-color:#fff;-webkit-transition:.4s cubic-bezier(.175,.885,.32,1);-o-transition:.4s cubic-bezier(.175,.885,.32,1);transition:.4s cubic-bezier(.175,.885,.32,1);-webkit-transition-property:background,outline;-o-transition-property:background,outline;transition-property:background,outline}.datagrid-row-head{font-weight:700;color:grey;background-color:#f1f1f1}.datagrid-fixed.datagrid-row{z-index:35}.datagrid-fixed.datagrid-cell{z-index:30}.datagrid-fixed-edge-top{-webkit-box-shadow:0 2px 5px 0 rgba(0,0,0,.125),0 1px 0 rgba(0,0,0,.25);box-shadow:0 2px 5px 0 rgba(0,0,0,.125),0 1px 0 rgba(0,0,0,.25)}.datagrid-fixed-edge-bottom{-webkit-box-shadow:0 -2px 5px 0 rgba(0,0,0,.125),0 -1px 0 rgba(0,0,0,.25);box-shadow:0 -2px 5px 0 rgba(0,0,0,.125),0 -1px 0 rgba(0,0,0,.25)}.datagrid-fixed-edge-left{-webkit-box-shadow:-1px 0 0 rgba(0,0,0,.25) inset;box-shadow:-1px 0 0 rgba(0,0,0,.25) inset}.datagrid-fixed-edge-right{-webkit-box-shadow:1px 0 0 rgba(0,0,0,.25) inset;box-shadow:1px 0 0 rgba(0,0,0,.25) inset}.datagrid-row-cell.active .datagrid-cell{background-color:#fff0d5}.datagrid-row-cell.active .datagrid-cell.datagrid-cell-index{background-color:#ffe7bc}.datagrid-hover-row .datagrid-row-cell:hover{z-index:20}.datagrid-hover-row .datagrid-row-cell:hover .datagrid-cell{background-color:#ebf2f9}.datagrid-hover-row .datagrid-row-cell:hover.datagrid-fixed{z-index:38}.datagrid-hover-row .datagrid-row-cell:hover>.datagrid-cell-index{background-color:#ddd}.datagrid-hover-row .datagrid-row-cell:hover.active .datagrid-cell{background-color:#ffe1ac}.datagrid-hover-row .datagrid-row-cell:hover.active .datagrid-cell-index{background-color:#ffda98}.datagrid-hover-row.datagrid-hover-shadow .datagrid-row-cell:hover{-webkit-box-shadow:0 1px 3px 2px rgba(0,0,0,.05),0 0 2px 1px rgba(0,0,0,.075);box-shadow:0 1px 3px 2px rgba(0,0,0,.05),0 0 2px 1px rgba(0,0,0,.075)}.datagrid-hover-cell .datagrid-row-cell .datagrid-cell-cell:hover{z-index:40;background-color:#fff;outline:1px solid grey;outline-offset:-1px}.datagrid-hover-cell .datagrid-row-cell .datagrid-cell-cell.datagrid-fixed:hover,.datagrid-hover-cell .datagrid-row-cell.datagrid-fixed .datagrid-cell-cell:hover{z-index:42}.datagrid-hover-cell.datagrid-hover-shadow .datagrid-row-cell .datagrid-cell:hover{-webkit-box-shadow:0 1px 3px 3px rgba(0,0,0,.075),0 0 2px rgba(0,0,0,.1);box-shadow:0 1px 3px 3px rgba(0,0,0,.075),0 0 2px rgba(0,0,0,.1)}.datagrid-hover-col .datagrid-cell.hover{background-color:#ebf2f9}.datagrid-hover-col .datagrid-cell-head.hover,.datagrid-hover-col .datagrid-cell-index.hover{background-color:#ddd}.datagrid-hover-col .datagrid-row-cell.active .datagrid-cell.hover{background-color:#d7e5f3}.datagrid-scrollbar{position:absolute;right:0;bottom:0;z-index:50;opacity:0;-webkit-transition:2.5s cubic-bezier(.175,.885,.32,1);-o-transition:2.5s cubic-bezier(.175,.885,.32,1);transition:2.5s cubic-bezier(.175,.885,.32,1);-webkit-transition-property:background,opacity;-o-transition-property:background,opacity;transition-property:background,opacity}.datagrid-container:hover .datagrid-scrollbar,.datagrid-scrollbar.scrolling{opacity:1}.datagrid-scrollbar>.bar{position:absolute;min-width:10px;background-color:#ddd;background-color:rgba(0,0,0,.25)}.datagrid-scrollbar.scrolling,.datagrid-scrollbar:hover{background-color:rgba(0,0,0,.075)}.datagrid-scrollbar.scrolling>.bar,.datagrid-scrollbar:hover>.bar{position:absolute;background-color:grey;background-color:rgba(0,0,0,.5)}.datagrid-scrollbar-h{left:0;height:10px}.datagrid-scrollbar-h>.bar{top:0!important;bottom:0!important;min-width:20px}.datagrid-scrollbar-v{top:0;width:10px}.datagrid-scrollbar-v>.bar{right:0!important;left:0!important;min-height:20px}.datagrid-messager{position:absolute;top:0;right:0;left:0;z-index:60;padding:5px 10px;text-align:center}.datagrid-messager>.close{position:absolute;top:0;right:0;display:block;width:30px;height:30px;padding-bottom:5px;line-height:20px;text-align:center}.datagrid-messager>.close:hover{background-color:rgba(0,0,0,.1)}.datagrid-loading{position:absolute;top:0;right:0;bottom:0;left:0;z-index:61;background-color:rgba(255,255,255,.6)}.datagrid-loading>.content{position:relative;top:50%;display:block;height:50px;margin-top:-25px;text-align:center}.datagrid-loading>.content>.icon{color:#3280fc}.datagrid-col-sortable{padding-right:20px;cursor:pointer}.datagrid-sorter{position:absolute;top:3px;right:0;bottom:0;width:20px;line-height:30px;text-align:center}.datagrid-sort-down>.icon-sort:before{color:#3280fc;content:'\e6b8'}.datagrid-sort-up>.icon-sort:before{color:#3280fc;content:'\e6b9'}.datagrid-borderless .datagrid-container{border-color:transparent}.datagrid-borderless .datagrid-cell{border-right-color:transparent;border-left-color:transparent}.datagrid-borderless .datagrid-fixed-edge-left{-webkit-box-shadow:-1px 0 0 rgba(0,0,0,.1) inset;box-shadow:-1px 0 0 rgba(0,0,0,.1) inset}.datagrid-borderless .datagrid-fixed-edge-right{-webkit-box-shadow:1px 0 0 rgba(0,0,0,.1) inset;box-shadow:1px 0 0 rgba(0,0,0,.1) inset}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd) .datagrid-cell-cell{background-color:#f9f9f9}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd).active .datagrid-cell{background-color:#fff0d5}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd).active .datagrid-cell.datagrid-cell-index{background-color:#ffe7bc}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd) .datagrid-cell-cell.hover{background-color:#ebf2f9}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd) .datagrid-cell-head.hover,.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd) .datagrid-cell-index.hover{background-color:#ddd}.datagrid-striped .datagrid-cells>.datagrid-row-cell:nth-child(odd).active .datagrid-cell.hover{background-color:#d7e5f3} \ No newline at end of file diff --git a/public/static/zui/lib/datagrid/zui.datagrid.min.js b/public/static/zui/lib/datagrid/zui.datagrid.min.js new file mode 100755 index 0000000..feec2e2 --- /dev/null +++ b/public/static/zui/lib/datagrid/zui.datagrid.min.js @@ -0,0 +1,14 @@ +/*! + * ZUI: 数据表格② - v1.10.0 - 2021-11-04 + * http://openzui.com + * GitHub: https://github.com/easysoft/zui.git + * Copyright (c) 2021 cnezsoft.com; Licensed MIT + */ +/*! + * jQuery Mousewheel 3.1.13 + * + * Copyright jQuery Foundation and other contributors + * Released under the MIT license + * http://jquery.org/license + */ +!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e:e(jQuery)}(function(e){function t(t){var n=t||window.event,l=s.call(arguments,1),d=0,h=0,g=0,f=0,u=0,p=0;if(t=e.event.fix(n),t.type="mousewheel","detail"in n&&(g=n.detail*-1),"wheelDelta"in n&&(g=n.wheelDelta),"wheelDeltaY"in n&&(g=n.wheelDeltaY),"wheelDeltaX"in n&&(h=n.wheelDeltaX*-1),"axis"in n&&n.axis===n.HORIZONTAL_AXIS&&(h=g*-1,g=0),d=0===g?h:g,"deltaY"in n&&(g=n.deltaY*-1,d=g),"deltaX"in n&&(h=n.deltaX,0===g&&(d=h*-1)),0!==g||0!==h){if(1===n.deltaMode){var m=e.data(this,"mousewheel-line-height");d*=m,g*=m,h*=m}else if(2===n.deltaMode){var v=e.data(this,"mousewheel-page-height");d*=v,g*=v,h*=v}if(f=Math.max(Math.abs(g),Math.abs(h)),(!i||f=1?"floor":"ceil"](d/i),h=Math[h>=1?"floor":"ceil"](h/i),g=Math[g>=1?"floor":"ceil"](g/i),c.settings.normalizeOffset&&this.getBoundingClientRect){var y=this.getBoundingClientRect();u=t.clientX-y.left,p=t.clientY-y.top}return t.deltaX=h,t.deltaY=g,t.deltaFactor=i,t.offsetX=u,t.offsetY=p,t.deltaMode=0,l.unshift(t,d,h,g),o&&clearTimeout(o),o=setTimeout(a,200),(e.event.dispatch||e.event.handle).apply(this,l)}}function a(){i=null}function r(e,t){return c.settings.adjustOldDeltas&&"mousewheel"===e.type&&t%120===0}var o,i,n=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],l="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],s=Array.prototype.slice;if(e.event.fixHooks)for(var d=n.length;d;)e.event.fixHooks[n[--d]]=e.event.mouseHooks;var c=e.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var a=l.length;a;)this.addEventListener(l[--a],t,!1);else this.onmousewheel=t;e.data(this,"mousewheel-line-height",c.getLineHeight(this)),e.data(this,"mousewheel-page-height",c.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var a=l.length;a;)this.removeEventListener(l[--a],t,!1);else this.onmousewheel=null;e.removeData(this,"mousewheel-line-height"),e.removeData(this,"mousewheel-page-height")},getLineHeight:function(t){var a=e(t),r=a["offsetParent"in e.fn?"offsetParent":"parent"]();return r.length||(r=e("body")),parseInt(r.css("fontSize"),10)||parseInt(a.css("fontSize"),10)||16},getPageHeight:function(t){return e(t).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};e.fn.extend({mousewheel:function(e){return e?this.bind("mousewheel",e):this.trigger("mousewheel")},unmousewheel:function(e){return this.unbind("mousewheel",e)}})}),function(e,t){"use strict";var a=function(t){var a=[];t.find("thead>tr:first>th").each(function(t){var r=e(this);if(a.push(e.extend({name:t,label:r.html(),html:!0,width:r.outerWidth()},r.data())),r.attr("colspan")&&"1"!==r.attr("colspan"))throw new Error("Table th element with colspan attribute is not support.")});var r=[];return t.find("tbody>tr").each(function(){var t=e(this),a={};t.children("td").each(function(t){a[t]=e(this).html()}),r.push(e.extend(a,t.data()))}),{cols:a,array:r,length:r.length}},r="zui.datagrid",o={date:{getter:function(e,t,a){var r=a.options.defaultDateFormatter||a.options.defaultDateFormater;return Date.create(e).format(r)},setter:function(e,t,a){if("string"==typeof e){var r=parseInt(e,10);isNaN(r)||(e=r)}return Date.timestamp(e)}}},i={},n={page:0,recTotal:0,recPerPage:10},l={fixedLeftUntil:0,fixedTopUntil:0,order:"asc",sortBy:null,pager:n,selections:{}},s=function(t,a){var r=0,o=a.length,i=0,n={};return e.each(t,function(e,t){var l=typeof t;"number"===l||"number"===l?t+="":"string"!==l&&(t=JSON.stringify(l));for(var s=0,d=0;d').insertAfter(s.$));var u=d.find(".datagrid-container:first");u.length||(u=e('
').appendTo(d)),u.css({width:n.width,borderWidth:n.borderWidth});var p=e(document),m=function(t){var a=u.find(".datagrid-scrollbar-"+t);a.length||(a=e('
').appendTo(u));var o,i,n,l,d=!1,c=null,h=".scrollbar"+t+"."+r+"."+s.uuid,g=function(e){if(d){var a=e["h"===t?"pageX":"pageY"];if(c!==a){c=a,a=a-o+i;var r,h=s.layout[t+"Scroll"];r=n?c-o+l:Math.max(0,Math.min(h.space,a-Math.round(h.barSize/2))),"h"===t?s.setScrollbarOffset(r):s.setScrollbarOffset(null,r)}}};a.on("mousedown",function(r){r.preventDefault(),d=!0;var c=s.layout[t+"Scroll"],f="h"===t?"X":"Y";i=r["offset"+f],o=r["page"+f],n=e(r.target).is(".bar"),l=c.offset,n&&(i+=l),g(r),a.addClass("scrolling"),p.on("mouseup"+h,function(e){d=!1,g(e),p.off(h),a.removeClass("scrolling")}).on("mousemove"+h,g)}),s["$"+t+"Scroll"]=a,s["$"+t+"Scrollbar"]=a.find(".bar")};m("h"),m("v");var v=n.mouseWheelFactor,y=window.navigator.userAgent.match(/Win/i);y&&(v*=20),u.on("mousewheel",function(e){var t=s.layout,a=t.scrollLeft-Math.round(e.deltaX*v),r=t.scrollTop-Math.round(e.deltaY*v);a=Math.max(0,Math.min(a,t.width-t.containerWidth)),r=Math.max(0,Math.min(r,t.height-t.containerHeight)),a===t.scrollLeft&&r===t.scrollTop||(s.scroll(a,r),e.preventDefault())}),s.$container=u;var w=d.find(".datagrid-cells:first");if(w.length||(w=e('
').appendTo(u)),w.toggleClass("datagrid-hover-cell",!!n.hoverCell).toggleClass("datagrid-hover-row",!!n.hoverRow).toggleClass("datagrid-hover-col",!!n.hoverCol).toggleClass("datagrid-hover-shadow",!!n.hoverCol),s.$cells=w,s.isFuncConfigs="function"==typeof n.configs,s.configs=s.isFuncConfigs?n.configs:e.extend({},i,n.configs),s.layout={scrollLeft:0,scrollTop:0},s.configsCache={},s.userConfigs={},s.states=e.extend(!0,{},l,n.states),s.cells=[],s.setPager(s.states.pager),s.setDataSource(n.dataSource),n.responsive&&u.on("resize",function(){s.layout.cols=null,s.render()}),n.hoverCol&&w.on("mouseenter",".datagrid-cell-head",function(){var t=e(this),a=t.data("col");s.$cells.find(".datagrid-cell.hover").removeClass("hover"),s.$cells.find('.datagrid-cell[data-col="'+a+'"]').addClass("hover")}).on("mouseleave",".datagrid-cell-head.hover",function(){s.$cells.find(".datagrid-cell.hover").removeClass("hover")}),n.sortable&&w.on("click",".datagrid-col-sortable",function(){var t=e(this).data("col"),a=s.getColConfig(t),r=s.states.sortBy,o=s.states.order;r!==a.name?(r=a.name,o="desc"):"desc"===o?o="asc":"asc"===o&&(r=""),s.sortBy(r,o)}),n.onClickCell&&w.on("click",".datagrid-cell",function(t){var a=e(this),r=s.getCell(a.data("row"),a.data("col"));s.$.callComEvent(s,"onClickCell",[t,r,a])}),n.checkable&&(n.selectable&&e.fn.selectable?(s.selectable=w.selectable(e.extend({selector:".datagrid-row-cell",trigger:n.checkByClickRow?null:".datagrid-row-cell .datagrid-has-checkbox",clickBehavior:"multi",select:function(e){s.checkRow(e.id,!0)},unselect:function(e){s.checkRow(e.id,!1)}},e.isPlainObject(n.selectable)?n.selectable:null)).data("zui.selectable"),w.on("click",".datagrid-cell-head.datagrid-has-checkbox",function(){s.checkRow(e(this).data("row")),s.selectable.syncSelectionsFromClass()})):w.on("click",n.checkByClickRow?".datagrid-row":".datagrid-has-checkbox",function(t){var a=e(this).data("row");(a||e(t.target).closest(".datagrid-has-checkbox").length)&&s.checkRow(a)})),e.fn.pager){var C=s.$.find(".pager");C.length&&(s.pagerObj=C.pager(e.extend({},s.pager,{onPageChange:function(e){s.setPager(e).render()}})).data("zui.pager"))}if(e.fn.searchBox){var b=s.$.find(".search-box");b&&(s.searchbox=b.searchBox({onSearchChange:function(e){s.search(e)}}))}s.render()};h.prototype.setPager=function(t,a,r){var o=this;"object"==typeof t&&(r=t.recPerPage,a=t.recTotal,t=t.page);var i=o.pager,l=e.extend({},i);return i||(i=e.extend({},n)),"number"==typeof r&&r>0&&(i.recPerPage=r),"number"==typeof a&&a>=0&&(i.recTotal=a),"number"==typeof t&&t>=0&&(i.page=t),i.totalPage=i.recTotal&&i.recPerPage?Math.ceil(i.recTotal/i.recPerPage):1,i.page=Math.max(0,Math.min(i.page,i.totalPage)),i.pageRecCount=i.recTotal,i.page&&i.recTotal&&(i.page1&&(i.pageRecCount=i.recTotal-i.recPerPage*(i.page-1))),i.skip=i.page>1?(i.page-1)*i.recPerPage:0,i.end=i.skip+i.pageRecCount,o.pager=i,l.page===i.page&&l.recTotal===i.recTotal&&l.recPerPage===i.recPerPage||(o.scroll(0,0),o.layout.cols=null),o},h.prototype.goToPage=function(e){return this.goToPage(e)},h.prototype.gotoPage=function(e){return this.setPager(e).render()},h.prototype.setSearch=function(a){return a!==t&&null!==a||(a=""),this.states.search=e.trim(a),this},h.prototype.search=function(e){var t=this;return e!==t.states.search&&t.pager.page&&t.setPager(1),t.setSearch(e).render()},h.prototype.setSorter=function(e,a){var r=this;return a===t&&(a="desc"===r.states.order?"asc":"desc"),r.states.order=a.toLowerCase(),r.states.sortBy=e,r},h.prototype.sortBy=function(e,t){return this.setSorter(e,t).render()},h.prototype.setDataSource=function(a,r){var o=this,i={},n=o.dataSource&&o.dataSource.cols;if(Array.isArray(a)?(i.array=a,i.length=a.length,o.setPager("",a.length)):e.isPlainObject(a)?i=e.extend(i,a):"string"==typeof a&&(i.remote=a),i.cache===!0||i.cache===t?(i.cache=[],i.cacheSize=1):"number"==typeof i.cache&&(i.cacheSize=i.cache,i.cache=[]),Array.isArray(i.data)?(i.array=i.data,i.length=i.array.length,o.setPager("",i.length),delete i.data):i.data||"function"!=typeof i.getByIndex||o.setPager("",i.length),o.dataSource=i,r=r||i.cols||n||[],r.length)for(var l=0;l1?v.page*v.recPerPage:0;r=r.slice(v.skip,v.end)}}return r},h.prototype.getFilterParams=function(){var e=this,t=e.states;return{page:e.pager.page,recPerPage:e.pager.recPerPage,search:t.search,sortBy:t.sortBy,order:t.order}},h.prototype.loadData=function(t){var a=this;a.loadingId=e.zui.uuid();var r=function(e){return a.$.callComEvent(a,"onLoad",e),t&&t(e)},o=a.getFilterParams(),i=[o.page,o.recPerPage,o.search,o.sortBy,o.order].join("&"),n=a.getData(i);if(n)return r(n);var l=a.dataSource;if(l.array)return n=a.filterData(l.array,o),a.resetData(i,n,a.pager),r(n);if(l.getByIndex)return n=l.getByIndex,a.resetData(i,n),r(n);var s=l.loader,d=l.remote;if(!s&&d&&(s=function(t,r){var o="function"==typeof d?d(t,a):{url:d};e.ajax(e.extend({type:"GET",data:t,dataType:"json",success:function(t,o,i){if(l.remoteConverter&&(t=l.remoteConverter(t,o,i,a)),"string"==typeof t&&(t=e.parseJSON(t)),e.isPlainObject(t)&&t.data){var n=t.result||t.status;"success"===n||"ok"===n||200===n?r(t):r(!1,t.message||t.reason||a.lang.errorCannotHandleRemoteData,t)}else r(!1,a.lang.errorCannotHandleRemoteData,t)},error:function(){r(!1,a.lang.errorCannotGetDataFromRemote.format(l.remote))}},o))}),!s)return r(!1);a.renderLoading(!0);var c=a.loadingId;s(o,function(e,t){if(c===a.loadingId){if(a.renderLoading(!1),t)return a.showMessage(t,"danger"),void r(!1);a.resetData(i,e.data,e.pager),r(e.data)}})},h.prototype.getDataItem=function(e,t,a){var r=this;return t=t||r.getData(),"function"==typeof t?(a=a||r.getFilterParams(),t(e,a)):t[e]},h.prototype.showMessage=function(a,r,o){var i=this;i.messagerAutoCloseTimer&&(clearTimeout(i.messagerAutoCloseTimer),i.messagerAutoCloseTimer=null);var n=i.$container.find(".datagrid-messager");return a?(r=r||"info",o===t&&(o=5e3),n.length||(n=e('').appendTo(i.$container).on("click",".close",function(){n.slideUp(),i.messagerAutoCloseTimer&&(clearTimeout(i.messagerAutoCloseTimer),i.messagerAutoCloseTimer=null)})),n.attr("class","datagrid-messager bg-"+r).find(".content").text(a),n.slideDown(),void(o&&(i.messagerAutoCloseTimer=setTimeout(function(){n.slideUp(),i.messagerAutoCloseTimer=null},o)))):void n.slideUp()},h.prototype.renderLoading=function(a){var r=this;a!==t&&(r.states.loading=a);var o=r.$container.find(".datagrid-loading");a?(o.length||(o=e('').appendTo(r.$container)),o.find(".datagrid-loading-message").text("string"==typeof a?a:""),o.fadeIn()):o.fadeOut()},h.prototype.getData=function(e){var t=this.dataSource,a=null;if(e&&e!==t.dataId){if(t.cache&&t.cache.length)for(var r=t.cache.length-1;r>=0;--r){var o=t.cache[r];if(o.id===e){t.dataId=e,t.data=o.data,this.setPager(o.pager),a=o.data;break}}}else a=t.data;return a},h.prototype.resetData=function(t,a,r){var o=this.dataSource;if(o.dataId=t,o.data=a,o.cache){for(var i=o.cache.length-1;i>0;--i){var n=o.cache[i];if(n.id===t){o.cache.splice(i,1);break}}for(o.cache.push({id:t,data:a,pager:e.extend({},r)});o.cache.length>o.cacheSize;)o.cache.shift()}r&&this.setPager(r)},h.prototype.getRowLayout=function(e){var t=this.layout;if(0===e)return{top:0,height:t.headerHeight};var a=t.rowHeight;return{height:a,top:t.headerHeight+(e>1?(e-1)*a:0)+e*t.borderWidth}},h.prototype.updateLayout=function(){var a=this,r=a.options,o=a.layout,i=(a.data,a.pager),n=i.pageRecCount,l=a.$container,s=l.width(),d=a.dataSource;if(!d.cols.length&&n&&e.each(a.getDataItem(0),function(e){d.cols.push({name:e})}),!o.cols){for(var c,h,g=d.cols,f=r.colAutoMinWidth,u=r.colAutoDefaultWidth,p=0,m=0,v=r.rowIndexWidth,y=[{left:0,width:r.showRowIndex?"auto"===v?8*(n+a.pager.skip+"").length+18:v:0}],w=0,C=y[0].width,b=!1,x=0,S=0,T=0;T=1?(D.minWidth!==t&&(h=Math.max(h,D.minWidth)),c.width=h,C+=h):(D.minWidth===t&&(D.minWidth=f),c.grow=h,p+=h,m+=D.minWidth,x<=c.grow&&(x=c.grow,b=T+1)),c.minWidth=D.minWidth,!S&&D.checkbox&&(S=T+1,c.checkbox=!0),y.push(c))}r.checkable&&!S&&(y[0].checkbox=!0,"auto"===v&&(y[0].width+=30,C+=30));for(var M=s-C,R=M0){var L=y[P-1];c.left=L.left+L.width}w+=h}var k=s-w;b&&k>0&&(y[b].width+=k,w+=k),o.width=w,o.cols=y}o.containerWidth=s,o.rowHeight=r.rowDefaultHeight,o.borderWidth=r.borderWidth,o.headerHeight=r.showHeader?r.headerHeight:0,o.rowsLength=n+1,o.colsLength=o.cols.length,o.height=o.headerHeight+n*(o.rowHeight+o.borderWidth),o.spanMap={};var H=r.height;"page"===H&&(H=o.headerHeight+a.pager.recPerPage*(o.rowHeight+o.borderWidth)),l.css("height",H),o.containerHeight=H,o.vScrollSpare=o.height-o.containerHeight,o.hScrollSpare=o.width-o.containerWidth,a.layout=o;var $=!!i.page||r.partialRendering;return"auto"===$&&($=o.height>2*o.containerHeight),o.partialRendering=$,o},h.prototype.getCell=function(e,a){var r,o,i=this,n=i.getCellConfig(e,a),l=a>0?i.dataSource.cols[a-1]:null,s={rowIndex:e,colIndex:a,config:n,checked:i.isRowChecked(n.rowId)};if(0===a){r="index";var d=e>0?i.pager.skip+e:"";o=n.label!==t?n.label:d}else 0===e?(r="head",o=n.label!==t?n.label:n.name!==t?n.name:a):(r="cell",o=n.data&&n.data[i.options.dataItemIsArray?a:l.name]);if(e>0){var c=i.options.valueOperator,h=n.valueType,g=n.valueOperator||(c&&h?c[h]:null);g&&g.getter&&(o=g.getter(o,s,i))}o===t&&(o=""),s.value=o,s.type=r;var f=i.layout.spanMap;if(f[n.id]||n.hidden)s.hidden=!0;else if(n.colspan&&n.colspan>1||n.rowspan&&n.rowspan>1){for(var u=e+(n.rowspan||1),p=a+(n.colspan||1),m=e;m0?r.getDataItem(a-1):null;return i.data=n,n&&(o=n.rowId||n.id),i.rowId=o!==t?o:0===a?"#header":a,i},h.prototype.getColConfigByName=function(e){for(var t=this.dataSource.cols,a=0;a0?a.dataSource.cols[t-1]:null,a.layout.cols?a.layout.cols[t]:null,a.isFuncConfigs?a.configs(r):a.configs[r],a.userConfigs[r]),0!==t||a.options.showRowIndex||(o.hidden=!0)),o},h.prototype.getCellConfig=function(t,a){var r=this,o="R"+t+"C"+a,i=null;return i||(i=e.extend({id:o},r.getColConfig(a),r.getRowConfig(t),r.isFuncConfigs?r.configs(o):r.configs[o],r.userConfigs[o])),i},h.prototype.isRowChecked=function(e){return!!this.states.selections[e]},h.prototype.checkRow=function(e,a,r){var o=this,i=o.states.selections,n=o.getRowConfig(e),l=n.rowId;if(a===t&&(a=!i[l]),i[l]!==a){if(a?i[l]=n:(delete i[l],e>0&&i["#header"]&&(delete i["#header"],o.renderRow(0))),o.renderRow(e),0===e){o.toggleAnimation(!1);for(var s=1;s')).appendTo(r),c.attr({id:d,"data-type":n.type,"data-col":n.colIndex,"data-row":n.rowIndex}).toggleClass("datagrid-cell-head",0===t).toggleClass("datagrid-cell-cell","cell"===n.type).toggleClass("datagrid-cell-index",0===a),s)){var h=c.find(".datagrid-checkbox");h.length||(h=e('
').prependTo(c.addClass("datagrid-has-checkbox")))}var g=i.borderWidth,f=o.layout,u=f.colsLength,p={top:g?-g:0,bottom:g?-g:0,left:g?l.left-g:l.left,width:g?l.width+(u-1===a?2:1)*g:l.width,borderWidth:g};if(l.span&&(l.rowspan&&l.rowspan>1&&(p.bottom-=(l.rowspan-1)*(f.rowHeight+g)),l.colspan&&l.colspan>1))for(var m=a+l.colspan,v=a+1;v0&&0===t&&i.sortable&&l.sort!==!1){var S=!1;l.name===o.states.sortBy&&(S="desc"===o.states.order?"down":"up");var T=c.find(".datagrid-sorter");T.length||(T=e('
').appendTo(c),c.addClass("datagrid-col-sortable")),T.toggleClass("datagrid-sort-up","up"===S).toggleClass("datagrid-sort-down","down"===S)}return s&&(c.find(".datagrid-checkbox").toggleClass("checked",n.checked),r.toggleClass("active",n.checked)),c}},h.prototype.renderRow=function(t){var a=this,r=a.layout,o=a.options,i=a.getRowLayout(t),n=r.colsLength,l=a.id+"-row-"+t,s=e("#"+l);s.length?r.partialRendering&&s.css("top",i.top-r.scrollTop):(s=(o.rowCreator?o.rowCreator(t,a):e('
')).appendTo(a.$cells),s.attr({id:l,"data-row":t,"data-id":t}).css({top:r.partialRendering?i.top-r.scrollTop:i.top,height:i.height}).toggleClass("datagrid-row-head",0===t).toggleClass("datagrid-row-cell",0!==t));for(var d=0;d0&&!t.hasClass("datagrid-fixed")&&(ao)&&t.remove()})}t.options.showHeader&&t.renderRow(0);for(var n=r;n<=o;++n)t.renderRow(n);if(a.vScrollSpare){var l=t.states,s=l.fixedTopUntil,d=l.fixedBottomFrom;if("number"==typeof s&&s>0&&s0&&d>o)for(var n=d;n<=a.rowsLength-1;++n)t.renderRow(n)}t.pagerObj&&t.pagerObj.set(t.pager)},h.prototype.render=function(e){var t=this,a=t.options;return!e&&a.renderDelay?(t.renderDelayTimer&&clearTimeout(t.renderDelayTimer),t.renderDelayTimer=setTimeout(function(){t.render(!0)},a.renderDelay),t):(t.renderDelayTimer&&(clearTimeout(t.renderDelayTimer),t.renderDelayTimer=null),t.loadData(function(e){var a=t.updateLayout();t.$cells.css({width:a.width,height:a.partialRendering?a.containerHeight:t.layout.height}),t.renderData(),t.renderScrolls(),t.renderFixeds(),t.$.callComEvent(t,"onRender")}),t)},h.prototype.setScrollbarOffset=function(e,t){var a=this,r=a.layout,o=r.scrollLeft,i=r.scrollTop;if("number"==typeof e){var n=r.hScroll;n.offset!==e&&(o=Math.round(e*r.hScrollSpare/n.space))}if("number"==typeof t){var l=r.vScroll;l.offset!==t&&(i=Math.round(t*r.vScrollSpare/l.space))}a.scroll(o,i)},h.prototype.renderScrolls=function(){var e=this,t=e.layout,a=t.vScrollSpare,r=t.hScrollSpare,o=a>0,i=r>0;if(e.$vScroll.toggle(o),e.$hScroll.toggle(i),t.scrollLeft=i?Math.max(0,Math.min(r,t.scrollLeft)):0,t.scrollTop=o?Math.max(0,Math.min(a,t.scrollTop)):0,o){var n=e.$vScrollbar,l=t.containerHeight/t.height,s=Math.max(20,Math.floor(l*t.containerHeight)),d=t.containerHeight-s,c=d/a,h=Math.round(t.scrollTop*c);t.vScroll={space:d,size:a,scale:c,barSize:s,offset:h};var g={height:s,top:h};n.css(g)}if(i){var n=e.$hScrollbar,l=t.containerWidth/t.width,s=Math.max(20,Math.floor(l*t.containerWidth)),d=t.containerWidth-s,h=Math.round(t.scrollLeft*d/r),g={width:s,left:h};t.hScroll={offset:h,space:d,size:r,barSize:s},n.css(g)}e.$cells.css({top:t.partialRendering?0:-t.scrollTop,left:-t.scrollLeft})},h.prototype.scroll=function(e,t,a){var r=this,o=new Date,i=r.options.scrollDelay;if(i){if(!a&&r.lastScrollTime&&o-r.lastScrollTime-1){o=Math.min(o,r.rowsLength);for(var i=0;i<=o;++i){var n=t.getRowLayout(i),l=e("#"+t.id+"-row-"+i),s=r.partialRendering?n.top:n.top+r.scrollTop;l.addClass("datagrid-fixed").css("top",s),i===o&&r.scrollTop&&l.addClass("datagrid-fixed-edge-top")}}else o=-1;var d=a.fixedBottomFrom;if("number"==typeof d&&d>-1){d=Math.max(o>-1?o+1:1,Math.min(d,r.rowsLength));for(var i=d;i-1){c=Math.min(c,r.colsLength);for(var i=0;i<=c;++i){var h=r.cols[i],g=t.$cells.find('.datagrid-cell[data-col="'+i+'"]'),f=h.left+r.scrollLeft-r.borderWidth;g.addClass("datagrid-fixed").css("left",f),i===c&&r.scrollLeft&&g.addClass("datagrid-fixed-edge-left")}}else c=-1;var u=a.fixedRightFrom;if("number"==typeof u&&u>-1){u=Math.max(c>-1?c+1:1,Math.min(u,r.colsLength));for(var i=u;i