ry-ui.js 85 KB

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