Commit 5c58f588 by zhuzhequan

扫码逻辑代码整理

parent 4e672b59
......@@ -297,6 +297,92 @@ export default {
let res = await this.$api.post("/downloadByDesignId", params);
this.$message.success(res.msg);
},
async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList){
let imageResList = []
if (this.detail.adjustable && designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
if(designImagesCanvasJsonList[0].images){
designImagesCanvasJsonList.forEach((el) => {
el.images.forEach((item) => {
imageResList.push({
productionFile: item,
title: el.title
});
});
});
}else{
let imageList = await this.canvasToImage(designImagesCanvasJsonList);
let fm = new FormData();
for (let img of imageList) {
let filename = uuid.v4().replace("-", "") + ".png";
fm.append("files", this.base64ToFile(img, filename));
}
// console.log("fm", fm);
let Sres = await this.$api.post("/saveToPng", fm);
Sres.data.forEach((item, i) => {
item.title = designImagesCanvasJsonList[i].options.title;
item.productionFile = item.url;
});
imageResList = Sres.data;
}
}
if(!imageResList.length){
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", {
ids: [this.detail.id],
device: this.$store.state.desktopDevice,
type: this.factoryType,
});
if (res.data.length === 0)
return this.$message.warning("未找到素材图!");
this.imgList = [];
res.data.forEach((el) => {
imageResList = imageResList.concat(el.list || []);
});
}
if (this.checked) {
imageResList = await this.cutImgFn(imageResList);
imageResList.forEach((el) => {
el.isCut = true;
});
}
// 延迟后强制激活窗口
if (this.desktopDevice !== 1) {
if (imageResList.length) {
let pathUrl = imageResList[0].productionFile;
setTimeout(async () => {
// await this.focusExplorerWindow(pathUrl);
const pathParts = pathUrl.split("\\");
pathParts.pop();
// 使用 join() 将剩余部分重新拼接成路径
const folderPath = pathParts.join("\\");
ipcRenderer.send("select-files", folderPath);
// 删除最后一个部分,即文件名
}, 500);
}
}else{
let obj = {
type: "sendFile",
value: imageResList.map((el, index) => {
el.designId = el.designId || index;
return el;
})
};
if (
this.detail.mssWidth &&
this.detail.adjustable &&
this.detail.mssHeight
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
}
},
async getDataInfo() {
if (
this.detail &&
......@@ -325,131 +411,11 @@ export default {
}
);
this.detail = findByPodProductionNo.data;
// console.log("detail111111", findByPodProductionNo);
let imageResList = [];
this.imgList = [];
let designImagesCanvasJsonList = this.detail.drParam
if (designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
if (this.detail.adjustable) {
let imageList = await this.canvasToImage(designImagesCanvasJsonList);
let fm = new FormData();
for (let img of imageList) {
let filename = uuid.v4().replace("-", "") + ".png";
fm.append("files", this.base64ToFile(img, filename));
}
// console.log("fm", fm);
let Sres = await this.$api.post("/saveToPng", fm);
Sres.data.forEach((item, i) => {
item.title = designImagesCanvasJsonList[i].options.title;
item.productionFile = item.url;
});
imageResList = Sres.data;
this.imgList = [];
if (this.checked) {
imageResList = await this.cutImgFn(imageResList);
imageResList.forEach((el) => {
el.isCut = true;
});
}
} else {
this.imgList = [];
designImagesCanvasJsonList.forEach((el) => {
el.images.forEach((item) => {
this.imgList.push({
productionFile: item,
title: el.title
});
});
});
}
}
let designImagesCanvasJsonList = this.detail.drParam
await this.hasDesignImagesCanvasJsonList(designImagesCanvasJsonList);
this.$store.commit("setProductDetail", findByPodProductionNo.data);
ipcRenderer.send("win-subScreen", findByPodProductionNo.data);
if (imageResList && imageResList.length) {
let obj = {
type: "sendFile",
value: imageResList.map((el, index) => {
el.designId = el.designId || index;
return el;
})
};
if (
this.detail.mssWidth &&
this.detail.adjustable &&
this.detail.mssHeight
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
} else {
if(!this.imgList.length){
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", {
ids: [this.detail.id],
device: this.$store.state.desktopDevice,
type: this.factoryType,
});
if (res.data.length === 0)
return this.$message.warning("未找到素材图!");
res.data.forEach((el) => {
this.imgList = this.imgList.concat(el.list || []);
});
}
// res.data = arr.filter((el) => el.type !== 1);
let newImgList;
if(this.imgList.length)
if (this.checked) {
newImgList = await this.cutImgFn(this.imgList);
newImgList.forEach((el) => {
el.isCut = true;
});
} else {
newImgList = this.imgList;
}
// 延迟后强制激活窗口
if (this.desktopDevice !== 1) {
if (this.imgList.length) {
let pathUrl = this.imgList[0].productionFile;
setTimeout(async () => {
// await this.focusExplorerWindow(pathUrl);
const pathParts = pathUrl.split("\\");
pathParts.pop();
// 使用 join() 将剩余部分重新拼接成路径
const folderPath = pathParts.join("\\");
ipcRenderer.send("select-files", folderPath);
// 删除最后一个部分,即文件名
}, 500);
}
} else {
console.log("newImgList", newImgList);
let obj = {
type: "sendFile",
value: newImgList.map((el, index) => {
el.designId = el.designId || index;
return el;
})
};
if (
this.detail.mssWidth &&
this.detail.adjustable &&
this.detail.mssHeight
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
}
}
this.$dataStore.set("production_no", this.productionNo);
this.productionNo = "";
this.$refs.searchRef.focus();
......@@ -556,7 +522,7 @@ export default {
console.log(347, store.state.desktopDevice);
},
async cutImgFn(arr) {
if (!arr.length) return;
if (!arr.length) return arr;
console.log(arr);
try {
......
......@@ -652,7 +652,6 @@ export default {
that.$nextTick(async () => {
let w = bw / 2;
let h = bh / 2;
let width_px, height_px, rate, x, y;
if (size && !files[i].isCut) {
width_px = that.WHproportion * mmToPx(size.width);
......@@ -1053,12 +1052,7 @@ export default {
});
break;
case "sendFile":
console.log("sendFile");
if (size) {
this.hasSize = true;
} else {
this.hasSize = false;
}
this.hasSize = !!size;
this.detail.designImageSize = size;
console.log(this.detail, "this.detail");
this.imgList = [];
......
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