ry-ui.js 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845
  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. addToSet: function(id, width, height){
  1146. table.set();
  1147. $.modal.openFull("添加" + table.options.modalName, $.operate.addUrl(id), width, height)
  1148. },
  1149. // 添加信息,以tab页展现
  1150. addTab: function (id) {
  1151. table.set();
  1152. $.modal.openTab("添加" + table.options.modalName, $.operate.addUrl(id));
  1153. },
  1154. // 添加信息 全屏
  1155. addFull: function(id) {
  1156. table.set();
  1157. $.modal.openFull("添加" + table.options.modalName, $.operate.addUrl(id));
  1158. },
  1159. // 添加访问地址
  1160. addUrl: function(id) {
  1161. var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id);
  1162. return url;
  1163. },
  1164. // 兑换礼品
  1165. exchange: function(id) {
  1166. table.set();
  1167. if ($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
  1168. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  1169. var url = table.options.exchangeUrl.replace("{id}", row[table.options.uniqueId]);
  1170. $.modal.open("兑换" + table.options.modalName, url);
  1171. } else {
  1172. $.modal.open("兑换" + table.options.modalName, $.operate.changeUrl(id));
  1173. }
  1174. },
  1175. // 兑换礼品访问地址
  1176. changeUrl: function(id) {
  1177. var url = "/404.html";
  1178. if ($.common.isNotEmpty(id)) {
  1179. url = table.options.exchangeUrl.replace("{id}", id);
  1180. } else {
  1181. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1182. url = table.options.exchangeUrl.replace("{id}", id);
  1183. }
  1184. return url;
  1185. },
  1186. // 修改信息
  1187. edit: function(id) {
  1188. table.set();
  1189. if ($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
  1190. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  1191. if ($.common.isEmpty(row)) {
  1192. $.modal.alertWarning("请至少选择一条记录");
  1193. return;
  1194. }
  1195. var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
  1196. $.modal.open("修改" + table.options.modalName, url);
  1197. } else {
  1198. $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id));
  1199. }
  1200. },
  1201. editToSet: function(id){
  1202. table.set();
  1203. if ($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
  1204. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  1205. if ($.common.isEmpty(row)) {
  1206. $.modal.alertWarning("请至少选择一条记录");
  1207. return;
  1208. }
  1209. var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
  1210. $.modal.openFull("修改" + table.options.modalName, url);
  1211. } else {
  1212. $.modal.openFull("修改" + table.options.modalName, $.operate.editUrl(id));
  1213. }
  1214. },
  1215. publish: function(id, dataName){
  1216. table.set();
  1217. $.modal.confirm("确定发布该条" + dataName + "信息吗?<br/>发布后赛事信息无法修改!", function() {
  1218. var url = $.common.isEmpty(id) ? table.options.publishUrl : table.options.publishUrl.replace("{id}", id);
  1219. if (table.options.type == table_type.bootstrapTreeTable) {
  1220. $.operate.get(url);
  1221. } else {
  1222. var data = { "id": id };
  1223. $.operate.submit(url, "post", "json", data);
  1224. }
  1225. });
  1226. },
  1227. // 修改信息,以tab页展现
  1228. editTab: function(id) {
  1229. table.set();
  1230. $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id));
  1231. },
  1232. // 修改信息 全屏
  1233. editFull: function(id) {
  1234. table.set();
  1235. var url = "/404.html";
  1236. if ($.common.isNotEmpty(id)) {
  1237. url = table.options.updateUrl.replace("{id}", id);
  1238. } else {
  1239. if (table.options.type == table_type.bootstrapTreeTable) {
  1240. var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
  1241. if ($.common.isEmpty(row)) {
  1242. $.modal.alertWarning("请至少选择一条记录");
  1243. return;
  1244. }
  1245. url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
  1246. } else {
  1247. var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1248. url = table.options.updateUrl.replace("{id}", row);
  1249. }
  1250. }
  1251. $.modal.openFull("修改" + table.options.modalName, url);
  1252. },
  1253. // 修改访问地址
  1254. editUrl: function(id) {
  1255. var url = "/404.html";
  1256. if ($.common.isNotEmpty(id)) {
  1257. url = table.options.updateUrl.replace("{id}", id);
  1258. } else {
  1259. var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
  1260. if (id.length == 0) {
  1261. $.modal.alertWarning("请至少选择一条记录");
  1262. return;
  1263. }
  1264. url = table.options.updateUrl.replace("{id}", id);
  1265. }
  1266. return url;
  1267. },
  1268. // 右侧弹出详情
  1269. view: function(id){
  1270. table.set();
  1271. var url = table.options.viewUrl.replace("{id}", id);
  1272. $.modal.popupRight(table.options.modalName + "信息详情", url);
  1273. },
  1274. // 保存信息 刷新表格
  1275. save: function(url, data, callback) {
  1276. var config = {
  1277. url: url,
  1278. type: "post",
  1279. dataType: "json",
  1280. data: data,
  1281. beforeSend: function () {
  1282. $.modal.loading("正在处理中,请稍候...");
  1283. $.modal.disable();
  1284. },
  1285. success: function(result) {
  1286. if (typeof callback == "function") {
  1287. callback(result);
  1288. }
  1289. $.operate.successCallback(result);
  1290. }
  1291. };
  1292. $.ajax(config)
  1293. },
  1294. // 保存信息 弹出结果提示框
  1295. saveModal: function(url, data, callback) {
  1296. var config = {
  1297. url: url,
  1298. type: "post",
  1299. dataType: "json",
  1300. data: data,
  1301. beforeSend: function () {
  1302. $.modal.loading("正在处理中,请稍候...");
  1303. },
  1304. success: function(result) {
  1305. if (typeof callback == "function") {
  1306. callback(result);
  1307. }
  1308. if (result.code == web_status.SUCCESS) {
  1309. $.modal.alertSuccess(result.msg)
  1310. } else if (result.code == web_status.WARNING) {
  1311. $.modal.alertWarning(result.msg)
  1312. } else {
  1313. $.modal.alertError(result.msg);
  1314. }
  1315. $.modal.closeLoading();
  1316. }
  1317. };
  1318. $.ajax(config)
  1319. },
  1320. // 保存选项卡信息
  1321. saveTab: function(url, data, callback) {
  1322. var config = {
  1323. url: url,
  1324. type: "post",
  1325. dataType: "json",
  1326. data: data,
  1327. beforeSend: function () {
  1328. $.modal.loading("正在处理中,请稍候...");
  1329. },
  1330. success: function(result) {
  1331. if (typeof callback == "function") {
  1332. callback(result);
  1333. }
  1334. $.operate.successTabCallback(result);
  1335. }
  1336. };
  1337. $.ajax(config)
  1338. },
  1339. // 保存结果弹出msg刷新table表格
  1340. ajaxSuccess: function (result) {
  1341. if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTable) {
  1342. $.modal.msgSuccess(result.msg);
  1343. $.table.refresh();
  1344. } else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) {
  1345. $.modal.msgSuccess(result.msg);
  1346. $.treeTable.refresh();
  1347. } else if (result.code == web_status.SUCCESS && $.common.isEmpty(table.options.type)) {
  1348. $.modal.msgSuccess(result.msg)
  1349. } else if (result.code == web_status.WARNING) {
  1350. $.modal.alertWarning(result.msg)
  1351. } else {
  1352. $.modal.alertError(result.msg);
  1353. }
  1354. $.modal.closeLoading();
  1355. },
  1356. // 保存结果重新加载页面
  1357. saveReload: function (result) {
  1358. if (result.code == web_status.SUCCESS) {
  1359. $.modal.msgSuccessReload(result.msg);
  1360. } else if (result.code == web_status.WARNING) {
  1361. $.modal.alertWarning(result.msg)
  1362. } else {
  1363. $.modal.alertError(result.msg);
  1364. }
  1365. $.modal.closeLoading();
  1366. },
  1367. // 成功回调执行事件(父窗体静默更新)
  1368. successCallback: function(result) {
  1369. if (result.code == web_status.SUCCESS) {
  1370. var parent = activeWindow();
  1371. if ($.common.isEmpty(parent.table)) {
  1372. $.modal.msgSuccessReload(result.msg);
  1373. } else if (parent.table.options.type == table_type.bootstrapTable) {
  1374. $.modal.close();
  1375. parent.$.modal.msgSuccess(result.msg);
  1376. parent.$.table.refresh();
  1377. } else if (parent.table.options.type == table_type.bootstrapTreeTable) {
  1378. $.modal.close();
  1379. parent.$.modal.msgSuccess(result.msg);
  1380. parent.$.treeTable.refresh();
  1381. }
  1382. } else if (result.code == web_status.WARNING) {
  1383. $.modal.alertWarning(result.msg)
  1384. } else {
  1385. $.modal.alertError(result.msg);
  1386. }
  1387. $.modal.closeLoading();
  1388. $.modal.enable();
  1389. },
  1390. // 选项卡成功回调执行事件(父窗体静默更新)
  1391. successTabCallback: function(result) {
  1392. if (result.code == web_status.SUCCESS) {
  1393. var topWindow = $(window.parent.document);
  1394. var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel');
  1395. var topWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0];
  1396. if ($.common.isNotEmpty(topWindow) && $.common.isNotEmpty(currentId)) {
  1397. var $contentWindow = topWindow.contentWindow;
  1398. $contentWindow.$.modal.msgSuccess(result.msg);
  1399. $contentWindow.$(".layui-layer-padding").removeAttr("style");
  1400. if ($contentWindow.table.options.type == table_type.bootstrapTable) {
  1401. $contentWindow.$.table.refresh();
  1402. } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) {
  1403. $contentWindow.$.treeTable.refresh();
  1404. }
  1405. } else {
  1406. $.modal.msgSuccess(result.msg);
  1407. }
  1408. $.modal.close();
  1409. $.modal.closeTab();
  1410. } else if (result.code == web_status.WARNING) {
  1411. $.modal.alertWarning(result.msg)
  1412. } else {
  1413. $.modal.alertError(result.msg);
  1414. }
  1415. $.modal.closeLoading();
  1416. }
  1417. },
  1418. // 校验封装处理
  1419. validate: {
  1420. // 表单验证
  1421. form: function (formId) {
  1422. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1423. return $("#" + currentId).validate().form();
  1424. },
  1425. // 重置表单验证(清除提示信息)
  1426. reset: function (formId) {
  1427. var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
  1428. return $("#" + currentId).validate().resetForm();
  1429. }
  1430. },
  1431. // 树插件封装处理
  1432. tree: {
  1433. _option: {},
  1434. _lastValue: {},
  1435. // 初始化树结构
  1436. init: function(options) {
  1437. var defaults = {
  1438. id: "tree", // 属性ID
  1439. expandLevel: 0, // 展开等级节点
  1440. view: {
  1441. selectedMulti: false, // 设置是否允许同时选中多个节点
  1442. nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本
  1443. },
  1444. check: {
  1445. enable: false, // 置 zTree 的节点上是否显示 checkbox / radio
  1446. nocheckInherit: true, // 设置子节点是否自动继承
  1447. chkboxType: { "Y": "ps", "N": "ps" } // 父子节点的关联关系
  1448. },
  1449. data: {
  1450. key: {
  1451. title: "title" // 节点数据保存节点提示信息的属性名称
  1452. },
  1453. simpleData: {
  1454. enable: true // true / false 分别表示 使用 / 不使用 简单数据模式
  1455. }
  1456. },
  1457. };
  1458. var options = $.extend(defaults, options);
  1459. $.tree._option = options;
  1460. // 树结构初始化加载
  1461. var setting = {
  1462. callback: {
  1463. onClick: options.onClick, // 用于捕获节点被点击的事件回调函数
  1464. onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数
  1465. onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数
  1466. },
  1467. check: options.check,
  1468. view: options.view,
  1469. data: options.data
  1470. };
  1471. $.get(options.url, function(data) {
  1472. var treeId = $("#treeId").val();
  1473. tree = $.fn.zTree.init($("#" + options.id), setting, data);
  1474. $._tree = tree;
  1475. for (var i = 0; i < options.expandLevel; i++) {
  1476. var nodes = tree.getNodesByParam("level", i);
  1477. for (var j = 0; j < nodes.length; j++) {
  1478. tree.expandNode(nodes[j], true, false, false);
  1479. }
  1480. }
  1481. var node = tree.getNodesByParam("id", treeId, null)[0];
  1482. $.tree.selectByIdName(treeId, node);
  1483. // 回调tree方法
  1484. if (typeof(options.callBack) === "function"){
  1485. options.callBack(tree);
  1486. }
  1487. });
  1488. },
  1489. // 搜索节点
  1490. searchNode: function() {
  1491. // 取得输入的关键字的值
  1492. var value = $.common.trim($("#keyword").val());
  1493. if ($.tree._lastValue == value) {
  1494. return;
  1495. }
  1496. // 保存最后一次搜索名称
  1497. $.tree._lastValue = value;
  1498. var nodes = $._tree.getNodes();
  1499. // 如果要查空字串,就退出不查了。
  1500. if (value == "") {
  1501. $.tree.showAllNode(nodes);
  1502. return;
  1503. }
  1504. $.tree.hideAllNode(nodes);
  1505. // 根据搜索值模糊匹配
  1506. $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value));
  1507. },
  1508. // 根据Id和Name选中指定节点
  1509. selectByIdName: function(treeId, node) {
  1510. if ($.common.isNotEmpty(treeId) && node && treeId == node.id) {
  1511. $._tree.selectNode(node, true);
  1512. }
  1513. },
  1514. // 显示所有节点
  1515. showAllNode: function(nodes) {
  1516. nodes = $._tree.transformToArray(nodes);
  1517. for (var i = nodes.length - 1; i >= 0; i--) {
  1518. if (nodes[i].getParentNode() != null) {
  1519. $._tree.expandNode(nodes[i], true, false, false, false);
  1520. } else {
  1521. $._tree.expandNode(nodes[i], true, true, false, false);
  1522. }
  1523. $._tree.showNode(nodes[i]);
  1524. $.tree.showAllNode(nodes[i].children);
  1525. }
  1526. },
  1527. // 隐藏所有节点
  1528. hideAllNode: function(nodes) {
  1529. var nodes = $._tree.transformToArray(nodes);
  1530. for (var i = nodes.length - 1; i >= 0; i--) {
  1531. $._tree.hideNode(nodes[i]);
  1532. }
  1533. },
  1534. // 显示所有父节点
  1535. showParent: function(treeNode) {
  1536. var parentNode;
  1537. while ((parentNode = treeNode.getParentNode()) != null) {
  1538. $._tree.showNode(parentNode);
  1539. $._tree.expandNode(parentNode, true, false, false);
  1540. treeNode = parentNode;
  1541. }
  1542. },
  1543. // 显示所有孩子节点
  1544. showChildren: function(treeNode) {
  1545. if (treeNode.isParent) {
  1546. for (var idx in treeNode.children) {
  1547. var node = treeNode.children[idx];
  1548. $._tree.showNode(node);
  1549. $.tree.showChildren(node);
  1550. }
  1551. }
  1552. },
  1553. // 更新节点状态
  1554. updateNodes: function(nodeList) {
  1555. $._tree.showNodes(nodeList);
  1556. for (var i = 0, l = nodeList.length; i < l; i++) {
  1557. var treeNode = nodeList[i];
  1558. $.tree.showChildren(treeNode);
  1559. $.tree.showParent(treeNode)
  1560. }
  1561. },
  1562. // 获取当前被勾选集合
  1563. getCheckedNodes: function(column) {
  1564. var _column = $.common.isEmpty(column) ? "id" : column;
  1565. var nodes = $._tree.getCheckedNodes(true);
  1566. return $.map(nodes, function (row) {
  1567. return row[_column];
  1568. }).join();
  1569. },
  1570. // 不允许根父节点选择
  1571. notAllowParents: function(_tree) {
  1572. var nodes = _tree.getSelectedNodes();
  1573. if (nodes.length == 0){
  1574. $.modal.msgError("请选择节点后提交");
  1575. return false;
  1576. }
  1577. for (var i = 0; i < nodes.length; i++) {
  1578. if (nodes[i].level == 0) {
  1579. $.modal.msgError("不能选择根节点(" + nodes[i].name + ")");
  1580. return false;
  1581. }
  1582. if (nodes[i].isParent) {
  1583. $.modal.msgError("不能选择父节点(" + nodes[i].name + ")");
  1584. return false;
  1585. }
  1586. }
  1587. return true;
  1588. },
  1589. // 不允许最后层级节点选择
  1590. notAllowLastLevel: function(_tree) {
  1591. var nodes = _tree.getSelectedNodes();
  1592. for (var i = 0; i < nodes.length; i++) {
  1593. if (!nodes[i].isParent) {
  1594. $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")");
  1595. return false;
  1596. }
  1597. }
  1598. return true;
  1599. },
  1600. // 隐藏/显示搜索栏
  1601. toggleSearch: function() {
  1602. $('#search').slideToggle(200);
  1603. $('#btnShow').toggle();
  1604. $('#btnHide').toggle();
  1605. $('#keyword').focus();
  1606. },
  1607. // 折叠
  1608. collapse: function() {
  1609. $._tree.expandAll(false);
  1610. },
  1611. // 展开
  1612. expand: function() {
  1613. $._tree.expandAll(true);
  1614. }
  1615. },
  1616. // 通用方法封装处理
  1617. common: {
  1618. // 判断字符串是否为空
  1619. isEmpty: function (value) {
  1620. if (value == null || this.trim(value) == "" || value == undefined || value == "undefined") {
  1621. return true;
  1622. }
  1623. return false;
  1624. },
  1625. // 判断一个字符串是否为非空串
  1626. isNotEmpty: function (value) {
  1627. return !$.common.isEmpty(value);
  1628. },
  1629. // 如果值是空,则返回指定默认字符串,否则返回字符串本身
  1630. nullToDefault: function (value, defaultValue) {
  1631. return $.common.isEmpty(value) ? defaultValue : value;
  1632. },
  1633. // 空对象转字符串
  1634. nullToStr: function(value) {
  1635. if ($.common.isEmpty(value)) {
  1636. return "-";
  1637. }
  1638. return value;
  1639. },
  1640. // 是否显示数据 为空默认为显示
  1641. visible: function (value) {
  1642. if ($.common.isEmpty(value) || value == true) {
  1643. return true;
  1644. }
  1645. return false;
  1646. },
  1647. // 空格截取
  1648. trim: function (value) {
  1649. if (value == null) {
  1650. return "";
  1651. }
  1652. return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
  1653. },
  1654. // 比较两个字符串(大小写敏感)
  1655. equals: function (str, that) {
  1656. return str == that;
  1657. },
  1658. // 比较两个字符串(大小写不敏感)
  1659. equalsIgnoreCase: function (str, that) {
  1660. return String(str).toUpperCase() === String(that).toUpperCase();
  1661. },
  1662. // 将字符串按指定字符分割
  1663. split: function (str, sep, maxLen) {
  1664. if ($.common.isEmpty(str)) {
  1665. return null;
  1666. }
  1667. var value = String(str).split(sep);
  1668. return maxLen ? value.slice(0, maxLen - 1) : value;
  1669. },
  1670. // 字符串格式化(%s )
  1671. sprintf: function (str) {
  1672. var args = arguments, flag = true, i = 1;
  1673. str = str.replace(/%s/g, function () {
  1674. var arg = args[i++];
  1675. if (typeof arg === 'undefined') {
  1676. flag = false;
  1677. return '';
  1678. }
  1679. return arg == null ? '' : arg;
  1680. });
  1681. return flag ? str : '';
  1682. },
  1683. // 日期格式化 时间戳 -> yyyy-MM-dd HH-mm-ss
  1684. dateFormat: function(date, format) {
  1685. var that = this;
  1686. if (that.isEmpty(date)) return "";
  1687. if (!date) return;
  1688. if (!format) format = "yyyy-MM-dd";
  1689. switch (typeof date) {
  1690. case "string":
  1691. date = new Date(date.replace(/-/g, "/"));
  1692. break;
  1693. case "number":
  1694. date = new Date(date);
  1695. break;
  1696. }
  1697. if (!date instanceof Date) return;
  1698. var dict = {
  1699. "yyyy": date.getFullYear(),
  1700. "M": date.getMonth() + 1,
  1701. "d": date.getDate(),
  1702. "H": date.getHours(),
  1703. "m": date.getMinutes(),
  1704. "s": date.getSeconds(),
  1705. "MM": ("" + (date.getMonth() + 101)).substr(1),
  1706. "dd": ("" + (date.getDate() + 100)).substr(1),
  1707. "HH": ("" + (date.getHours() + 100)).substr(1),
  1708. "mm": ("" + (date.getMinutes() + 100)).substr(1),
  1709. "ss": ("" + (date.getSeconds() + 100)).substr(1)
  1710. };
  1711. return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g,
  1712. function() {
  1713. return dict[arguments[0]];
  1714. });
  1715. },
  1716. // 获取节点数据,支持多层级访问
  1717. getItemField: function (item, field) {
  1718. var value = item;
  1719. if (typeof field !== 'string' || item.hasOwnProperty(field)) {
  1720. return item[field];
  1721. }
  1722. var props = field.split('.');
  1723. for (var p in props) {
  1724. value = value && value[props[p]];
  1725. }
  1726. return value;
  1727. },
  1728. // 指定随机数返回
  1729. random: function (min, max) {
  1730. return Math.floor((Math.random() * max) + min);
  1731. },
  1732. // 判断字符串是否是以start开头
  1733. startWith: function(value, start) {
  1734. var reg = new RegExp("^" + start);
  1735. return reg.test(value)
  1736. },
  1737. // 判断字符串是否是以end结尾
  1738. endWith: function(value, end) {
  1739. var reg = new RegExp(end + "$");
  1740. return reg.test(value)
  1741. },
  1742. // 数组去重
  1743. uniqueFn: function(array) {
  1744. var result = [];
  1745. var hashObj = {};
  1746. for (var i = 0; i < array.length; i++) {
  1747. if (!hashObj[array[i]]) {
  1748. hashObj[array[i]] = true;
  1749. result.push(array[i]);
  1750. }
  1751. }
  1752. return result;
  1753. },
  1754. // 数组中的所有元素放入一个字符串
  1755. join: function(array, separator) {
  1756. if ($.common.isEmpty(array)) {
  1757. return null;
  1758. }
  1759. return array.join(separator);
  1760. },
  1761. // 获取form下所有的字段并转换为json对象
  1762. formToJSON: function(formId) {
  1763. var json = {};
  1764. $.each($("#" + formId).serializeArray(), function(i, field) {
  1765. if (json[field.name]) {
  1766. json[field.name] += ("," + field.value);
  1767. } else {
  1768. json[field.name] = field.value;
  1769. }
  1770. });
  1771. return json;
  1772. },
  1773. // 数据字典转下拉框
  1774. dictToSelect: function(datas, value, name) {
  1775. var actions = [];
  1776. actions.push($.common.sprintf("<select class='form-control' name='%s'>", name));
  1777. $.each(datas, function(index, dict) {
  1778. actions.push($.common.sprintf("<option value='%s'", dict.dictValue));
  1779. if (dict.dictValue == ('' + value)) {
  1780. actions.push(' selected');
  1781. }
  1782. actions.push($.common.sprintf(">%s</option>", dict.dictLabel));
  1783. });
  1784. actions.push('</select>');
  1785. return actions.join('');
  1786. },
  1787. // 获取obj对象长度
  1788. getLength: function(obj) {
  1789. var count = 0;  
  1790. for (var i in obj) {
  1791. if (obj.hasOwnProperty(i)) {
  1792. count++;
  1793. }  
  1794. }
  1795. return count;
  1796. },
  1797. // 判断移动端
  1798. isMobile: function () {
  1799. return navigator.userAgent.match(/(Android|iPhone|SymbianOS|Windows Phone|iPad|iPod)/i);
  1800. },
  1801. // 数字正则表达式,只能为0-9数字
  1802. numValid : function(text){
  1803. var patten = new RegExp(/^[0-9]+$/);
  1804. return patten.test(text);
  1805. },
  1806. // 英文正则表达式,只能为a-z和A-Z字母
  1807. enValid : function(text){
  1808. var patten = new RegExp(/^[a-zA-Z]+$/);
  1809. return patten.test(text);
  1810. },
  1811. // 英文、数字正则表达式,必须包含(字母,数字)
  1812. enNumValid : function(text){
  1813. var patten = new RegExp(/^(?=.*[a-zA-Z]+)(?=.*[0-9]+)[a-zA-Z0-9]+$/);
  1814. return patten.test(text);
  1815. },
  1816. // 英文、数字、特殊字符正则表达式,必须包含(字母,数字,特殊字符!@#$%^&*()-=_+)
  1817. charValid : function(text){
  1818. var patten = new RegExp(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[~!@#\$%\^&\*\(\)\-=_\+])[A-Za-z\d~!@#\$%\^&\*\(\)\-=_\+]{6,}$/);
  1819. return patten.test(text);
  1820. },
  1821. }
  1822. });
  1823. })(jQuery);
  1824. /** 表格类型 */
  1825. table_type = {
  1826. bootstrapTable: 0,
  1827. bootstrapTreeTable: 1
  1828. };
  1829. /** 消息状态码 */
  1830. web_status = {
  1831. SUCCESS: 0,
  1832. FAIL: 500,
  1833. WARNING: 301
  1834. };
  1835. /** 弹窗状态码 */
  1836. modal_status = {
  1837. SUCCESS: "success",
  1838. FAIL: "error",
  1839. WARNING: "warning"
  1840. };