Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
EcomWeb
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zhanbo.xu
2026-01-28 17:22:07 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9de8413f1ab1e0b375c78046f049a76cdc06222b
9de8413f
1 parent
b9caf032
优化导出并修改代码
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
213 additions
and
75 deletions
src/api/exportList-api.js
src/utils/request.js
src/utils/zipdownload.js
src/views/exportListQuery/index.vue
src/api/exportList-api.js
View file @
9de8413
...
...
@@ -64,3 +64,29 @@ export function getCustomizeExcel(data) {
data
:
data
,
});
}
// 查询导出的任务ID
// POST
// /exportList/submitExportTask
export
function
getSubmitExportTask
(
data
)
{
return
request
({
url
:
"/bus-customer/exportList/submitExportTask"
,
method
:
"post"
,
data
:
data
,
});
}
// /asyncExport/taskStatus/{taskId}
export
function
getTaskStatus
(
data
)
{
return
request
({
url
:
"/bus-customer/asyncExport/taskStatus/"
+
data
.
taskId
,
method
:
"get"
,
});
}
// /asyncExport/download/{taskId}
export
function
getDownload
(
data
)
{
return
request
({
url
:
"/bus-customer/asyncExport/download/"
+
data
.
taskId
,
method
:
"get"
,
});
}
...
...
src/utils/request.js
View file @
9de8413
import
axios
from
'axios'
import
{
MessageBox
,
Message
}
from
'element-ui'
import
store
from
'@/store'
import
{
getToken
,
setTime
,
removeTime
,
removeToken
}
from
'@/utils/auth'
import
errorCode
from
'@/utils/errorCode'
import
i18n
from
'@/assets/languages'
import
axios
from
"axios"
;
import
{
MessageBox
,
Message
}
from
"element-ui"
;
import
store
from
"@/store"
;
import
{
getToken
,
setTime
,
removeTime
,
removeToken
}
from
"@/utils/auth"
;
import
errorCode
from
"@/utils/errorCode"
;
import
i18n
from
"@/assets/languages"
;
axios
.
defaults
.
headers
[
'Content-Type'
]
=
'application/json;charset=utf-8'
axios
.
defaults
.
headers
[
"Content-Type"
]
=
"application/json;charset=utf-8"
;
// 创建axios实例
const
service
=
axios
.
create
({
// axios中请求配置有baseURL选项,表示请求URL公共部分
baseURL
:
process
.
env
.
VUE_APP_BASE_API
,
// 超时
timeout
:
1800000
})
timeout
:
1800000
00
,
})
;
// request拦截器
service
.
interceptors
.
request
.
use
(
config
=>
{
service
.
interceptors
.
request
.
use
(
(
config
)
=>
{
// 是否需要设置 token
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
const
isToken
=
(
config
.
headers
||
{}).
isToken
===
false
;
// if (getToken() && !isToken) {
config
.
headers
[
'Authorization'
]
=
getToken
()
==
null
?
'1'
:
'Bearer '
+
getToken
()
// 让每个请求携带自定义token 请根据实际情况自行修改
config
.
headers
[
"Authorization"
]
=
getToken
()
==
null
?
"1"
:
"Bearer "
+
getToken
();
// 让每个请求携带自定义token 请根据实际情况自行修改
// }
config
.
headers
[
'Lang'
]
=
localStorage
.
getItem
(
'iClearExpLang'
)
?
localStorage
.
getItem
(
'iClearExpLang'
)
:
'1'
config
.
headers
[
'Ver'
]
=
process
.
env
.
VUE_APP_APIVERSION
config
.
headers
[
"Lang"
]
=
localStorage
.
getItem
(
"iClearExpLang"
)
?
localStorage
.
getItem
(
"iClearExpLang"
)
:
"1"
;
config
.
headers
[
"Ver"
]
=
process
.
env
.
VUE_APP_APIVERSION
;
// get请求映射params参数
if
(
config
.
method
===
'get'
&&
config
.
params
)
{
let
url
=
config
.
url
+
'?'
;
if
(
config
.
method
===
"get"
&&
config
.
params
)
{
let
url
=
config
.
url
+
"?"
;
for
(
const
propName
of
Object
.
keys
(
config
.
params
))
{
const
value
=
config
.
params
[
propName
];
var
part
=
encodeURIComponent
(
propName
)
+
"="
;
if
(
value
!==
null
&&
typeof
(
value
)
!==
"undefined"
)
{
if
(
typeof
value
===
'object'
)
{
if
(
value
!==
null
&&
typeof
value
!==
"undefined"
)
{
if
(
typeof
value
===
"object"
)
{
for
(
const
key
of
Object
.
keys
(
value
))
{
let
params
=
propName
+
'['
+
key
+
']'
;
let
params
=
propName
+
"["
+
key
+
"]"
;
var
subPart
=
encodeURIComponent
(
params
)
+
"="
;
url
+=
subPart
+
encodeURIComponent
(
value
[
key
])
+
"&"
;
}
...
...
@@ -58,78 +62,86 @@ service.interceptors.request.use(config => {
// })
// return config
// } else {
return
config
return
config
;
// }
},
error
=>
{
console
.
log
(
error
)
Promise
.
reject
(
error
)
})
},
(
error
)
=>
{
console
.
log
(
error
);
Promise
.
reject
(
error
);
}
);
// 响应拦截器
service
.
interceptors
.
response
.
use
(
res
=>
{
if
(
res
.
config
.
url
!=
'/manager-server/systemAddressInfoController/findSystemAddressInfoAll'
)
{
setTime
(
new
Date
().
getTime
())
service
.
interceptors
.
response
.
use
(
(
res
)
=>
{
if
(
res
.
config
.
url
!=
"/manager-server/systemAddressInfoController/findSystemAddressInfoAll"
)
{
setTime
(
new
Date
().
getTime
());
}
// 未设置状态码则默认成功状态
const
code
=
Number
(
res
.
data
.
code
)
||
200
;
// 获取错误信息
const
msg
=
errorCode
[
code
]
||
res
.
data
.
message
||
errorCode
[
'default'
]
const
msg
=
errorCode
[
code
]
||
res
.
data
.
message
||
errorCode
[
"default"
];
if
(
code
===
50000
||
code
===
530
)
{
removeToken
()
MessageBox
.
alert
(
i18n
.
t
(
'system.loginOut'
),
i18n
.
t
(
'system.systemTip'
),
{
confirmButtonText
:
i18n
.
t
(
'system.relogin'
),
cancelButtonText
:
i18n
.
t
(
'system.close'
),
type
:
'warning'
}
).
finally
(()
=>
{
store
.
dispatch
(
'FedLogOut'
)
})
removeToken
();
MessageBox
.
alert
(
i18n
.
t
(
"system.loginOut"
),
i18n
.
t
(
"system.systemTip"
),
{
confirmButtonText
:
i18n
.
t
(
"system.relogin"
),
cancelButtonText
:
i18n
.
t
(
"system.close"
),
type
:
"warning"
,
}).
finally
(()
=>
{
store
.
dispatch
(
"FedLogOut"
);
});
}
else
if
(
code
===
10005
)
{
removeToken
()
MessageBox
.
alert
(
'<span style="font-weight:700">系统版本已更新!</span><br/>当前版本非最新版,请退出系统后刷新您当前所使用的浏览器后,重新登录系统!</br> </br>常用浏览器的快速刷新页面操作方法有:</br>1、谷歌浏览器请按“F5键”或“Ctrl键 + R键”快速刷新页面</br>2、360浏览器跟EDGE浏览器请按“Ctrl键 + R键”快速刷新页面</br>3、IE浏览器请按“F5键”或“Ctrl键 + R键”快速刷新页面</br> </br>其它浏览器的刷新方式请根据浏览器的菜单进行操作!'
,
i18n
.
t
(
'system.systemTip'
),
{
confirmButtonText
:
i18n
.
t
(
'system.relogin'
),
cancelButtonText
:
i18n
.
t
(
'system.close'
),
type
:
'warning'
,
customClass
:
'systemVerError'
,
dangerouslyUseHTMLString
:
true
removeToken
();
MessageBox
.
alert
(
'<span style="font-weight:700">系统版本已更新!</span><br/>当前版本非最新版,请退出系统后刷新您当前所使用的浏览器后,重新登录系统!</br> </br>常用浏览器的快速刷新页面操作方法有:</br>1、谷歌浏览器请按“F5键”或“Ctrl键 + R键”快速刷新页面</br>2、360浏览器跟EDGE浏览器请按“Ctrl键 + R键”快速刷新页面</br>3、IE浏览器请按“F5键”或“Ctrl键 + R键”快速刷新页面</br> </br>其它浏览器的刷新方式请根据浏览器的菜单进行操作!'
,
i18n
.
t
(
"system.systemTip"
),
{
confirmButtonText
:
i18n
.
t
(
"system.relogin"
),
cancelButtonText
:
i18n
.
t
(
"system.close"
),
type
:
"warning"
,
customClass
:
"systemVerError"
,
dangerouslyUseHTMLString
:
true
,
}
).
finally
(()
=>
{
store
.
dispatch
(
'FedLogOut'
)
})
store
.
dispatch
(
"FedLogOut"
);
});
}
else
if
(
code
===
500
)
{
MessageBox
.
alert
(
msg
,
i18n
.
t
(
'system.tipTitle2'
),
{
dangerouslyUseHTMLString
:
true
MessageBox
.
alert
(
msg
,
i18n
.
t
(
"system.tipTitle2"
),
{
dangerouslyUseHTMLString
:
true
,
});
return
Promise
.
reject
(
new
Error
(
msg
))
return
Promise
.
reject
(
new
Error
(
msg
));
}
else
if
(
code
!==
200
)
{
// MessageBox.alert(msg, '注意', {
// dangerouslyUseHTMLString: true
// });
return
res
.
data
return
res
.
data
;
}
else
{
return
res
.
data
return
res
.
data
;
}
},
error
=>
{
removeTime
()
console
.
log
(
'err'
+
error
)
},
(
error
)
=>
{
removeTime
()
;
console
.
log
(
"err"
+
error
);
let
{
message
}
=
error
;
if
(
message
==
"Network Error"
)
{
message
=
i18n
.
t
(
'system.systemError1'
);
}
else
if
(
message
.
includes
(
"timeout"
))
{
message
=
i18n
.
t
(
'system.systemError2'
);
}
else
if
(
message
.
includes
(
"Request failed with status code"
))
{
message
=
i18n
.
t
(
'system.systemError3'
,
{
a
:
message
.
substr
(
message
.
length
-
3
)
});
message
=
i18n
.
t
(
"system.systemError1"
);
}
else
if
(
message
.
includes
(
"timeout"
))
{
message
=
i18n
.
t
(
"system.systemError2"
);
}
else
if
(
message
.
includes
(
"Request failed with status code"
))
{
message
=
i18n
.
t
(
"system.systemError3"
,
{
a
:
message
.
substr
(
message
.
length
-
3
),
});
}
Message
({
message
:
message
,
type
:
'error'
,
duration
:
5
*
1000
})
return
Promise
.
reject
(
error
)
type
:
"error"
,
duration
:
5
*
1000
,
})
;
return
Promise
.
reject
(
error
)
;
}
)
)
;
export
default
service
export
default
service
;
...
...
src/utils/zipdownload.js
View file @
9de8413
...
...
@@ -20,6 +20,8 @@ const apiUrl = {
declareDataModel
:
"/bus-customer/declareData/downloadTemplate"
,
// 清单查询下载
listExport
:
"/bus-customer/exportList/listExport"
,
// 根据id导出
customDownloadXls
:
"/bus-customer/asyncExport/download"
,
};
const
baseUrl
=
process
.
env
.
VUE_APP_BASE_API
;
...
...
@@ -31,6 +33,8 @@ export function downLoadZip(urlStatus, str, filename, type, method, data) {
url
=
baseUrl
+
apiUrl
[
str
];
}
else
if
(
urlStatus
==
"res"
)
{
url
=
str
;
}
else
if
(
urlStatus
==
"task"
)
{
url
=
baseUrl
+
apiUrl
[
str
]
+
"/"
+
data
.
taskId
;
}
console
.
log
(
url
);
...
...
src/views/exportListQuery/index.vue
View file @
9de8413
...
...
@@ -215,6 +215,7 @@
size="small"
icon="el-icon-download"
@click="downloadData"
:loading="isPolling || exportLoading"
>
导出
</el-button>
...
...
@@ -282,7 +283,12 @@
</template>
<script>
import { getAllexportList, getListReceiptData } from "@/api/exportList-api.js";
import {
getAllexportList,
getListReceiptData,
getSubmitExportTask,
getTaskStatus,
} from "@/api/exportList-api.js";
import CustomDialog from "./custom-dialog.vue";
import { formatDateNew } from "../../utils";
...
...
@@ -415,6 +421,11 @@ export default {
formItemconsignmentHeadCode: false,
},
tableMaxheight: null,
exportLoading: false,
pollTimer: null, // 定时器实例
pollInterval: 5000, // 轮询间隔(5秒)
isPolling: false, // 轮询状态标识
currentTaskId: null,
};
},
created() {
...
...
@@ -423,9 +434,13 @@ export default {
mounted() {
this.tableMaxheight = window.innerHeight - 360;
},
beforeDestroy() {
this.stopPolling(); // 组件销毁前清理定时器
},
watch: {
$route() {
this.popoverClose();
this.stopPolling(); // 组件销毁前清理定时器
},
},
methods: {
...
...
@@ -496,6 +511,68 @@ export default {
summaryApplicationStatus: "",
};
},
// 查询成功后调用的其他接口
async callOtherApi() {
try {
const fileName = `${formatDateNew(new Date())}.xlsx`;
this.fileDownload
.downLoadZip("task", "customDownloadXls", fileName, "xlsx", "get", {
taskId: this.currentTaskId,
})
.finally(() => {
// this.cancelDownload();
this.exportLoading = false;
});
} catch (error) {
console.error("后续接口调用失败:", error);
}
},
// 轮询查询状态
async pollStatus() {
try {
const result = await getTaskStatus({ taskId: this.currentTaskId });
if (+result.code === 200) {
// PENDING, PROCESSING, COMPLETED, FAILED
if (result.data.status === "COMPLETED") {
this.stopPolling(); // 停止轮询
await this.callOtherApi(); // 调用其他接口
} else if (result.data.status === "FAILED") {
this.stopPolling();
this.handleFailure();
this.alertWarningMsg(result.data.errorMessage);
} else {
this.startPolling(); // 启动轮询
}
} else {
this.stopPolling();
this.handleFailure();
}
// 其他状态继续轮询
} catch (error) {
console.error("轮询查询失败:", error);
this.stopPolling();
}
},
// 启动轮询
startPolling() {
if (this.isPolling) return;
this.isPolling = true;
this.pollTimer = setInterval(() => {
this.pollStatus();
}, this.pollInterval);
},
// 停止轮询
stopPolling() {
if (this.pollTimer) {
clearInterval(this.pollTimer);
this.pollTimer = null;
}
this.isPolling = false;
this.exportLoading = false;
},
//导出
downloadData() {
let obj = { ...this.sreachFormData };
...
...
@@ -527,13 +604,32 @@ export default {
// // 2. 清单查询
// console.log(res);
// });
const fileName = `${formatDateNew(new Date())}.xlsx`;
this.fileDownload
.downLoadZip("api", "listExport", fileName, "xlsx", "post", {
...obj,
this.exportLoading = true;
this.$confirm(`正在导出中,请稍候!`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.finally(() => {
this.cancelDownload();
.then(() => {
getSubmitExportTask(obj).then((res) => {
if (+res.code === 200) {
console.log(res);
this.currentTaskId = res.data;
this.startPolling();
}
});
// this.fileDownload
// .downLoadZip("api", "listExport", fileName, "xlsx", "post", {
// ...obj,
// })
// .finally(() => {
// // this.cancelDownload();
// this.exportLoading = false;
// });
})
.catch(() => {
this.exportLoading = false;
});
},
//查询详情
...
...
Please
register
or
login
to post a comment