ry-ui.js 55 KB

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