From dcaf505772121a38ce9bc1466826769209ba1a67 Mon Sep 17 00:00:00 2001 From: Sight <1453017105@qq.com> Date: Sat, 28 May 2022 11:39:32 +0000 Subject: [PATCH] =?UTF-8?q?fix(menu):=20=E9=A1=B6=E9=83=A8=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E6=A8=A1=E5=BC=8F=E8=87=AA=E9=80=82=E5=BA=94=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/menu.js | 55 +++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/component/pear/module/menu.js b/component/pear/module/menu.js index 3ddb59d..0f2a119 100644 --- a/component/pear/module/menu.js +++ b/component/pear/module/menu.js @@ -20,7 +20,7 @@ layui.define(['table', 'jquery', 'element'], function (exports) { defaultOpen: opt.defaultOpen, defaultSelect: opt.defaultSelect, control: opt.control, - controlWidth: opt.controlWidth ? opt.controlWidth : 500, + controlWidth: opt.controlWidth ? opt.controlWidth : "auto", defaultMenu: opt.defaultMenu, accordion: opt.accordion, height: opt.height, @@ -29,6 +29,14 @@ layui.define(['table', 'jquery', 'element'], function (exports) { change: opt.change ? opt.change : function () { }, done: opt.done ? opt.done : function () { } } + var tempDone = option.done; + option.done = function(){ + if (option.control) { + rationalizeHeaderControlWidthAuto(option); + } + tempDone(); + } + if (option.async) { if (option.method === "GET") { getData(option.url).then(function (data) { @@ -211,8 +219,16 @@ layui.define(['table', 'jquery', 'element'], function (exports) { $("#" + this.option.elem).removeClass("pear-nav-mini"); $("#" + this.option.elem).animate({ width: "220px" - }, 150); - isHoverMenu(false, config); + }, 180); + var that = this; + $("#" + this.option.elem) + .promise() + .done(function () { + isHoverMenu(false, config); + if (that.option.control) { + rationalizeHeaderControlWidth(that.option); + } + }) } else { activeMenus = $("#" + this.option.elem).find(".layui-nav-itemed>a"); $("#" + this.option.elem).find(".layui-nav-itemed").removeClass("layui-nav-itemed"); @@ -220,10 +236,15 @@ layui.define(['table', 'jquery', 'element'], function (exports) { $("#" + this.option.elem).animate({ width: "60px" }, 400); - // 使菜单在折叠动画过程中不触发 hover - setTimeout(function () { + var that = this; + $("#" + this.option.elem) + .promise() + .done(function () { isHoverMenu(true, config); - }, 100); + if (that.option.control) { + rationalizeHeaderControlWidth(that.option); + } + }) } } @@ -519,5 +540,27 @@ layui.define(['table', 'jquery', 'element'], function (exports) { $("#" + option.elem + " dd").off('mouseenter').unbind('mouseleave'); } } + + function rationalizeHeaderControlWidth(option) { + var $headerControl = $(".layui-layout-control"); + var $headerRight = $(".layui-layout-right"); + var rationalizeWidth = $headerRight.position().left - $headerControl.position().left; + if (option.controlWidth && rationalizeWidth >= option.controlWidth) { + rationalizeWidth = option.controlWidth; + } + $(".layui-layout-control .control").css({ "width": rationalizeWidth, "transition": "width .15s"}); + + } + + function rationalizeHeaderControlWidthAuto(option){ + $(window).on('resize', function () { + rationalizeHeaderControlWidth(option); + }) + + $(document).ready(function () { + rationalizeHeaderControlWidth(option); + }); + } + exports(MOD_NAME, new pearMenu()); }) -- Gitee