ry-ui.js 84 KB

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