tableChild.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. /**
  2. *
  3. * @name: 子表格扩展
  4. * @author: yelog
  5. * @version: v1.4.4
  6. */
  7. layui.define(['table', 'element', 'form', 'laytpl'], function (exports) {
  8. var $ = layui.jquery,
  9. table = layui.table,
  10. laytpl = layui.laytpl,
  11. tableChildren = {},
  12. ELEM_HOVER = 'soul-table-hover';
  13. // 封装方法
  14. var mod = {
  15. /**
  16. * 渲染入口
  17. * @param myTable
  18. */
  19. render: function (myTable) {
  20. var _this = this,
  21. $table = $(myTable.elem),
  22. $tableBox = $table.next().children('.layui-table-box'),
  23. tableId = myTable.id,
  24. $tableHead = $tableBox.children('.layui-table-header').children('table'),
  25. $fixedBody = $tableBox.children('.layui-table-fixed').children('.layui-table-body').children('table'),
  26. $noFixedBody = $tableBox.children('.layui-table-body').children('table'),
  27. $tableBody = $.merge($tableBox.children('.layui-table-body').children('table'), $fixedBody),
  28. columns = _this.getCompleteCols(myTable.cols),
  29. childIndex = [],
  30. soulSort = typeof myTable.soulSort === 'undefined' || myTable.soulSort,
  31. i;
  32. // 修复hover样式
  33. _this.fixHoverStyle(myTable)
  34. // 获取子表配置信息
  35. for (i = 0; i < columns.length; i++) {
  36. if (columns[i].children && columns[i].children.length > 0) {
  37. childIndex.push(i);
  38. }
  39. }
  40. if (typeof $table.attr('lay-filter') === 'undefined') {
  41. $table.attr('lay-filter', tableId);
  42. }
  43. // 绑定一下主表事件
  44. if ($table.parents('.childTr').length === 0) {
  45. if (typeof myTable.rowEvent === 'function') {
  46. table.on('row(' + $table.attr('lay-filter') + ')', function (obj) {
  47. var index = $(this).data('index');
  48. obj.tr = $tableBody.children('tbody').children('tr[data-index="' + index + '"]');
  49. myTable.rowEvent(obj);
  50. })
  51. }
  52. if (typeof myTable.rowDoubleEvent === 'function') {
  53. table.on('rowDouble(' + $table.attr('lay-filter') + ')', function (obj) {
  54. var index = $(this).data('index');
  55. obj.tr = $tableBody.children('tbody').children('tr[data-index="' + index + '"]');
  56. myTable.rowDoubleEvent(obj);
  57. })
  58. }
  59. }
  60. if (childIndex.length > 0) {
  61. for (i = 0; i < childIndex.length; i++) {
  62. (function f() {
  63. var child = columns[childIndex[i]]
  64. , curIndex = childIndex[i]
  65. , icon = child.icon || ['layui-icon layui-icon-right', 'layui-icon layui-icon-down'];
  66. if (soulSort && !(myTable.url && myTable.page)) {
  67. // 前台排序
  68. table.on('sort(' + $table.attr('lay-filter') + ')', function () {
  69. _this.render(myTable)
  70. });
  71. }
  72. if (child.isChild && typeof child.isChild === 'function') {
  73. $tableBody.find('tr').find('td[data-key$="' + child.key + '"]>div').each(function (index) {
  74. if (child.isChild(layui.table.cache[tableId][index])) {
  75. if (child.field) {
  76. $(this).prepend('<i style="cursor: pointer" class="childTable ' + icon[0] + '"></i>');
  77. } else {
  78. $(this).html('<i style="cursor: pointer" class="childTable ' + icon[0] + '"></i>');
  79. }
  80. }
  81. })
  82. } else {
  83. if (child.field) {
  84. $tableBody.find('tr').find('td[data-key$="' + child.key + '"]>div').prepend('<i style="cursor: pointer" class="childTable ' + icon[0] + '"></i>');
  85. } else {
  86. $tableBody.find('tr').find('td[data-key$="' + child.key + '"]>div').html('<i style="cursor: pointer" class="childTable ' + icon[0] + '"></i>');
  87. }
  88. }
  89. $tableBody.children('tbody').children('tr').each(function () {
  90. $(this).children('td:eq(' + curIndex + ')').find('.childTable').on('click', function (e) {
  91. layui.stope(e)
  92. var rowIndex = $(this).parents('tr:eq(0)').data('index'),
  93. key = $(this).parents('td:eq(0)').data('key'),
  94. $this = $noFixedBody.children('tbody').children('tr[data-index=' + rowIndex + ']').children('td[data-key="' + key + '"]').find('.childTable:eq(0)'),
  95. $fixedThis = $fixedBody.find('tr[data-index=' + rowIndex + ']').children('td[data-key="' + key + '"]').find('.childTable:eq(0)'),
  96. data = table.cache[myTable.id][rowIndex],
  97. children = child.children;
  98. if (typeof child.children === 'function') {
  99. children = child.children(data)
  100. }
  101. if (child.show === 2) { // 弹窗模式
  102. layer.open($.extend({
  103. type: 1,
  104. title: '子表',
  105. maxmin: true,
  106. content: _this.getTables(this, data, child, myTable, children),
  107. area: '1000px',
  108. offset: '100px'
  109. }, child.layerOption || {}));
  110. _this.renderTable(this, data, child, myTable, children, icon);
  111. } else { // 展开模式
  112. // 开启手风琴模式
  113. if (!$this.hasClass(icon[1]) && child.collapse) {
  114. $tableBody.children('tbody').children('tr').children('td').find('.childTable').each(function () {
  115. if ($(this).hasClass(icon[1])) {
  116. _this.destroyChildren($(this).parents('tr:eq(0)').data('index'), myTable, icon)
  117. }
  118. })
  119. }
  120. // 多个入口时,关闭其他入口
  121. if (!$this.hasClass(icon[1])) {
  122. $this.parents('tr:eq(0)').children('td').find('.childTable').each(function () {
  123. if ($(this).hasClass(icon[1])) {
  124. $(this).removeClass(icon[1]).addClass(icon[0])
  125. _this.destroyChildren($(this).parents('tr:eq(0)').data('index'), myTable, icon)
  126. }
  127. })
  128. }
  129. if ($this.hasClass(icon[1])) {
  130. $this.removeClass(icon[1]).addClass(icon[0])
  131. $fixedThis.removeClass(icon[1]).addClass(icon[0])
  132. } else {
  133. $this.removeClass(icon[0]).addClass(icon[1])
  134. $fixedThis.removeClass(icon[0]).addClass(icon[1])
  135. }
  136. var rowspanIndex = $this.parents('td:eq(0)').attr("rowspan");
  137. if ($this.hasClass(icon[1])) {
  138. var newTr = [];
  139. newTr.push('<tr class="noHover childTr"><td colspan="' + $tableHead.find('th:visible').length + '" style="cursor: inherit; padding: 0; width: ' + $this.parents('tr:eq(0)').width() + 'px">');
  140. newTr.push(_this.getTables(this, data, child, myTable, children));
  141. newTr.push('</td></tr>');
  142. if (rowspanIndex) {
  143. var index = parseInt($this.parents('tr:eq(0)').data("index")) + parseInt(rowspanIndex) - 1;
  144. $this.parents('table:eq(0)').children().children("[data-index='" + index + "']").after(newTr.join(''));
  145. } else {
  146. $this.parents('tr:eq(0)').after(newTr.join(''));
  147. }
  148. _this.renderTable(this, data, child, myTable, children, icon);
  149. if ($fixedBody.length > 0) {
  150. var $tr = $this.parents('tr:eq(0)').next(),
  151. height = $tr.children('td').height(),
  152. $patchDiv = '<div class="soul-table-child-patch" style="height: ' + height + 'px"></div>';
  153. $tr.children('td').children('.layui-tab-card').css({
  154. position: 'absolute',
  155. top: 0,
  156. width: '100%',
  157. background: 'white',
  158. 'z-index': 200
  159. })
  160. $tr.children('td').append($patchDiv);
  161. $fixedBody.find('tr[data-index="' + rowIndex + '"]').each(function () {
  162. $(this).after('<tr><td style="padding: 0;" colspan="' + $(this).children('[data-key]').length + '">' + $patchDiv + '</td></tr>')
  163. })
  164. table.resize(tableId)
  165. }
  166. if (child.show === 3) {
  167. $this.parents('tr:eq(0)').next().find('.layui-table-view').css({
  168. margin: 0,
  169. 'border-width': 0
  170. });
  171. $this.parents('tr:eq(0)').next().find('.layui-table-header').css('display', 'none');
  172. }
  173. // 阻止事件冒泡
  174. $this.parents('tr:eq(0)').next().children('td').children('.layui-tab').children('.layui-tab-content').on('click', function (e) {
  175. e.stopPropagation()
  176. }).off('dblclick').on('dblclick', function (e) {
  177. e.stopPropagation()
  178. }).on('mouseenter', 'td', function (e) {
  179. e.stopPropagation()
  180. })
  181. } else {
  182. _this.destroyChildren(rowIndex, myTable, icon);
  183. table.resize(tableId)
  184. }
  185. }
  186. })
  187. })
  188. if (child.spread && child.show !== 2) {
  189. $tableBody.children('tbody').children('tr').children('td').find('.childTable').trigger('click');
  190. }
  191. })()
  192. }
  193. }
  194. },
  195. /**
  196. * 生成子表内容
  197. * @param _this
  198. * @param data
  199. * @param child
  200. * @param myTable
  201. * @param children 子表配置
  202. * @returns {string}
  203. */
  204. getTables: function (_this, data, child, myTable, children) {
  205. var tables = [],
  206. $table = $(myTable.elem),
  207. tableId = myTable.id,
  208. rowTableId = tableId + $(_this).parents('tr:eq(0)').data('index'),
  209. $tableMain = $table.next().children('.layui-table-box').children('.layui-table-body'),
  210. $tableBody = $tableMain.children('table'),
  211. scrollWidth = 0,
  212. i;
  213. tables.push('<div class="layui-tab layui-tab-card" lay-filter="table-child-' + rowTableId + '" style="margin: 0;border: 0;box-shadow: none;');
  214. if (child.show === 2) {
  215. tables.push('max-width: ' + ($tableBody.width() - 2) + 'px">')
  216. } else if (child.show === 3) {
  217. //不限制宽度
  218. tables.push('">')
  219. } else {
  220. if (child.childWidth === 'full') {
  221. //不限制宽度
  222. tables.push('">')
  223. } else {
  224. if ($tableMain.prop('scrollHeight') + (children.length > 0 ? children[0].height : 0) > $tableMain.height()) {
  225. scrollWidth = this.getScrollWidth();
  226. }
  227. tables.push('max-width: ' + ($tableMain.width() - 1 - scrollWidth) + 'px">')
  228. }
  229. }
  230. if (child.show !== 3 && (typeof child.childTitle === 'undefined' || child.childTitle)) {
  231. tables.push('<ul class="layui-tab-title">')
  232. for (i = 0; i < children.length; i++) {
  233. tables.push('<li class="' + (i === 0 ? 'layui-this' : '') + '">' + (typeof children[i].title === 'function' ? children[i].title(data) : children[i].title) + '</li>');
  234. }
  235. tables.push('</ul>')
  236. }
  237. if (child.show === 3) {
  238. tables.push('<div class="layui-tab-content" style="padding: 0">');
  239. } else {
  240. tables.push('<div class="layui-tab-content" style="padding: 0 10px">');
  241. }
  242. for (i = 0; i < children.length; i++) {
  243. var childTableId = rowTableId + i;
  244. tables.push('<div class="layui-tab-item layui-show"><form action="" class="layui-form" ><table id="' + childTableId + '" lay-filter="' + childTableId + '"></table></form></div>');
  245. }
  246. tables.push('</div></div>');
  247. return tables.join('')
  248. },
  249. /**
  250. * 渲染子表
  251. * @param _this
  252. * @param data 父表当前行数据
  253. * @param child 子表列
  254. * @param myTable 父表配置
  255. * @param children 子表配置
  256. */
  257. renderTable: function (_this, data, child, myTable, children, icon) {
  258. var tables = []
  259. , _that = this
  260. , tableId = myTable.id
  261. , rowTableId = tableId + $(_this).parents('tr:eq(0)').data('index');
  262. if (child.lazy) {
  263. tables.push(renderChildTable(_that, _this, data, child, myTable, 0, children, icon));
  264. } else {
  265. for (var i = 0; i < children.length; i++) {
  266. tables.push(renderChildTable(_that, _this, data, child, myTable, i, children, icon));
  267. }
  268. }
  269. tableChildren[rowTableId] = tables;
  270. layui.element.on('tab(table-child-' + rowTableId + ')', function (tabData) {
  271. if (child.lazy) {
  272. var isRender = false; // 是否已经渲染
  273. for (i = 0; i < tableChildren[rowTableId].length; i++) {
  274. if (tableChildren[rowTableId][i].config.id === (rowTableId + tabData.index)) {
  275. isRender = true;
  276. break;
  277. }
  278. }
  279. if (!isRender) {
  280. tableChildren[rowTableId].push(renderChildTable(_that, _this, data, child, myTable, tabData.index, children))
  281. }
  282. }
  283. var rowIndex = $(_this).parents('tr:eq(0)').data('index'),
  284. height = $(tabData.elem).height();
  285. $(_this).parents('.layui-table-box:eq(0)').children('.layui-table-body').children('table').children('tbody').children('tr[data-index=' + rowIndex + ']').next().children().children('.soul-table-child-patch').css('height', height)
  286. $(_this).parents('.layui-table-box:eq(0)').children('.layui-table-fixed').children('.layui-table-body').children('table').children('tbody').children('tr[data-index=' + rowIndex + ']').next().children().children('.soul-table-child-patch').css('height', height)
  287. table.resize(tableId)
  288. });
  289. function renderChildTable(_that, _this, data, child, myTable, i, children, icon) {
  290. var param = _that.deepClone(children[i]), thisTableChild,
  291. tableId = myTable.id,
  292. rowIndex = $(_this).parents('tr:eq(0)').data('index'),
  293. childTableId = tableId + rowIndex + i,
  294. $table = $(myTable.elem),
  295. $tableBox = $table.next().children('.layui-table-box'),
  296. $tableBody = $.merge($tableBox.children('.layui-table-body').children('table'), $tableBox.children('.layui-table-fixed').children('.layui-table-body').children('table')),
  297. tr = $tableBody.children('tbody').children('tr[data-index="' + rowIndex + '"]'),
  298. row = table.cache[tableId][rowIndex],
  299. // 父表当前行对象
  300. pobj = {
  301. data: row,
  302. tr: tr,
  303. del: function () {
  304. table.cache[tableId][rowIndex] = [];
  305. _that.destroyChildren(rowIndex, myTable, icon)
  306. tr.remove();
  307. table.resize(tableId);
  308. },
  309. update: function (fields) {
  310. fields = fields || {};
  311. layui.each(fields, function (key, value) {
  312. if (key in row) {
  313. var templet, td = tr.children('td[data-field="' + key + '"]');
  314. row[key] = value;
  315. table.eachCols(tableId, function (i, item2) {
  316. if (item2.field == key && item2.templet) {
  317. templet = item2.templet;
  318. }
  319. });
  320. td.children('.layui-table-cell').html(function () {
  321. return templet ? function () {
  322. return typeof templet === 'function'
  323. ? templet(row)
  324. : laytpl($(templet).html() || value).render(row)
  325. }() : value;
  326. }());
  327. td.data('content', value);
  328. }
  329. });
  330. },
  331. close: function () {
  332. _that.destroyChildren(rowIndex, myTable, icon)
  333. table.resize(tableId);
  334. }
  335. };
  336. param.id = childTableId;
  337. param.elem = '#' + childTableId;
  338. typeof param.where === 'function' && (param.where = param.where(data));
  339. typeof param.data === 'function' && (param.data = param.data(data));
  340. typeof param.url === 'function' && (param.url = param.url(data));
  341. thisTableChild = table.render(param);
  342. if (!child.lazy && i !== 0) {
  343. $('#' + childTableId).parents('.layui-tab-item:eq(0)').removeClass('layui-show'); //解决隐藏时计算表格高度有问题
  344. }
  345. // 绑定 checkbox 事件
  346. if (typeof param.checkboxEvent === 'function') {
  347. table.on('checkbox(' + childTableId + ')', function (obj) {
  348. param.checkboxEvent(obj, pobj)
  349. })
  350. }
  351. // 绑定 edit 事件
  352. if (typeof param.editEvent === 'function') {
  353. table.on('edit(' + childTableId + ')', function (obj) {
  354. obj.oldValue = $(this).prev().text();
  355. param.editEvent(obj, pobj)
  356. })
  357. }
  358. // 绑定 tool 事件
  359. if (typeof param.toolEvent === 'function') {
  360. table.on('tool(' + childTableId + ')', function (obj) {
  361. param.toolEvent(obj, pobj)
  362. })
  363. }
  364. // 绑定 toolbar 事件
  365. if (typeof param.toolbarEvent === 'function') {
  366. table.on('toolbar(' + childTableId + ')', function (obj) {
  367. param.toolbarEvent(obj, pobj)
  368. })
  369. }
  370. // 绑定单击行事件
  371. if (typeof param.rowEvent === 'function') {
  372. table.on('row(' + childTableId + ')', function (obj) {
  373. param.rowEvent(obj, pobj)
  374. })
  375. }
  376. // 绑定双击行事件
  377. if (typeof param.rowDoubleEvent === 'function') {
  378. table.on('rowDouble(' + childTableId + ')', function (obj) {
  379. param.rowDoubleEvent(obj, pobj)
  380. })
  381. }
  382. return thisTableChild;
  383. }
  384. },
  385. destroyChildren: function (rowIndex, myTable, icon) {
  386. var tableId = myTable.id,
  387. $table = $(myTable.elem),
  388. $tableBox = $table.next().children('.layui-table-box'),
  389. $fixedBody = $tableBox.children('.layui-table-fixed').children('.layui-table-body').children('table'),
  390. $tableBody = $.merge($tableBox.children('.layui-table-body').children('table'), $fixedBody),
  391. $tr = $tableBody.children('tbody').children('tr[data-index="' + rowIndex + '"]');
  392. $tr.find('.childTable').removeClass(icon[1]).addClass(icon[0]);
  393. // 暂时不处理 rowspan 情况
  394. // var rowspanIndex = $this.parents('td:eq(0)').attr("rowspan");
  395. // if(rowspanIndex){
  396. // var index=$this.parents('tr:eq(0)').index()+parseInt(rowspanIndex);
  397. // $this.parents('table:eq(0)').children().children('tr:eq('+index+')').remove()
  398. // }else{
  399. // $this.parents('tr:eq(0)').next().remove();
  400. // }
  401. $tr.next().remove()
  402. var tables = tableChildren[tableId + rowIndex];
  403. if (layui.tableFilter) { //如果使用了筛选功能,怎同时清理筛选渲染的数据
  404. layui.tableFilter.destroy(tables);
  405. }
  406. delete tableChildren[tableId + rowIndex]
  407. },
  408. cloneJSON: function (obj) {
  409. var JSON_SERIALIZE_FIX = {
  410. PREFIX: "[[JSON_FUN_PREFIX_",
  411. SUFFIX: "_JSON_FUN_SUFFIX]]"
  412. };
  413. var sobj = JSON.stringify(obj, function (key, value) {
  414. if (typeof value === 'function') {
  415. return JSON_SERIALIZE_FIX.PREFIX + value.toString() + JSON_SERIALIZE_FIX.SUFFIX;
  416. }
  417. return value;
  418. });
  419. return JSON.parse(sobj, function (key, value) {
  420. if (typeof value === 'string' &&
  421. value.indexOf(JSON_SERIALIZE_FIX.SUFFIX) > 0 && value.indexOf(JSON_SERIALIZE_FIX.PREFIX) === 0) {
  422. return eval("(" + value.replace(JSON_SERIALIZE_FIX.PREFIX, "").replace(JSON_SERIALIZE_FIX.SUFFIX, "") + ")");
  423. }
  424. return value;
  425. }) || {};
  426. },
  427. fixHoverStyle: function (myTable) {
  428. var $table = $(myTable.elem)
  429. ,
  430. $tableBody = $table.next().children('.layui-table-box').children('.layui-table-body').children('table')
  431. ,
  432. $tableFixed = $table.next().children('.layui-table-box').children('.layui-table-fixed').children('.layui-table-body').children('table')
  433. , style = $table.next().find('style')[0],
  434. sheet = style.sheet || style.styleSheet || {};
  435. // 屏蔽掉layui原生 hover 样式
  436. this.addCSSRule(sheet, '.layui-table-hover', 'background-color: inherit');
  437. this.addCSSRule(sheet, '.layui-table-hover.soul-table-hover', 'background-color: #F2F2F2');
  438. $.merge($tableFixed.children('tbody').children('tr'), $tableBody.children('tbody').children('tr'))
  439. .on('mouseenter', function () {
  440. var othis = $(this)
  441. , index = $(this).data('index');
  442. if (othis.data('off')) return;
  443. $tableFixed.children('tbody').children('tr[data-index=' + index + ']').addClass(ELEM_HOVER);
  444. $tableBody.children('tbody').children('tr[data-index=' + index + ']').addClass(ELEM_HOVER);
  445. }).on('mouseleave', function () {
  446. var othis = $(this)
  447. , index = $(this).data('index');
  448. if (othis.data('off')) return;
  449. $tableFixed.children('tbody').children('tr[data-index=' + index + ']').removeClass(ELEM_HOVER);
  450. $tableBody.children('tbody').children('tr[data-index=' + index + ']').removeClass(ELEM_HOVER);
  451. })
  452. },
  453. addCSSRule: function (sheet, selector, rules, index) {
  454. if ('insertRule' in sheet) {
  455. sheet.insertRule(selector + '{' + rules + '}', index)
  456. } else if ('addRule' in sheet) {
  457. sheet.addRule(selector, rules, index)
  458. }
  459. },
  460. // 深度克隆-不丢失方法
  461. deepClone: function (obj) {
  462. var newObj = Array.isArray(obj) ? [] : {}
  463. if (obj && typeof obj === "object") {
  464. for (var key in obj) {
  465. if (obj.hasOwnProperty(key)) {
  466. newObj[key] = (obj && typeof obj[key] === 'object') ? this.deepClone(obj[key]) : obj[key];
  467. }
  468. }
  469. }
  470. return newObj
  471. },
  472. getCompleteCols: function (origin) {
  473. var cols = this.deepClone(origin);
  474. var i, j, k, cloneCol;
  475. for (i = 0; i < cols.length; i++) {
  476. for (j = 0; j < cols[i].length; j++) {
  477. if (!cols[i][j].exportHandled) {
  478. if (cols[i][j].rowspan > 1) {
  479. cloneCol = this.deepClone(cols[i][j])
  480. cloneCol.exportHandled = true;
  481. k = i + 1;
  482. while (k < cols.length) {
  483. cols[k].splice(j, 0, cloneCol)
  484. k++
  485. }
  486. }
  487. if (cols[i][j].colspan > 1) {
  488. cloneCol = this.deepClone(cols[i][j])
  489. cloneCol.exportHandled = true;
  490. for (k = 1; k < cols[i][j].colspan; k++) {
  491. cols[i].splice(j, 0, cloneCol)
  492. }
  493. j = j + cols[i][j].colspan - 1
  494. }
  495. }
  496. }
  497. }
  498. return cols[cols.length - 1];
  499. },
  500. getScrollWidth: function (elem) {
  501. var width = 0;
  502. if (elem) {
  503. width = elem.offsetWidth - elem.clientWidth;
  504. } else {
  505. elem = document.createElement('div');
  506. elem.style.width = '100px';
  507. elem.style.height = '100px';
  508. elem.style.overflowY = 'scroll';
  509. document.body.appendChild(elem);
  510. width = elem.offsetWidth - elem.clientWidth;
  511. document.body.removeChild(elem);
  512. }
  513. return width;
  514. }
  515. };
  516. // 输出
  517. exports('tableChild', mod);
  518. });