Merge branch '2.x' into feat/touch

This commit is contained in:
sight 2023-12-10 19:40:50 +08:00
commit f0a0c7f5e6
8 changed files with 64 additions and 28 deletions

View File

@ -222,13 +222,22 @@ layui.use(['table', 'dropdown'], function(){
},{
id: 'unchecked',
title: '取消选中某行'
},{
id: 'mult-checked',
title: '同时选中多个'
},{
id: 'reset-checked',
title: '给选中行取消选中状态'
}],
// 菜单被点击的事件
click: function(obj){
if(obj.id === 'reset-checked'){
click: function(obj) {
if (obj.id === 'mult-checked') {
// 同时选中多个
table.setRowChecked(id, {
index: [3, 4, 5], // 2.9.1+
checked: true
});
} else if(obj.id === 'reset-checked') {
// 给选中行取消选中状态
table.setRowChecked(id, {
index: 'all',

View File

@ -16,7 +16,8 @@ body{padding: 50px;}
<button class="layui-btn" lay-on="e1">事件1</button>
<button class="layui-btn" lay-on="e2">事件2</button>
<button class="layui-btn" lay-on="e3">事件3</button>
<button class="layui-btn" lay-active="e4">事件4</button>
<button class="layui-btn" lay-active="e4">hover: active - 事件4</button>
<button class="layui-btn" lay-active1="e4">hover: active1 - 事件4</button>
<br><br>
@ -108,7 +109,7 @@ layui.use(['lay', 'util', 'layer'], function(){
}
});
// 事件集的替换和增加
// Test: 事件集的替换和增加
util.on({
e1: function(othis){ // 重置事件 e1
alert(othis.html() + ' - replace')
@ -121,8 +122,19 @@ layui.use(['lay', 'util', 'layer'], function(){
// 自定义触发事件的元素属性名、自定义触发事件的方式
util.on('lay-active', {
e4: layui.throttle(function(othis) {
layer.tips(othis.html(), this);
}, 3000) // 3s 内不重复执行
layer.tips(othis.html(), this, { tips: 3 });
}, 3000), // 3s 内不重复执行
e5: function() {
console.log(111);
}
}, {
trigger: 'mouseenter'
});
// Test: 不同属性、相同值
util.on('lay-active1', {
e4: function(othis) {
this.innerHTML = 'hover: '+ (Math.random()*100000 | 0);
}
}, {
trigger: 'mouseenter'
});

View File

@ -1319,7 +1319,7 @@ body .layui-table-tips .layui-layer-content{background: none; padding: 0; box-sh
.layui-nav-itemed>a{color: #fff !important;}
.layui-nav-tree .layui-nav-bar{background-color: #16baaa;}
.layui-nav-tree .layui-nav-child{position: relative; z-index: 0; top: 0; border: none; background-color: rgba(0,0,0,.3); box-shadow: none;}
.layui-nav-tree .layui-nav-child{position: relative; z-index: 0; top: 0; border: none; background: none; background-color: rgba(0,0,0,.3); box-shadow: none;}
.layui-nav-tree .layui-nav-child dd{margin: 0;}
.layui-nav-tree .layui-nav-child a{color: #fff; color: rgba(255,255,255,.7);}
.layui-nav-tree .layui-nav-child a:hover{background: none; color: #fff;}

View File

@ -260,7 +260,6 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;}
.layui-layer-photos-footer a:hover{text-decoration: underline;}
.layui-layer-photos-footer em{font-style: normal;}
/* 关闭动画 */
@-webkit-keyframes layer-bounceOut {
100% {opacity: 0; -webkit-transform: scale(.7); transform: scale(.7)}
@ -273,9 +272,3 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;}
0% {-webkit-transform: scale(1); -ms-transform: scale(1);transform: scale(1);}
}
.layer-anim-close{-webkit-animation-name: layer-bounceOut; animation-name: layer-bounceOut; -webkit-animation-fill-mode: both; animation-fill-mode: both; -webkit-animation-duration:.2s; animation-duration:.2s;}
@media screen and (max-width: 1100px) {
.layui-layer-iframe{overflow-y: auto; -webkit-overflow-scrolling: touch;}
}

View File

@ -671,13 +671,15 @@ Class.pt.tips = function(){
};
// 辨别 tips 的方位
// 21 为箭头大小 8*2 + 箭头相对父元素的top偏移 5
goal.where = [function(){ // 上
goal.autoLeft();
goal.tipTop = goal.top - layArea[1] - 10;
tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
}, function(){ // 右
goal.tipLeft = goal.left + goal.width + 10;
goal.tipTop = goal.top;
goal.tipTop = goal.top - (goal.height * 0.75 < 21 ? 21 - goal.height * 0.5 : 0);
goal.tipTop = Math.max(goal.tipTop, 0);
tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
}, function(){ // 下
goal.autoLeft();
@ -685,7 +687,8 @@ Class.pt.tips = function(){
tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
}, function(){ // 左
goal.tipLeft = goal.left - layArea[0] - 10;
goal.tipTop = goal.top;
goal.tipTop = goal.top - (goal.height * 0.75 < 21 ? 21 - goal.height * 0.5 : 0);
goal.tipTop = Math.max(goal.tipTop, 0);
tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
}];
goal.where[guide-1]();

View File

@ -1560,10 +1560,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
Class.prototype.setRowChecked = function(opts){
var that = this;
var options = that.config;
var isCheckAll = opts.index === 'all';
var tr = that.layBody.find('tr'+ (
isCheckAll ? '' : '[data-index="'+ opts.index +'"]'
));
var isCheckAll = opts.index === 'all'; // 是否操作全部
var isCheckMult = layui.type(opts.index) === 'array'; // 是否操作多个
// 匹配行元素
var tr = function(tr) {
return isCheckAll ? tr : tr.filter(isCheckMult ? function() {
var dataIndex = $(this).data('index');
return opts.index.indexOf(dataIndex) !== -1;
} : '[data-index="'+ opts.index +'"]');
}(that.layBody.find('tr'));
// 默认属性
opts = $.extend({
@ -1573,18 +1579,31 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
// 同步数据选中属性值
var thisData = table.cache[that.key];
var existChecked = 'checked' in opts;
// 若为单选框,则单向选中;若为复选框,则切换选中。
var getChecked = function(value){
// 若为单选框,则单向选中;若为复选框,则切换选中。
return opts.type === 'radio' ? true : (existChecked ? opts.checked : !value)
};
// 设置数据选中属性
// 设置选中状态
layui.each(thisData, function(i, item){
if(layui.type(item) === 'array' || item[options.disabledName]) return; // 空项
if(Number(opts.index) === i || isCheckAll){
// 绕过空项和禁用项
if(layui.type(item) === 'array' || item[options.disabledName]) return;
// 匹配条件
var matched = isCheckAll || (
isCheckMult ? opts.index.indexOf(i) !== -1 : Number(opts.index) === i
);
// 设置匹配项的选中值
if(matched){
// 标记数据选中状态
var checked = item[options.checkName] = getChecked(item[options.checkName]);
var currTr = isCheckAll ? tr.filter('[data-index="'+ i +'"]') : tr;
currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色
// 标记当前行背景色
var currTr = tr.filter('[data-index="'+ i +'"]');
currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED);
// 若为 radio 类型,则取消其他行选中背景色
if(opts.type === 'radio'){
currTr.siblings().removeClass(ELEM_CHECKED);

View File

@ -93,7 +93,7 @@ layui.define(['table'], function (exports) {
var updateCache = function (id, childrenKey, data) {
var tableCache = table.cache[id];
layui.each(data || tableCache, function (index, item) {
var itemDataIndex = item[LAY_DATA_INDEX];
var itemDataIndex = item[LAY_DATA_INDEX] || '';
if (itemDataIndex.indexOf('-') !== -1) {
tableCache[itemDataIndex] = item
}

View File

@ -427,7 +427,7 @@ layui.define('jquery', function(exports){
var callbacks = dataCache.callbacks;
// 根据 attr 记录事件集合
events = $.extend(true, dataCache.events, events) || {};
events = dataCache.events[attr] = $.extend(true, dataCache.events[attr], events);
// 清除事件委托,避免重复绑定
elem.off(options.trigger, attrSelector, callbacks[attr]);