修改BUG:更改dropdown扩展方法val select

This commit is contained in:
Argo-MacBookPro 2018-08-05 15:31:21 +08:00
parent 7afbe56e1a
commit dcd9020729
8 changed files with 41 additions and 53 deletions

View File

@ -20,8 +20,8 @@
</div> </div>
<div class="form-group col-sm-6 col-md-5"> <div class="form-group col-sm-6 col-md-5">
<label class="control-label" for="txt_dict_define">字典类别</label> <label class="control-label" for="txt_dict_define">字典类别</label>
<div class="lgbDropdown"> <div class="dropdown">
<button id="txt_dict_define" class="btn btn-success dropdown-toggle" data-toggle="dropdown">全部</button> <button id="txt_dict_define" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown">全部</button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="#" data-val="">全部</a></li> <li><a href="#" data-val="">全部</a></li>
<li class="divider"></li> <li class="divider"></li>
@ -66,8 +66,8 @@
</div> </div>
<div class="form-group col-12"> <div class="form-group col-12">
<label class="control-label" for="dictDefine">字典类型</label> <label class="control-label" for="dictDefine">字典类型</label>
<div class="lgbDropdown"> <div class="dropdown">
<button id="dictDefine" class="btn btn-success dropdown-toggle" data-toggle="dropdown" data-default-val="1">全部</button> <button id="dictDefine" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="1">全部</button>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li><a href="#" data-val="0">系统使用</a></li> <li><a href="#" data-val="0">系统使用</a></li>
<li><a href="#" data-val="1">自定义</a></li> <li><a href="#" data-val="1">自定义</a></li>

View File

@ -24,8 +24,8 @@
</div> </div>
<div class="form-group col-6 col-lg-5"> <div class="form-group col-6 col-lg-5">
<label class="control-label" for="sel_menus_category">菜单类别</label> <label class="control-label" for="sel_menus_category">菜单类别</label>
<div class="lgbDropdown"> <div class="dropdown">
<button id="sel_menus_category" class="btn btn-success dropdown-toggle" data-toggle="dropdown">全部</button> <button id="sel_menus_category" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown">全部</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" data-val="">全部</a></li> <li><a href="#" data-val="">全部</a></li>
<li class="divider"></li> <li class="divider"></li>
@ -36,8 +36,8 @@
</div> </div>
<div class="form-group col-6 col-lg-5"> <div class="form-group col-6 col-lg-5">
<label class="control-label" for="sel_menus_category">菜单类型</label> <label class="control-label" for="sel_menus_category">菜单类型</label>
<div class="lgbDropdown"> <div class="dropdown">
<button id="sel_menus_res" class="btn btn-success dropdown-toggle" data-toggle="dropdown">全部</button> <button id="sel_menus_res" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown">全部</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" data-val="">全部</a></li> <li><a href="#" data-val="">全部</a></li>
<li class="divider"></li> <li class="divider"></li>
@ -122,8 +122,8 @@
</div> </div>
<div class="form-group col-6"> <div class="form-group col-6">
<label class="control-label" for="category">菜单类别</label> <label class="control-label" for="category">菜单类别</label>
<div class="lgbDropdown"> <div class="dropup">
<button id="category" class="btn btn-success dropdown-toggle" data-toggle="dropdown" data-default-val="1">外部菜单</button> <button id="category" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="1">外部菜单</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" data-val="0">系统菜单</a></li> <li><a href="#" data-val="0">系统菜单</a></li>
<li><a href="#" data-val="1">外部菜单</a></li> <li><a href="#" data-val="1">外部菜单</a></li>
@ -132,8 +132,8 @@
</div> </div>
<div class="form-group col-6"> <div class="form-group col-6">
<label class="control-label" for="target">目标</label> <label class="control-label" for="target">目标</label>
<div class="lgbDropdown"> <div class="dropup">
<button id="target" class="btn btn-info dropdown-toggle" data-toggle="dropdown" data-default-val="_self">本窗口</button> <button id="target" class="btn btn-info dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="_self">本窗口</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" data-val="_self">本窗口</a></li> <li><a href="#" data-val="_self">本窗口</a></li>
<li><a href="#" data-val="_blank">新窗口</a></li> <li><a href="#" data-val="_blank">新窗口</a></li>
@ -144,8 +144,8 @@
</div> </div>
<div class="form-group col-6"> <div class="form-group col-6">
<label class="control-label" for="isRes">菜单类型</label> <label class="control-label" for="isRes">菜单类型</label>
<div class="lgbDropdown"> <div class="dropup">
<button id="isRes" class="btn btn-success dropdown-toggle" data-toggle="dropdown" data-default-val="0">菜单</button> <button id="isRes" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="0">菜单</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="#" data-val="0">菜单</a></li> <li><a href="#" data-val="0">菜单</a></li>
<li><a href="#" data-val="1">资源</a></li> <li><a href="#" data-val="1">资源</a></li>
@ -154,8 +154,8 @@
</div> </div>
<div class="form-group col-6"> <div class="form-group col-6">
<label class="control-label" for="app">所属应用</label> <label class="control-label" for="app">所属应用</label>
<div class="lgbDropdown"> <div class="dropup">
<button id="app" class="btn btn-info dropdown-toggle" data-toggle="dropdown" data-default-val="0">未设置</button> <button id="app" class="btn btn-info dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="0">未设置</button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
@foreach (var kv in Model.Applications) @foreach (var kv in Model.Applications)
{ {

View File

@ -50,8 +50,8 @@
<div class="card-body"> <div class="card-body">
<form id="CssDataForm" class="form-inline"> <form id="CssDataForm" class="form-inline">
<div class="form-group"> <div class="form-group">
<div class="lgbDropdown"> <div class="dropdown">
<button id="dictCssDefine" class="btn btn-success dropdown-toggle" data-toggle="dropdown" data-default-val="">默认样式</button> <button id="dictCssDefine" class="btn btn-success dropdown-select dropdown-toggle" data-toggle="dropdown" data-default-val="">默认样式</button>
<ul class="dropdown-menu" role="menu" id="cssContainer"> <ul class="dropdown-menu" role="menu" id="cssContainer">
<li><a href="#" data-val="">默认样式</a></li> <li><a href="#" data-val="">默认样式</a></li>
</ul> </ul>

View File

@ -1,4 +1,4 @@
.lgbDropdown .dropdown-menu > li > a:hover { .dropdown-select + .dropdown-menu a:hover {
background: #007AC0; background: #007AC0;
color: #fff; color: #fff;
} }

View File

@ -354,27 +354,22 @@
}).insertBefore(this.parents('.bootstrap-table').find('.fixed-table-toolbar > .bs-bars')); }).insertBefore(this.parents('.bootstrap-table').find('.fixed-table-toolbar > .bs-bars'));
return this; return this;
}, },
lgbDropdown: function (options) { });
var $this = $(this);
var op = typeof options === 'object' && options; //extend dropdown method
if (/val/.test(options)) { $.extend($.fn.dropdown.Constructor.prototype, {
if (arguments.length === 1) val: function () {
return $this.find('[data-toggle="dropdown"').attr("data-val"); var $element = $(this._element);
else { var $op = $(this._menu).find('[data-val="' + $element.val() + '"]:first');
var $element = $this.find('[data-toggle="dropdown"]'); $element.text($op.text());
$element.text($this.find('[data-val="' + arguments[1] + '"]').text()); },
$element.attr('data-val', arguments[1]); select: function () {
} var $element = $(this._element);
} $(this._menu).on('click', 'a', function (event) {
else { event.preventDefault();
$this.each(function () { var $op = $(this);
$(this).on('click', '.dropdown-menu a', { $parent: $(this) }, function (event) { $element.text($op.text()).val($op.attr('data-val'));
event.preventDefault(); });
var $op = $(this);
event.data.$parent.children('button').attr('data-val', $op.attr('data-val')).text($op.text());
});
});
}
} }
}); });
})(jQuery); })(jQuery);

View File

@ -36,7 +36,7 @@
}); });
break; break;
case 'css': case 'css':
var cssDefine = $('#dictCssDefine').attr("data-val"); var cssDefine = $css.val();
$.bc({ $.bc({
url: Settings.url, data: { name: '使用样式', code: cssDefine, category: '当前样式' }, title: '网站样式', url: Settings.url, data: { name: '使用样式', code: cssDefine, category: '当前样式' }, title: '网站样式',
callback: function (result) { callback: function (result) {
@ -153,6 +153,7 @@
listCacheUrl(); listCacheUrl();
}); });
var $css = $('#dictCssDefine');
$.bc({ $.bc({
url: Dicts.css, swal: false, url: Dicts.css, swal: false,
callback: function (result) { callback: function (result) {
@ -162,7 +163,7 @@
url: Dicts.css, swal: false, method: 'get', url: Dicts.css, swal: false, method: 'get',
callback: function (result) { callback: function (result) {
if (result.length > 0) if (result.length > 0)
$('.lgbDropdown').lgbDropdown('val', result); $css.val(result).dropdown('val');
} }
}); });
} }

View File

@ -197,7 +197,7 @@ $(function () {
} }
}); });
$('.lgbDropdown').lgbDropdown(); $('[data-toggle="dropdown"].dropdown-select').dropdown('select');
// load widget data // load widget data
$.reloadWidget(); $.reloadWidget();

View File

@ -12,10 +12,7 @@
for (name in this.options.map) { for (name in this.options.map) {
var ctl = $("#" + this.options.map[name]); var ctl = $("#" + this.options.map[name]);
if (ctl.attr('data-toggle') == "dropdown") { if (ctl.attr('data-toggle') == "dropdown") {
var val = value[name]; ctl.val(value[name]).dropdown('val');
if ((typeof val == "string" && val == "") || val == undefined) val = ctl.attr('data-default-val');
ctl.text(ctl.parent().find('.dropdown-menu [data-val="' + val + '"]').text());
ctl.attr('data-val', val);
} }
else if (ctl.attr('data-toggle') == 'toggle') { else if (ctl.attr('data-toggle') == 'toggle') {
ctl.bootstrapToggle(value[name] ? 'on' : 'off'); ctl.bootstrapToggle(value[name] ? 'on' : 'off');
@ -29,7 +26,7 @@
var dv = ctl.attr("data-default-val"); var dv = ctl.attr("data-default-val");
if (dv === undefined) dv = ""; if (dv === undefined) dv = "";
if (ctl.attr('data-toggle') == "dropdown") { if (ctl.attr('data-toggle') == "dropdown") {
ctl.text(ctl.parent().find('.dropdown-menu [data-val="' + dv + '"]').text()); ctl.val(dv).dropdown('val');
} }
else if (ctl.attr('data-toggle') == 'toggle') { else if (ctl.attr('data-toggle') == 'toggle') {
ctl.bootstrapToggle(dv == "true" ? 'on' : 'off'); ctl.bootstrapToggle(dv == "true" ? 'on' : 'off');
@ -46,15 +43,10 @@
target[name] = ctl.prop('checked'); target[name] = ctl.prop('checked');
continue; continue;
} }
else if (ctl.attr('data-toggle') == 'dropdown') {
target[name] = ctl.attr('data-val');
continue;
}
else if (dv != undefined && ctl.val() == "") target[name] = dv; else if (dv != undefined && ctl.val() == "") target[name] = dv;
else target[name] = ctl.val(); else target[name] = ctl.val();
if (target[name] == "true" || target[name] == "True") target[name] = true; if (target[name] == "true" || target[name] == "True") target[name] = true;
if (target[name] == "false" || target[name] == "False") target[name] = false; if (target[name] == "false" || target[name] == "False") target[name] = false;
} }
return target; return target;
} }