ry-ui.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. id : options.id, // 用于设置父子关系
  136. parentId : options.parentId, // 用于设置父子关系
  137. type: 'get', // 请求方式(*)
  138. url: options.url, // 请求后台的URL(*)
  139. ajaxParams : {}, // 请求数据的ajax的data属性
  140. expandColumn : '1', // 在哪一列上面显示展开按钮
  141. striped : false, // 是否各行渐变色
  142. bordered : true, // 是否显示边框
  143. toolbar: '#toolbar', // 指定工作栏
  144. expandAll : $.common.visible(options.expandAll), // 是否全部展开
  145. columns: options.columns
  146. });
  147. $._treeTable = treeTable;
  148. },
  149. // 条件查询
  150. search: function(formId) {
  151. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  152. var params = {};
  153. $.each($("#" + currentId).serializeArray(), function(i, field) {
  154. params[field.name] = field.value;
  155. });
  156. $._treeTable.bootstrapTreeTable('refresh', params);
  157. },
  158. // 刷新
  159. refresh: function() {
  160. $._treeTable.bootstrapTreeTable('refresh');
  161. },
  162. },
  163. // 表单封装处理
  164. form: {
  165. // 表单重置
  166. reset: function(formId) {
  167. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  168. $("#" + currentId)[0].reset();
  169. },
  170. // 获取选中复选框项
  171. selectCheckeds: function(name) {
  172. var checkeds = "";
  173. $('input:checkbox[name="' + name + '"]:checked').each(function(i) {
  174. if (0 == i) {
  175. checkeds = $(this).val();
  176. } else {
  177. checkeds += ("," + $(this).val());
  178. }
  179. });
  180. return checkeds;
  181. },
  182. // 获取选中下拉框项
  183. selectSelects: function(name) {
  184. var selects = "";
  185. $('#' + name + ' option:selected').each(function (i) {
  186. if (0 == i) {
  187. selects = $(this).val();
  188. } else {
  189. selects += ("," + $(this).val());
  190. }
  191. });
  192. return selects;
  193. }
  194. },
  195. // 弹出层封装处理
  196. modal: {
  197. // 显示图标
  198. icon: function(type) {
  199. var icon = "";
  200. if (type == modal_status.WARNING) {
  201. icon = 0;
  202. } else if (type == modal_status.SUCCESS) {
  203. icon = 1;
  204. } else if (type == modal_status.FAIL) {
  205. icon = 2;
  206. } else {
  207. icon = 3;
  208. }
  209. return icon;
  210. },
  211. // 消息提示
  212. msg: function(content, type) {
  213. if (type != undefined) {
  214. layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 });
  215. } else {
  216. layer.msg(content);
  217. }
  218. },
  219. // 错误消息
  220. msgError: function(content) {
  221. $.modal.msg(content, modal_status.FAIL);
  222. },
  223. // 成功消息
  224. msgSuccess: function(content) {
  225. $.modal.msg(content, modal_status.SUCCESS);
  226. },
  227. // 警告消息
  228. msgWarning: function(content) {
  229. $.modal.msg(content, modal_status.WARNING);
  230. },
  231. // 弹出提示
  232. alert: function(content, type) {
  233. layer.alert(content, {
  234. icon: $.modal.icon(type),
  235. title: "系统提示",
  236. btn: ['确认'],
  237. btnclass: ['btn btn-primary'],
  238. });
  239. },
  240. // 消息提示并刷新父窗体
  241. msgReload: function(msg, type) {
  242. layer.msg(msg, {
  243. icon: $.modal.icon(type),
  244. time: 500,
  245. shade: [0.1, '#8F8F8F']
  246. },
  247. function() {
  248. $.modal.reload();
  249. });
  250. },
  251. // 错误提示
  252. alertError: function(content) {
  253. $.modal.alert(content, modal_status.FAIL);
  254. },
  255. // 成功提示
  256. alertSuccess: function(content) {
  257. $.modal.alert(content, modal_status.SUCCESS);
  258. },
  259. // 警告提示
  260. alertWarning: function(content) {
  261. $.modal.alert(content, modal_status.WARNING);
  262. },
  263. // 关闭窗体
  264. close: function () {
  265. var index = parent.layer.getFrameIndex(window.name);
  266. parent.layer.close(index);
  267. },
  268. // 确认窗体
  269. confirm: function (content, callBack) {
  270. layer.confirm(content, {
  271. icon: 3,
  272. title: "系统提示",
  273. btn: ['确认', '取消'],
  274. btnclass: ['btn btn-primary', 'btn btn-danger'],
  275. }, function (index) {
  276. layer.close(index);
  277. callBack(true);
  278. });
  279. },
  280. // 弹出层指定宽度
  281. open: function (title, url, width, height) {
  282. //如果是移动端,就使用自适应大小弹窗
  283. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  284. width = 'auto';
  285. height = 'auto';
  286. }
  287. if ($.common.isEmpty(title)) {
  288. title = false;
  289. };
  290. if ($.common.isEmpty(url)) {
  291. url = "/404.html";
  292. };
  293. if ($.common.isEmpty(width)) {
  294. width = 800;
  295. };
  296. if ($.common.isEmpty(height)) {
  297. height = ($(window).height() - 50);
  298. };
  299. layer.open({
  300. type: 2,
  301. area: [width + 'px', height + 'px'],
  302. fix: false,
  303. //不固定
  304. maxmin: true,
  305. shade: 0.3,
  306. title: title,
  307. content: url,
  308. btn: ['确定', '关闭'],
  309. // 弹层外区域关闭
  310. shadeClose: true,
  311. yes: function(index, layero) {
  312. var iframeWin = layero.find('iframe')[0];
  313. iframeWin.contentWindow.submitHandler();
  314. },
  315. cancel: function(index) {
  316. return true;
  317. }
  318. });
  319. },
  320. // 弹出层指定参数选项
  321. openOptions: function (options) {
  322. var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
  323. var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
  324. var _width = $.common.isEmpty(options.width) ? "800" : options.width;
  325. var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height;
  326. layer.open({
  327. type: 2,
  328. maxmin: true,
  329. shade: 0.3,
  330. title: _title,
  331. fix: false,
  332. area: [_width + 'px', _height + 'px'],
  333. content: _url,
  334. shadeClose: true,
  335. btn: ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
  336. yes: function (index, layero) {
  337. options.callBack(index, layero)
  338. }, cancel: function () {
  339. return true;
  340. }
  341. });
  342. },
  343. // 弹出层全屏
  344. openFull: function (title, url, width, height) {
  345. //如果是移动端,就使用自适应大小弹窗
  346. if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
  347. width = 'auto';
  348. height = 'auto';
  349. }
  350. if ($.common.isEmpty(title)) {
  351. title = false;
  352. };
  353. if ($.common.isEmpty(url)) {
  354. url = "/404.html";
  355. };
  356. if ($.common.isEmpty(width)) {
  357. width = 800;
  358. };
  359. if ($.common.isEmpty(height)) {
  360. height = ($(window).height() - 50);
  361. };
  362. var index = layer.open({
  363. type: 2,
  364. area: [width + 'px', height + 'px'],
  365. fix: false,
  366. //不固定
  367. maxmin: true,
  368. shade: 0.3,
  369. title: title,
  370. content: url,
  371. // 弹层外区域关闭
  372. shadeClose: true
  373. });
  374. layer.full(index);
  375. },
  376. // 打开遮罩层
  377. loading: function (message) {
  378. $.blockUI({ message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>' });
  379. },
  380. // 关闭遮罩层
  381. closeLoading: function () {
  382. setTimeout(function(){
  383. $.unblockUI();
  384. }, 50);
  385. },
  386. // 重新加载
  387. reload: function () {
  388. parent.location.reload();
  389. }
  390. },
  391. // 操作封装处理
  392. operate: {
  393. // 提交数据
  394. submit: function(url, type, dataType, data) {
  395. $.modal.loading("正在处理中,请稍后...");
  396. var config = {
  397. url: url,
  398. type: type,
  399. dataType: dataType,
  400. data: data,
  401. success: function(result) {
  402. $.operate.ajaxSuccess(result);
  403. }
  404. };
  405. $.ajax(config)
  406. },
  407. // post请求传输
  408. post: function(url, data) {
  409. $.operate.submit(url, "post", "json", data);
  410. },
  411. // 详细信息
  412. detail: function(id) {
  413. var _url = $.common.isEmpty(id) ? $.table._option.detailUrl : $.table._option.detailUrl.replace("{id}", id);
  414. layer.open({
  415. type: 2,
  416. area: ['800px', ($(window).height() - 50) + 'px'],
  417. fix: false,
  418. //不固定
  419. maxmin: true,
  420. shade: 0.3,
  421. title: $.table._option.modalName + "详细",
  422. content: _url,
  423. btn: ['<i class="fa fa-close"></i> 关闭'],
  424. // 弹层外区域关闭
  425. shadeClose: true,
  426. cancel: function(index) {
  427. return true;
  428. }
  429. });
  430. },
  431. // 删除信息
  432. remove: function(id) {
  433. $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗?", function() {
  434. var url = $.common.isEmpty(id) ? $.table._option.removeUrl : $.table._option.removeUrl.replace("{id}", id);
  435. var data = { "ids": id };
  436. $.operate.submit(url, "post", "json", data);
  437. });
  438. },
  439. // 批量删除信息
  440. removeAll: function() {
  441. var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
  442. if (rows.length == 0) {
  443. $.modal.alertWarning("请至少选择一条记录");
  444. return;
  445. }
  446. $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
  447. var url = $.table._option.removeUrl;
  448. var data = { "ids": rows.join() };
  449. $.operate.submit(url, "post", "json", data);
  450. });
  451. },
  452. // 清空信息
  453. clean: function() {
  454. $.modal.confirm("确定清空所有" + $.table._option.modalName + "吗?", function() {
  455. var url = $.table._option.cleanUrl;
  456. $.operate.submit(url, "post", "json", "");
  457. });
  458. },
  459. // 添加信息
  460. add: function(id) {
  461. var url = $.common.isEmpty(id) ? $.table._option.createUrl : $.table._option.createUrl.replace("{id}", id);
  462. $.modal.open("添加" + $.table._option.modalName, url);
  463. },
  464. // 修改信息
  465. edit: function(id) {
  466. var url = "/404.html";
  467. if ($.common.isNotEmpty(id)) {
  468. url = $.table._option.updateUrl.replace("{id}", id);
  469. } else {
  470. var id = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
  471. if (id.length == 0) {
  472. $.modal.alertWarning("请至少选择一条记录");
  473. return;
  474. }
  475. url = $.table._option.updateUrl.replace("{id}", id);
  476. }
  477. $.modal.open("修改" + $.table._option.modalName, url);
  478. },
  479. // 工具栏表格树修改
  480. editTree: function() {
  481. var row = $('#bootstrap-table').bootstrapTreeTable('getSelections')[0];
  482. if ($.common.isEmpty(row)) {
  483. $.modal.alertWarning("请至少选择一条记录");
  484. return;
  485. }
  486. var url = $.table._option.updateUrl.replace("{id}", row[$.table._option.id]);
  487. $.modal.open("修改" + $.table._option.modalName, url);
  488. },
  489. // 添加信息 全屏
  490. addFull: function(id) {
  491. var url = $.common.isEmpty(id) ? $.table._option.createUrl : $.table._option.createUrl.replace("{id}", id);
  492. $.modal.openFull("添加" + $.table._option.modalName, url);
  493. },
  494. // 修改信息 全屏
  495. editFull: function(id) {
  496. var url = "/404.html";
  497. if ($.common.isNotEmpty(id)) {
  498. url = $.table._option.updateUrl.replace("{id}", id);
  499. } else {
  500. var row = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
  501. url = $.table._option.updateUrl.replace("{id}", row);
  502. }
  503. $.modal.openFull("修改" + $.table._option.modalName, url);
  504. },
  505. // 保存信息
  506. save: function(url, data) {
  507. $.modal.loading("正在处理中,请稍后...");
  508. var config = {
  509. url: url,
  510. type: "post",
  511. dataType: "json",
  512. data: data,
  513. success: function(result) {
  514. $.operate.saveSuccess(result);
  515. }
  516. };
  517. $.ajax(config)
  518. },
  519. // 保存结果弹出msg刷新table表格
  520. ajaxSuccess: function (result) {
  521. if (result.code == web_status.SUCCESS) {
  522. $.modal.msgSuccess(result.msg);
  523. $.table.refresh();
  524. } else {
  525. $.modal.alertError(result.msg);
  526. }
  527. $.modal.closeLoading();
  528. },
  529. // 保存结果提示msg
  530. saveSuccess: function (result) {
  531. if (result.code == web_status.SUCCESS) {
  532. $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
  533. } else {
  534. $.modal.alertError(result.msg);
  535. }
  536. $.modal.closeLoading();
  537. }
  538. },
  539. // 校验封装处理
  540. validate: {
  541. // 判断返回标识是否唯一 false 不存在 true 存在
  542. unique: function (value) {
  543. if (value == "0") {
  544. return true;
  545. }
  546. return false;
  547. },
  548. // 表单验证
  549. form: function (formId) {
  550. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  551. return $("#" + currentId).validate().form();
  552. }
  553. },
  554. // 树插件封装处理
  555. tree: {
  556. _option: {},
  557. _lastValue: {},
  558. // 初始化树结构
  559. init: function(options) {
  560. $.tree._option = options;
  561. // 属性ID
  562. var _id = $.common.isEmpty(options.id) ? "tree" : options.id;
  563. // 展开等级节点
  564. var _expandLevel = $.common.isEmpty(options.expandLevel) ? 0 : options.expandLevel;
  565. // 树结构初始化加载
  566. var setting = {
  567. check: options.check,
  568. view: { selectedMulti: false, nameIsHTML: true },
  569. data: { key: { title: "title" }, simpleData: { enable: true } },
  570. callback: { onClick: options.onClick }
  571. };
  572. $.get(options.url, function(data) {
  573. var treeName = $("#treeName").val();
  574. var treeId = $("#treeId").val();
  575. tree = $.fn.zTree.init($("#" + _id), setting, data);
  576. $._tree = tree;
  577. // 展开第一级节点
  578. var nodes = tree.getNodesByParam("level", 0);
  579. for (var i = 0; i < nodes.length; i++) {
  580. if(_expandLevel > 0) {
  581. tree.expandNode(nodes[i], true, false, false);
  582. }
  583. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  584. }
  585. // 展开第二级节点
  586. nodes = tree.getNodesByParam("level", 1);
  587. for (var i = 0; i < nodes.length; i++) {
  588. if(_expandLevel > 1) {
  589. tree.expandNode(nodes[i], true, false, false);
  590. }
  591. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  592. }
  593. // 展开第三级节点
  594. nodes = tree.getNodesByParam("level", 2);
  595. for (var i = 0; i < nodes.length; i++) {
  596. if(_expandLevel > 2) {
  597. tree.expandNode(nodes[i], true, false, false);
  598. }
  599. $.tree.selectByIdName(treeId, treeName, nodes[i]);
  600. }
  601. }, null, null, "正在加载,请稍后...");
  602. },
  603. // 搜索节点
  604. searchNode: function() {
  605. // 取得输入的关键字的值
  606. var value = $.common.trim($("#keyword").val());
  607. if ($.tree._lastValue === value) {
  608. return;
  609. }
  610. // 保存最后一次搜索名称
  611. $.tree._lastValue = value;
  612. var nodes = $._tree.getNodes();
  613. // 如果要查空字串,就退出不查了。
  614. if (value == "") {
  615. $.tree.showAllNode(nodes);
  616. return;
  617. }
  618. $.tree.hideAllNode(nodes);
  619. // 根据搜索值模糊匹配
  620. $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
  621. },
  622. // 根据Id和Name选中指定节点
  623. selectByIdName: function(treeId, treeName, node) {
  624. if ($.common.isNotEmpty(treeName) && $.common.isNotEmpty(treeId)) {
  625. if (treeId == node.id && treeName == node.name) {
  626. $._tree.selectNode(node, true);
  627. }
  628. }
  629. },
  630. // 显示所有节点
  631. showAllNode: function(nodes) {
  632. nodes = $._tree.transformToArray(nodes);
  633. for (var i = nodes.length - 1; i >= 0; i--) {
  634. if (nodes[i].getParentNode() != null) {
  635. $._tree.expandNode(nodes[i], true, false, false, false);
  636. } else {
  637. $._tree.expandNode(nodes[i], true, true, false, false);
  638. }
  639. $._tree.showNode(nodes[i]);
  640. $.tree.showAllNode(nodes[i].children);
  641. }
  642. },
  643. // 隐藏所有节点
  644. hideAllNode: function(nodes) {
  645. var tree = $.fn.zTree.getZTreeObj("tree");
  646. var nodes = $._tree.transformToArray(nodes);
  647. for (var i = nodes.length - 1; i >= 0; i--) {
  648. $._tree.hideNode(nodes[i]);
  649. }
  650. },
  651. // 显示所有父节点
  652. showParent: function(treeNode) {
  653. var parentNode;
  654. while ((parentNode = treeNode.getParentNode()) != null) {
  655. $._tree.showNode(parentNode);
  656. $._tree.expandNode(parentNode, true, false, false);
  657. treeNode = parentNode;
  658. }
  659. },
  660. // 显示所有孩子节点
  661. showChildren: function(treeNode) {
  662. if (treeNode.isParent) {
  663. for (var idx in treeNode.children) {
  664. var node = treeNode.children[idx];
  665. $._tree.showNode(node);
  666. $.tree.showChildren(node);
  667. }
  668. }
  669. },
  670. // 更新节点状态
  671. updateNodes: function(nodeList) {
  672. $._tree.showNodes(nodeList);
  673. for (var i = 0, l = nodeList.length; i < l; i++) {
  674. var treeNode = nodeList[i];
  675. $.tree.showChildren(treeNode);
  676. $.tree.showParent(treeNode)
  677. }
  678. },
  679. // 获取当前被勾选集合
  680. getCheckedNodes: function(column) {
  681. var _column = $.common.isEmpty(column) ? "id" : column;
  682. var nodes = $._tree.getCheckedNodes(true);
  683. return $.map(nodes, function (row) {
  684. return row[_column];
  685. }).join();
  686. },
  687. // 不允许根父节点选择
  688. notAllowParents: function(_tree) {
  689. var nodes = _tree.getSelectedNodes();
  690. for (var i = 0; i < nodes.length; i++) {
  691. if (nodes[i].level == 0) {
  692. $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
  693. return false;
  694. }
  695. if (nodes[i].isParent) {
  696. $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
  697. return false;
  698. }
  699. }
  700. return true;
  701. },
  702. // 隐藏/显示搜索栏
  703. toggleSearch: function() {
  704. $('#search').slideToggle(200);
  705. $('#btnShow').toggle();
  706. $('#btnHide').toggle();
  707. $('#keyword').focus();
  708. },
  709. // 折叠
  710. collapse: function() {
  711. $._tree.expandAll(false);
  712. },
  713. // 展开
  714. expand: function() {
  715. $._tree.expandAll(true);
  716. }
  717. },
  718. // 通用方法封装处理
  719. common: {
  720. // 判断字符串是否为空
  721. isEmpty: function (value) {
  722. if (value == null || this.trim(value) == "") {
  723. return true;
  724. }
  725. return false;
  726. },
  727. // 判断一个字符串是否为非空串
  728. isNotEmpty: function (value) {
  729. return !$.common.isEmpty(value);
  730. },
  731. // 是否显示数据 为空默认为显示
  732. visible: function (value) {
  733. if ($.common.isEmpty(value) || value == true) {
  734. return true;
  735. }
  736. return false;
  737. },
  738. // 空格截取
  739. trim: function (value) {
  740. if (value == null) {
  741. return "";
  742. }
  743. return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  744. },
  745. // 指定随机数返回
  746. random: function (min, max) {
  747. return Math.floor((Math.random() * max) + min);
  748. }
  749. }
  750. });
  751. })(jQuery);
  752. /** 消息状态码 */
  753. web_status = {
  754. SUCCESS: 0,
  755. FAIL: 500
  756. };
  757. /** 弹窗状态码 */
  758. modal_status = {
  759. SUCCESS: "success",
  760. FAIL: "error",
  761. WARNING: "warning"
  762. };