zhoufan лет назад: 4
Родитель
Сommit
58cc31e7d6
1 измененных файлов с 59 добавлено и 1 удалено
  1. 59 1
      WebUI/CallCenterWeb.UI/Script/Common/huayi.http.js

+ 59 - 1
WebUI/CallCenterWeb.UI/Script/Common/huayi.http.js

@@ -905,6 +905,65 @@ helper.luyin = {
905 905
 	isexist: function() {
906 906
 	}
907 907
 };
908
+function download(url) {
909
+    layer.load(2);
910
+    var xmlResquest = new XMLHttpRequest();
911
+    xmlResquest.open("GET", url, true);
912
+    xmlResquest.setRequestHeader("Content-type", "application/json");
913
+    //xmlResquest.timeout = timeout || (1000 * 60);// 超时时间,单位是毫秒
914
+    xmlResquest.responseType = "blob";//该属性必须设置
915
+    xmlResquest.onload = function (oEvent) {
916
+        layer.closeAll('loading');
917
+        var content = xmlResquest.response;
918
+        var blob = new Blob([content]);
919
+
920
+        //判断有没有请求头content-disposition,该请求头在后台文件流导出成功时添加
921
+        if (xmlResquest.getAllResponseHeaders().indexOf('content-disposition')!=-1) {
922
+            var elink = document.createElement('a');
923
+            //获取文件名
924
+            var fileName = xmlResquest.getResponseHeader("content-disposition").split(";")[1].split("=")[1];
925
+            //响应头中的内容如果包含中文会出现乱码,需要解码才能正常显示
926
+            var explorer = navigator.userAgent;
927
+            if (explorer.indexOf("MSIE") >= 0 || explorer.indexOf("Chrome") >= 0) {  //IE和google浏览器
928
+                fileName = decodeURIComponent(fileName);
929
+            } else {
930
+                fileName = decodeURI(escape(fileName));
931
+            }
932
+            elink.download = fileName;
933
+            elink.style.display = 'none';
934
+            elink.href = window.URL.createObjectURL(blob);
935
+            document.body.appendChild(elink);
936
+            elink.click();
937
+            document.body.removeChild(elink);
938
+            window.URL.revokeObjectURL(url);
939
+
940
+        } else {//后台出现异常时的处理
941
+            var r = new FileReader();
942
+            r.readAsText(blob, 'utf-8');
943
+            r.onload = function (e) {
944
+                var data = JSON.parse(r.result);
945
+                if (data.state.toLowerCase() == "error") {
946
+                    layer.confirm(data.message, {
947
+                        btn: ['确定']
948
+                    });
949
+                }
950
+            }
951
+        }
952
+    };
953
+    //xmlResquest.ontimeout = function (e) {
954
+    //    layer.closeAll('loading');
955
+    //    layer.confirm("导出超时,请重新导出!", {
956
+    //        btn: ['确定'] //按钮
957
+    //    });
958
+    //};
959
+    xmlResquest.onerror = function (e) {
960
+        layer.closeAll('loading');
961
+        layer.confirm("导出失败", {
962
+            btn: ['确定'] //按钮
963
+        });
964
+    };
965
+    xmlResquest.send();//发送请求
966
+}
908 967
 helper.init = {
909 968
 	isload: 1,
910 969
 	setajax: function() { /// 配置AJAX
@@ -924,7 +983,6 @@ helper.init = {
924 983
 					data = data
925 984
 				}
926 985
 				if(data.state.toLowerCase() == "notoken") {
927
-                    debugger;
928 986
 					top.window.location.href = "/login.html";
929 987
 					return;
930 988
 				}