async_excel.jsp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <%@ page language="java" contentType="text/html; charset=utf-8"
  2. pageEncoding="utf-8"%>
  3. <%
  4. String path = request.getContextPath();
  5. String basePath = request.getScheme() + "://"
  6. + request.getServerName() + ":" + request.getServerPort()
  7. + path + "/";
  8. %>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  13. <title>数据导出</title>
  14. <link rel="icon" href="<%=basePath%>resource/images/icon_title.png"
  15. type="image/x-icon" />
  16. <style>
  17. body {
  18. font-family: Microsoft YaHei, Arial, Helvetica, "Lucida Grande",
  19. sans-serif;
  20. font-size: .875rem;
  21. line-height: 1.5rem;
  22. color: #40444f;
  23. background: #f5f9fa;
  24. text-shadow: 0 .0625rem 0 rgba(255, 255, 255, .6);
  25. }
  26. .container {
  27. width: 80%;
  28. margin: 10% auto;
  29. text-align: center;
  30. }
  31. .progress {
  32. margin-bottom: 1.875rem;
  33. padding: .1875rem;
  34. border: .0625rem solid #ddd;
  35. -webkit-border-radius: .9375rem;
  36. border-radius: .9375rem;
  37. background-color: #fff;
  38. height: 1.875rem;
  39. -webkit-transform: translateZ(0);
  40. -moz-transform: translateZ(0);
  41. -o-transform: translateZ(0);
  42. -ms-transform: translateZ(0);
  43. transform: translateZ(0);
  44. }
  45. .box {
  46. width: 100%;
  47. -webkit-box-sizing: border-box;
  48. -moz-box-sizing: border-box;
  49. box-sizing: border-box;
  50. float: left;
  51. white-space: nowrap;
  52. overflow: hidden;
  53. -o-text-overflow: ellipsis;
  54. text-overflow: ellipsis;
  55. }
  56. .bar {
  57. min-width: 1.375rem;
  58. width: 100%;
  59. height: 100%;
  60. -webkit-border-radius: .6875rem;
  61. border-radius: .6875rem;
  62. -webkit-box-shadow: rgba(0, 0, 0, .08) 0 -.6rem 1rem 0 inset;
  63. box-shadow: rgba(0, 0, 0, .08) 0 -.6rem 1rem 0 inset;
  64. -webkit-transition: width .3s ease;
  65. -o-transition: width .3s ease;
  66. transition: width .3s ease;
  67. }
  68. .bar.bar-striped {
  69. background: -webkit-linear-gradient(315deg, rgba(0, 0, 0, 0) 0%,
  70. rgba(0, 0, 0, 0) 31%, rgba(0, 0, 0, .05) 33%, rgba(0, 0, 0, .05) 67%,
  71. rgba(0, 0, 0, 0) 69%);
  72. background: -moz-linear-gradient(315deg, rgba(0, 0, 0, 0) 0%,
  73. rgba(0, 0, 0, 0) 31%, rgba(0, 0, 0, .05) 33%, rgba(0, 0, 0, .05) 67%,
  74. rgba(0, 0, 0, 0) 69%);
  75. background: -o-linear-gradient(315deg, rgba(0, 0, 0, 0) 0%,
  76. rgba(0, 0, 0, 0) 31%, rgba(0, 0, 0, .05) 33%, rgba(0, 0, 0, .05) 67%,
  77. rgba(0, 0, 0, 0) 69%);
  78. background: -ms-linear-gradient(315deg, rgba(0, 0, 0, 0) 0%,
  79. rgba(0, 0, 0, 0) 31%, rgba(0, 0, 0, .05) 33%, rgba(0, 0, 0, .05) 67%,
  80. rgba(0, 0, 0, 0) 69%);
  81. background: linear-gradient(135deg, rgba(0, 0, 0, 0) 0%,
  82. rgba(0, 0, 0, 0) 31%, rgba(0, 0, 0, .05) 33%, rgba(0, 0, 0, .05) 67%,
  83. rgba(0, 0, 0, 0) 69%);
  84. -webkit-background-size: 3rem 1.4rem;
  85. -moz-background-size: 3rem 1.4rem;
  86. background-size: 3rem 1.4rem;
  87. }
  88. .bar-striped.active {
  89. -webkit-animation: bar-striped 1.5s linear 0 infinite;
  90. -moz-animation: bar-striped 1.5s linear 0s infinite;
  91. -o-animation: bar-striped 1.5s linear 0 infinite;
  92. -ms-animation: bar-striped 1.5s linear 0 infinite;
  93. animation: bar-striped 1.5s linear 0s infinite;
  94. }
  95. @-webkit-keyframes bar-striped {
  96. 0%{
  97. background-position: 0;
  98. }
  99. 100%{
  100. background-position: 3rem;
  101. }
  102. }
  103. @-o-keyframes bar-striped {
  104. 0%{
  105. background-position: 0;
  106. }
  107. 100%{
  108. background-position: 3rem;
  109. }
  110. }
  111. @-ms-keyframes bar-striped {
  112. 0%{
  113. background-position: 0;
  114. }
  115. 100%{
  116. background-position: 3rem;
  117. }
  118. }
  119. @keyframes bar-striped {
  120. 0%{
  121. background-position: 0;
  122. }
  123. 100%{
  124. background-position: 3rem;
  125. }
  126. }
  127. .progress.waiting .bar {
  128. width: 0;
  129. background-color: transparent;
  130. }
  131. .progress.loading .bar {
  132. width: 1%;
  133. background-color: #3ee283;
  134. }
  135. .progress.creating .bar {
  136. width: 100%;
  137. background-color: #48d9ea;
  138. }
  139. .progress.complete .bar {
  140. width: 100%;
  141. background-color: #95e22d;
  142. background-image: none;
  143. -webkit-animation: none;
  144. -moz-animation: none;
  145. -o-animation: none;
  146. -ms-animation: none;
  147. animation: none;
  148. }
  149. .bar:after {
  150. position: absolute;
  151. margin: 0;
  152. left: 0;
  153. right: 0;
  154. padding: .3rem 0;
  155. font-size: .8rem;
  156. font-weight: 400;
  157. text-align: center;
  158. letter-spacing: .02rem;
  159. opacity: .9;
  160. -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=90)";
  161. filter: alpha(opacity = 90);
  162. line-height: 1em;
  163. padding: .3rem 0;
  164. }
  165. .waiting .bar:after {
  166. content: "请稍等"
  167. }
  168. .loading .bar:after {
  169. content: "正在获取数据, 请稍等"
  170. }
  171. .creating .bar:after {
  172. content: "正在创建文件, 请稍等"
  173. }
  174. .complete .bar:after {
  175. content: "下载完成"
  176. }
  177. .muted {
  178. color: #999;
  179. }
  180. .num {
  181. font-style: normal;
  182. font-family: verdana;
  183. font-weight: 700;
  184. color: #ffb433;
  185. }
  186. </style>
  187. <script type="text/javascript"
  188. src="<%=basePath%>resource/ext/ext-all.js"></script>
  189. <script type="text/javascript" src="<%=basePath%>resource/i18n/i18n.js"></script>
  190. <script type="text/javascript"
  191. src="<%=basePath%>resource/ux/downloadify/swfobject.js"></script>
  192. <script type="text/javascript"
  193. src="<%=basePath%>resource/ux/downloadify/downloadify.min.js"></script>
  194. <script type="text/javascript"
  195. src="<%=basePath%>resource/ux/downloadify/excel.js"></script>
  196. <script type="text/javascript">
  197. var setting = ${setting}, caller = getUrlParam('caller'), condition = getUrlParam('condition'), title = getUrlParam('title');
  198. </script>
  199. </head>
  200. <body>
  201. <div class="container">
  202. <div id="progress" class="progress waiting box">
  203. <div id="progress-bar" class="bar bar-striped active"></div>
  204. </div>
  205. <p class="muted">
  206. 已找到<span id="dataCount" class="num">0</span>条数据
  207. </p>
  208. <p id="downloadify"></p>
  209. </div>
  210. </body>
  211. <script type="text/javascript">
  212. function loadData(callable) {
  213. var step = 20, stepSize = 5000, req = function(idx, callback){
  214. Ext.Ajax.request({
  215. url: basePath + 'common/datalist/data.action',
  216. params: {
  217. caller: caller,
  218. condition: condition,
  219. page: (idx + 1),
  220. pageSize: stepSize,
  221. _f: 1,
  222. _alia: 1
  223. },
  224. timeout: 600000,
  225. callback: function(opt, s, r) {
  226. callback.call(null, idx, s, r);
  227. }
  228. });
  229. }, comp = 0, data = {}, total = 0;
  230. for(var i = 0;i < step;i++ ) {
  231. req(i, function(idx, s, r){
  232. ++comp;
  233. if(s && r.responseText) {
  234. data[idx] = Ext.JSON.decode(r.responseText).data;
  235. total += data[idx].length;
  236. setState(total, 100 * comp / step);
  237. }
  238. if(comp == step) {
  239. var sortedData = [];
  240. for(var k in data) {
  241. var t = data[k];
  242. for(var j in t) {
  243. sortedData.push(t[j]);
  244. }
  245. }
  246. callable.call(null, sortedData);
  247. return;
  248. }
  249. });
  250. }
  251. }
  252. function setState(dataCount, width) {
  253. Ext.defer(function(){
  254. Ext.get('dataCount').dom.innerHTML = dataCount;
  255. Ext.get('progress-bar').setWidth(width + '%');
  256. }, 20);
  257. }
  258. function updateProgress(oldState, newState) {
  259. Ext.get('progress').replaceCls(oldState, newState);
  260. }
  261. function createFile(params, data, title) {
  262. var el = new $excel(params);
  263. el.addData(data);
  264. if(typeof window.webkitRequestFileSystem != 'undefined') {
  265. var url = el.create();
  266. var a = document.createElement("a");
  267. document.body.appendChild(a);
  268. a.style = "display: none";
  269. a.href = url;
  270. a.download = title;
  271. a.click();
  272. URL.revokeObjectURL(url);
  273. updateProgress('creating', 'complete');
  274. Ext.defer(function(){
  275. window.close();
  276. }, 100);
  277. } else {
  278. Downloadify.create('downloadify', {
  279. filename : function() {
  280. return title;
  281. },
  282. data : function() {
  283. return el.getXml();
  284. },
  285. onError : function() {
  286. alert('文件下载失败!');
  287. },
  288. swf : basePath + 'resource/ux/downloadify/media/downloadify.swf',
  289. downloadImage : basePath + 'resource/ux/downloadify/images/download.png',
  290. width : 100,
  291. height : 30,
  292. transparent : true,
  293. append : false
  294. });
  295. }
  296. }
  297. Ext.onReady(function(){
  298. updateProgress('waiting', 'loading');
  299. loadData(function(data){
  300. updateProgress('loading', 'creating');
  301. Ext.defer(function(){
  302. createFile(setting, data, (title || '导出') + '.xls');
  303. }, 50);
  304. });
  305. });
  306. </script>
  307. </html>