ry-ui.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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. data = {};
  341. },
  342. // 导出数据
  343. exportExcel: function(formId) {
  344. table.set();
  345. $.modal.confirm("确定导出所有" + table.options.modalName + "吗?", function() {
  346. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  347. var params = $("#" + table.options.id).bootstrapTable('getOptions');
  348. var dataParam = $("#" + currentId).serializeArray();
  349. dataParam.push({ "name": "orderByColumn", "value": params.sortName });
  350. dataParam.push({ "name": "isAsc", "value": params.sortOrder });
  351. $.modal.loading("正在导出数据,请稍后...");
  352. $.post(table.options.exportUrl, dataParam, function(result) {
  353. if (result.code == web_status.SUCCESS) {
  354. window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
  355. } else if (result.code == web_status.WARNING) {
  356. $.modal.alertWarning(result.msg)
  357. } else {
  358. $.modal.alertError(result.msg);
  359. }
  360. $.modal.closeLoading();
  361. });
  362. });
  363. },
  364. // 下载模板
  365. importTemplate: function() {
  366. table.set();
  367. $.get(table.options.importTemplateUrl, function(result) {
  368. if (result.code == web_status.SUCCESS) {
  369. window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
  370. } else if (result.code == web_status.WARNING) {
  371. $.modal.alertWarning(result.msg)
  372. } else {
  373. $.modal.alertError(result.msg);
  374. }
  375. });
  376. },
  377. // 导入数据
  378. importExcel: function(formId) {
  379. table.set();
  380. var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
  381. layer.open({
  382. type: 1,
  383. area: ['400px', '230px'],
  384. fix: false,
  385. //不固定
  386. maxmin: true,
  387. shade: 0.3,
  388. title: '导入' + table.options.modalName + '数据',
  389. content: $('#' + currentId).html(),
  390. btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
  391. // 弹层外区域关闭
  392. shadeClose: true,
  393. btn1: function(index, layero){
  394. var file = layero.find('#file').val();
  395. if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){
  396. $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。");
  397. return false;
  398. }
  399. var index = layer.load(2, {shade: false});
  400. $.modal.disable();
  401. var formData = new FormData(layero.find('form')[0]);
  402. $.ajax({
  403. url: table.options.importUrl,
  404. data: formData,
  405. cache: false,
  406. contentType: false,
  407. processData: false,
  408. type: 'POST',
  409. success: function (result) {
  410. if (result.code == web_status.SUCCESS) {
  411. $.modal.closeAll();
  412. $.modal.alertSuccess(result.msg);
  413. $.table.refresh();
  414. } else if (result.code == web_status.WARNING) {
  415. layer.close(index);
  416. $.modal.enable();
  417. $.modal.alertWarning(result.msg)
  418. } else {
  419. layer.close(index);
  420. $.modal.enable();
  421. $.modal.alertError(result.msg);
  422. }
  423. }
  424. });
  425. }
  426. });
  427. },
  428. // 刷新表格
  429. refresh: function(tableId) {
  430. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  431. $("#" + currentId).bootstrapTable('refresh', {
  432. silent: true
  433. });
  434. },
  435. // 查询表格指定列值
  436. selectColumns: function(column) {
  437. var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
  438. return row[column];
  439. });
  440. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  441. var selectedRows = table.rememberSelecteds[table.options.id];
  442. if($.common.isNotEmpty(selectedRows)) {
  443. rows = $.map(table.rememberSelecteds[table.options.id], function (row) {
  444. return row[column];
  445. });
  446. }
  447. }
  448. return $.common.uniqueFn(rows);
  449. },
  450. // 获取当前页选中或者取消的行ID
  451. affectedRowIds: function(rows) {
  452. var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId;
  453. var rowIds;
  454. if ($.isArray(rows)) {
  455. rowIds = $.map(rows, function(row) {
  456. return row[column];
  457. });
  458. } else {
  459. rowIds = [rows[column]];
  460. }
  461. return rowIds;
  462. },
  463. // 查询表格首列值
  464. selectFirstColumns: function() {
  465. var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) {
  466. return row[table.options.columns[1].field];
  467. });
  468. if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) {
  469. var selectedRows = table.rememberSelecteds[table.options.id];
  470. if($.common.isNotEmpty(selectedRows)) {
  471. rows = $.map(selectedRows, function (row) {
  472. return row[table.options.columns[1].field];
  473. });
  474. }
  475. }
  476. return $.common.uniqueFn(rows);
  477. },
  478. // 回显数据字典
  479. selectDictLabel: function(datas, value) {
  480. var actions = [];
  481. $.each(datas, function(index, dict) {
  482. if (dict.dictValue == ('' + value)) {
  483. var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
  484. actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
  485. return false;
  486. }
  487. });
  488. return actions.join('');
  489. },
  490. // 显示表格指定列
  491. showColumn: function(column, tableId) {
  492. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  493. $("#" + currentId).bootstrapTable('showColumn', column);
  494. },
  495. // 隐藏表格指定列
  496. hideColumn: function(column, tableId) {
  497. var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
  498. $("#" + currentId).bootstrapTable('hideColumn', column);
  499. }
  500. },
  501. // 表格树封装处理
  502. treeTable: {
  503. // 初始化表格
  504. init: function(options) {
  505. var defaults = {
  506. id: "bootstrap-tree-table",
  507. type: 1, // 0 代表bootstrapTable 1代表bootstrapTreeTable
  508. height: 0,
  509. rootIdValue: null,
  510. ajaxParams: {},
  511. toolbar: "toolbar",
  512. striped: false,
  513. expandColumn: 1,
  514. showSearch: true,
  515. showRefresh: true,
  516. showColumns: true,
  517. expandAll: true,
  518. expandFirst: true
  519. };
  520. var options = $.extend(defaults, options);
  521. table.options = options;
  522. table.config[options.id] = options;
  523. $.bttTable = $('#' + options.id).bootstrapTreeTable({
  524. code: options.code, // 用于设置父子关系
  525. parentCode: options.parentCode, // 用于设置父子关系
  526. type: 'post', // 请求方式(*)
  527. url: options.url, // 请求后台的URL(*)
  528. data: options.data, // 无url时用于渲染的数据
  529. ajaxParams: options.ajaxParams, // 请求数据的ajax的data属性
  530. rootIdValue: options.rootIdValue, // 设置指定根节点id值
  531. height: options.height, // 表格树的高度
  532. expandColumn: options.expandColumn, // 在哪一列上面显示展开按钮
  533. striped: options.striped, // 是否显示行间隔色
  534. bordered: false, // 是否显示边框
  535. toolbar: '#' + options.toolbar, // 指定工作栏
  536. showSearch: options.showSearch, // 是否显示检索信息
  537. showRefresh: options.showRefresh, // 是否显示刷新按钮
  538. showColumns: options.showColumns, // 是否显示隐藏某列下拉框
  539. expandAll: options.expandAll, // 是否全部展开
  540. expandFirst: options.expandFirst, // 是否默认第一级展开--expandAll为false时生效
  541. columns: options.columns, // 显示列信息(*)
  542. responseHandler: $.treeTable.responseHandler // 当所有数据被加载时触发处理函数
  543. });
  544. },
  545. // 条件查询
  546. search: function(formId) {
  547. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  548. var params = $.common.formToJSON(currentId);
  549. $.bttTable.bootstrapTreeTable('refresh', params);
  550. },
  551. // 刷新
  552. refresh: function() {
  553. $.bttTable.bootstrapTreeTable('refresh');
  554. },
  555. // 查询表格树指定列值
  556. selectColumns: function(column) {
  557. var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) {
  558. return row[column];
  559. });
  560. return $.common.uniqueFn(rows);
  561. },
  562. // 请求获取数据后处理回调函数,校验异常状态提醒
  563. responseHandler: function(res) {
  564. if (typeof table.options.responseHandler == "function") {
  565. table.options.responseHandler(res);
  566. }
  567. if (res.code != undefined && res.code != 0) {
  568. $.modal.alertWarning(res.msg);
  569. return [];
  570. } else {
  571. return res;
  572. }
  573. },
  574. },
  575. // 表单封装处理
  576. form: {
  577. // 表单重置
  578. reset: function(formId, tableId) {
  579. table.set(tableId);
  580. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  581. $("#" + currentId)[0].reset();
  582. if (table.options.type == table_type.bootstrapTable) {
  583. if($.common.isEmpty(tableId)){
  584. $("#" + table.options.id).bootstrapTable('refresh');
  585. } else{
  586. $("#" + tableId).bootstrapTable('refresh');
  587. }
  588. } else if (table.options.type == table_type.bootstrapTreeTable) {
  589. if($.common.isEmpty(tableId)){
  590. $("#" + table.options.id).bootstrapTreeTable('refresh', []);
  591. } else{
  592. $("#" + tableId).bootstrapTreeTable('refresh', []);
  593. }
  594. }
  595. },
  596. // 获取选中复选框项
  597. selectCheckeds: function(name) {
  598. var checkeds = "";
  599. $('input:checkbox[name="' + name + '"]:checked').each(function(i) {
  600. if (0 == i) {
  601. checkeds = $(this).val();
  602. } else {
  603. checkeds += ("," + $(this).val());
  604. }
  605. });
  606. return checkeds;
  607. },
  608. // 获取选中下拉框项
  609. selectSelects: function(name) {
  610. var selects = "";
  611. $('#' + name + ' option:selected').each(function (i) {
  612. if (0 == i) {
  613. selects = $(this).val();
  614. } else {
  615. selects += ("," + $(this).val());
  616. }
  617. });
  618. return selects;
  619. }
  620. },
  621. // 弹出层封装处理
  622. modal: {
  623. // 显示图标
  624. icon: function(type) {
  625. var icon = "";
  626. if (type == modal_status.WARNING) {
  627. icon = 0;
  628. } else if (type == modal_status.SUCCESS) {
  629. icon = 1;
  630. } else if (type == modal_status.FAIL) {
  631. icon = 2;
  632. } else {
  633. icon = 3;
  634. }
  635. return icon;
  636. },
  637. // 消息提示
  638. msg: function(content, type) {
  639. if (type != undefined) {
  640. layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 });
  641. } else {
  642. layer.msg(content);
  643. }
  644. },
  645. // 错误消息
  646. msgError: function(content) {
  647. $.modal.msg(content, modal_status.FAIL);
  648. },
  649. // 成功消息
  650. msgSuccess: function(content) {
  651. $.modal.msg(content, modal_status.SUCCESS);
  652. },
  653. // 警告消息
  654. msgWarning: function(content) {
  655. $.modal.msg(content, modal_status.WARNING);
  656. },
  657. // 弹出提示
  658. alert: function(content, type) {
  659. layer.alert(content, {
  660. icon: $.modal.icon(type),
  661. title: "系统提示",
  662. btn: ['确认'],
  663. btnclass: ['btn btn-primary'],
  664. });
  665. },
  666. // 消息提示并刷新父窗体
  667. msgReload: function(msg, type) {
  668. layer.msg(msg, {
  669. icon: $.modal.icon(type),
  670. time: 500,
  671. shade: [0.1, '#8F8F8F']
  672. },
  673. function() {
  674. $.modal.reload();
  675. });
  676. },
  677. // 错误提示
  678. alertError: function(content) {
  679. $.modal.alert(content, modal_status.FAIL);
  680. },
  681. // 成功提示
  682. alertSuccess: function(content) {
  683. $.modal.alert(content, modal_status.SUCCESS);
  684. },
  685. // 警告提示
  686. alertWarning: function(content) {
  687. $.modal.alert(content, modal_status.WARNING);
  688. },
  689. // 关闭窗体
  690. close: function () {
  691. var index = parent.layer.getFrameIndex(window.name);
  692. parent.layer.close(index);
  693. },
  694. // 关闭全部窗体
  695. closeAll: function () {
  696. layer.closeAll();
  697. },
  698. // 确认窗体
  699. confirm: function (content, callBack) {
  700. layer.confirm(content, {
  701. icon: 3,
  702. title: "系统提示",
  703. btn: ['确认', '取消']
  704. }, function (index) {
  705. layer.close(index);
  706. callBack(true);
  707. });
  708. },
  709. // 弹出层指定宽度
  710. open: function (title, url, width, height, callback) {
  711. //如果是移动端,就使用自适应大小弹窗
  712. if ($.common.isMobile()) {
  713. width = 'auto';
  714. height = 'auto';
  715. }
  716. if ($.common.isEmpty(title)) {
  717. title = false;
  718. }
  719. if ($.common.isEmpty(url)) {
  720. url = "/404.html";
  721. }
  722. if ($.common.isEmpty(width)) {
  723. width = 800;
  724. }
  725. if ($.common.isEmpty(height)) {
  726. height = ($(window).height() - 50);
  727. }
  728. if ($.common.isEmpty(callback)) {
  729. callback = function(index, layero) {
  730. var iframeWin = layero.find('iframe')[0];
  731. iframeWin.contentWindow.submitHandler(index, layero);
  732. }
  733. }
  734. layer.open({
  735. type: 2,
  736. area: [width + 'px', height + 'px'],
  737. fix: false,
  738. //不固定
  739. maxmin: true,
  740. shade: 0.3,
  741. title: title,
  742. content: url,
  743. btn: ['确定', '关闭'],
  744. // 弹层外区域关闭
  745. shadeClose: true,
  746. yes: callback,
  747. cancel: function(index) {
  748. return true;
  749. }
  750. });
  751. },
  752. // 弹出层指定参数选项
  753. openOptions: function (options) {
  754. var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
  755. var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
  756. var _width = $.common.isEmpty(options.width) ? "800" : options.width;
  757. var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
  758. var _btn = ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'];
  759. if ($.common.isEmpty(options.yes)) {
  760. options.yes = function(index, layero) {
  761. options.callBack(index, layero);
  762. }
  763. }
  764. layer.open({
  765. type: 2,
  766. maxmin: true,
  767. shade: 0.3,
  768. title: _title,
  769. fix: false,
  770. area: [_width + 'px', _height + 'px'],
  771. content: _url,
  772. shadeClose: $.common.isEmpty(options.shadeClose) ? true : options.shadeClose,
  773. skin: options.skin,
  774. btn: $.common.isEmpty(options.btn) ? _btn : options.btn,
  775. yes: options.yes,
  776. cancel: function () {
  777. return true;
  778. }
  779. });
  780. },
  781. // 弹出层全屏
  782. openFull: function (title, url, width, height) {
  783. //如果是移动端,就使用自适应大小弹窗
  784. if ($.common.isMobile()) {
  785. width = 'auto';
  786. height = 'auto';
  787. }
  788. if ($.common.isEmpty(title)) {
  789. title = false;
  790. }
  791. if ($.common.isEmpty(url)) {
  792. url = "/404.html";
  793. }
  794. if ($.common.isEmpty(width)) {
  795. width = 800;
  796. }
  797. if ($.common.isEmpty(height)) {
  798. height = ($(window).height() - 50);
  799. }
  800. var index = layer.open({
  801. type: 2,
  802. area: [width + 'px', height + 'px'],
  803. fix: false,
  804. //不固定
  805. maxmin: true,
  806. shade: 0.3,
  807. title: title,
  808. content: url,
  809. btn: ['确定', '关闭'],
  810. // 弹层外区域关闭
  811. shadeClose: true,
  812. yes: function(index, layero) {
  813. var iframeWin = layero.find('iframe')[0];
  814. iframeWin.contentWindow.submitHandler(index, layero);
  815. },
  816. cancel: function(index) {
  817. return true;
  818. }
  819. });
  820. layer.full(index);
  821. },
  822. // 选卡页方式打开
  823. openTab: function (title, url) {
  824. createMenuItem(url, title);
  825. },
  826. // 选卡页同一页签打开
  827. parentTab: function (title, url) {
  828. var dataId = window.frameElement.getAttribute('data-id');
  829. createMenuItem(url, title);
  830. closeItem(dataId);
  831. },
  832. // 关闭选项卡
  833. closeTab: function (dataId) {
  834. closeItem(dataId);
  835. },
  836. // 禁用按钮
  837. disable: function() {
  838. var doc = window.top == window.parent ? window.document : window.parent.document;
  839. $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
  840. },
  841. // 启用按钮
  842. enable: function() {
  843. var doc = window.top == window.parent ? window.document : window.parent.document;
  844. $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
  845. },
  846. // 打开遮罩层
  847. loading: function (message) {
  848. $.blockUI({ message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>' });
  849. },
  850. // 关闭遮罩层
  851. closeLoading: function () {
  852. setTimeout(function(){
  853. $.unblockUI();
  854. }, 50);
  855. },
  856. // 重新加载
  857. reload: function () {
  858. parent.location.reload();
  859. }
  860. },
  861. // 操作封装处理
  862. operate: {
  863. // 提交数据
  864. submit: function(url, type, dataType, data, callback) {
  865. var config = {
  866. url: url,
  867. type: type,
  868. dataType: dataType,
  869. data: data,
  870. beforeSend: function () {
  871. $.modal.loading("正在处理中,请稍后...");
  872. },
  873. success: function(result) {
  874. if (typeof callback == "function") {
  875. callback(result);
  876. }
  877. $.operate.ajaxSuccess(result);
  878. }
  879. };
  880. $.ajax(config)
  881. },
  882. // post请求传输
  883. post: function(url, data, callback) {
  884. $.operate.submit(url, "post", "json", data, callback);
  885. },
  886. // get请求传输
  887. get: function(url, callback) {
  888. $.operate.submit(url, "get", "json", "", callback);
  889. },
  890. // 详细信息
  891. detail: function(id, width, height) {
  892. table.set();
  893. var _url = $.operate.detailUrl(id);
  894. var _width = $.common.isEmpty(width) ? "800" : width;
  895. var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
  896. //如果是移动端,就使用自适应大小弹窗
  897. if ($.common.isMobile()) {
  898. _width = 'auto';
  899. _height = 'auto';
  900. }
  901. var options = {
  902. title: table.options.modalName + "详细",
  903. width: _width,
  904. height: _height,
  905. url: _url,
  906. skin: 'layui-layer-gray',
  907. btn: ['关闭'],
  908. yes: function (index, layero) {
  909. layer.close(index);
  910. }
  911. };
  912. $.modal.openOptions(options);
  913. },
  914. // 详细访问地址
  915. detailUrl: function(id) {
  916. var url = "/404.html";
  917. if ($.common.isNotEmpty(id)) {
  918. url = table.options.detailUrl.replace("{id}", id);
  919. } else {
  920. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  921. if (id.length == 0) {
  922. $.modal.alertWarning("请至少选择一条记录");
  923. return;
  924. }
  925. url = table.options.detailUrl.replace("{id}", id);
  926. }
  927. return url;
  928. },
  929. // 删除信息
  930. remove: function(id) {
  931. table.set();
  932. $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗?", function() {
  933. var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id);
  934. if(table.options.type == table_type.bootstrapTreeTable) {
  935. $.operate.get(url);
  936. } else {
  937. var data = { "ids": id };
  938. $.operate.submit(url, "post", "json", data);
  939. }
  940. });
  941. },
  942. // 批量删除信息
  943. removeAll: function() {
  944. table.set();
  945. var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  946. if (rows.length == 0) {
  947. $.modal.alertWarning("请至少选择一条记录");
  948. return;
  949. }
  950. $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
  951. var url = table.options.removeUrl;
  952. var data = { "ids": rows.join() };
  953. $.operate.submit(url, "post", "json", data);
  954. });
  955. },
  956. // 清空信息
  957. clean: function() {
  958. table.set();
  959. $.modal.confirm("确定清空所有" + table.options.modalName + "吗?", function() {
  960. var url = table.options.cleanUrl;
  961. $.operate.submit(url, "post", "json", "");
  962. });
  963. },
  964. // 添加信息
  965. add: function(id) {
  966. table.set();
  967. $.modal.open("添加" + table.options.modalName, $.operate.addUrl(id));
  968. },
  969. // 添加信息,以tab页展现
  970. addTab: function (id) {
  971. table.set();
  972. $.modal.openTab("添加" + table.options.modalName, $.operate.addUrl(id));
  973. },
  974. // 添加信息 全屏
  975. addFull: function(id) {
  976. table.set();
  977. var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id);
  978. $.modal.openFull("添加" + table.options.modalName, url);
  979. },
  980. // 添加访问地址
  981. addUrl: function(id) {
  982. var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id);
  983. return url;
  984. },
  985. // 修改信息
  986. edit: function(id) {
  987. table.set();
  988. if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
  989. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  990. if ($.common.isEmpty(row)) {
  991. $.modal.alertWarning("请至少选择一条记录");
  992. return;
  993. }
  994. var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
  995. $.modal.open("修改" + table.options.modalName, url);
  996. } else {
  997. $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id));
  998. }
  999. },
  1000. // 修改信息,以tab页展现
  1001. editTab: function(id) {
  1002. table.set();
  1003. $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id));
  1004. },
  1005. // 修改信息 全屏
  1006. editFull: function(id) {
  1007. table.set();
  1008. var url = "/404.html";
  1009. if ($.common.isNotEmpty(id)) {
  1010. url = table.options.updateUrl.replace("{id}", id);
  1011. } else {
  1012. var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1013. url = table.options.updateUrl.replace("{id}", row);
  1014. }
  1015. $.modal.openFull("修改" + table.options.modalName, url);
  1016. },
  1017. // 修改访问地址
  1018. editUrl: function(id) {
  1019. var url = "/404.html";
  1020. if ($.common.isNotEmpty(id)) {
  1021. url = table.options.updateUrl.replace("{id}", id);
  1022. } else {
  1023. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1024. if (id.length == 0) {
  1025. $.modal.alertWarning("请至少选择一条记录");
  1026. return;
  1027. }
  1028. url = table.options.updateUrl.replace("{id}", id);
  1029. }
  1030. return url;
  1031. },
  1032. // 保存信息 刷新表格
  1033. save: function(url, data, callback) {
  1034. var config = {
  1035. url: url,
  1036. type: "post",
  1037. dataType: "json",
  1038. data: data,
  1039. beforeSend: function () {
  1040. $.modal.loading("正在处理中,请稍后...");
  1041. $.modal.disable();
  1042. },
  1043. success: function(result) {
  1044. if (typeof callback == "function") {
  1045. callback(result);
  1046. }
  1047. $.operate.successCallback(result);
  1048. }
  1049. };
  1050. $.ajax(config)
  1051. },
  1052. // 保存信息 弹出提示框
  1053. saveModal: function(url, data, callback) {
  1054. var config = {
  1055. url: url,
  1056. type: "post",
  1057. dataType: "json",
  1058. data: data,
  1059. beforeSend: function () {
  1060. $.modal.loading("正在处理中,请稍后...");
  1061. },
  1062. success: function(result) {
  1063. if (typeof callback == "function") {
  1064. callback(result);
  1065. }
  1066. if (result.code == web_status.SUCCESS) {
  1067. $.modal.alertSuccess(result.msg)
  1068. } else if (result.code == web_status.WARNING) {
  1069. $.modal.alertWarning(result.msg)
  1070. } else {
  1071. $.modal.alertError(result.msg);
  1072. }
  1073. $.modal.closeLoading();
  1074. }
  1075. };
  1076. $.ajax(config)
  1077. },
  1078. // 保存选项卡信息
  1079. saveTab: function(url, data, callback) {
  1080. var config = {
  1081. url: url,
  1082. type: "post",
  1083. dataType: "json",
  1084. data: data,
  1085. beforeSend: function () {
  1086. $.modal.loading("正在处理中,请稍后...");
  1087. },
  1088. success: function(result) {
  1089. if (typeof callback == "function") {
  1090. callback(result);
  1091. }
  1092. $.operate.successTabCallback(result);
  1093. }
  1094. };
  1095. $.ajax(config)
  1096. },
  1097. // 保存结果弹出msg刷新table表格
  1098. ajaxSuccess: function (result) {
  1099. if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTable) {
  1100. $.modal.msgSuccess(result.msg);
  1101. $.table.refresh();
  1102. } else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) {
  1103. $.modal.msgSuccess(result.msg);
  1104. $.treeTable.refresh();
  1105. } else if (result.code == web_status.SUCCESS && table.option.type == undefined) {
  1106. $.modal.msgSuccess(result.msg)
  1107. } else if (result.code == web_status.WARNING) {
  1108. $.modal.alertWarning(result.msg)
  1109. } else {
  1110. $.modal.alertError(result.msg);
  1111. }
  1112. $.modal.closeLoading();
  1113. },
  1114. // 成功结果提示msg(父窗体全局更新)
  1115. saveSuccess: function (result) {
  1116. if (result.code == web_status.SUCCESS) {
  1117. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  1118. } else if (result.code == web_status.WARNING) {
  1119. $.modal.alertWarning(result.msg)
  1120. } else {
  1121. $.modal.alertError(result.msg);
  1122. }
  1123. $.modal.closeLoading();
  1124. },
  1125. // 成功回调执行事件(父窗体静默更新)
  1126. successCallback: function(result) {
  1127. if (result.code == web_status.SUCCESS) {
  1128. var parent = window.parent;
  1129. if (parent.table.options.type == table_type.bootstrapTable) {
  1130. $.modal.close();
  1131. parent.$.modal.msgSuccess(result.msg);
  1132. parent.$.table.refresh();
  1133. } else if (parent.table.options.type == table_type.bootstrapTreeTable) {
  1134. $.modal.close();
  1135. parent.$.modal.msgSuccess(result.msg);
  1136. parent.$.treeTable.refresh();
  1137. } else {
  1138. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  1139. }
  1140. } else if (result.code == web_status.WARNING) {
  1141. $.modal.alertWarning(result.msg)
  1142. } else {
  1143. $.modal.alertError(result.msg);
  1144. }
  1145. $.modal.closeLoading();
  1146. $.modal.enable();
  1147. },
  1148. // 选项卡成功回调执行事件(父窗体静默更新)
  1149. successTabCallback: function(result) {
  1150. if (result.code == web_status.SUCCESS) {
  1151. var topWindow = $(window.parent.document);
  1152. var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel');
  1153. var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow;
  1154. $.modal.close();
  1155. $contentWindow.$.modal.msgSuccess(result.msg);
  1156. $contentWindow.$(".layui-layer-padding").removeAttr("style");
  1157. if ($contentWindow.table.options.type == table_type.bootstrapTable) {
  1158. $contentWindow.$.table.refresh();
  1159. } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) {
  1160. $contentWindow.$.treeTable.refresh();
  1161. }
  1162. $.modal.closeTab();
  1163. } else if (result.code == web_status.WARNING) {
  1164. $.modal.alertWarning(result.msg)
  1165. } else {
  1166. $.modal.alertError(result.msg);
  1167. }
  1168. $.modal.closeLoading();
  1169. }
  1170. },
  1171. // 校验封装处理
  1172. validate: {
  1173. // 判断返回标识是否唯一 false 不存在 true 存在
  1174. unique: function (value) {
  1175. if (value == "0") {
  1176. return true;
  1177. }
  1178. return false;
  1179. },
  1180. // 表单验证
  1181. form: function (formId) {
  1182. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1183. return $("#" + currentId).validate().form();
  1184. },
  1185. // 重置表单验证(清除提示信息)
  1186. reset: function (formId) {
  1187. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1188. return $("#" + currentId).validate().resetForm();
  1189. }
  1190. },
  1191. // 树插件封装处理
  1192. tree: {
  1193. _option: {},
  1194. _lastValue: {},
  1195. // 初始化树结构
  1196. init: function(options) {
  1197. var defaults = {
  1198. id: "tree", // 属性ID
  1199. expandLevel: 0, // 展开等级节点
  1200. view: {
  1201. selectedMulti: false, // 设置是否允许同时选中多个节点
  1202. nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本
  1203. },
  1204. check: {
  1205. enable: false, // 置 zTree 的节点上是否显示 checkbox / radio
  1206. nocheckInherit: true, // 设置子节点是否自动继承
  1207. },
  1208. data: {
  1209. key: {
  1210. title: "title" // 节点数据保存节点提示信息的属性名称
  1211. },
  1212. simpleData: {
  1213. enable: true // true / false 分别表示 使用 / 不使用 简单数据模式
  1214. }
  1215. },
  1216. };
  1217. var options = $.extend(defaults, options);
  1218. $.tree._option = options;
  1219. // 树结构初始化加载
  1220. var setting = {
  1221. callback: {
  1222. onClick: options.onClick, // 用于捕获节点被点击的事件回调函数
  1223. onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
  1224. onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数
  1225. },
  1226. check: options.check,
  1227. view: options.view,
  1228. data: options.data
  1229. };
  1230. $.get(options.url, function(data) {
  1231. var treeId = $("#treeId").val();
  1232. tree = $.fn.zTree.init($("#" + options.id), setting, data);
  1233. $._tree = tree;
  1234. var nodes = tree.getNodesByParam("level", options.expandLevel - 1);
  1235. for (var i = 0; i < nodes.length; i++) {
  1236. tree.expandNode(nodes[i], true, false, false);
  1237. }
  1238. var node = tree.getNodesByParam("id", treeId, null)[0];
  1239. $.tree.selectByIdName(treeId, node);
  1240. });
  1241. },
  1242. // 搜索节点
  1243. searchNode: function() {
  1244. // 取得输入的关键字的值
  1245. var value = $.common.trim($("#keyword").val());
  1246. if ($.tree._lastValue == value) {
  1247. return;
  1248. }
  1249. // 保存最后一次搜索名称
  1250. $.tree._lastValue = value;
  1251. var nodes = $._tree.getNodes();
  1252. // 如果要查空字串,就退出不查了。
  1253. if (value == "") {
  1254. $.tree.showAllNode(nodes);
  1255. return;
  1256. }
  1257. $.tree.hideAllNode(nodes);
  1258. // 根据搜索值模糊匹配
  1259. $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
  1260. },
  1261. // 根据Id和Name选中指定节点
  1262. selectByIdName: function(treeId, node) {
  1263. if ($.common.isNotEmpty(treeId) && treeId == node.id) {
  1264. $._tree.selectNode(node, true);
  1265. }
  1266. },
  1267. // 显示所有节点
  1268. showAllNode: function(nodes) {
  1269. nodes = $._tree.transformToArray(nodes);
  1270. for (var i = nodes.length - 1; i >= 0; i--) {
  1271. if (nodes[i].getParentNode() != null) {
  1272. $._tree.expandNode(nodes[i], true, false, false, false);
  1273. } else {
  1274. $._tree.expandNode(nodes[i], true, true, false, false);
  1275. }
  1276. $._tree.showNode(nodes[i]);
  1277. $.tree.showAllNode(nodes[i].children);
  1278. }
  1279. },
  1280. // 隐藏所有节点
  1281. hideAllNode: function(nodes) {
  1282. var tree = $.fn.zTree.getZTreeObj("tree");
  1283. var nodes = $._tree.transformToArray(nodes);
  1284. for (var i = nodes.length - 1; i >= 0; i--) {
  1285. $._tree.hideNode(nodes[i]);
  1286. }
  1287. },
  1288. // 显示所有父节点
  1289. showParent: function(treeNode) {
  1290. var parentNode;
  1291. while ((parentNode = treeNode.getParentNode()) != null) {
  1292. $._tree.showNode(parentNode);
  1293. $._tree.expandNode(parentNode, true, false, false);
  1294. treeNode = parentNode;
  1295. }
  1296. },
  1297. // 显示所有孩子节点
  1298. showChildren: function(treeNode) {
  1299. if (treeNode.isParent) {
  1300. for (var idx in treeNode.children) {
  1301. var node = treeNode.children[idx];
  1302. $._tree.showNode(node);
  1303. $.tree.showChildren(node);
  1304. }
  1305. }
  1306. },
  1307. // 更新节点状态
  1308. updateNodes: function(nodeList) {
  1309. $._tree.showNodes(nodeList);
  1310. for (var i = 0, l = nodeList.length; i < l; i++) {
  1311. var treeNode = nodeList[i];
  1312. $.tree.showChildren(treeNode);
  1313. $.tree.showParent(treeNode)
  1314. }
  1315. },
  1316. // 获取当前被勾选集合
  1317. getCheckedNodes: function(column) {
  1318. var _column = $.common.isEmpty(column) ? "id" : column;
  1319. var nodes = $._tree.getCheckedNodes(true);
  1320. return $.map(nodes, function (row) {
  1321. return row[_column];
  1322. }).join();
  1323. },
  1324. // 不允许根父节点选择
  1325. notAllowParents: function(_tree) {
  1326. var nodes = _tree.getSelectedNodes();
  1327. if(nodes.length == 0){
  1328. $.modal.msgError("请选择节点后提交");
  1329. return false;
  1330. }
  1331. for (var i = 0; i < nodes.length; i++) {
  1332. if (nodes[i].level == 0) {
  1333. $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
  1334. return false;
  1335. }
  1336. if (nodes[i].isParent) {
  1337. $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
  1338. return false;
  1339. }
  1340. }
  1341. return true;
  1342. },
  1343. // 不允许最后层级节点选择
  1344. notAllowLastLevel: function(_tree) {
  1345. var nodes = _tree.getSelectedNodes();
  1346. for (var i = 0; i < nodes.length; i++) {
  1347. if (!nodes[i].isParent) {
  1348. $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")");
  1349. return false;
  1350. }
  1351. }
  1352. return true;
  1353. },
  1354. // 隐藏/显示搜索栏
  1355. toggleSearch: function() {
  1356. $('#search').slideToggle(200);
  1357. $('#btnShow').toggle();
  1358. $('#btnHide').toggle();
  1359. $('#keyword').focus();
  1360. },
  1361. // 折叠
  1362. collapse: function() {
  1363. $._tree.expandAll(false);
  1364. },
  1365. // 展开
  1366. expand: function() {
  1367. $._tree.expandAll(true);
  1368. }
  1369. },
  1370. // 通用方法封装处理
  1371. common: {
  1372. // 判断字符串是否为空
  1373. isEmpty: function (value) {
  1374. if (value == null || this.trim(value) == "") {
  1375. return true;
  1376. }
  1377. return false;
  1378. },
  1379. // 判断一个字符串是否为非空串
  1380. isNotEmpty: function (value) {
  1381. return !$.common.isEmpty(value);
  1382. },
  1383. // 空对象转字符串
  1384. nullToStr: function(value) {
  1385. if ($.common.isEmpty(value)) {
  1386. return "-";
  1387. }
  1388. return value;
  1389. },
  1390. // 是否显示数据 为空默认为显示
  1391. visible: function (value) {
  1392. if ($.common.isEmpty(value) || value == true) {
  1393. return true;
  1394. }
  1395. return false;
  1396. },
  1397. // 空格截取
  1398. trim: function (value) {
  1399. if (value == null) {
  1400. return "";
  1401. }
  1402. return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  1403. },
  1404. // 比较两个字符串(大小写敏感)
  1405. equals: function (str, that) {
  1406. return str == that;
  1407. },
  1408. // 比较两个字符串(大小写不敏感)
  1409. equalsIgnoreCase: function (str, that) {
  1410. return String(str).toUpperCase() === String(that).toUpperCase();
  1411. },
  1412. // 将字符串按指定字符分割
  1413. split: function (str, sep, maxLen) {
  1414. if ($.common.isEmpty(str)) {
  1415. return null;
  1416. }
  1417. var value = String(str).split(sep);
  1418. return maxLen ? value.slice(0, maxLen - 1) : value;
  1419. },
  1420. // 字符串格式化(%s )
  1421. sprintf: function (str) {
  1422. var args = arguments, flag = true, i = 1;
  1423. str = str.replace(/%s/g, function () {
  1424. var arg = args[i++];
  1425. if (typeof arg === 'undefined') {
  1426. flag = false;
  1427. return '';
  1428. }
  1429. return arg;
  1430. });
  1431. return flag ? str : '';
  1432. },
  1433. // 指定随机数返回
  1434. random: function (min, max) {
  1435. return Math.floor((Math.random() * max) + min);
  1436. },
  1437. // 判断字符串是否是以start开头
  1438. startWith: function(value, start) {
  1439. var reg = new RegExp("^" + start);
  1440. return reg.test(value)
  1441. },
  1442. // 判断字符串是否是以end结尾
  1443. endWith: function(value, end) {
  1444. var reg = new RegExp(end + "$");
  1445. return reg.test(value)
  1446. },
  1447. // 数组去重
  1448. uniqueFn: function(array) {
  1449. var result = [];
  1450. var hashObj = {};
  1451. for (var i = 0; i < array.length; i++) {
  1452. if (!hashObj[array[i]]) {
  1453. hashObj[array[i]] = true;
  1454. result.push(array[i]);
  1455. }
  1456. }
  1457. return result;
  1458. },
  1459. // 数组中的所有元素放入一个字符串
  1460. join: function(array, separator) {
  1461. if ($.common.isEmpty(array)) {
  1462. return null;
  1463. }
  1464. return array.join(separator);
  1465. },
  1466. // 获取form下所有的字段并转换为json对象
  1467. formToJSON: function(formId) {
  1468. var json = {};
  1469. $.each($("#" + formId).serializeArray(), function(i, field) {
  1470. if(json[field.name]) {
  1471. json[field.name] += ("," + field.value);
  1472. } else {
  1473. json[field.name] = field.value;
  1474. }
  1475. });
  1476. return json;
  1477. },
  1478. // 获取obj对象长度
  1479. getLength: function(obj) {
  1480. var count = 0;  
  1481. for (var i in obj) {
  1482. if (obj.hasOwnProperty(i)) {
  1483. count++;
  1484. }  
  1485. }
  1486. return count;
  1487. },
  1488. // 判断移动端
  1489. isMobile: function () {
  1490. return navigator.userAgent.match(/(Android|iPhone|SymbianOS|Windows Phone|iPad|iPod)/i);
  1491. },
  1492. }
  1493. });
  1494. })(jQuery);
  1495. /** 表格类型 */
  1496. table_type = {
  1497. bootstrapTable: 0,
  1498. bootstrapTreeTable: 1
  1499. };
  1500. /** 消息状态码 */
  1501. web_status = {
  1502. SUCCESS: 0,
  1503. FAIL: 500,
  1504. WARNING: 301
  1505. };
  1506. /** 弹窗状态码 */
  1507. modal_status = {
  1508. SUCCESS: "success",
  1509. FAIL: "error",
  1510. WARNING: "warning"
  1511. };