Commit 549fd693 by linjinhong

feat:修改下载流提示

parent 4964d56c
......@@ -48,11 +48,15 @@
>
<div class="text-label">
<span>客户:</span>
<span style="color: #f56c6c;">{{ info.customer }}</span>
<span style="color: #f56c6c;font-size: 20px;font-weight: 700;">{{
info.userMark
}}</span>
</div>
<div class="text-label">
<span>订单号:</span>
<span style="color: #f56c6c;">{{ info.orderNo }}</span>
<span style="color: #f56c6c;font-size: 20px;font-weight: 700;">{{
info.factoryOrderNumber
}}</span>
</div>
</div>
......@@ -88,7 +92,9 @@
<!-- 底部按钮 -->
<div style="text-align: right;">
<el-button type="primary" size="medium">下载素材</el-button>
<el-button type="primary" size="medium" @click="downloadFn"
>下载素材</el-button
>
</div>
</div>
</div>
......@@ -96,6 +102,7 @@
</template>
<script>
import bus from "@/bus";
export default {
name: "OrderDetailDialog",
props: {
......@@ -159,6 +166,9 @@ export default {
} catch {
return [{ url: trimmed }];
}
},
downloadFn() {
bus.$emit("downLoadFile", this.info);
}
}
};
......
......@@ -831,6 +831,7 @@ export default {
const token = req.headers["jwt-token"];
const { id } = req.body;
let url = pathMap["getPodOrderLog"];
console.log(req.body);
try {
let { data } = await axios.get(`${env}/${url}?id=${id}`, {
......
......@@ -651,7 +651,6 @@ function formatTime() {
*/
export function downloadDTFFiles(fileUrl, targetDir, options = {}) {
const { deleteZipAfterUnzip = true, unzipToSubdir = false } = options;
console.log("downloadDTFFiles---------", fileUrl, targetDir);
return new Promise((resolve, reject) => {
try {
......@@ -692,6 +691,7 @@ export function downloadDTFFiles(fileUrl, targetDir, options = {}) {
const finalRedirectUrl = redirectUrl.startsWith("http")
? redirectUrl
: new URL(redirectUrl, fileUrl).href;
console.log("downloadDTFFiles---------", finalRedirectUrl, targetDir);
downloadDTFFiles(finalRedirectUrl, targetDir, options)
.then(resolve)
......
......@@ -11,7 +11,18 @@ const url = require("url");
*/
function getFileName(urlStr) {
const formatUrl = urlStr.replace(/\\/g, "/");
return path.basename(formatUrl);
const lastName = path.basename(formatUrl);
console.log("lastName", lastName);
// 先分割拿到数组
const nameArr = lastName.split("-");
// 判断是否存在横线分割成两段
if (nameArr.length >= 2) {
// OP260630368_test_1361_11852.png
return `${nameArr[1]}_${nameArr[0]}`;
}
// 没有横线直接返回原名
return lastName;
}
/**
......@@ -26,7 +37,12 @@ function isAbsoluteUrl(urlStr) {
*/
function resolveUrl(urlStr, baseUrl) {
if (isAbsoluteUrl(urlStr)) return urlStr;
return `${baseUrl.replace(/\/$/, "")}/${urlStr.replace(/^\//, "")}`;
let url = urlStr.replace(/^\//, "");
const nameArr = url.split("-");
if (nameArr.length >= 2) url = nameArr[0];
console.log("resolveUrl", `${baseUrl.replace(/\/$/, "")}/${url}`);
return `${baseUrl.replace(/\/$/, "")}/${url}`;
}
/**
......@@ -88,6 +104,8 @@ function pLimit(concurrency) {
function streamDownload(fileUrl, filePath, timeout = 30000, redirectCount = 0) {
return new Promise((resolve, reject) => {
try {
console.log("fileUrl", fileUrl);
const requestModule = fileUrl.startsWith("https") ? https : http;
const req = requestModule.get(fileUrl, { timeout }, res => {
// 重定向处理,最多3次防死循环
......@@ -188,7 +206,7 @@ async function batchDownloadByList(urlList, targetDir, options = {}) {
retryTimes = 0,
baseUrl = "",
skipExists = true,
fileNameFormatter = null // 新增:自定义文件名回调
fileNameFormatter = null // 新增:自定义文件名回调,
} = options;
const success = [];
......@@ -223,7 +241,6 @@ async function batchDownloadByList(urlList, targetDir, options = {}) {
success.push(savePath);
return;
}
await downloadWithRetry(fullUrl, savePath, retryTimes, timeout);
console.log(`[批量下载][成功] ${fileName}`);
success.push(savePath);
......
......@@ -27,14 +27,14 @@ function submitTask(params) {
if (taskState.isRunning) {
return {
code: 1,
code: 501,
msg: `当前正在下载批次【${taskState.currentBatchNo}】,请等待完成后再操作`,
data: { isRunning: true }
};
}
if (!Array.isArray(urls) || urls.length === 0) {
return { code: 1, msg: "下载链接数组为空" };
return { code: 500, msg: "下载链接数组为空" };
}
taskState.isRunning = true;
......@@ -65,15 +65,15 @@ function submitTask(params) {
});
return {
code: 0,
msg: "下载任务已提交,后台处理中",
code: 200,
msg: "下载进行中,下载完成的素材将在文件夹原素材中显示",
data: { isRunning: true }
};
}
function getStatus() {
return {
code: 0,
code: 200,
data: {
isRunning: taskState.isRunning,
currentBatchNo: taskState.currentBatchNo,
......
......@@ -44,7 +44,7 @@ async function batchDownloadUrls(urlStr, targetDir, options = {}) {
/* ===================== 新增:IPC 任务管理模块(独立锁,与原素材隔离) ===================== */
const taskState = {
isRunning: false,
latestResult: { success: [], failed: [] }
latestResult: { success: [], failed: [], currentBatchNo: "" }
};
/**
......@@ -66,19 +66,19 @@ function broadcastStatus() {
* 提交下载任务(异步执行,立即返回)
*/
function submitTask(params) {
const { urlStr, targetPath } = params;
const { urlStr, targetPath, batchArrangeNum } = params;
taskState.currentBatchNo = batchArrangeNum;
// 全局互斥:有任务在跑直接拒绝
if (taskState.isRunning) {
return {
code: 1,
code: 500,
msg: "当前正在下载手动排版素材,请等待完成后再操作",
data: { isRunning: true }
};
}
if (!urlStr || typeof urlStr !== "string") {
return { code: 1, msg: "下载链接为空或格式无效" };
return { code: 500, msg: "下载链接为空或格式无效" };
}
// 加锁
......@@ -104,8 +104,8 @@ function submitTask(params) {
});
return {
code: 0,
msg: "手动排版素材下载任务已提交,后台处理中",
code: 200,
msg: "排版进行中,请查看处理状态,排版完成的素材至文件夹排版素材查看",
data: { isRunning: true }
};
}
......
......@@ -5,7 +5,7 @@ const { statusMap } = require("@/config/index.js");
const { pathMap } = require("@/config/index.js");
const { getUser } = require("@/server/utils/store");
var path = require("path");
import bus from "@/bus";
export default {
props: {
selection: { type: Array, default: () => [] },
......@@ -26,6 +26,29 @@ export default {
mounted() {
const params = this.$route.params;
this.curBatchArrangeNum = params.batchArrangeNum;
bus.$on("downLoadFile", async v => {
let { podOrderProductId, batchArrangeNumber } = v;
console.log(31, v);
try {
let res = await this.$api.post(
pathMap["downloadBySubOrderNumber"]["OP"],
{
ids: [podOrderProductId],
device: 4,
orderType: "OP",
targetDir: path.join(
getDTFSetting().downloadDir,
`批次号:${batchArrangeNumber}`,
"原素材"
)
}
);
console.log(77, res);
} catch (error) {
this.$message.error(error);
}
});
},
created() {},
......@@ -64,7 +87,7 @@ export default {
goBack() {
this.$router.push({ name: "design-dtf" });
},
async goSetting() {
async downLoadFn() {
if (!this.podOrderProductIds.length) {
return this.$message.warning("请选择操作单");
}
......@@ -226,7 +249,7 @@ export default {
</el-button></el-form-item
>
<el-form-item>
<el-button @click="goSetting" type="success"
<el-button @click="downLoadFn" type="success"
>下载素材
</el-button></el-form-item
>
......
......@@ -36,6 +36,7 @@ export default {
total: 2
},
cardList: [],
timer: null,
curBatchArrangeNum: "",
detailRow: {
batchArrangeNum: { label: "批次号", value: "" },
......@@ -59,10 +60,16 @@ export default {
},
mounted() {
this.loadRowData();
this.timer = setInterval(() => this.getCardList(), 5 * 60 * 1000);
this.curData = {};
this.selection = [];
this.podOrderProductIds = [];
},
beforeDestroy() {
if (this.timer) {
clearInterval(this.timer);
}
},
methods: {
async loadRowData() {
try {
......@@ -195,10 +202,9 @@ export default {
},
async openLogDialog(item) {
try {
const { data } = await this.$api.post(
pathMap["getPodOrderLog"],
item.id
);
const { data } = await this.$api.post(pathMap["getPodOrderLog"], {
id: item.id
});
this.logList = data;
this.logVisible = true;
} catch (error) {
......
......@@ -226,18 +226,11 @@ export default {
//打开手动排版弹窗
changeTypesetting(value) {
if (
this.dtfSetting.autoLayoutStrategy == 3 ||
[3, 5].includes(value.layoutStatus)
) {
if (![2].includes(value.layoutStatus)) {
this.dialogVisible = true;
this.radio = "";
this.templateBatchArrangeNum = value.batchArrangeNum;
this.templateId = value.id;
} else {
this.$message(
"排版进行中,请查看处理状态,排版完成的素材至文件夹排版素材查看"
);
}
},
......@@ -278,17 +271,23 @@ export default {
}
);
await submitTypesettingDownload({
const res = await submitTypesettingDownload({
urlStr: data.data.url,
targetPath: path.join(
getDTFSetting().downloadDir,
`批次号:${this.templateBatchArrangeNum}`,
"手动排版素材"
)
),
batchArrangeNum: this.templateBatchArrangeNum
});
this.$message(
"排版进行中,请查看处理状态,排版完成的素材至文件夹排版素材查看"
);
console.log(res);
if (res.code == 200) {
this.$message(res.msg);
} else {
this.TypeDownloading = false;
this.$message.error(res.msg);
}
this.dialogVisible = false;
this.fetchBatchList(this.searchForm);
} catch (error) {
......@@ -328,14 +327,19 @@ export default {
const { data } = await this.$api.post(pathMap["listMaterialsByBatch"], {
batchArrangeNum: value
});
const newUrls = data.flatMap(el => el.urls);
// const newUrls = data.flatMap(el => el.urls);
const newUrls = data.flatMap(({ operationNo, urls }) =>
urls.map(url => `${url}-${operationNo}`)
);
console.log(newUrls);
if (newUrls.length === 0) {
this.$message.warning("该批次暂无素材可下载");
this.isDownloading = false;
return;
}
await submitDownload({
const res = await submitDownload({
urls: newUrls,
targetPath: path.join(
this.dtfSetting.downloadDir,
......@@ -344,9 +348,12 @@ export default {
),
batchArrangeNum: value
});
this.$message("下载进行中,下载完成的素材将在文件夹原素材中显示");
// 提交成功后,锁由 onDownloadStatusChange 事件维护,不再手动修改
if (res.code == 200) {
this.$message(res.msg);
} else {
this.isDownloading = false;
this.$message.error(res.msg);
}
} catch (error) {
console.error("下载提交失败", error);
this.$message.error("下载提交失败,请重试");
......@@ -363,9 +370,9 @@ export default {
this[statusKey] = status.isRunning;
if (!status.isRunning && status.result) {
const { success, failed } = status.result;
console.log(
`下载完成:成功 ${success.length} 个,失败 ${failed.length} 个`
const { success, failed, currentBatchNo } = status.result;
this.$message.success(
`批次号:${currentBatchNo}下载完成:成功 ${success.length} 个,失败 ${failed.length} 个`
);
if (failed.length > 0) {
console.warn("下载失败明细:", failed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment