| | |
| | | table = layui.table, |
| | | form = layui.form; |
| | | var tableSelect = function () { |
| | | this.v = '1.3.0'; |
| | | this.v = '1.4.0'; |
| | | }; |
| | | |
| | | /** |
| | |
| | | var elem = $(opt.elem); |
| | | |
| | | //默认设置 |
| | | opt.searchKey = opt.searchKey || 'keyword'; |
| | | opt.searchKey = opt.searchKey || 'keyword';//可多个用,分割 |
| | | opt.table.page = opt.table.page || false; |
| | | opt.table.height = opt.table.height || 290; |
| | | elem.off('click').on('click', function(e) { |
| | |
| | | } |
| | | |
| | | }) |
| | | // 防抖函数 |
| | | function debounce(func, wait) { |
| | | let timeout; |
| | | return function () { |
| | | const context = this, args = arguments; |
| | | clearTimeout(timeout); |
| | | timeout = setTimeout(() => func.apply(context, args), wait); |
| | | }; |
| | | } |
| | | |
| | | |
| | | //输入框输入执行 |
| | | elem.off('input').on('input', function (e) { |
| | | elem.off('input').on('input', debounce( |
| | | function (e) { |
| | | // 阻止表单提交(如果输入框在表单内) |
| | | e.preventDefault(); |
| | | var searchKeyList = opt.searchKey.split(',');//获取查找的关键字搜索框 |
| | | //拼接sql字符串 |
| | | var sWhereStr = " and (" |
| | | searchKeyList.forEach(function (value, index) { |
| | | if (index == 0) { |
| | | sWhereStr += (value + " like '%" + elem.val() + "%' ") |
| | | } else { |
| | | sWhereStr += ("or " + value + " like '%" + elem.val() + "%' ") |
| | | } |
| | | }) |
| | | sWhereStr +=")" |
| | | //后端分页搜索 |
| | | if (opt.table.where != undefined) { |
| | | opt.table.where['sWhere'] = opt.sWhere + " and " + opt.searchKey + " like '%" + elem.val() + "%' "; |
| | | opt.table.where['sWhere'] = opt.sWhere + sWhereStr; |
| | | tableSelect_table.reload({ |
| | | where: opt.table.where, |
| | | page: { |
| | |
| | | } |
| | | }); |
| | | } else { |
| | | var sWhere = opt.sWhere + " and " + opt.searchKey + " like '%" + elem.val() + "%' "; |
| | | var sWhere = opt.sWhere + sWhereStr; |
| | | tableSelect_table.reload({ |
| | | data: opt.ajaxSelect(sWhere) |
| | | }); |
| | | } |
| | | |
| | | }) |
| | | },200)) |
| | | |
| | | //双击行选中 |
| | | table.on('rowDouble('+tableName+')', function(obj){ |