ry-ui.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499
  1. /**
  2. * 通用js方法封装处理
  3. * Copyright (c) 2019 ruoyi
  4. */
  5. // 当前table相关信息
  6. var table = {
  7. config: {},
  8. // 当前实例配置
  9. options: {},
  10. // 设置实例配置
  11. set: function(id) {
  12. if($.common.getLength(table.config) > 1) {
  13. var tableId = $.common.isEmpty(id) ? $(event.currentTarget).parents(".bootstrap-table").find(".table").attr("id") : id;
  14. if ($.common.isNotEmpty(tableId)) {
  15. table.options = table.get(tableId);
  16. }
  17. }
  18. },
  19. // 获取实例配置
  20. get: function(id) {
  21. return table.config[id];
  22. },
  23. // 记住选择实例组
  24. rememberSelecteds: {},
  25. // 记住选择ID组
  26. rememberSelectedIds: {}
  27. };
  28. (function ($) {
  29. $.extend({
  30. _tree: {},
  31. bttTable: {},
  32. // 表格封装处理
  33. table: {
  34. // 初始化表格参数
  35. init: function(options) {
  36. var defaults = {
  37. id: "bootstrap-table",
  38. type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTable
  39. height: undefined,
  40. sidePagination: "server",
  41. sortName: "",
  42. sortOrder: "asc",
  43. pagination: true,
  44. pageSize: 10,
  45. pageList: [10, 25, 50],
  46. toolbar: "toolbar",
  47. striped: false,
  48. escape: false,
  49. firstLoad: true,
  50. showFooter: false,
  51. search: false,
  52. showSearch: true,
  53. showPageGo: false,
  54. showRefresh: true,
  55. showColumns: true,
  56. showToggle: true,
  57. showExport: false,
  58. clickToSelect: false,
  59. singleSelect: false,
  60. mobileResponsive: true,
  61. rememberSelected: false,
  62. fixedColumns: false,
  63. fixedNumber: 0,
  64. rightFixedColumns: false,
  65. rightFixedNumber: 0,
  66. queryParams: $.table.queryParams,
  67. rowStyle: {},
  68. };
  69. var options = $.extend(defaults, options);
  70. table.options = options;
  71. table.config[options.id] = options;
  72. $.table.initEvent();
  73. $('#' + options.id).bootstrapTable({
  74. id: options.id,
  75. url: options.url, // 请求后台的URL(*)
  76. contentType: "application/x-www-form-urlencoded", // 编码类型
  77. method: 'post', // 请求方式(*)
  78. cache: false, // 是否使用缓存
  79. height: options.height, // 表格的高度
  80. striped: options.striped, // 是否显示行间隔色
  81. sortable: true, // 是否启用排序
  82. sortStable: true, // 设置为 true 将获得稳定的排序
  83. sortName: options.sortName, // 排序列名称
  84. sortOrder: options.sortOrder, // 排序方式 asc 或者 desc
  85. pagination: options.pagination, // 是否显示分页(*)
  86. pageNumber: 1, // 初始化加载第一页,默认第一页
  87. pageSize: options.pageSize, // 每页的记录行数(*)
  88. pageList: options.pageList, // 可供选择的每页的行数(*)
  89. firstLoad: options.firstLoad, // 是否首次请求加载数据,对于数据较大可以配置false
  90. escape: options.escape, // 转义HTML字符串
  91. showFooter: options.showFooter, // 是否显示表尾
  92. iconSize: 'outline', // 图标大小:undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
  93. toolbar: '#' + options.toolbar, // 指定工作栏
  94. sidePagination: options.sidePagination, // server启用服务端分页client客户端分页
  95. search: options.search, // 是否显示搜索框功能
  96. searchText: options.searchText, // 搜索框初始显示的内容,默认为空
  97. showSearch: options.showSearch, // 是否显示检索信息
  98. showPageGo: options.showPageGo, // 是否显示跳转页
  99. showRefresh: options.showRefresh, // 是否显示刷新按钮
  100. showColumns: options.showColumns, // 是否显示隐藏某列下拉框
  101. showToggle: options.showToggle, // 是否显示详细视图和列表视图的切换按钮
  102. showExport: options.showExport, // 是否支持导出文件
  103. uniqueId: options.uniqueId, // 唯 一的标识符
  104. clickToSelect: options.clickToSelect, // 是否启用点击选中行
  105. singleSelect: options.singleSelect, // 是否单选checkbox
  106. mobileResponsive: options.mobileResponsive, // 是否支持移动端适配
  107. detailView: options.detailView, // 是否启用显示细节视图
  108. onClickRow: options.onClickRow, // 点击某行触发的事件
  109. onDblClickRow: options.onDblClickRow, // 双击某行触发的事件
  110. onClickCell: options.onClickCell, // 单击某格触发的事件
  111. onDblClickCell: options.onDblClickCell, // 双击某格触发的事件
  112. onEditableSave: options.onEditableSave, // 行内编辑保存的事件
  113. onExpandRow: options.onExpandRow, // 点击详细视图的事件
  114. rememberSelected: options.rememberSelected, // 启用翻页记住前面的选择
  115. fixedColumns: options.fixedColumns, // 是否启用冻结列(左侧)
  116. fixedNumber: options.fixedNumber, // 列冻结的个数(左侧)
  117. rightFixedColumns: options.rightFixedColumns, // 是否启用冻结列(右侧)
  118. rightFixedNumber: options.rightFixedNumber, // 列冻结的个数(右侧)
  119. onReorderRow: options.onReorderRow, // 当拖拽结束后处理函数
  120. queryParams: options.queryParams, // 传递参数(*)
  121. rowStyle: options.rowStyle, // 通过自定义函数设置行样式
  122. columns: options.columns, // 显示列信息(*)
  123. responseHandler: $.table.responseHandler, // 在加载服务器发送来的数据之前处理函数
  124. onLoadSuccess: $.table.onLoadSuccess, // 当所有数据被加载时触发处理函数
  125. exportOptions: options.exportOptions, // 前端导出忽略列索引
  126. detailFormatter: options.detailFormatter, // 在行下面展示其他数据列表
  127. });
  128. },
  129. // 获取实例ID,如存在多个返回#id1,#id2 delimeter分隔符
  130. getOptionsIds: function(separator) {
  131. var _separator = $.common.isEmpty(separator) ? "," : separator;
  132. var optionsIds = "";
  133. $.each(table.config, function(key, value){
  134. optionsIds += "#" + key + _separator;
  135. });
  136. return optionsIds.substring(0, optionsIds.length - 1);
  137. },
  138. // 查询条件
  139. queryParams: function(params) {
  140. var curParams = {
  141. // 传递参数查询参数
  142. pageSize: params.limit,
  143. pageNum: params.offset / params.limit + 1,
  144. searchValue: params.search,
  145. orderByColumn: params.sort,
  146. isAsc: params.order
  147. };
  148. var currentId = $.common.isEmpty(table.options.formId) ? $('form').attr('id') : table.options.formId;
  149. return $.extend(curParams, $.common.formToJSON(currentId));
  150. },
  151. // 请求获取数据后处理回调函数
  152. responseHandler: function(res) {
  153. if (typeof table.options.responseHandler == "function") {
  154. table.options.responseHandler(res);
  155. }
  156. if (res.code == 0) {
  157. if ($.common.isNotEmpty(table.options.sidePagination) && table.options.sidePagination == 'client') {
  158. return res.rows;
  159. } else {
  160. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  161. var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
  162. $.each(res.rows, function(i, row) {
  163. row.state = $.inArray(row[column], table.rememberSelectedIds[table.options.id]) !== -1;
  164. })
  165. }
  166. return { rows: res.rows, total: res.total };
  167. }
  168. } else {
  169. $.modal.alertWarning(res.msg);
  170. return { rows: [], total: 0 };
  171. }
  172. },
  173. // 初始化事件
  174. initEvent: function() {
  175. // 实例ID信息
  176. var optionsIds = $.table.getOptionsIds();
  177. // 监听事件处理
  178. $(optionsIds).on(TABLE_EVENTS, function () {
  179. table.set($(this).attr("id"));
  180. });
  181. // 选中、取消、全部选中、全部取消(事件)
  182. $(optionsIds).on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rows) {
  183. // 复选框分页保留保存选中数组
  184. var rowIds = $.table.affectedRowIds(rows);
  185. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  186. func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
  187. var selectedIds = table.rememberSelectedIds[table.options.id];
  188. if($.common.isNotEmpty(selectedIds)) {
  189. table.rememberSelectedIds[table.options.id] = _[func](selectedIds, rowIds);
  190. } else {
  191. table.rememberSelectedIds[table.options.id] = _[func]([], rowIds);
  192. }
  193. var selectedRows = table.rememberSelecteds[table.options.id];
  194. if($.common.isNotEmpty(selectedRows)) {
  195. table.rememberSelecteds[table.options.id] = _[func](selectedRows, rows);
  196. } else {
  197. table.rememberSelecteds[table.options.id] = _[func]([], rows);
  198. }
  199. }
  200. });
  201. // 加载成功、选中、取消、全部选中、全部取消(事件)
  202. $(optionsIds).on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () {
  203. var toolbar = table.options.toolbar;
  204. var uniqueId = table.options.uniqueId;
  205. // 工具栏按钮控制
  206. var rows = $.common.isEmpty(uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(uniqueId);
  207. // 非多个禁用
  208. $('#' + toolbar + ' .multiple').toggleClass('disabled', !rows.length);
  209. // 非单个禁用
  210. $('#' + toolbar + ' .single').toggleClass('disabled', rows.length!=1);
  211. });
  212. // 图片预览事件
  213. $(optionsIds).off("click").on("click", '.img-circle', function() {
  214. var src = $(this).attr('src');
  215. var target = $(this).data('target');
  216. var height = $(this).data('height');
  217. var width = $(this).data('width');
  218. if($.common.equals("self", target)) {
  219. layer.open({
  220. title: false,
  221. type: 1,
  222. closeBtn: true,
  223. shadeClose: true,
  224. area: ['auto', 'auto'],
  225. content: "<img src='" + src + "' height='" + height + "' width='" + width + "'/>"
  226. });
  227. } else if ($.common.equals("blank", target)) {
  228. window.open(src);
  229. }
  230. });
  231. // 单击tooltip事件
  232. $(optionsIds).on("click", '.tooltip-show', function() {
  233. var target = $(this).data('target');
  234. var input = $(this).prev();
  235. if ($.common.equals("copy", target)) {
  236. input.select();
  237. document.execCommand("copy");
  238. } else if ($.common.equals("open", target)) {
  239. parent.layer.alert(input.val(), {
  240. title: "信息内容",
  241. shadeClose: true,
  242. btn: ['确认'],
  243. btnclass: ['btn btn-primary'],
  244. });
  245. }
  246. });
  247. },
  248. // 当所有数据被加载时触发
  249. onLoadSuccess: function(data) {
  250. if (typeof table.options.onLoadSuccess == "function") {
  251. table.options.onLoadSuccess(data);
  252. }
  253. // 浮动提示框特效
  254. $("[data-toggle='tooltip']").tooltip();
  255. },
  256. // 表格销毁
  257. destroy: function (tableId) {
  258. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  259. $("#" + currentId).bootstrapTable('destroy');
  260. },
  261. // 序列号生成
  262. serialNumber: function (index, tableId) {
  263. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  264. var tableParams = $("#" + currentId).bootstrapTable('getOptions');
  265. var pageSize = tableParams.pageSize;
  266. var pageNumber = tableParams.pageNumber;
  267. return pageSize * (pageNumber - 1) + index + 1;
  268. },
  269. // 列超出指定长度浮动提示 target(copy单击复制文本 open弹窗打开文本)
  270. tooltip: function (value, length, target) {
  271. var _length = $.common.isEmpty(length) ? 20 : length;
  272. var _text = "";
  273. var _value = $.common.nullToStr(value);
  274. var _target = $.common.isEmpty(target) ? 'copy' : target;
  275. if (_value.length > _length) {
  276. _text = _value.substr(0, _length) + "...";
  277. _value = _value.replace(/\'/g,"&apos;");
  278. _value = _value.replace(/\"/g,"&quot;");
  279. var actions = [];
  280. actions.push($.common.sprintf('<input id="tooltip-show" style="opacity: 0;position: absolute;z-index:-1" type="text" value="%s"/>', _value));
  281. actions.push($.common.sprintf('<a href="###" class="tooltip-show" data-toggle="tooltip" data-target="%s" title="%s">%s</a>', _target, _value, _text));
  282. return actions.join('');
  283. } else {
  284. _text = _value;
  285. return _text;
  286. }
  287. },
  288. // 下拉按钮切换
  289. dropdownToggle: function (value) {
  290. var actions = [];
  291. actions.push('<div class="btn-group">');
  292. actions.push('<button type="button" class="btn btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false">');
  293. actions.push('<i class="fa fa-cog"></i>&nbsp;<span class="fa fa-chevron-down"></span></button>');
  294. actions.push('<ul class="dropdown-menu">');
  295. actions.push(value.replace(/<a/g,"<li><a").replace(/<\/a>/g,"</a></li>"));
  296. actions.push('</ul>');
  297. actions.push('</div>');
  298. return actions.join('');
  299. },
  300. // 图片预览
  301. imageView: function (value, height, width, target) {
  302. if ($.common.isEmpty(width)) {
  303. width = 'auto';
  304. }
  305. if ($.common.isEmpty(height)) {
  306. height = 'auto';
  307. }
  308. // blank or self
  309. var _target = $.common.isEmpty(target) ? 'self' : target;
  310. if ($.common.isNotEmpty(value)) {
  311. return $.common.sprintf("<img class='img-circle img-xs' data-height='%s' data-width='%s' data-target='%s' src='%s'/>", height, width, _target, value);
  312. } else {
  313. return $.common.nullToStr(value);
  314. }
  315. },
  316. // 搜索-默认第一个form
  317. search: function(formId, tableId, data) {
  318. table.set(tableId);
  319. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  320. var params = $.common.isEmpty(tableId) ? $("#" + table.options.id).bootstrapTable('getOptions') : $("#" + tableId).bootstrapTable('getOptions');
  321. params.queryParams = function(params) {
  322. var search = $.common.formToJSON(currentId);
  323. if($.common.isNotEmpty(data)){
  324. $.each(data, function(key) {
  325. search[key] = data[key];
  326. });
  327. }
  328. search.pageSize = params.limit;
  329. search.pageNum = params.offset / params.limit + 1;
  330. search.searchValue = params.search;
  331. search.orderByColumn = params.sort;
  332. search.isAsc = params.order;
  333. return search;
  334. }
  335. if($.common.isNotEmpty(tableId)){
  336. $("#" + tableId).bootstrapTable('refresh', params);
  337. } else{
  338. $("#" + table.options.id).bootstrapTable('refresh', params);
  339. }
  340. },
  341. // 导出数据
  342. exportExcel: function(formId) {
  343. table.set();
  344. $.modal.confirm("确定导出所有" + table.options.modalName + "吗?", function() {
  345. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  346. $.modal.loading("正在导出数据,请稍后...");
  347. $.post(table.options.exportUrl, $("#" + currentId).serializeArray(), function(result) {
  348. if (result.code == web_status.SUCCESS) {
  349. window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
  350. } else if (result.code == web_status.WARNING) {
  351. $.modal.alertWarning(result.msg)
  352. } else {
  353. $.modal.alertError(result.msg);
  354. }
  355. $.modal.closeLoading();
  356. });
  357. });
  358. },
  359. // 下载模板
  360. importTemplate: function() {
  361. table.set();
  362. $.get(table.options.importTemplateUrl, function(result) {
  363. if (result.code == web_status.SUCCESS) {
  364. window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
  365. } else if (result.code == web_status.WARNING) {
  366. $.modal.alertWarning(result.msg)
  367. } else {
  368. $.modal.alertError(result.msg);
  369. }
  370. });
  371. },
  372. // 导入数据
  373. importExcel: function(formId) {
  374. table.set();
  375. var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
  376. layer.open({
  377. type: 1,
  378. area: ['400px', '230px'],
  379. fix: false,
  380. //不固定
  381. maxmin: true,
  382. shade: 0.3,
  383. title: '导入' + table.options.modalName + '数据',
  384. content: $('#' + currentId).html(),
  385. btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
  386. // 弹层外区域关闭
  387. shadeClose: true,
  388. btn1: function(index, layero){
  389. var file = layero.find('#file').val();
  390. if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
  391. $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
  392. return false;
  393. }
  394. var index = layer.load(2, {shade: false});
  395. $.modal.disable();
  396. var formData = new FormData();
  397. formData.append("file", layero.find('#file')[0].files[0]);
  398. formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
  399. $.ajax({
  400. url: table.options.importUrl,
  401. data: formData,
  402. cache: false,
  403. contentType: false,
  404. processData: false,
  405. type: 'POST',
  406. success: function (result) {
  407. if (result.code == web_status.SUCCESS) {
  408. $.modal.closeAll();
  409. $.modal.alertSuccess(result.msg);
  410. $.table.refresh();
  411. } else if (result.code == web_status.WARNING) {
  412. layer.close(index);
  413. $.modal.enable();
  414. $.modal.alertWarning(result.msg)
  415. } else {
  416. layer.close(index);
  417. $.modal.enable();
  418. $.modal.alertError(result.msg);
  419. }
  420. }
  421. });
  422. }
  423. });
  424. },
  425. // 刷新表格
  426. refresh: function(tableId) {
  427. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  428. $("#" + currentId).bootstrapTable('refresh', {
  429. silent: true
  430. });
  431. },
  432. // 查询表格指定列值
  433. selectColumns: function(column) {
  434. var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
  435. return row[column];
  436. });
  437. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  438. var selectedRows = table.rememberSelecteds[table.options.id];
  439. if($.common.isNotEmpty(selectedRows)) {
  440. rows = $.map(table.rememberSelecteds[table.options.id], function (row) {
  441. return row[column];
  442. });
  443. }
  444. }
  445. return $.common.uniqueFn(rows);
  446. },
  447. // 获取当前页选中或者取消的行ID
  448. affectedRowIds: function(rows) {
  449. var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
  450. var rowIds;
  451. if ($.isArray(rows)) {
  452. rowIds = $.map(rows, function(row) {
  453. return row[column];
  454. });
  455. } else {
  456. rowIds = [rows[column]];
  457. }
  458. return rowIds;
  459. },
  460. // 查询表格首列值
  461. selectFirstColumns: function() {
  462. var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
  463. return row[table.options.columns[1].field];
  464. });
  465. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  466. var selectedRows = table.rememberSelecteds[table.options.id];
  467. if($.common.isNotEmpty(selectedRows)) {
  468. rows = $.map(selectedRows, function (row) {
  469. return row[table.options.columns[1].field];
  470. });
  471. }
  472. }
  473. return $.common.uniqueFn(rows);
  474. },
  475. // 回显数据字典
  476. selectDictLabel: function(datas, value) {
  477. var actions = [];
  478. $.each(datas, function(index, dict) {
  479. if (dict.dictValue == ('' + value)) {
  480. var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
  481. actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
  482. return false;
  483. }
  484. });
  485. return actions.join('');
  486. },
  487. // 显示表格指定列
  488. showColumn: function(column, tableId) {
  489. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  490. $("#" + currentId).bootstrapTable('showColumn', column);
  491. },
  492. // 隐藏表格指定列
  493. hideColumn: function(column, tableId) {
  494. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  495. $("#" + currentId).bootstrapTable('hideColumn', column);
  496. }
  497. },
  498. // 表格树封装处理
  499. treeTable: {
  500. // 初始化表格
  501. init: function(options) {
  502. var defaults = {
  503. id: "bootstrap-tree-table",
  504. type: 1, // 0 代表bootstrapTable 1代表bootstrapTreeTable
  505. height: 0,
  506. rootIdValue: null,
  507. ajaxParams: {},
  508. toolbar: "toolbar",
  509. striped: false,
  510. expandColumn: 1,
  511. showSearch: true,
  512. showRefresh: true,
  513. showColumns: true,
  514. expandAll: true,
  515. expandFirst: true
  516. };
  517. var options = $.extend(defaults, options);
  518. table.options = options;
  519. table.config[options.id] = options;
  520. $.bttTable = $('#' + options.id).bootstrapTreeTable({
  521. code: options.code, // 用于设置父子关系
  522. parentCode: options.parentCode, // 用于设置父子关系
  523. type: 'post', // 请求方式(*)
  524. url: options.url, // 请求后台的URL(*)
  525. data: options.data, // 无url时用于渲染的数据
  526. ajaxParams: options.ajaxParams, // 请求数据的ajax的data属性
  527. rootIdValue: options.rootIdValue, // 设置指定根节点id值
  528. height: options.height, // 表格树的高度
  529. expandColumn: options.expandColumn, // 在哪一列上面显示展开按钮
  530. striped: options.striped, // 是否显示行间隔色
  531. bordered: false, // 是否显示边框
  532. toolbar: '#' + options.toolbar, // 指定工作栏
  533. showSearch: options.showSearch, // 是否显示检索信息
  534. showRefresh: options.showRefresh, // 是否显示刷新按钮
  535. showColumns: options.showColumns, // 是否显示隐藏某列下拉框
  536. expandAll: options.expandAll, // 是否全部展开
  537. expandFirst: options.expandFirst, // 是否默认第一级展开--expandAll为false时生效
  538. columns: options.columns, // 显示列信息(*)
  539. responseHandler: $.treeTable.responseHandler // 当所有数据被加载时触发处理函数
  540. });
  541. },
  542. // 条件查询
  543. search: function(formId) {
  544. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  545. var params = $.common.formToJSON(currentId);
  546. $.bttTable.bootstrapTreeTable('refresh', params);
  547. },
  548. // 刷新
  549. refresh: function() {
  550. $.bttTable.bootstrapTreeTable('refresh');
  551. },
  552. // 查询表格树指定列值
  553. selectColumns: function(column) {
  554. var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) {
  555. return row[column];
  556. });
  557. return $.common.uniqueFn(rows);
  558. },
  559. // 请求获取数据后处理回调函数,校验异常状态提醒
  560. responseHandler: function(data) {
  561. if (data.code != undefined && data.code != 0) {
  562. $.modal.alertWarning(data.msg);
  563. return [];
  564. } else {
  565. return data;
  566. }
  567. },
  568. },
  569. // 表单封装处理
  570. form: {
  571. // 表单重置
  572. reset: function(formId, tableId) {
  573. table.set(tableId);
  574. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  575. $("#" + currentId)[0].reset();
  576. if (table.options.type == table_type.bootstrapTable) {
  577. if($.common.isEmpty(tableId)){
  578. $("#" + table.options.id).bootstrapTable('refresh');
  579. } else{
  580. $("#" + tableId).bootstrapTable('refresh');
  581. }
  582. }
  583. },
  584. // 获取选中复选框项
  585. selectCheckeds: function(name) {
  586. var checkeds = "";
  587. $('input:checkbox[name="' + name + '"]:checked').each(function(i) {
  588. if (0 == i) {
  589. checkeds = $(this).val();
  590. } else {
  591. checkeds += ("," + $(this).val());
  592. }
  593. });
  594. return checkeds;
  595. },
  596. // 获取选中下拉框项
  597. selectSelects: function(name) {
  598. var selects = "";
  599. $('#' + name + ' option:selected').each(function (i) {
  600. if (0 == i) {
  601. selects = $(this).val();
  602. } else {
  603. selects += ("," + $(this).val());
  604. }
  605. });
  606. return selects;
  607. }
  608. },
  609. // 弹出层封装处理
  610. modal: {
  611. // 显示图标
  612. icon: function(type) {
  613. var icon = "";
  614. if (type == modal_status.WARNING) {
  615. icon = 0;
  616. } else if (type == modal_status.SUCCESS) {
  617. icon = 1;
  618. } else if (type == modal_status.FAIL) {
  619. icon = 2;
  620. } else {
  621. icon = 3;
  622. }
  623. return icon;
  624. },
  625. // 消息提示
  626. msg: function(content, type) {
  627. if (type != undefined) {
  628. layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 });
  629. } else {
  630. layer.msg(content);
  631. }
  632. },
  633. // 错误消息
  634. msgError: function(content) {
  635. $.modal.msg(content, modal_status.FAIL);
  636. },
  637. // 成功消息
  638. msgSuccess: function(content) {
  639. $.modal.msg(content, modal_status.SUCCESS);
  640. },
  641. // 警告消息
  642. msgWarning: function(content) {
  643. $.modal.msg(content, modal_status.WARNING);
  644. },
  645. // 弹出提示
  646. alert: function(content, type) {
  647. layer.alert(content, {
  648. icon: $.modal.icon(type),
  649. title: "系统提示",
  650. btn: ['确认'],
  651. btnclass: ['btn btn-primary'],
  652. });
  653. },
  654. // 消息提示并刷新父窗体
  655. msgReload: function(msg, type) {
  656. layer.msg(msg, {
  657. icon: $.modal.icon(type),
  658. time: 500,
  659. shade: [0.1, '#8F8F8F']
  660. },
  661. function() {
  662. $.modal.reload();
  663. });
  664. },
  665. // 错误提示
  666. alertError: function(content) {
  667. $.modal.alert(content, modal_status.FAIL);
  668. },
  669. // 成功提示
  670. alertSuccess: function(content) {
  671. $.modal.alert(content, modal_status.SUCCESS);
  672. },
  673. // 警告提示
  674. alertWarning: function(content) {
  675. $.modal.alert(content, modal_status.WARNING);
  676. },
  677. // 关闭窗体
  678. close: function () {
  679. var index = parent.layer.getFrameIndex(window.name);
  680. parent.layer.close(index);
  681. },
  682. // 关闭全部窗体
  683. closeAll: function () {
  684. layer.closeAll();
  685. },
  686. // 确认窗体
  687. confirm: function (content, callBack) {
  688. layer.confirm(content, {
  689. icon: 3,
  690. title: "系统提示",
  691. btn: ['确认', '取消']
  692. }, function (index) {
  693. layer.close(index);
  694. callBack(true);
  695. });
  696. },
  697. // 弹出层指定宽度
  698. open: function (title, url, width, height, callback) {
  699. //如果是移动端,就使用自适应大小弹窗
  700. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  701. width = 'auto';
  702. height = 'auto';
  703. }
  704. if ($.common.isEmpty(title)) {
  705. title = false;
  706. }
  707. if ($.common.isEmpty(url)) {
  708. url = "/404.html";
  709. }
  710. if ($.common.isEmpty(width)) {
  711. width = 800;
  712. }
  713. if ($.common.isEmpty(height)) {
  714. height = ($(window).height() - 50);
  715. }
  716. if ($.common.isEmpty(callback)) {
  717. callback = function(index, layero) {
  718. var iframeWin = layero.find('iframe')[0];
  719. iframeWin.contentWindow.submitHandler(index, layero);
  720. }
  721. }
  722. layer.open({
  723. type: 2,
  724. area: [width + 'px', height + 'px'],
  725. fix: false,
  726. //不固定
  727. maxmin: true,
  728. shade: 0.3,
  729. title: title,
  730. content: url,
  731. btn: ['确定', '关闭'],
  732. // 弹层外区域关闭
  733. shadeClose: true,
  734. yes: callback,
  735. cancel: function(index) {
  736. return true;
  737. }
  738. });
  739. },
  740. // 弹出层指定参数选项
  741. openOptions: function (options) {
  742. var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
  743. var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
  744. var _width = $.common.isEmpty(options.width) ? "800" : options.width;
  745. var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
  746. var _btn = ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'];
  747. if ($.common.isEmpty(options.yes)) {
  748. options.yes = function(index, layero) {
  749. options.callBack(index, layero);
  750. }
  751. }
  752. layer.open({
  753. type: 2,
  754. maxmin: true,
  755. shade: 0.3,
  756. title: _title,
  757. fix: false,
  758. area: [_width + 'px', _height + 'px'],
  759. content: _url,
  760. shadeClose: $.common.isEmpty(options.shadeClose) ? true : options.shadeClose,
  761. skin: options.skin,
  762. btn: $.common.isEmpty(options.btn) ? _btn : options.btn,
  763. yes: options.yes,
  764. cancel: function () {
  765. return true;
  766. }
  767. });
  768. },
  769. // 弹出层全屏
  770. openFull: function (title, url, width, height) {
  771. //如果是移动端,就使用自适应大小弹窗
  772. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  773. width = 'auto';
  774. height = 'auto';
  775. }
  776. if ($.common.isEmpty(title)) {
  777. title = false;
  778. }
  779. if ($.common.isEmpty(url)) {
  780. url = "/404.html";
  781. }
  782. if ($.common.isEmpty(width)) {
  783. width = 800;
  784. }
  785. if ($.common.isEmpty(height)) {
  786. height = ($(window).height() - 50);
  787. }
  788. var index = layer.open({
  789. type: 2,
  790. area: [width + 'px', height + 'px'],
  791. fix: false,
  792. //不固定
  793. maxmin: true,
  794. shade: 0.3,
  795. title: title,
  796. content: url,
  797. btn: ['确定', '关闭'],
  798. // 弹层外区域关闭
  799. shadeClose: true,
  800. yes: function(index, layero) {
  801. var iframeWin = layero.find('iframe')[0];
  802. iframeWin.contentWindow.submitHandler(index, layero);
  803. },
  804. cancel: function(index) {
  805. return true;
  806. }
  807. });
  808. layer.full(index);
  809. },
  810. // 选卡页方式打开
  811. openTab: function (title, url) {
  812. createMenuItem(url, title);
  813. },
  814. // 选卡页同一页签打开
  815. parentTab: function (title, url) {
  816. var dataId = window.frameElement.getAttribute('data-id');
  817. createMenuItem(url, title);
  818. closeItem(dataId);
  819. },
  820. // 关闭选项卡
  821. closeTab: function (dataId) {
  822. closeItem(dataId);
  823. },
  824. // 禁用按钮
  825. disable: function() {
  826. var doc = window.top == window.parent ? window.document : window.parent.document;
  827. $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
  828. },
  829. // 启用按钮
  830. enable: function() {
  831. var doc = window.top == window.parent ? window.document : window.parent.document;
  832. $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
  833. },
  834. // 打开遮罩层
  835. loading: function (message) {
  836. $.blockUI({ message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>' });
  837. },
  838. // 关闭遮罩层
  839. closeLoading: function () {
  840. setTimeout(function(){
  841. $.unblockUI();
  842. }, 50);
  843. },
  844. // 重新加载
  845. reload: function () {
  846. parent.location.reload();
  847. }
  848. },
  849. // 操作封装处理
  850. operate: {
  851. // 提交数据
  852. submit: function(url, type, dataType, data, callback) {
  853. var config = {
  854. url: url,
  855. type: type,
  856. dataType: dataType,
  857. data: data,
  858. beforeSend: function () {
  859. $.modal.loading("正在处理中,请稍后...");
  860. },
  861. success: function(result) {
  862. if (typeof callback == "function") {
  863. callback(result);
  864. }
  865. $.operate.ajaxSuccess(result);
  866. }
  867. };
  868. $.ajax(config)
  869. },
  870. // post请求传输
  871. post: function(url, data, callback) {
  872. $.operate.submit(url, "post", "json", data, callback);
  873. },
  874. // get请求传输
  875. get: function(url, callback) {
  876. $.operate.submit(url, "get", "json", "", callback);
  877. },
  878. // 详细信息
  879. detail: function(id, width, height) {
  880. table.set();
  881. var _url = $.operate.detailUrl(id);
  882. var _width = $.common.isEmpty(width) ? "800" : width;
  883. var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
  884. //如果是移动端,就使用自适应大小弹窗
  885. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  886. _width = 'auto';
  887. _height = 'auto';
  888. }
  889. var options = {
  890. title: table.options.modalName + "详细",
  891. width: _width,
  892. height: _height,
  893. url: _url,
  894. skin: 'layui-layer-gray',
  895. btn: ['关闭'],
  896. yes: function (index, layero) {
  897. layer.close(index);
  898. }
  899. };
  900. $.modal.openOptions(options);
  901. },
  902. // 详细访问地址
  903. detailUrl: function(id) {
  904. var url = "/404.html";
  905. if ($.common.isNotEmpty(id)) {
  906. url = table.options.detailUrl.replace("{id}", id);
  907. } else {
  908. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  909. if (id.length == 0) {
  910. $.modal.alertWarning("请至少选择一条记录");
  911. return;
  912. }
  913. url = table.options.detailUrl.replace("{id}", id);
  914. }
  915. return url;
  916. },
  917. // 删除信息
  918. remove: function(id) {
  919. table.set();
  920. $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗?", function() {
  921. var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
  922. if(table.options.type == table_type.bootstrapTreeTable) {
  923. $.operate.get(url);
  924. } else {
  925. var data = { "ids": id };
  926. $.operate.submit(url, "post", "json", data);
  927. }
  928. });
  929. },
  930. // 批量删除信息
  931. removeAll: function() {
  932. table.set();
  933. var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  934. if (rows.length == 0) {
  935. $.modal.alertWarning("请至少选择一条记录");
  936. return;
  937. }
  938. $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
  939. var url = table.options.removeUrl;
  940. var data = { "ids": rows.join() };
  941. $.operate.submit(url, "post", "json", data);
  942. });
  943. },
  944. // 清空信息
  945. clean: function() {
  946. table.set();
  947. $.modal.confirm("确定清空所有" + table.options.modalName + "吗?", function() {
  948. var url = table.options.cleanUrl;
  949. $.operate.submit(url, "post", "json", "");
  950. });
  951. },
  952. // 添加信息
  953. add: function(id) {
  954. table.set();
  955. $.modal.open("添加" + table.options.modalName, $.operate.addUrl(id));
  956. },
  957. // 添加信息,以tab页展现
  958. addTab: function (id) {
  959. table.set();
  960. $.modal.openTab("添加" + table.options.modalName, $.operate.addUrl(id));
  961. },
  962. // 添加信息 全屏
  963. addFull: function(id) {
  964. table.set();
  965. var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id);
  966. $.modal.openFull("添加" + table.options.modalName, url);
  967. },
  968. // 添加访问地址
  969. addUrl: function(id) {
  970. var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id);
  971. return url;
  972. },
  973. // 修改信息
  974. edit: function(id) {
  975. table.set();
  976. if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
  977. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  978. if ($.common.isEmpty(row)) {
  979. $.modal.alertWarning("请至少选择一条记录");
  980. return;
  981. }
  982. var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
  983. $.modal.open("修改" + table.options.modalName, url);
  984. } else {
  985. $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id));
  986. }
  987. },
  988. // 修改信息,以tab页展现
  989. editTab: function(id) {
  990. table.set();
  991. $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id));
  992. },
  993. // 修改信息 全屏
  994. editFull: function(id) {
  995. table.set();
  996. var url = "/404.html";
  997. if ($.common.isNotEmpty(id)) {
  998. url = table.options.updateUrl.replace("{id}", id);
  999. } else {
  1000. var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1001. url = table.options.updateUrl.replace("{id}", row);
  1002. }
  1003. $.modal.openFull("修改" + table.options.modalName, url);
  1004. },
  1005. // 修改访问地址
  1006. editUrl: function(id) {
  1007. var url = "/404.html";
  1008. if ($.common.isNotEmpty(id)) {
  1009. url = table.options.updateUrl.replace("{id}", id);
  1010. } else {
  1011. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1012. if (id.length == 0) {
  1013. $.modal.alertWarning("请至少选择一条记录");
  1014. return;
  1015. }
  1016. url = table.options.updateUrl.replace("{id}", id);
  1017. }
  1018. return url;
  1019. },
  1020. // 保存信息 刷新表格
  1021. save: function(url, data, callback) {
  1022. var config = {
  1023. url: url,
  1024. type: "post",
  1025. dataType: "json",
  1026. data: data,
  1027. beforeSend: function () {
  1028. $.modal.loading("正在处理中,请稍后...");
  1029. $.modal.disable();
  1030. },
  1031. success: function(result) {
  1032. if (typeof callback == "function") {
  1033. callback(result);
  1034. }
  1035. $.operate.successCallback(result);
  1036. }
  1037. };
  1038. $.ajax(config)
  1039. },
  1040. // 保存信息 弹出提示框
  1041. saveModal: function(url, data, callback) {
  1042. var config = {
  1043. url: url,
  1044. type: "post",
  1045. dataType: "json",
  1046. data: data,
  1047. beforeSend: function () {
  1048. $.modal.loading("正在处理中,请稍后...");
  1049. },
  1050. success: function(result) {
  1051. if (typeof callback == "function") {
  1052. callback(result);
  1053. }
  1054. if (result.code == web_status.SUCCESS) {
  1055. $.modal.alertSuccess(result.msg)
  1056. } else if (result.code == web_status.WARNING) {
  1057. $.modal.alertWarning(result.msg)
  1058. } else {
  1059. $.modal.alertError(result.msg);
  1060. }
  1061. $.modal.closeLoading();
  1062. }
  1063. };
  1064. $.ajax(config)
  1065. },
  1066. // 保存选项卡信息
  1067. saveTab: function(url, data, callback) {
  1068. var config = {
  1069. url: url,
  1070. type: "post",
  1071. dataType: "json",
  1072. data: data,
  1073. beforeSend: function () {
  1074. $.modal.loading("正在处理中,请稍后...");
  1075. },
  1076. success: function(result) {
  1077. if (typeof callback == "function") {
  1078. callback(result);
  1079. }
  1080. $.operate.successTabCallback(result);
  1081. }
  1082. };
  1083. $.ajax(config)
  1084. },
  1085. // 保存结果弹出msg刷新table表格
  1086. ajaxSuccess: function (result) {
  1087. if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTable) {
  1088. $.modal.msgSuccess(result.msg);
  1089. $.table.refresh();
  1090. } else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) {
  1091. $.modal.msgSuccess(result.msg);
  1092. $.treeTable.refresh();
  1093. } else if (result.code == web_status.WARNING) {
  1094. $.modal.alertWarning(result.msg)
  1095. } else {
  1096. $.modal.alertError(result.msg);
  1097. }
  1098. $.modal.closeLoading();
  1099. },
  1100. // 成功结果提示msg(父窗体全局更新)
  1101. saveSuccess: function (result) {
  1102. if (result.code == web_status.SUCCESS) {
  1103. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  1104. } else if (result.code == web_status.WARNING) {
  1105. $.modal.alertWarning(result.msg)
  1106. } else {
  1107. $.modal.alertError(result.msg);
  1108. }
  1109. $.modal.closeLoading();
  1110. },
  1111. // 成功回调执行事件(父窗体静默更新)
  1112. successCallback: function(result) {
  1113. if (result.code == web_status.SUCCESS) {
  1114. var parent = window.parent;
  1115. if (parent.table.options.type == table_type.bootstrapTable) {
  1116. $.modal.close();
  1117. parent.$.modal.msgSuccess(result.msg);
  1118. parent.$.table.refresh();
  1119. } else if (parent.table.options.type == table_type.bootstrapTreeTable) {
  1120. $.modal.close();
  1121. parent.$.modal.msgSuccess(result.msg);
  1122. parent.$.treeTable.refresh();
  1123. } else {
  1124. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  1125. }
  1126. } else if (result.code == web_status.WARNING) {
  1127. $.modal.alertWarning(result.msg)
  1128. } else {
  1129. $.modal.alertError(result.msg);
  1130. }
  1131. $.modal.closeLoading();
  1132. $.modal.enable();
  1133. },
  1134. // 选项卡成功回调执行事件(父窗体静默更新)
  1135. successTabCallback: function(result) {
  1136. if (result.code == web_status.SUCCESS) {
  1137. var topWindow = $(window.parent.document);
  1138. var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel');
  1139. var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow;
  1140. $.modal.close();
  1141. $contentWindow.$.modal.msgSuccess(result.msg);
  1142. $contentWindow.$(".layui-layer-padding").removeAttr("style");
  1143. if ($contentWindow.table.options.type == table_type.bootstrapTable) {
  1144. $contentWindow.$.table.refresh();
  1145. } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) {
  1146. $contentWindow.$.treeTable.refresh();
  1147. }
  1148. $.modal.closeTab();
  1149. } else if (result.code == web_status.WARNING) {
  1150. $.modal.alertWarning(result.msg)
  1151. } else {
  1152. $.modal.alertError(result.msg);
  1153. }
  1154. $.modal.closeLoading();
  1155. }
  1156. },
  1157. // 校验封装处理
  1158. validate: {
  1159. // 判断返回标识是否唯一 false 不存在 true 存在
  1160. unique: function (value) {
  1161. if (value == "0") {
  1162. return true;
  1163. }
  1164. return false;
  1165. },
  1166. // 表单验证
  1167. form: function (formId) {
  1168. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1169. return $("#" + currentId).validate().form();
  1170. },
  1171. // 重置表单验证(清除提示信息)
  1172. reset: function (formId) {
  1173. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1174. return $("#" + currentId).validate().resetForm();
  1175. }
  1176. },
  1177. // 树插件封装处理
  1178. tree: {
  1179. _option: {},
  1180. _lastValue: {},
  1181. // 初始化树结构
  1182. init: function(options) {
  1183. var defaults = {
  1184. id: "tree", // 属性ID
  1185. expandLevel: 0, // 展开等级节点
  1186. view: {
  1187. selectedMulti: false, // 设置是否允许同时选中多个节点
  1188. nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本
  1189. },
  1190. check: {
  1191. enable: false, // 置 zTree 的节点上是否显示 checkbox / radio
  1192. nocheckInherit: true, // 设置子节点是否自动继承
  1193. },
  1194. data: {
  1195. key: {
  1196. title: "title" // 节点数据保存节点提示信息的属性名称
  1197. },
  1198. simpleData: {
  1199. enable: true // true / false 分别表示 使用 / 不使用 简单数据模式
  1200. }
  1201. },
  1202. };
  1203. var options = $.extend(defaults, options);
  1204. $.tree._option = options;
  1205. // 树结构初始化加载
  1206. var setting = {
  1207. callback: {
  1208. onClick: options.onClick, // 用于捕获节点被点击的事件回调函数
  1209. onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
  1210. onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数
  1211. },
  1212. check: options.check,
  1213. view: options.view,
  1214. data: options.data
  1215. };
  1216. $.get(options.url, function(data) {
  1217. var treeId = $("#treeId").val();
  1218. tree = $.fn.zTree.init($("#" + options.id), setting, data);
  1219. $._tree = tree;
  1220. var nodes = tree.getNodesByParam("level", options.expandLevel - 1);
  1221. for (var i = 0; i < nodes.length; i++) {
  1222. tree.expandNode(nodes[i], true, false, false);
  1223. }
  1224. var node = tree.getNodesByParam("id", treeId, null)[0];
  1225. $.tree.selectByIdName(treeId, node);
  1226. });
  1227. },
  1228. // 搜索节点
  1229. searchNode: function() {
  1230. // 取得输入的关键字的值
  1231. var value = $.common.trim($("#keyword").val());
  1232. if ($.tree._lastValue == value) {
  1233. return;
  1234. }
  1235. // 保存最后一次搜索名称
  1236. $.tree._lastValue = value;
  1237. var nodes = $._tree.getNodes();
  1238. // 如果要查空字串,就退出不查了。
  1239. if (value == "") {
  1240. $.tree.showAllNode(nodes);
  1241. return;
  1242. }
  1243. $.tree.hideAllNode(nodes);
  1244. // 根据搜索值模糊匹配
  1245. $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
  1246. },
  1247. // 根据Id和Name选中指定节点
  1248. selectByIdName: function(treeId, node) {
  1249. if ($.common.isNotEmpty(treeId) && treeId == node.id) {
  1250. $._tree.selectNode(node, true);
  1251. }
  1252. },
  1253. // 显示所有节点
  1254. showAllNode: function(nodes) {
  1255. nodes = $._tree.transformToArray(nodes);
  1256. for (var i = nodes.length - 1; i >= 0; i--) {
  1257. if (nodes[i].getParentNode() != null) {
  1258. $._tree.expandNode(nodes[i], true, false, false, false);
  1259. } else {
  1260. $._tree.expandNode(nodes[i], true, true, false, false);
  1261. }
  1262. $._tree.showNode(nodes[i]);
  1263. $.tree.showAllNode(nodes[i].children);
  1264. }
  1265. },
  1266. // 隐藏所有节点
  1267. hideAllNode: function(nodes) {
  1268. var tree = $.fn.zTree.getZTreeObj("tree");
  1269. var nodes = $._tree.transformToArray(nodes);
  1270. for (var i = nodes.length - 1; i >= 0; i--) {
  1271. $._tree.hideNode(nodes[i]);
  1272. }
  1273. },
  1274. // 显示所有父节点
  1275. showParent: function(treeNode) {
  1276. var parentNode;
  1277. while ((parentNode = treeNode.getParentNode()) != null) {
  1278. $._tree.showNode(parentNode);
  1279. $._tree.expandNode(parentNode, true, false, false);
  1280. treeNode = parentNode;
  1281. }
  1282. },
  1283. // 显示所有孩子节点
  1284. showChildren: function(treeNode) {
  1285. if (treeNode.isParent) {
  1286. for (var idx in treeNode.children) {
  1287. var node = treeNode.children[idx];
  1288. $._tree.showNode(node);
  1289. $.tree.showChildren(node);
  1290. }
  1291. }
  1292. },
  1293. // 更新节点状态
  1294. updateNodes: function(nodeList) {
  1295. $._tree.showNodes(nodeList);
  1296. for (var i = 0, l = nodeList.length; i < l; i++) {
  1297. var treeNode = nodeList[i];
  1298. $.tree.showChildren(treeNode);
  1299. $.tree.showParent(treeNode)
  1300. }
  1301. },
  1302. // 获取当前被勾选集合
  1303. getCheckedNodes: function(column) {
  1304. var _column = $.common.isEmpty(column) ? "id" : column;
  1305. var nodes = $._tree.getCheckedNodes(true);
  1306. return $.map(nodes, function (row) {
  1307. return row[_column];
  1308. }).join();
  1309. },
  1310. // 不允许根父节点选择
  1311. notAllowParents: function(_tree) {
  1312. var nodes = _tree.getSelectedNodes();
  1313. if(nodes.length == 0){
  1314. $.modal.msgError("请选择节点后提交");
  1315. return false;
  1316. }
  1317. for (var i = 0; i < nodes.length; i++) {
  1318. if (nodes[i].level == 0) {
  1319. $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
  1320. return false;
  1321. }
  1322. if (nodes[i].isParent) {
  1323. $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
  1324. return false;
  1325. }
  1326. }
  1327. return true;
  1328. },
  1329. // 不允许最后层级节点选择
  1330. notAllowLastLevel: function(_tree) {
  1331. var nodes = _tree.getSelectedNodes();
  1332. for (var i = 0; i < nodes.length; i++) {
  1333. if (!nodes[i].isParent) {
  1334. $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")");
  1335. return false;
  1336. }
  1337. }
  1338. return true;
  1339. },
  1340. // 隐藏/显示搜索栏
  1341. toggleSearch: function() {
  1342. $('#search').slideToggle(200);
  1343. $('#btnShow').toggle();
  1344. $('#btnHide').toggle();
  1345. $('#keyword').focus();
  1346. },
  1347. // 折叠
  1348. collapse: function() {
  1349. $._tree.expandAll(false);
  1350. },
  1351. // 展开
  1352. expand: function() {
  1353. $._tree.expandAll(true);
  1354. }
  1355. },
  1356. // 通用方法封装处理
  1357. common: {
  1358. // 判断字符串是否为空
  1359. isEmpty: function (value) {
  1360. if (value == null || this.trim(value) == "") {
  1361. return true;
  1362. }
  1363. return false;
  1364. },
  1365. // 判断一个字符串是否为非空串
  1366. isNotEmpty: function (value) {
  1367. return !$.common.isEmpty(value);
  1368. },
  1369. // 空对象转字符串
  1370. nullToStr: function(value) {
  1371. if ($.common.isEmpty(value)) {
  1372. return "-";
  1373. }
  1374. return value;
  1375. },
  1376. // 是否显示数据 为空默认为显示
  1377. visible: function (value) {
  1378. if ($.common.isEmpty(value) || value == true) {
  1379. return true;
  1380. }
  1381. return false;
  1382. },
  1383. // 空格截取
  1384. trim: function (value) {
  1385. if (value == null) {
  1386. return "";
  1387. }
  1388. return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  1389. },
  1390. // 比较两个字符串(大小写敏感)
  1391. equals: function (str, that) {
  1392. return str == that;
  1393. },
  1394. // 比较两个字符串(大小写不敏感)
  1395. equalsIgnoreCase: function (str, that) {
  1396. return String(str).toUpperCase() === String(that).toUpperCase();
  1397. },
  1398. // 将字符串按指定字符分割
  1399. split: function (str, sep, maxLen) {
  1400. if ($.common.isEmpty(str)) {
  1401. return null;
  1402. }
  1403. var value = String(str).split(sep);
  1404. return maxLen ? value.slice(0, maxLen - 1) : value;
  1405. },
  1406. // 字符串格式化(%s )
  1407. sprintf: function (str) {
  1408. var args = arguments, flag = true, i = 1;
  1409. str = str.replace(/%s/g, function () {
  1410. var arg = args[i++];
  1411. if (typeof arg === 'undefined') {
  1412. flag = false;
  1413. return '';
  1414. }
  1415. return arg;
  1416. });
  1417. return flag ? str : '';
  1418. },
  1419. // 指定随机数返回
  1420. random: function (min, max) {
  1421. return Math.floor((Math.random() * max) + min);
  1422. },
  1423. // 判断字符串是否是以start开头
  1424. startWith: function(value, start) {
  1425. var reg = new RegExp("^" + start);
  1426. return reg.test(value)
  1427. },
  1428. // 判断字符串是否是以end结尾
  1429. endWith: function(value, end) {
  1430. var reg = new RegExp(end + "$");
  1431. return reg.test(value)
  1432. },
  1433. // 数组去重
  1434. uniqueFn: function(array) {
  1435. var result = [];
  1436. var hashObj = {};
  1437. for (var i = 0; i < array.length; i++) {
  1438. if (!hashObj[array[i]]) {
  1439. hashObj[array[i]] = true;
  1440. result.push(array[i]);
  1441. }
  1442. }
  1443. return result;
  1444. },
  1445. // 数组中的所有元素放入一个字符串
  1446. join: function(array, separator) {
  1447. if ($.common.isEmpty(array)) {
  1448. return null;
  1449. }
  1450. return array.join(separator);
  1451. },
  1452. // 获取form下所有的字段并转换为json对象
  1453. formToJSON: function(formId) {
  1454. var json = {};
  1455. $.each($("#" + formId).serializeArray(), function(i, field) {
  1456. if(json[field.name]) {
  1457. json[field.name] += ("," + field.value);
  1458. } else {
  1459. json[field.name] = field.value;
  1460. }
  1461. });
  1462. return json;
  1463. },
  1464. // 获取obj对象长度
  1465. getLength: function(obj) {
  1466. var count = 0;  
  1467. for (var i in obj) {
  1468. if (obj.hasOwnProperty(i)) {
  1469. count++;
  1470. }  
  1471. }
  1472. return count;
  1473. }
  1474. }
  1475. });
  1476. })(jQuery);
  1477. /** 表格类型 */
  1478. table_type = {
  1479. bootstrapTable: 0,
  1480. bootstrapTreeTable: 1
  1481. };
  1482. /** 消息状态码 */
  1483. web_status = {
  1484. SUCCESS: 0,
  1485. FAIL: 500,
  1486. WARNING: 301
  1487. };
  1488. /** 弹窗状态码 */
  1489. modal_status = {
  1490. SUCCESS: "success",
  1491. FAIL: "error",
  1492. WARNING: "warning"
  1493. };