diff --git a/app/common/controller/AdminController.php b/app/common/controller/AdminController.php index cc34e28..c3f53b3 100644 --- a/app/common/controller/AdminController.php +++ b/app/common/controller/AdminController.php @@ -88,9 +88,24 @@ class AdminController extends BaseController parent::initialize(); $this->adminUid = request()->adminUserInfo['id'] ?? 0; $this->isDemo = env('EASYADMIN.IS_DEMO', false); + $this->setOrder(); $this->viewInit(); } + /** + * 初始化排序 + * @return $this + */ + public function setOrder(): static + { + $tableOrder = $this->request->param('tableOrder/s', ''); + if (!empty($tableOrder)) { + [$orderField, $orderType] = explode(' ', $tableOrder); + $this->sort = [$orderField => $orderType]; + } + return $this; + } + /** * 模板变量赋值 * @param array|string $name 模板变量 diff --git a/public/static/plugs/easy-admin/easy-admin.js b/public/static/plugs/easy-admin/easy-admin.js index ea7ebbc..cff92db 100644 --- a/public/static/plugs/easy-admin/easy-admin.js +++ b/public/static/plugs/easy-admin/easy-admin.js @@ -272,6 +272,9 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { // 监听表格开关切换 admin.table.listenEdit(options.init, options.layFilter, options.id, options.modifyReload); + // 监听表格排序 + admin.table.listenSort(options); + return newTable; }, renderToolbar: function (data, elem, tableId, init) { @@ -898,6 +901,15 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { }); } }, + listenSort: function (options) { + table.on('sort(' + options.layFilter + ')', function (obj) { + let defaultWhere = options.where || {} + let sortWhere = {tableOrder: obj.field + ' ' + obj.type} + table.reload(options.id, { + where: {...defaultWhere, ...sortWhere} + }); + }); + } }, checkMobile: function () { var userAgentInfo = navigator.userAgent;