behavior_statistics_data_export.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>线上巡店数据导出预览</title>
  8. <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css">
  9. <style>
  10. #loading {
  11. width: 100%;
  12. height: 100%;
  13. background-color: #cdcdcd;
  14. z-index: 99999;
  15. position: fixed;
  16. top: 0px;
  17. opacity: 50%;
  18. text-align: center;
  19. padding-top: 300px;
  20. }
  21. #loading i {
  22. font-size: 50px;
  23. }
  24. table {
  25. display: block;
  26. overflow: auto;
  27. position: relative;
  28. border-collapse: collapse;
  29. }
  30. table thead tr th {
  31. text-align: center;
  32. white-space: nowrap;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div>
  38. <table class="layui-table table_box" id="data-table">
  39. <thead class="tableHeader">
  40. <tr>
  41. {volist name="header1" id="h1"}
  42. <th rowspan="{$h1.rowspan??1}" colspan="{$h1.colspan??1}" class="{$h1.class}">{$h1.title|raw}</th>
  43. {/volist}
  44. </tr>
  45. {notempty name="header2"}
  46. <tr>
  47. {volist name="header2" id="h2"}
  48. <th rowspan="{$h2.rowspan??1}" colspan="{$h2.colspan??1}" class="{$h2.class}">{$h2.title|raw}</th>
  49. {/volist}
  50. </tr>
  51. {/notempty}
  52. {notempty name="header3"}
  53. <tr>
  54. {volist name="header3" id="h3"}
  55. <th class="{$h3.class}">{$h3.title|raw}</th>
  56. {/volist}
  57. </tr>
  58. {/notempty}
  59. </thead>
  60. <tbody class="table_tbody">
  61. </tbody>
  62. </table>
  63. </div>
  64. <div id="loading">
  65. <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
  66. </div>
  67. <script src="/static/layuiadmin/layui/layui.js"></script>
  68. <script>
  69. //IE方法
  70. function getXlsFromTbl(inTblId, inWindow) {
  71. try {
  72. var allStr = "";
  73. var curStr = "";
  74. if (inTblId != null && inTblId != "" && inTblId != "null") {
  75. curStr = getTblData(inTblId, inWindow);
  76. }
  77. if (curStr != null) {
  78. allStr += curStr;
  79. }
  80. else {
  81. alert("你要导出的表不存在");
  82. return;
  83. }
  84. var fileName = getExcelFileName();
  85. doFileExport(fileName, allStr);
  86. }
  87. catch (e) {
  88. alert("导出发生异常:" + e.name + "->" + e.description + "!");
  89. }
  90. }
  91. function getTblData(inTbl, inWindow) {
  92. var rows = 0;
  93. var tblDocument = document;
  94. if (!!inWindow && inWindow != "") {
  95. if (!document.all(inWindow)) {
  96. return null;
  97. }
  98. else {
  99. tblDocument = eval(inWindow).document;
  100. }
  101. }
  102. var curTbl = tblDocument.getElementById(inTbl);
  103. var outStr = "";
  104. if (curTbl != null) {
  105. for (var j = 0; j < curTbl.rows.length; j++) {
  106. for (var i = 0; i < curTbl.rows[j].cells.length; i++) {
  107. if (i == 0 && rows > 0) {
  108. outStr += " t";
  109. rows -= 1;
  110. }
  111. outStr += curTbl.rows[j].cells[i].innerText + "t";
  112. if (curTbl.rows[j].cells[i].colSpan > 1) {
  113. for (var k = 0; k < curTbl.rows[j].cells[i].colSpan - 1; k++) {
  114. outStr += " t";
  115. }
  116. }
  117. if (i == 0) {
  118. if (rows == 0 && curTbl.rows[j].cells[i].rowSpan > 1) {
  119. rows = curTbl.rows[j].cells[i].rowSpan - 1;
  120. }
  121. }
  122. }
  123. outStr += "rn";
  124. }
  125. }
  126. else {
  127. outStr = null;
  128. alert(inTbl + "不存在 !");
  129. }
  130. return outStr;
  131. }
  132. function getExcelFileName() {
  133. var d = new Date();
  134. var curYear = d.getYear();
  135. var curMonth = "" + (d.getMonth() + 1);
  136. var curDate = "" + d.getDate();
  137. var curHour = "" + d.getHours();
  138. var curMinute = "" + d.getMinutes();
  139. var curSecond = "" + d.getSeconds();
  140. if (curMonth.length == 1) {
  141. curMonth = "0" + curMonth;
  142. }
  143. if (curDate.length == 1) {
  144. curDate = "0" + curDate;
  145. }
  146. if (curHour.length == 1) {
  147. curHour = "0" + curHour;
  148. }
  149. if (curMinute.length == 1) {
  150. curMinute = "0" + curMinute;
  151. }
  152. if (curSecond.length == 1) {
  153. curSecond = "0" + curSecond;
  154. }
  155. var fileName = "table" + "_" + curYear + curMonth + curDate + "_"
  156. + curHour + curMinute + curSecond + ".csv";
  157. return fileName;
  158. }
  159. function doFileExport(inName, inStr) {
  160. var xlsWin = null;
  161. if (!!document.all("glbHideFrm")) {
  162. xlsWin = glbHideFrm;
  163. }
  164. else {
  165. var width = 6;
  166. var height = 4;
  167. var openPara = "left=" + (window.screen.width / 2 - width / 2)
  168. + ",top=" + (window.screen.height / 2 - height / 2)
  169. + ",scrollbars=no,width=" + width + ",height=" + height;
  170. xlsWin = window.open("", "_blank", openPara);
  171. }
  172. xlsWin.document.write(inStr);
  173. xlsWin.document.close();
  174. xlsWin.document.execCommand('Saveas', true, inName);
  175. xlsWin.close();
  176. }
  177. //Chrome方法
  178. var idTmr;
  179. function getExplorer() {
  180. var explorer = window.navigator.userAgent;
  181. //ie
  182. if (explorer.indexOf("MSIE") >= 0) {
  183. return 'ie';
  184. }
  185. //firefox
  186. else if (explorer.indexOf("Firefox") >= 0) {
  187. return 'Firefox';
  188. }
  189. //Chrome
  190. else if (explorer.indexOf("Chrome") >= 0) {
  191. return 'Chrome';
  192. }
  193. //Opera
  194. else if (explorer.indexOf("Opera") >= 0) {
  195. return 'Opera';
  196. }
  197. //Safari
  198. else if (explorer.indexOf("Safari") >= 0) {
  199. return 'Safari';
  200. }
  201. }
  202. function method5(tableid) {
  203. if (getExplorer() == 'ie') {
  204. var curTbl = document.getElementById(tableid);
  205. var oXL = new ActiveXObject("Excel.Application");
  206. var oWB = oXL.Workbooks.Add();
  207. var xlsheet = oWB.Worksheets(1);
  208. var sel = document.body.createTextRange();
  209. sel.moveToElementText(curTbl);
  210. sel.select();
  211. sel.execCommand("Copy");
  212. xlsheet.Paste();
  213. oXL.Visible = true;
  214. try {
  215. var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
  216. } catch (e) {
  217. print("Nested catch caught " + e);
  218. } finally {
  219. oWB.SaveAs(fname);
  220. oWB.Close(savechanges = false);
  221. oXL.Quit();
  222. oXL = null;
  223. idTmr = window.setInterval("Cleanup();", 1);
  224. }
  225. }
  226. else {
  227. tableToExcel(tableid)
  228. }
  229. }
  230. function Cleanup() {
  231. window.clearInterval(idTmr);
  232. CollectGarbage();
  233. }
  234. var tableToExcel = (function () {
  235. var uri = 'data:application/vnd.ms-excel;base64,',
  236. template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></head><body><table>{table}</table></body></html>',
  237. base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
  238. format = function (s, c) {
  239. return s.replace(/{(\w+)}/g,
  240. function (m, p) { return c[p]; })
  241. }
  242. return function (table, name) {
  243. if (!table.nodeType) table = document.getElementById(table)
  244. var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
  245. window.location.href = uri + base64(format(template, ctx))
  246. }
  247. })()
  248. layui.config({
  249. base: '/static/layuiadmin/' //静态资源所在路径
  250. }).extend({
  251. index: 'lib/index' //主入口模块
  252. }).use(['form'], function () {
  253. var $ = layui.$;
  254. var row = eval('{$row|raw}');
  255. var getData = function (page) {
  256. $.ajax({
  257. url: location.href,
  258. data: { page },
  259. success: function (rs) {
  260. if (rs.code == 1) {
  261. layer.msg(res.msg);
  262. return;
  263. }
  264. rs.data.forEach(function (item) {
  265. let tr = document.createElement('tr');
  266. row.forEach(function (k) {
  267. let td = document.createElement('td');
  268. td.innerText = item[k.field];
  269. tr.appendChild(td);
  270. })
  271. $('.table_tbody').append(tr);
  272. });
  273. if (page < rs.page) {
  274. page++;
  275. getData(page);
  276. } else {
  277. $('#loading').hide();
  278. method5('data-table');
  279. }
  280. }
  281. });
  282. }
  283. getData(1);
  284. });
  285. </script>
  286. </body>
  287. </html>