diff --git a/component/pear/module/menu.js b/component/pear/module/menu.js index 3ddb59dfbc31c4e6ec61fc55282d8ade54e6ad68..0f2a1193fb5c2e35940331d8cd5083a21bfddeda 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()); })