xuwell.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. 
  2. var xuwell = {
  3. //加载数据到Select控件,参数:id url data fieldKey fieldValue autoDisabled
  4. 'loadSelect': function (opt) {
  5. var id = typeof (opt.id) == 'undefined' ? null : opt.id;
  6. var url = typeof (opt.url) == 'undefined' ? null : opt.url;
  7. var data = typeof (opt.data) == 'undefined' ? null : opt.data;
  8. var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey;
  9. var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue;
  10. var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false;
  11. var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle;
  12. var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad;
  13. var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError;
  14. $.get(url, data, function (result) {
  15. var json = JSON.parse(result);
  16. if (json['success'] == true) {
  17. var temp = '<option value="$key$">$value$</option>';
  18. $(id).empty();
  19. if (addTitle) $(id).append('<option value="">请选择...</option>');
  20. for (var i = 0; i < json['rows'].length; i++) {
  21. $(id).append(temp
  22. .replace('$key$', json['rows'][i][fieldKey])
  23. .replace('$value$', json['rows'][i][fieldValue])
  24. );
  25. }
  26. $(id).prop('disabled', json['total'] == 0 && autoDisabled );
  27. $(id).get(0).selectedIndex = 0;
  28. if (onLoad != null) onLoad(json);
  29. }
  30. else {
  31. swal({
  32. title: '登录异常!',
  33. text: '请您先登录系统!',
  34. icon: 'error',
  35. button: '确定'
  36. }).then(function () {
  37. window.location = '../common/login.html';
  38. });
  39. }
  40. }).fail(function () {
  41. if (onError != null) onError();
  42. });
  43. },
  44. 'loadSelectPicker': function (opt) {
  45. var id = typeof (opt.id) == 'undefined' ? null : opt.id;
  46. var url = typeof (opt.url) == 'undefined' ? null : opt.url;
  47. var data = typeof (opt.data) == 'undefined' ? null : opt.data;
  48. var fieldKey = typeof (opt.fieldKey) == 'undefined' ? null : opt.fieldKey;
  49. var fieldValue = typeof (opt.fieldValue) == 'undefined' ? null : opt.fieldValue;
  50. var autoDisabled = typeof (opt.autoDisabled) == 'undefined' ? true : false;
  51. var addTitle = typeof (opt.addTitle) == 'undefined' ? true : opt.addTitle;
  52. var onLoad = typeof (opt.onLoad) == 'undefined' ? null : opt.onLoad;
  53. var onError = typeof (opt.onError) == 'undefined' ? null : opt.onError;
  54. $.get(url, data, function (result) {
  55. var json = JSON.parse(result);
  56. if (json['success'] == true) {
  57. var temp = '<option data-tokens="$key$">$value$</option>';
  58. $(id).empty();
  59. if (addTitle) $(id).append('<option data-tokens="" value="">请选择...</option>');
  60. for (var i = 0; i < json['rows'].length; i++) {
  61. $(id).append(temp
  62. .replace('$key$', json['rows'][i][fieldKey])
  63. .replace('$value$', json['rows'][i][fieldValue])
  64. );
  65. }
  66. $(id).prop('disabled', json['total'] == 0 && autoDisabled);
  67. $(id).get(0).selectedIndex = 0;
  68. $(id).selectpicker('refresh');
  69. if (onLoad != null) onLoad(json);
  70. }
  71. else {
  72. swal({
  73. title: '登录异常!',
  74. text: '请您先登录系统!',
  75. icon: 'error',
  76. button: '确定'
  77. }).then(function () {
  78. window.location = '../common/login.html';
  79. });
  80. }
  81. }).fail(function () {
  82. if (onError != null) onError();
  83. });
  84. },
  85. //加载bootstrapTable
  86. 'loadTable': function (opt) {
  87. var id = typeof (opt.id) == 'undefined' ? '#table' : opt.id;
  88. var toolbar = typeof (opt.toolbar) == 'undefined' ? '#toolbar' : opt.toolbar;
  89. var formSearchId = typeof (opt.formSearchId) == 'undefined' ? '#formSearch' : opt.formSearchId;
  90. var pageSize = typeof (opt.pageSize) == 'undefined' ? 10 : opt.pageSize;
  91. var pageNumber = typeof (opt.pageNumber) == 'undefined' ? 1 : opt.pageNumber;
  92. var sortable = typeof (opt.sortable) == 'undefined' ? false : opt.sortable;
  93. var url = typeof (opt.url) == 'undefined' ? '' : opt.url;
  94. $(id).bootstrapTable('destroy').bootstrapTable({
  95. toggle: "table",
  96. boolbar: toolbar,
  97. url: url,
  98. locale: "zh-CN",
  99. //showExport: true,  //是否显示导出按钮
  100. //exportdatatype: 'all',//basic', 'all', 'selected'.
  101. //exportOptions: {
  102. // ignoreColumn: [0, 1],  //忽略某一列的索引  
  103. // fileName: '导出数据',  //文件名称设置  
  104. // worksheetName: 'sheet1',  //表格工作区名称  
  105. // tableName: '数据',
  106. // excelstyles: ['background-color', 'color', 'font-size', 'font-weight', 'border-top']
  107. //},
  108. //buttonsAlign: "right",  //按钮位置
  109. //exportTypes: ['csv'],  //导出文件类型
  110. sortable: sortable,
  111. sortOrder: "asc",
  112. pagination: true,
  113. pageNumber: pageNumber,
  114. pageSize: pageSize,
  115. pageList: "[10, 100, 500, 1000, 2000, 5000, ALL]",
  116. striped: true,
  117. sidePagination: 'server',
  118. queryParams: function (params) {
  119. var args = $.param({
  120. pageNumber: params.offset / params.limit,
  121. pageSize: params.limit,
  122. sort: params.sort,
  123. order: params.order
  124. }) + "&" + $(formSearchId).serialize();
  125. return args;
  126. },
  127. responseHandler: function (res) {
  128. return res;
  129. },
  130. onLoadSuccess: function (json) {
  131. //var json = JSON.parse(data);
  132. if (json['success'] == false) {
  133. swal({
  134. title: '登录异常!',
  135. text: '请您先登录系统!',
  136. icon: 'error',
  137. button: '确定'
  138. }).then(function () {
  139. window.location = '../common/login.html';
  140. });
  141. }
  142. }
  143. });
  144. },
  145. 'exportFile': function exportFile(tableId, fileName) {
  146. /**
  147. * 表格导出
  148. * style="mso-number-format:'@';"
  149. * 1) 文本:'@'
  150. * 2) 日期:'yyyy/mm/dd'
  151. * 3) 数字:'#,##0.00'
  152. * 4) 货币:'¥#,##0.00'
  153. * 5) 百分比:'#0.00%'
  154. */
  155. if (tableId == 'undefined') tableId = 'table';
  156. if (fileName == 'undefined') fileName = '数据导出.xls';
  157. //获取表格
  158. var exportFileContent = document.getElementById(tableId).innerHTML;
  159. exportFileContent = '<table border="1">' + exportFileContent + '</table>';
  160. exportFileContent = exportFileContent.replace('<tfoot style="display: none;"><tr></tr></tfoot>', '');
  161. //使用Blob
  162. var blob = new Blob([exportFileContent], { type: "text/plain;charset=utf-8" });
  163. //解决中文乱码问题
  164. blob = new Blob([String.fromCharCode(0xFEFF), blob], { type: blob.type });
  165. //设置链接
  166. var link = window.URL.createObjectURL(blob);
  167. var a = document.createElement("a");
  168. a.download = fileName;
  169. a.href = link;
  170. document.body.appendChild(a);
  171. a.click();
  172. document.body.removeChild(a);
  173. }
  174. }