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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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