ry-ui.js 58 KB

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