ry-ui.js 82 KB

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