Browse Source

穿梭组件新增双击穿梭功能

pull/1036/head
sunxiaobin89 2 years ago
parent
commit
b83f7d376a
  1. 98
      src/modules/transfer.js

98
src/modules/transfer.js

@ -323,39 +323,16 @@ layui.define(['laytpl', 'form'], function(exports){
return selectedData; return selectedData;
}; };
//事件 //执行穿梭
Class.prototype.events = function(){ Class.prototype.transfer = function (_index, elem) {
var that = this var that = this
,options = that.config; ,options = that.config
//左右复选框
that.elem.on('click', 'input[lay-filter="layTransferCheckbox"]+', function(){
var thisElemCheckbox = $(this).prev()
,checked = thisElemCheckbox[0].checked
,thisDataElem = thisElemCheckbox.parents('.'+ ELEM_BOX).eq(0).find('.'+ ELEM_DATA);
if(thisElemCheckbox[0].disabled) return;
//判断是否全选
if(thisElemCheckbox.attr('lay-type') === 'all'){
thisDataElem.find('input[type="checkbox"]').each(function(){
if(this.disabled) return;
this.checked = checked;
});
}
that.renderCheckBtn({stopNone: true});
});
//按钮事件
that.layBtn.on('click', function(){
var othis = $(this)
,_index = othis.data('index')
,thisBoxElem = that.layBox.eq(_index) ,thisBoxElem = that.layBox.eq(_index)
,arr = []; ,arr = []
if(othis.hasClass(DISABLED)) return;
that.layBox.eq(_index).each(function(_index){ if (!elem) {
//通过按钮触发找到选中的进行移动
thisBoxElem.each(function(_index){
var othis = $(this) var othis = $(this)
,thisDataElem = othis.find('.'+ ELEM_DATA); ,thisDataElem = othis.find('.'+ ELEM_DATA);
@ -376,6 +353,20 @@ layui.define(['laytpl', 'form'], function(exports){
that.setValue(); that.setValue();
}); });
}); });
} else {
//双击单条记录移动
var thisList = elem
,thisElemCheckbox = thisList.find('input[type="checkbox"]')
thisElemCheckbox[0].checked = false;
thisBoxElem.siblings('.'+ ELEM_BOX).find('.'+ ELEM_DATA).append(thisList.clone());
thisList.remove();
//记录当前穿梭的数据
arr.push(thisElemCheckbox[0].value);
that.setValue();
}
that.renderCheckBtn(); that.renderCheckBtn();
@ -385,6 +376,53 @@ layui.define(['laytpl', 'form'], function(exports){
//穿梭时的回调 //穿梭时的回调
options.onchange && options.onchange(that.getData(arr), _index); options.onchange && options.onchange(that.getData(arr), _index);
}
//事件
Class.prototype.events = function(){
var that = this
,options = that.config;
//左右复选框
that.elem.on('click', 'input[lay-filter="layTransferCheckbox"]+', function(){
var thisElemCheckbox = $(this).prev()
,checked = thisElemCheckbox[0].checked
,thisDataElem = thisElemCheckbox.parents('.'+ ELEM_BOX).eq(0).find('.'+ ELEM_DATA);
if(thisElemCheckbox[0].disabled) return;
//判断是否全选
if(thisElemCheckbox.attr('lay-type') === 'all'){
thisDataElem.find('input[type="checkbox"]').each(function(){
if(this.disabled) return;
this.checked = checked;
});
}
setTimeout(function () {
that.renderCheckBtn({stopNone: true});
}, 0)
});
//双击记录
that.elem.on('dblclick', '.' + ELEM_DATA + '>li', function(event){
var elemThis = $(this)
,thisElemCheckbox = elemThis.children('input[type="checkbox"]')
,thisDataElem = elemThis.parent()
,thisBoxElem = thisDataElem.parent()
if(thisElemCheckbox[0].disabled) return;
that.transfer(thisBoxElem.data('index'), elemThis);
})
//按钮事件
that.layBtn.on('click', function(){
var othis = $(this)
,_index = othis.data('index')
if(othis.hasClass(DISABLED)) return;
that.transfer(_index);
}); });
//搜索 //搜索

Loading…
Cancel
Save