ry-ui.js 93 KB

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