ry-ui.js 86 KB

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