ry-ui.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /**
  2. * 通用js方法封装处理
  3. * Copyright (c) 2018 ruoyi
  4. */
  5. (function ($) {
  6. $.extend({
  7. _treeTable: {},
  8. _tree: {},
  9. // 表格封装处理
  10. table: {
  11. _option: {},
  12. _params: {},
  13. // 初始化表格
  14. init: function(options) {
  15. $.table._option = options;
  16. $.table._params = $.common.isEmpty(options.queryParams) ? $.table.queryParams : options.queryParams;
  17. _sortOrder = $.common.isEmpty(options.sortOrder) ? "asc" : options.sortOrder;
  18. _sortName = $.common.isEmpty(options.sortName) ? "" : options.sortName;
  19. $('#bootstrap-table').bootstrapTable({
  20. url: options.url, // 请求后台的URL(*)
  21. contentType: "application/x-www-form-urlencoded", // 编码类型
  22. method: 'post', // 请求方式(*)
  23. cache: false, // 是否使用缓存
  24. sortable: true, // 是否启用排序
  25. sortStable: true, // 设置为 true 将获得稳定的排序
  26. sortName: _sortName, // 排序列名称
  27. sortOrder: _sortOrder, // 排序方式 asc 或者 desc
  28. pagination: $.common.visible(options.pagination), // 是否显示分页(*)
  29. pageNumber: 1, // 初始化加载第一页,默认第一页
  30. pageSize: 10, // 每页的记录行数(*)
  31. pageList: [10, 25, 50], // 可供选择的每页的行数(*)
  32. iconSize: 'outline', // 图标大小:undefined默认的按钮尺寸 xs超小按钮sm小按钮lg大按钮
  33. toolbar: '#toolbar', // 指定工作栏
  34. sidePagination: "server", // 启用服务端分页
  35. search: $.common.visible(options.search), // 是否显示搜索框功能
  36. showSearch: $.common.visible(options.showSearch), // 是否显示检索信息
  37. showRefresh: $.common.visible(options.showRefresh), // 是否显示刷新按钮
  38. showColumns: $.common.visible(options.showColumns), // 是否显示隐藏某列下拉框
  39. showToggle: $.common.visible(options.showToggle), // 是否显示详细视图和列表视图的切换按钮
  40. showExport: $.common.visible(options.showExport), // 是否支持导出文件
  41. queryParams: $.table._params, // 传递参数(*)
  42. columns: options.columns, // 显示列信息(*)
  43. responseHandler: $.table.responseHandler // 回调函数
  44. });
  45. },
  46. // 查询条件
  47. queryParams: function(params) {
  48. return {
  49. // 传递参数查询参数
  50. pageSize: params.limit,
  51. pageNum: params.offset / params.limit + 1,
  52. searchValue: params.search,
  53. orderByColumn: params.sort,
  54. isAsc: params.order
  55. };
  56. },
  57. // 请求获取数据后处理回调函数
  58. responseHandler: function(res) {
  59. if (res.code == 0) {
  60. return { rows: res.rows, total: res.total };
  61. } else {
  62. $.modal.alertWarning(res.msg);
  63. return { rows: [], total: 0 };
  64. }
  65. },
  66. // 搜索
  67. search: function(formId) {
  68. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  69. var params = $("#bootstrap-table").bootstrapTable('getOptions');
  70. params.queryParams = function(params) {
  71. var search = {};
  72. $.each($("#" + currentId).serializeArray(), function(i, field) {
  73. search[field.name] = field.value;
  74. });
  75. search.pageSize = params.limit;
  76. search.pageNum = params.offset / params.limit + 1;
  77. search.searchValue = params.search;
  78. search.orderByColumn = params.sort;
  79. search.isAsc = params.order;
  80. return search;
  81. }
  82. $("#bootstrap-table").bootstrapTable('refresh', params);
  83. },
  84. // 下载
  85. exportExcel: function(formId) {
  86. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  87. $.modal.loading("正在导出数据,请稍后...");
  88. $.post($.table._option.exportUrl, $("#" + currentId).serializeArray(), function(result) {
  89. if (result.code == web_status.SUCCESS) {
  90. window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true;
  91. } else {
  92. $.modal.alertError(result.msg);
  93. }
  94. $.modal.closeLoading();
  95. });
  96. },
  97. // 刷新
  98. refresh: function() {
  99. $("#bootstrap-table").bootstrapTable('refresh', {
  100. url: $.table._option.url,
  101. silent: true
  102. });
  103. },
  104. // 查询选中列值
  105. selectColumns: function(column) {
  106. return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
  107. return row[column];
  108. });
  109. },
  110. // 查询选中首列值
  111. selectFirstColumns: function() {
  112. return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
  113. return row[$.table._option.columns[1].field];
  114. });
  115. },
  116. // 回显数据字典
  117. selectDictLabel: function(datas, value) {
  118. var actions = [];
  119. $.each(datas, function(index, dict) {
  120. if (dict.dictValue == value) {
  121. actions.push("<span class='badge badge-" + dict.listClass + "'>" + dict.dictLabel + "</span>");
  122. return false;
  123. }
  124. });
  125. return actions.join('');
  126. }
  127. },
  128. // 表格树封装处理
  129. treeTable: {
  130. _option: {},
  131. // 初始化表格
  132. init: function(options) {
  133. $.table._option = options;
  134. var treeTable = $('#bootstrap-table').bootstrapTreeTable({
  135. code : options.id, // 用于设置父子关系
  136. parentCode : options.parentId, // 用于设置父子关系
  137. type: 'get', // 请求方式(*)
  138. url: options.url, // 请求后台的URL(*)
  139. ajaxParams : {}, // 请求数据的ajax的data属性
  140. expandColumn : '0', // 在哪一列上面显示展开按钮
  141. striped : false, // 是否各行渐变色
  142. bordered : true, // 是否显示边框
  143. expandAll : $.common.visible(options.expandAll), // 是否全部展开
  144. columns: options.columns
  145. });
  146. $._treeTable = treeTable;
  147. },
  148. // 条件查询
  149. search: function(formId) {
  150. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  151. var params = {};
  152. $.each($("#" + currentId).serializeArray(), function(i, field) {
  153. params[field.name] = field.value;
  154. });
  155. $._treeTable.bootstrapTreeTable('refresh', params);
  156. },
  157. // 刷新
  158. refresh: function() {
  159. $._treeTable.bootstrapTreeTable('refresh');
  160. },
  161. },
  162. // 表单封装处理
  163. form: {
  164. // 表单重置
  165. reset: function(formId) {
  166. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  167. $("#" + currentId)[0].reset();
  168. },
  169. // 获取选中复选框项
  170. selectCheckeds: function(name) {
  171. var checkeds = "";
  172. $('input:checkbox[name="' + name + '"]:checked').each(function(i) {
  173. if (0 == i) {
  174. checkeds = $(this).val();
  175. } else {
  176. checkeds += ("," + $(this).val());
  177. }
  178. });
  179. return checkeds;
  180. },
  181. // 获取选中下拉框项
  182. selectSelects: function(name) {
  183. var selects = "";
  184. $('#' + name + ' option:selected').each(function (i) {
  185. if (0 == i) {
  186. selects = $(this).val();
  187. } else {
  188. selects += ("," + $(this).val());
  189. }
  190. });
  191. return selects;
  192. }
  193. },
  194. // 弹出层封装处理
  195. modal: {
  196. // 显示图标
  197. icon: function(type) {
  198. var icon = "";
  199. if (type == modal_status.WARNING) {
  200. icon = 0;
  201. } else if (type == modal_status.SUCCESS) {
  202. icon = 1;
  203. } else if (type == modal_status.FAIL) {
  204. icon = 2;
  205. } else {
  206. icon = 3;
  207. }
  208. return icon;
  209. },
  210. // 消息提示
  211. msg: function(content, type) {
  212. if (type != undefined) {
  213. layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 });
  214. } else {
  215. layer.msg(content);
  216. }
  217. },
  218. // 错误消息
  219. msgError: function(content) {
  220. $.modal.msg(content, modal_status.FAIL);
  221. },
  222. // 成功消息
  223. msgSuccess: function(content) {
  224. $.modal.msg(content, modal_status.SUCCESS);
  225. },
  226. // 警告消息
  227. msgWarning: function(content) {
  228. $.modal.msg(content, modal_status.WARNING);
  229. },
  230. // 弹出提示
  231. alert: function(content, type) {
  232. layer.alert(content, {
  233. icon: $.modal.icon(type),
  234. title: "系统提示",
  235. btn: ['确认'],
  236. btnclass: ['btn btn-primary'],
  237. });
  238. },
  239. // 消息提示并刷新父窗体
  240. msgReload: function(msg, type) {
  241. layer.msg(msg, {
  242. icon: $.modal.icon(type),
  243. time: 500,
  244. shade: [0.1, '#8F8F8F']
  245. },
  246. function() {
  247. $.modal.reload();
  248. });
  249. },
  250. // 错误提示
  251. alertError: function(content) {
  252. $.modal.alert(content, modal_status.FAIL);
  253. },
  254. // 成功提示
  255. alertSuccess: function(content) {
  256. $.modal.alert(content, modal_status.SUCCESS);
  257. },
  258. // 警告提示
  259. alertWarning: function(content) {
  260. $.modal.alert(content, modal_status.WARNING);
  261. },
  262. // 关闭窗体
  263. close: function () {
  264. var index = parent.layer.getFrameIndex(window.name);
  265. parent.layer.close(index);
  266. },
  267. // 确认窗体
  268. confirm: function (content, callBack) {
  269. layer.confirm(content, {
  270. icon: 3,
  271. title: "系统提示",
  272. btn: ['确认', '取消'],
  273. btnclass: ['btn btn-primary', 'btn btn-danger'],
  274. }, function (index) {
  275. layer.close(index);
  276. callBack(true);
  277. });
  278. },
  279. // 弹出层指定宽度
  280. open: function (title, url, width, height) {
  281. //如果是移动端,就使用自适应大小弹窗
  282. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  283. width = 'auto';
  284. height = 'auto';
  285. }
  286. if ($.common.isEmpty(title)) {
  287. title = false;
  288. };
  289. if ($.common.isEmpty(url)) {
  290. url = "/404.html";
  291. };
  292. if ($.common.isEmpty(width)) {
  293. width = 800;
  294. };
  295. if ($.common.isEmpty(height)) {
  296. height = ($(window).height() - 50);
  297. };
  298. layer.open({
  299. type: 2,
  300. area: [width + 'px', height + 'px'],
  301. fix: false,
  302. //不固定
  303. maxmin: true,
  304. shade: 0.3,
  305. title: title,
  306. content: url,
  307. // 弹层外区域关闭
  308. shadeClose: true
  309. });
  310. },
  311. // 弹出层指定参数选项
  312. openOptions: function (options) {
  313. var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
  314. var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
  315. var _width = $.common.isEmpty(options.width) ? "800" : options.width;
  316. var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
  317. layer.open({
  318. type: 2,
  319. maxmin: true,
  320. shade: 0.3,
  321. title: _title,
  322. fix: false,
  323. area: [_width + 'px', _height + 'px'],
  324. content: _url,
  325. shadeClose: true,
  326. btn: ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
  327. yes: function (index, layero) {
  328. options.callBack(index, layero)
  329. }, cancel: function () {
  330. return true;
  331. }
  332. });
  333. },
  334. // 弹出层全屏
  335. openFull: function (title, url, width, height) {
  336. //如果是移动端,就使用自适应大小弹窗
  337. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  338. width = 'auto';
  339. height = 'auto';
  340. }
  341. if ($.common.isEmpty(title)) {
  342. title = false;
  343. };
  344. if ($.common.isEmpty(url)) {
  345. url = "/404.html";
  346. };
  347. if ($.common.isEmpty(width)) {
  348. width = 800;
  349. };
  350. if ($.common.isEmpty(height)) {
  351. height = ($(window).height() - 50);
  352. };
  353. var index = layer.open({
  354. type: 2,
  355. area: [width + 'px', height + 'px'],
  356. fix: false,
  357. //不固定
  358. maxmin: true,
  359. shade: 0.3,
  360. title: title,
  361. content: url,
  362. // 弹层外区域关闭
  363. shadeClose: true
  364. });
  365. layer.full(index);
  366. },
  367. // 打开遮罩层
  368. loading: function (message) {
  369. $.blockUI({ message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>' });
  370. },
  371. // 关闭遮罩层
  372. closeLoading: function () {
  373. setTimeout(function(){
  374. $.unblockUI();
  375. }, 50);
  376. },
  377. // 重新加载
  378. reload: function () {
  379. parent.location.reload();
  380. }
  381. },
  382. // 操作封装处理
  383. operate: {
  384. // 提交数据
  385. submit: function(url, type, dataType, data) {
  386. $.modal.loading("正在处理中,请稍后...");
  387. var config = {
  388. url: url,
  389. type: type,
  390. dataType: dataType,
  391. data: data,
  392. success: function(result) {
  393. $.operate.ajaxSuccess(result);
  394. }
  395. };
  396. $.ajax(config)
  397. },
  398. // post请求传输
  399. post: function(url, data) {
  400. $.operate.submit(url, "post", "json", data);
  401. },
  402. // 详细信息
  403. detail: function(id) {
  404. var url = $.common.isEmpty(id) ? $.table._option.detailUrl : $.table._option.detailUrl.replace("{id}", id);
  405. $.modal.open($.table._option.modalName + "详细", url);
  406. },
  407. // 删除信息
  408. remove: function(id) {
  409. $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗?", function() {
  410. var url = $.common.isEmpty(id) ? $.table._option.removeUrl : $.table._option.removeUrl.replace("{id}", id);
  411. var data = { "ids": id };
  412. $.operate.submit(url, "post", "json", data);
  413. });
  414. },
  415. // 批量删除信息
  416. removeAll: function() {
  417. var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
  418. if (rows.length == 0) {
  419. $.modal.alertWarning("请至少选择一条记录");
  420. return;
  421. }
  422. $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
  423. var url = $.table._option.removeUrl;
  424. var data = { "ids": rows.join() };
  425. $.operate.submit(url, "post", "json", data);
  426. });
  427. },
  428. // 添加信息
  429. add: function(id) {
  430. var url = $.common.isEmpty(id) ? $.table._option.createUrl : $.table._option.createUrl.replace("{id}", id);
  431. $.modal.open("添加" + $.table._option.modalName, url);
  432. },
  433. // 修改信息
  434. edit: function(id) {
  435. var url = $.table._option.updateUrl.replace("{id}", id);
  436. $.modal.open("修改" + $.table._option.modalName, url);
  437. },
  438. // 添加信息 全屏
  439. addFull: function(id) {
  440. var url = $.common.isEmpty(id) ? $.table._option.createUrl : $.table._option.createUrl.replace("{id}", id);
  441. $.modal.openFull("添加" + $.table._option.modalName, url);
  442. },
  443. // 修改信息 全屏
  444. editFull: function(id) {
  445. var url = $.table._option.updateUrl.replace("{id}", id);
  446. $.modal.openFull("修改" + $.table._option.modalName, url);
  447. },
  448. // 保存信息
  449. save: function(url, data) {
  450. $.modal.loading("正在处理中,请稍后...");
  451. var config = {
  452. url: url,
  453. type: "post",
  454. dataType: "json",
  455. data: data,
  456. success: function(result) {
  457. $.operate.saveSuccess(result);
  458. }
  459. };
  460. $.ajax(config)
  461. },
  462. // 保存结果弹出msg刷新table表格
  463. ajaxSuccess: function (result) {
  464. if (result.code == web_status.SUCCESS) {
  465. $.modal.msgSuccess(result.msg);
  466. $.table.refresh();
  467. } else {
  468. $.modal.alertError(result.msg);
  469. }
  470. $.modal.closeLoading();
  471. },
  472. // 保存结果提示msg
  473. saveSuccess: function (result) {
  474. if (result.code == web_status.SUCCESS) {
  475. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  476. } else {
  477. $.modal.alertError(result.msg);
  478. }
  479. $.modal.closeLoading();
  480. }
  481. },
  482. // 校验封装处理
  483. validate: {
  484. // 判断返回标识是否唯一 false 不存在 true 存在
  485. unique: function (value) {
  486. if (value == "0") {
  487. return true;
  488. }
  489. return false;
  490. }
  491. },
  492. // 树插件封装处理
  493. tree: {
  494. _option: {},
  495. _lastValue: {},
  496. // 初始化树结构
  497. init: function(options) {
  498. $.tree._option = options;
  499. // 属性ID
  500. var _id = $.common.isEmpty(options.id) ? "tree" : options.id;
  501. // 展开等级节点
  502. var _expandLevel = $.common.isEmpty(options.expandLevel) ? 0 : options.expandLevel;
  503. // 树结构初始化加载
  504. var setting = {
  505. check: options.check,
  506. view: { selectedMulti: false, nameIsHTML: true },
  507. data: { key: { title: "title" }, simpleData: { enable: true } },
  508. callback: { onClick: options.onClick }
  509. };
  510. $.get(options.url, function(data) {
  511. var treeName = $("#treeName").val();
  512. var treeId = $("#treeId").val();
  513. tree = $.fn.zTree.init($("#" + _id), setting, data);
  514. $._tree = tree;
  515. // 展开第一级节点
  516. var nodes = tree.getNodesByParam("level", 0);
  517. for (var i = 0; i < nodes.length; i++) {
  518. if(_expandLevel > 0) {
  519. tree.expandNode(nodes[i], true, false, false);
  520. }
  521. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  522. }
  523. // 展开第二级节点
  524. nodes = tree.getNodesByParam("level", 1);
  525. for (var i = 0; i < nodes.length; i++) {
  526. if(_expandLevel > 1) {
  527. tree.expandNode(nodes[i], true, false, false);
  528. }
  529. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  530. }
  531. // 展开第三级节点
  532. nodes = tree.getNodesByParam("level", 2);
  533. for (var i = 0; i < nodes.length; i++) {
  534. if(_expandLevel > 2) {
  535. tree.expandNode(nodes[i], true, false, false);
  536. }
  537. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  538. }
  539. }, null, null, "正在加载,请稍后...");
  540. },
  541. // 搜索节点
  542. searchNode: function() {
  543. // 取得输入的关键字的值
  544. var value = $.common.trim($("#keyword").val());
  545. if ($.tree._lastValue === value) {
  546. return;
  547. }
  548. // 保存最后一次搜索名称
  549. $.tree._lastValue = value;
  550. var nodes = $._tree.getNodes();
  551. // 如果要查空字串,就退出不查了。
  552. if (value == "") {
  553. $.tree.showAllNode(nodes);
  554. return;
  555. }
  556. $.tree.hideAllNode(nodes);
  557. // 根据搜索值模糊匹配
  558. $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
  559. },
  560. // 根据Id和Name选中指定节点
  561. selectByIdName: function(treeId, treeName, node) {
  562. if ($.common.isNotEmpty(treeName) && $.common.isNotEmpty(treeId)) {
  563. if (treeId == node.id && treeName == node.name) {
  564. $._tree.selectNode(node, true);
  565. }
  566. }
  567. },
  568. // 显示所有节点
  569. showAllNode: function(nodes) {
  570. nodes = $._tree.transformToArray(nodes);
  571. for (var i = nodes.length - 1; i >= 0; i--) {
  572. if (nodes[i].getParentNode() != null) {
  573. $._tree.expandNode(nodes[i], true, false, false, false);
  574. } else {
  575. $._tree.expandNode(nodes[i], true, true, false, false);
  576. }
  577. $._tree.showNode(nodes[i]);
  578. $.tree.showAllNode(nodes[i].children);
  579. }
  580. },
  581. // 隐藏所有节点
  582. hideAllNode: function(nodes) {
  583. var tree = $.fn.zTree.getZTreeObj("tree");
  584. var nodes = $._tree.transformToArray(nodes);
  585. for (var i = nodes.length - 1; i >= 0; i--) {
  586. $._tree.hideNode(nodes[i]);
  587. }
  588. },
  589. // 显示所有父节点
  590. showParent: function(treeNode) {
  591. var parentNode;
  592. while ((parentNode = treeNode.getParentNode()) != null) {
  593. $._tree.showNode(parentNode);
  594. $._tree.expandNode(parentNode, true, false, false);
  595. treeNode = parentNode;
  596. }
  597. },
  598. // 显示所有孩子节点
  599. showChildren: function(treeNode) {
  600. if (treeNode.isParent) {
  601. for (var idx in treeNode.children) {
  602. var node = treeNode.children[idx];
  603. $._tree.showNode(node);
  604. $.tree.showChildren(node);
  605. }
  606. }
  607. },
  608. // 更新节点状态
  609. updateNodes: function(nodeList) {
  610. $._tree.showNodes(nodeList);
  611. for (var i = 0, l = nodeList.length; i < l; i++) {
  612. var treeNode = nodeList[i];
  613. $.tree.showChildren(treeNode);
  614. $.tree.showParent(treeNode)
  615. }
  616. },
  617. // 获取当前被勾选集合
  618. getCheckedNodes: function(column) {
  619. var _column = $.common.isEmpty(column) ? "id" : column;
  620. var nodes = $._tree.getCheckedNodes(true);
  621. return $.map(nodes, function (row) {
  622. return row[_column];
  623. }).join();
  624. },
  625. // 不允许根父节点选择
  626. notAllowParents: function(_tree) {
  627. var nodes = _tree.getSelectedNodes();
  628. for (var i = 0; i < nodes.length; i++) {
  629. if (nodes[i].level == 0) {
  630. $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
  631. return false;
  632. }
  633. if (nodes[i].isParent) {
  634. $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
  635. return false;
  636. }
  637. }
  638. return true;
  639. },
  640. // 隐藏/显示搜索栏
  641. toggleSearch: function() {
  642. $('#search').slideToggle(200);
  643. $('#btnShow').toggle();
  644. $('#btnHide').toggle();
  645. $('#keyword').focus();
  646. },
  647. // 折叠
  648. collapse: function() {
  649. $._tree.expandAll(false);
  650. },
  651. // 展开
  652. expand: function() {
  653. $._tree.expandAll(true);
  654. }
  655. },
  656. // 通用方法封装处理
  657. common: {
  658. // 判断字符串是否为空
  659. isEmpty: function (value) {
  660. if (value == null || this.trim(value) == "") {
  661. return true;
  662. }
  663. return false;
  664. },
  665. // 判断一个字符串是否为非空串
  666. isNotEmpty: function (value) {
  667. return !$.common.isEmpty(value);
  668. },
  669. // 是否显示数据 为空默认为显示
  670. visible: function (value) {
  671. if ($.common.isEmpty(value) || value == true) {
  672. return true;
  673. }
  674. return false;
  675. },
  676. // 空格截取
  677. trim: function (value) {
  678. if (value == null) {
  679. return "";
  680. }
  681. return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  682. },
  683. // 指定随机数返回
  684. random: function (min, max) {
  685. return Math.floor((Math.random() * max) + min);
  686. }
  687. }
  688. });
  689. })(jQuery);
  690. /** 消息状态码 */
  691. web_status = {
  692. SUCCESS: 0,
  693. FAIL: 500
  694. };
  695. /** 弹窗状态码 */
  696. modal_status = {
  697. SUCCESS: "success",
  698. FAIL: "error",
  699. WARNING: "warning"
  700. };