ry-ui.js 55 KB

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