使用Promise封装XMLHttpRequest做异步请求
This commit is contained in:
@@ -88,20 +88,21 @@
|
||||
<script th:src="@{/axui-v2.1.1/js/ax.js}" type="text/javascript" charset="utf-8"></script>
|
||||
<script th:src="@{/common/js/basic.js}" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript" th:inline="javascript" charset="utf-8">
|
||||
let fileDel = (obj) => {
|
||||
const fileDel = (obj) => {
|
||||
const path = obj.getAttribute("value");
|
||||
let formData = {path: path};
|
||||
axAjax({
|
||||
url: '/fmt/download/delete',
|
||||
data: formData,
|
||||
type: 'post',
|
||||
success: function (result) {
|
||||
window.location.href = '/fmt/download/index';
|
||||
}
|
||||
const options = {
|
||||
url: Fmt.ctx() + '/download/delete',
|
||||
data: {path: path},
|
||||
method: 'post'
|
||||
};
|
||||
Fmt.axios(options).then((result) => {
|
||||
window.location.href = Fmt.ctx() + '/download/index';
|
||||
}).catch((err) => {
|
||||
new axMessage({content: err, result: 'error', iconShow: true}).show();
|
||||
});
|
||||
}
|
||||
|
||||
let fileDown = (obj) => {
|
||||
const fileDown = (obj) => {
|
||||
const path = obj.getAttribute("value");
|
||||
window.open(Fmt.ctx() + '/download/execute?path=' + encodeURIComponent(path) + '&temp=' + false);
|
||||
};
|
||||
@@ -109,7 +110,7 @@
|
||||
window.onload = () => {
|
||||
document.getElementById("search").onclick = () => {
|
||||
const keyboard = document.getElementById("keyboard").value;
|
||||
window.location.href = '/fmt/download/index?keyboard=' + keyboard;
|
||||
window.location.href = Fmt.ctx() + '/download/index?keyboard=' + keyboard;
|
||||
}
|
||||
|
||||
document.getElementById("zipDownBtn").onclick = () => {
|
||||
@@ -125,18 +126,19 @@
|
||||
new axMessage({content: '请选择要下载的文件',result: 'warning',iconShow: true}).show();
|
||||
return false;
|
||||
}
|
||||
let formData = {filenames: filenames.join(",")};
|
||||
let message = new axMessage({content: '',result: 'success',iconShow: true});
|
||||
message.update({content: '正在根据所选文件创建压缩包......', result: 'success'}).show();
|
||||
axAjax({
|
||||
url: '/fmt/download/packZip',
|
||||
data: formData,
|
||||
type: 'post',
|
||||
success: function (result) {
|
||||
const data = result.content;
|
||||
message.update({content: '压缩包' + data.filename + "创建完成,准备下载文件......", result: 'success'}).show();
|
||||
window.open(Fmt.ctx() + '/download/execute?path=' + encodeURIComponent(data.path) + '&temp=' + true);
|
||||
}
|
||||
const options = {
|
||||
url: Fmt.ctx() + '/download/packZip',
|
||||
data: {filenames: filenames.join(",")},
|
||||
method: 'post'
|
||||
};
|
||||
Fmt.axios(options).then((result) => {
|
||||
message.update({content: '压缩包' + result.filename + "创建完成,准备下载文件......", result: 'success'}).show();
|
||||
window.open(Fmt.ctx() + '/download/execute?path=' + encodeURIComponent(result.path) + '&temp=' + true);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
new axMessage({content: err, result: 'error', iconShow: true}).show();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -153,14 +155,15 @@
|
||||
new axMessage({content: '请选择要删除的文件',result: 'warning',iconShow: true}).show();
|
||||
return false;
|
||||
}
|
||||
let formData = {filenames: filenames.join(",")};
|
||||
axAjax({
|
||||
url: '/fmt/download/batchDel',
|
||||
data: formData,
|
||||
type: 'post',
|
||||
success: function (result) {
|
||||
window.location.href = '/fmt/download/index';
|
||||
}
|
||||
const options = {
|
||||
url: Fmt.ctx() + '/download/batchDel',
|
||||
data: {filenames: filenames.join(",")},
|
||||
method: 'post'
|
||||
};
|
||||
Fmt.axios(options).then((result) => {
|
||||
window.location.href = Fmt.ctx() + '/download/index';
|
||||
}).catch((err) => {
|
||||
new axMessage({content: err, result: 'error', iconShow: true}).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user