|
@@ -1,7 +1,7 @@
|
|
|
const qs = require('qs');
|
|
|
const $ = require("jquery");
|
|
|
var Utils = require('./rePromise');
|
|
|
-const baseUrl = "http://192.168.2.241:5858"
|
|
|
+const baseUrl = "http://192.168.3.113:5858"
|
|
|
//页面映射
|
|
|
const pageMap={
|
|
|
'YH-KZT':'console.html',
|
|
@@ -125,6 +125,66 @@ const post = function (url, data) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+// 导出
|
|
|
+const expJson = (url,data) =>{
|
|
|
+ const token = getCookie('accessToken')
|
|
|
+ if(!token&&window.location.href.indexOf('login')==-1){
|
|
|
+ window.location.href = "../login.html"
|
|
|
+ }
|
|
|
+ let need = window.location.href.indexOf('localhost')!=-1
|
|
|
+ return new Utils((resolve, reject) => {
|
|
|
+ $.ajax({
|
|
|
+ method: 'post',
|
|
|
+ url: (need?baseUrl:'')+url,
|
|
|
+ async:true,
|
|
|
+ cache: false,
|
|
|
+ contentType: false,
|
|
|
+ processData: false,
|
|
|
+ data: JSON.stringify(data),
|
|
|
+ contentType: "application/json; charset=UTF-8",
|
|
|
+ // contentType: "application/vnd.ms-excel;charset=UTF-8",
|
|
|
+ // responseType: 'blob', //必须添加,否则会乱码
|
|
|
+ beforeSend: function (xmlHttp) {
|
|
|
+ xmlHttp.setRequestHeader("If-Modified-Since", "0");
|
|
|
+ xmlHttp.setRequestHeader("Cache-Control", "no-cache");
|
|
|
+ xmlHttp.setRequestHeader("Authorization",token?"Bearer "+token:'')
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ resolve({ data: res });
|
|
|
+ },
|
|
|
+ error: function (error) {
|
|
|
+ if(error.status===403||error.status===401){
|
|
|
+ const wd = window.parent.window||window;
|
|
|
+ wd.location.href = "../login.html";
|
|
|
+ }
|
|
|
+ reject(error);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+// 导出
|
|
|
+function downloadExportedData(data, fileName) {
|
|
|
+ // var blob = new Blob([data], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'}); //type表示xlsx类型
|
|
|
+ // var blob = new Blob([data], {type: 'application/vnd.ms-excel;charset=UTF-8'}); //type表示xlsx类型
|
|
|
+ var blob = new Blob([data], {type: 'APPLICATION/OCTET-STREAM;charset=UTF-8'}); //type表示xlsx类型
|
|
|
+ var href = window.URL.createObjectURL(blob);//创建下载的链接
|
|
|
+ // 为兼容FF26 (不支持a标签的模拟点击事件)
|
|
|
+ if (navigator.userAgent.indexOf("Firefox") > -1){
|
|
|
+ //window.open(requestUrl);
|
|
|
+ window.location.href = href;
|
|
|
+ }else {
|
|
|
+ var downloadElement = document.createElement('a');
|
|
|
+ downloadElement.href = href;
|
|
|
+ downloadElement.download = fileName; //下载后文件名
|
|
|
+ document.body.appendChild(downloadElement);
|
|
|
+ downloadElement.click(); //点击下载
|
|
|
+ document.body.removeChild(downloadElement); //下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(href);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
//判断浏览器是否为Ie8
|
|
|
const isIe8 = function () {
|
|
|
var DEFAULT_VERSION = 8.0;
|
|
@@ -224,5 +284,7 @@ module.exports = {
|
|
|
hasData,
|
|
|
focusMenuItem,
|
|
|
emptyBox,
|
|
|
- picEmptyData
|
|
|
+ picEmptyData,
|
|
|
+ downloadExportedData,
|
|
|
+ expJson
|
|
|
};
|