ry-ui.js 57 KB

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