ry-ui.js 57 KB

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