123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>线上巡店数据导出预览</title>
- <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css">
- <style>
- #loading {
- width: 100%;
- height: 100%;
- background-color: #cdcdcd;
- z-index: 99999;
- position: fixed;
- top: 0px;
- opacity: 50%;
- text-align: center;
- padding-top: 300px;
- }
- #loading i {
- font-size: 50px;
- }
- table {
- display: block;
- overflow: auto;
- position: relative;
- border-collapse: collapse;
- }
- table thead tr th {
- text-align: center;
- white-space: nowrap;
- }
- </style>
- </head>
- <body>
- <div>
- <table class="layui-table table_box" id="data-table">
- <thead class="tableHeader">
- <tr>
- {volist name="header1" id="h1"}
- <th rowspan="{$h1.rowspan??1}" colspan="{$h1.colspan??1}" class="{$h1.class}">{$h1.title|raw}</th>
- {/volist}
- </tr>
- {notempty name="header2"}
- <tr>
- {volist name="header2" id="h2"}
- <th rowspan="{$h2.rowspan??1}" colspan="{$h2.colspan??1}" class="{$h2.class}">{$h2.title|raw}</th>
- {/volist}
- </tr>
- {/notempty}
- {notempty name="header3"}
- <tr>
- {volist name="header3" id="h3"}
- <th class="{$h3.class}">{$h3.title|raw}</th>
- {/volist}
- </tr>
- {/notempty}
- </thead>
- <tbody class="table_tbody">
- </tbody>
- </table>
- </div>
- <div id="loading">
- <i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
- </div>
- <script src="/static/layuiadmin/layui/layui.js"></script>
- <script>
- //IE方法
- function getXlsFromTbl(inTblId, inWindow) {
- try {
- var allStr = "";
- var curStr = "";
- if (inTblId != null && inTblId != "" && inTblId != "null") {
- curStr = getTblData(inTblId, inWindow);
- }
- if (curStr != null) {
- allStr += curStr;
- }
- else {
- alert("你要导出的表不存在");
- return;
- }
- var fileName = getExcelFileName();
- doFileExport(fileName, allStr);
- }
- catch (e) {
- alert("导出发生异常:" + e.name + "->" + e.description + "!");
- }
- }
- function getTblData(inTbl, inWindow) {
- var rows = 0;
- var tblDocument = document;
- if (!!inWindow && inWindow != "") {
- if (!document.all(inWindow)) {
- return null;
- }
- else {
- tblDocument = eval(inWindow).document;
- }
- }
- var curTbl = tblDocument.getElementById(inTbl);
- var outStr = "";
- if (curTbl != null) {
- for (var j = 0; j < curTbl.rows.length; j++) {
- for (var i = 0; i < curTbl.rows[j].cells.length; i++) {
- if (i == 0 && rows > 0) {
- outStr += " t";
- rows -= 1;
- }
- outStr += curTbl.rows[j].cells[i].innerText + "t";
- if (curTbl.rows[j].cells[i].colSpan > 1) {
- for (var k = 0; k < curTbl.rows[j].cells[i].colSpan - 1; k++) {
- outStr += " t";
- }
- }
- if (i == 0) {
- if (rows == 0 && curTbl.rows[j].cells[i].rowSpan > 1) {
- rows = curTbl.rows[j].cells[i].rowSpan - 1;
- }
- }
- }
- outStr += "rn";
- }
- }
- else {
- outStr = null;
- alert(inTbl + "不存在 !");
- }
- return outStr;
- }
- function getExcelFileName() {
- var d = new Date();
- var curYear = d.getYear();
- var curMonth = "" + (d.getMonth() + 1);
- var curDate = "" + d.getDate();
- var curHour = "" + d.getHours();
- var curMinute = "" + d.getMinutes();
- var curSecond = "" + d.getSeconds();
- if (curMonth.length == 1) {
- curMonth = "0" + curMonth;
- }
- if (curDate.length == 1) {
- curDate = "0" + curDate;
- }
- if (curHour.length == 1) {
- curHour = "0" + curHour;
- }
- if (curMinute.length == 1) {
- curMinute = "0" + curMinute;
- }
- if (curSecond.length == 1) {
- curSecond = "0" + curSecond;
- }
- var fileName = "table" + "_" + curYear + curMonth + curDate + "_"
- + curHour + curMinute + curSecond + ".csv";
- return fileName;
- }
- function doFileExport(inName, inStr) {
- var xlsWin = null;
- if (!!document.all("glbHideFrm")) {
- xlsWin = glbHideFrm;
- }
- else {
- var width = 6;
- var height = 4;
- var openPara = "left=" + (window.screen.width / 2 - width / 2)
- + ",top=" + (window.screen.height / 2 - height / 2)
- + ",scrollbars=no,width=" + width + ",height=" + height;
- xlsWin = window.open("", "_blank", openPara);
- }
- xlsWin.document.write(inStr);
- xlsWin.document.close();
- xlsWin.document.execCommand('Saveas', true, inName);
- xlsWin.close();
- }
- //Chrome方法
- var idTmr;
- function getExplorer() {
- var explorer = window.navigator.userAgent;
- //ie
- if (explorer.indexOf("MSIE") >= 0) {
- return 'ie';
- }
- //firefox
- else if (explorer.indexOf("Firefox") >= 0) {
- return 'Firefox';
- }
- //Chrome
- else if (explorer.indexOf("Chrome") >= 0) {
- return 'Chrome';
- }
- //Opera
- else if (explorer.indexOf("Opera") >= 0) {
- return 'Opera';
- }
- //Safari
- else if (explorer.indexOf("Safari") >= 0) {
- return 'Safari';
- }
- }
- function method5(tableid) {
- if (getExplorer() == 'ie') {
- var curTbl = document.getElementById(tableid);
- var oXL = new ActiveXObject("Excel.Application");
- var oWB = oXL.Workbooks.Add();
- var xlsheet = oWB.Worksheets(1);
- var sel = document.body.createTextRange();
- sel.moveToElementText(curTbl);
- sel.select();
- sel.execCommand("Copy");
- xlsheet.Paste();
- oXL.Visible = true;
- try {
- var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
- } catch (e) {
- print("Nested catch caught " + e);
- } finally {
- oWB.SaveAs(fname);
- oWB.Close(savechanges = false);
- oXL.Quit();
- oXL = null;
- idTmr = window.setInterval("Cleanup();", 1);
- }
- }
- else {
- tableToExcel(tableid)
- }
- }
- function Cleanup() {
- window.clearInterval(idTmr);
- CollectGarbage();
- }
- var tableToExcel = (function () {
- var uri = 'data:application/vnd.ms-excel;base64,',
- 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>',
- base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
- format = function (s, c) {
- return s.replace(/{(\w+)}/g,
- function (m, p) { return c[p]; })
- }
- return function (table, name) {
- if (!table.nodeType) table = document.getElementById(table)
- var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
- window.location.href = uri + base64(format(template, ctx))
- }
- })()
- layui.config({
- base: '/static/layuiadmin/' //静态资源所在路径
- }).extend({
- index: 'lib/index' //主入口模块
- }).use(['form'], function () {
- var $ = layui.$;
- var row = eval('{$row|raw}');
- var getData = function (page) {
- $.ajax({
- url: location.href,
- data: { page },
- success: function (rs) {
- if (rs.code == 1) {
- layer.msg(res.msg);
- return;
- }
- rs.data.forEach(function (item) {
- let tr = document.createElement('tr');
- row.forEach(function (k) {
- let td = document.createElement('td');
- td.innerText = item[k.field];
- tr.appendChild(td);
- })
- $('.table_tbody').append(tr);
- });
- if (page < rs.page) {
- page++;
- getData(page);
- } else {
- $('#loading').hide();
- method5('data-table');
- }
- }
- });
- }
- getData(1);
- });
- </script>
- </body>
- </html>
|