Commit 549fd693 by linjinhong

feat:修改下载流提示

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