From f8f0cf89251ae7b685b4bb1be8472f28c62c2455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E4=BB=AA=E5=BC=8F?= <854085467@qq.com> Date: Thu, 11 Mar 2021 02:42:57 +0800 Subject: [PATCH] add menu get data method support post --- component/pear/modules/admin.js | 1 + component/pear/modules/menu.js | 34 ++++++++++++++++++++++++--------- config/pear.config.yml | 2 ++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/component/pear/modules/admin.js b/component/pear/modules/admin.js index 4941e02..973a11b 100644 --- a/component/pear/modules/admin.js +++ b/component/pear/modules/admin.js @@ -80,6 +80,7 @@ layui.define(['table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'fram async: param.menu.async !== undefined ? param.menu.async : true, theme: "dark-theme", height: '100%', + method: param.menu.method, control: param.menu.control ? 'control' : false, // control defaultMenu: 0, accordion: param.menu.accordion, diff --git a/component/pear/modules/menu.js b/component/pear/modules/menu.js index 855a103..de160af 100644 --- a/component/pear/modules/menu.js +++ b/component/pear/modules/menu.js @@ -16,6 +16,7 @@ layui.define(['table', 'jquery', 'element'], function(exports) { async: opt.async, parseData: opt.parseData, url: opt.url, + method: opt.method ? opt.method : "GET", defaultOpen: opt.defaultOpen, defaultSelect: opt.defaultSelect, control: opt.control, @@ -28,10 +29,17 @@ layui.define(['table', 'jquery', 'element'], function(exports) { done: opt.done ? opt.done : function() {} } if (option.async) { - getData(option.url).then(function(data) { - option.data = data; - renderMenu(option); - }); + if (option.method === "GET") { + getData(option.url).then(function(data) { + option.data = data; + renderMenu(option); + }); + } else { + postData(option.url).then(function(data) { + option.data = data; + renderMenu(option); + }); + } } else { //renderMenu中需要调用done事件,done事件中需要menu对象,但是此时还未返回menu对象,做个延时提前返回对象 window.setTimeout(function() { @@ -66,11 +74,11 @@ layui.define(['table', 'jquery', 'element'], function(exports) { data['menuPath'] = domsss.find("span").text() + " / " + data['menuPath']; } if ($("#" + _this.option.elem).is(".pear-nav-mini")) { - if(_this.option.accordion){ - activeMenus = $(this).parent().parent().parent().children("a"); - }else{ - activeMenus.push($(this).parent().parent().parent().children("a")); - } + if (_this.option.accordion) { + activeMenus = $(this).parent().parent().parent().children("a"); + } else { + activeMenus.push($(this).parent().parent().parent().children("a")); + } } clickEvent(dom, data); }) @@ -147,6 +155,14 @@ layui.define(['table', 'jquery', 'element'], function(exports) { return defer.promise(); } + function postData(url) { + var defer = $.Deferred(); + $.post(url + "?fresh=" + Math.random(), function(result) { + defer.resolve(result) + }); + return defer.promise(); + } + function renderMenu(option) { if (option.parseData != false) { option.parseData(option.data); diff --git a/config/pear.config.yml b/config/pear.config.yml index 1d23796..d6fa264 100644 --- a/config/pear.config.yml +++ b/config/pear.config.yml @@ -9,6 +9,8 @@ logo: menu: ## 菜单数据来源 data: "admin/data/menu.json" + ## 菜单接口的请求方式 GET / POST + method: "GET" ## 是否同时只打开一个菜单目录 accordion: true ## 是否开启多系统菜单模式