2 changed files with 123 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||
|
layui.define(["layer", "jquery"], function (exports) { |
||||
|
|
||||
|
var iframeEdit = { |
||||
|
populateIframe: function (iframe, url, headers) { |
||||
|
var xhr = new XMLHttpRequest(); |
||||
|
xhr.open('GET', url); |
||||
|
xhr.onreadystatechange = handler; |
||||
|
xhr.responseType = 'blob'; |
||||
|
headers.forEach(function (header) { |
||||
|
xhr.setRequestHeader(header[0], header[1]); |
||||
|
}); |
||||
|
xhr.send(); |
||||
|
|
||||
|
function handler() { |
||||
|
if (this.readyState === this.DONE) { |
||||
|
if (this.status === 200) { |
||||
|
// this.response is a Blob, because we set responseType above
|
||||
|
iframe.src = URL.createObjectURL(this.response); |
||||
|
} else { |
||||
|
console.error('XHR failed', this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
}, |
||||
|
|
||||
|
setPDF: function (blob) { |
||||
|
document.querySelector('#blob').src = URL.createObjectURL(blob); |
||||
|
} |
||||
|
}; |
||||
|
exports('iframeEdit', iframeEdit); |
||||
|
}) |
||||
@ -0,0 +1,90 @@ |
|||||
|
layui.define(["layer", "jquery"], function (exports) { |
||||
|
var $ = layui.$, |
||||
|
layer = layui.layer; |
||||
|
|
||||
|
|
||||
|
var sendRequest = { |
||||
|
|
||||
|
sendGetForNoLayer: function (url, reqData, rollback) { |
||||
|
$.ajax({ |
||||
|
url: url, |
||||
|
type: "GET", |
||||
|
data: reqData, |
||||
|
contentType: "application/json;charset=utf-8", |
||||
|
beforeSend: function (xhr) { |
||||
|
xhr.setRequestHeader("user-key", window.localStorage.getItem("key")); |
||||
|
xhr.setRequestHeader("user-token", window.localStorage.getItem("token")); |
||||
|
}, |
||||
|
success: function (d) { |
||||
|
rollback(d); |
||||
|
}, |
||||
|
error: function (e) { |
||||
|
console.log(e) |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
sendGetForLayer: function (url, reqData, rollback) { |
||||
|
$.ajax({ |
||||
|
url: url, |
||||
|
type: "GET", |
||||
|
dataType: 'json', |
||||
|
data: reqData, |
||||
|
contentType: "application/json;charset=utf-8", |
||||
|
beforeSend: function (xhr) { |
||||
|
xhr.setRequestHeader("user-key", window.localStorage.getItem("key")); |
||||
|
xhr.setRequestHeader("user-token", window.localStorage.getItem("token")); |
||||
|
this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']}); |
||||
|
}, |
||||
|
success: function (d) { |
||||
|
rollback(d); |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
sendPostForNoLayer: function (url, reqData, rollback) { |
||||
|
$.ajax({ |
||||
|
url: url, |
||||
|
type: "POST", |
||||
|
dataType: 'json', |
||||
|
data: JSON.stringify(reqData), |
||||
|
contentType: "application/json;charset=utf-8", |
||||
|
beforeSend: function (xhr) { |
||||
|
xhr.setRequestHeader("user-key", window.localStorage.getItem("key")); |
||||
|
xhr.setRequestHeader("user-token", window.localStorage.getItem("token")); |
||||
|
}, |
||||
|
success: function (d) { |
||||
|
rollback(d); |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
|
||||
|
sendPostForLayer: function (url, reqData, rollback) { |
||||
|
$.ajax({ |
||||
|
url: url, |
||||
|
type: "POST", |
||||
|
dataType: 'json', |
||||
|
data: JSON.stringify(reqData), |
||||
|
contentType: "application/json;charset=utf-8", |
||||
|
beforeSend: function () { |
||||
|
xhr.setRequestHeader("user-key", window.localStorage.getItem("key")); |
||||
|
xhr.setRequestHeader("user-token", window.localStorage.getItem("token")); |
||||
|
this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']}); |
||||
|
}, |
||||
|
success: function (d) { |
||||
|
rollback(d); |
||||
|
} |
||||
|
}) |
||||
|
}, |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
exports('sendRequest', sendRequest); |
||||
|
}); |
||||
|
|
||||
Loading…
Reference in new issue