From f6bfafc3a6cd50f11fbf498ecf21498bd9112ff4 Mon Sep 17 00:00:00 2001 From: D:/workspace/chenjingjing/git/gx_tieta/gx_tieta/.gitignore <chenjingjing@LAPTOP-E51P2139> Date: 星期二, 08 一月 2019 17:37:51 +0800 Subject: [PATCH] Merge branch 'dev_lxw' of https://whyccjj@gitlab.com/whyclxw1/gx_tieta.git into dev_lxw --- gx_tieta/WebRoot/pages/js/mylayui.js | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 154 insertions(+), 0 deletions(-) diff --git a/gx_tieta/WebRoot/pages/js/mylayui.js b/gx_tieta/WebRoot/pages/js/mylayui.js index 91ecfb3..e1a8557 100644 --- a/gx_tieta/WebRoot/pages/js/mylayui.js +++ b/gx_tieta/WebRoot/pages/js/mylayui.js @@ -389,3 +389,157 @@ } }; +//layui琛ㄦ牸鍐呭鏇存柊 +var LayuiTbl = function(options, layui, laytpl, cache) { + this.opts = options; + this.cache = cache; + this.layui = layui; + this.tpl = laytpl; + this.ele = options.elem; + this.col = options.cols[0]; +}; + +// 璁剧疆鍘熷瀷鍑芥暟 +LayuiTbl.prototype = { + updateTr: function(index, data) { + var layui = this.layui; + var preData = this.cache[index]; + var _data = $.extend(preData||{}, data||{}); + var tds = this._getBodyTds(index); + var tdRs = this._getFixedRTds(index); + //console.log(_data); + // 閬嶅巻 + var _this = this; + layui.each(_data, function(key, value) { + // 閬嶅巻tds鐨勫�� + tds.each(function(k) { + var _field = $(this).data('field'); + if(key == _field) { + var cell = $(this).find('.layui-table-cell'); + var content = _this._getContent(key, value, _data); + cell.html(content); + } + }); + }); + + // 淇敼娴姩 + layui.each(_data, function(key, value) { + // 閬嶅巻tds鐨勫�� + tdRs.each(function(k) { + var _field = $(this).data('field'); + if(key == _field) { + var cell = $(this).find('.layui-table-cell'); + var content = _this._getContent(key, value, _data); + cell.html(content); + } + }); + }); + } + ,updateCol: function(major, field, data) { // 鏇存柊鍒楃殑鍊� + // 鍒ゆ柇褰撳墠灞炴�ф槸鍚︽槸data鐨勫睘鎬� + if(field in data) { + var index = this.getIndex(major, data[major]); // 鑾峰彇闇�瑕佹洿鏂扮殑琛� + if(index != undefined) { // 鑾峰彇鍒� + this.updateTr(index, data); // 鏇存柊琛ㄦ牸鐨勬暟鎹� + } + } + + } + ,update: function(field, data) { + for(var i=0; i<data.length; i++) { + var _data = data[i]; + if(field in _data) { // 鍒ゆ柇瀵硅薄涓槸鍚﹀瓨鍦ㄦ爣璇嗕綅 + var _field = _data[field]; // 鑾峰彇鏍囪瘑浣嶇殑鍊� + var index = this.getIndex(field, _field); // 鑾峰彇瀵硅薄鎵�鍦ㄧ殑琛� + if(index != undefined) { // 鍒ゆ柇鏄惁鑾峰彇鍒颁簡琛屽彿 + this.updateTr(index, _data); // 鏇存柊鎸囧畾鐨勮 + }else { + console.log(' 绗�'+i+'涓璞℃病鏈夊璞$殑琛ㄦ牸琛�'); + console.log(_data); + } + }else { + console.log(' 绗�'+i+'涓璞$殑'+field+'涓婚敭鏍囪瘑涓嶅瓨鍦�'); + } + } + } + ,_getBodyTds: function(index) { + var layuiTableView = $(this.ele).next('.layui-table-view'); + var layuiTableBody = layuiTableView.find('.layui-table-body .layui-table tbody'); + var trList = layuiTableBody.find('tr'); + + return trList.eq(index).find('td'); + } + ,_getFixedRTds: function(index) { + var layuiTableView = $(this.ele).next('.layui-table-view'); + var layuiFixedR = layuiTableView.find('.layui-table-fixed.layui-table-fixed-r .layui-table tbody'); + var trList = layuiFixedR.find('tr'); + return trList.eq(index).find('td'); + } + ,_getContent: function(key, value, data) { + var col = this.col; // 鎵�鏈夌殑鍒� + var laytpl = this.tpl; + var rs = ''; + var templet = ''; + // 閬嶅巻鎵�鏈夌殑鍒� + for(var i=0; i<col.length; i++) { + var _col = col[i]; + // 鍒ゆ柇褰撳墠鍐呭鏄惁涓哄搴旂殑闇�瑕佹洿鏂扮殑鏁版嵁 + if(key == _col.field) { + // 鍒ゆ柇鏄惁鏈夋ā鏉� + // console.log(key+'***'+_col.field); + // console.log(_col.templet); + templet = _col.templet?$(_col.templet).html():_col.toolbar?$(_col.toolbar).html():typeof value == 'number'?value.toString():value; + //console.log(templet); + templet = templet?templet:typeof value == 'number'?value.toString():value; + // 鏍规嵁妯℃澘鏋勬垚content + laytpl(templet).render(data, function(html) { + rs = html; + }); + + return rs; + } + } + + return false; + } + ,getIndex: function(field, value) { // 鑾峰彇tr鐨勪笅鏍� + // 閬嶅巻cache鐨勫�� + var cache = this.cache; + var index = undefined; + for(var i=0; i<cache.length; i++) { + var _cache = cache[i]; + // console.log(_cache) + if(field in _cache && _cache[field] == value) { + index = i; + break; + } + } + + return index; + } + ,getTr: function(field, value) { // 鑾峰彇Tr鐨勬暟鎹� + // 閬嶅巻cache鐨勫�� + var cache = this.cache; + var rs = { + code: 0 + ,data: {} + ,msg: '鑾峰彇鏍囪瘑浣�'+field+'锛屽�间负'+value+'瀵瑰簲鐨則r鐨勬暟鎹け璐�' + }; + // 閬嶅巻cache鐨勫�� + for(var i=0; i<cache.length; i++) { + var _cache = cache[i]; + if(field in _cache && _cache[field] == value) { + rs.code = 1; + rs.data = _cache; + rs.msg = '鑾峰彇鏍囪瘑浣�'+field+'锛屽�间负'+value+'瀵瑰簲鐨則r鐨勬暟鎹垚鍔�' + break; + } + } + + return rs; + } + ,setCache: function(cache) { + this.cache = cache; + } +}; + -- Gitblit v1.9.1