ry-ui.js 71 KB

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