Commit f89489d4 by linjinhong

添加美国工厂端接口、修改自动裁切会出现图片重复问题

parent d1c42c47
......@@ -66,28 +66,31 @@ export default {
}
},
downloadBySubOrderNumber: async (req, res) => {
const params = [...req.body];
params.pop();
const params = req.body;
const token = req.headers["jwt-token"];
console.log(72, params);
let url =
params.type === "CN"
? "factory/podJomallOrder/downloadByProduction"
: "factory/podJomallOrderProductUs/downloadDesignImages";
try {
let {
data,
} = await axios.post(
`${env}/factory/podJomallOrder/downloadByProduction`,
[req.body[0]],
{ headers: { "jwt-token": token } }
);
let { data } = await axios.post(`${env}/${url}`, [...params.ids], {
headers: { "jwt-token": token },
});
let files = [];
console.log(81, data);
if (data.code === 200) {
if (!data.data) data.data = [data.message];
files = data.data;
files = files.map((el) => {
return { url: `${fileEnv}${el}` };
// return { url: `${el}` };
});
if (req.body[1] === 1) {
if (params.device === 1) {
downloadImage(files)
.then((data) => {
res.json({ code: 200, data });
......@@ -116,15 +119,20 @@ export default {
},
findByPodProductionNo: async (req, res) => {
const token = req.headers["jwt-token"];
const q = req.body;
const params = req.body;
let url =
params.type === "CN"
? "factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber"
: "factory/podJomallOrderProductUs/getProductUsByFactorySubOrderNumber";
let paramsField =
params.type === "CN" ? "thirdSubOrderNumber" : "factorySubOrderNumber";
try {
let { data } = await axios.get(
`${env}/factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber`,
{
params: q,
headers: { "jwt-token": token },
}
);
let { data } = await axios.get(`${env}/${url}`, {
params: {
[paramsField]: params.thirdSubOrderNumber,
},
headers: { "jwt-token": token },
});
res.json(data);
} catch (err) {
res.json({ code: 500, msg: err });
......@@ -144,14 +152,20 @@ export default {
commitApply: async () => {},
completeDelivery: async (req, res) => {
const token = req.headers["jwt-token"];
const params = req.body;
let url =
params.type === "CN"
? "factory/podJomallOrderProduct/completeDelivery"
: "factory/podJomallOrderProductUs/completeDelivery";
let postData =
params.type === "CN"
? { id: params.id }
: { id: params.id, podJomallOrderUsId: params.podJomallOrderUsId };
try {
let {
data,
} = await axios.post(
`${env}/factory/podJomallOrderProduct/completeDelivery`,
req.body,
{ headers: { "jwt-token": token } }
);
let { data } = await axios.post(`${env}/${url}`, postData, {
headers: { "jwt-token": token },
});
res.send(data);
} catch (err) {
console.log(err);
......
......@@ -22,6 +22,7 @@ export default {
},
type: Object,
},
factoryType: { type: String, default: "CN" },
},
data() {
return {
......@@ -149,7 +150,13 @@ export default {
},
async setData(data) {
if (!data) return this.$message.warning("请扫描生产单号");
await this.$api.post("/completeDelivery", { id: data.id }).then(() => {});
await this.$api
.post("/completeDelivery", {
id: data.id,
type: this.factoryType,
podJomallOrderUsId: data.podJomallOrderUsId,
})
.then(() => {});
this.$message.success("操作成功");
},
async sureData() {
......@@ -203,7 +210,7 @@ export default {
responseType: "blob",
})
.then((res) => {
console.log("item", item);
// console.log("item", item);
var url = URL.createObjectURL(res.data);
let img = new Image();
......@@ -215,7 +222,7 @@ export default {
reject();
};
img.onload = function() {
console.log(img, "img");
// console.log(img, "img");
img.onload = null;
const ctx = canvas.getContext("2d");
ctx.drawImage(img, ...item.drawImage);
......@@ -309,25 +316,22 @@ export default {
"/findByPodProductionNo",
{
thirdSubOrderNumber: this.productionNo,
type: this.factoryType,
}
);
this.detail = findByPodProductionNo.data;
console.log("detail111111", findByPodProductionNo);
// console.log("detail111111", findByPodProductionNo);
let imageResList = [];
let designImagesCanvasJsonList = this.detail.drParam;
if (designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
console.log(316, designImagesCanvasJsonList);
let imageList = await this.canvasToImage(designImagesCanvasJsonList);
// console.log(9999999, imageList);
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);
// console.log("fm", fm);
let Sres = await this.$api.post("/saveToPng", fm);
Sres.data.forEach((item, i) => {
item.title = designImagesCanvasJsonList[i].options.title;
......@@ -368,10 +372,11 @@ export default {
bus.$emit("busEmit", obj);
} else {
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", [
this.detail.id,
this.$store.state.desktopDevice,
]);
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 = [];
......@@ -411,7 +416,7 @@ export default {
}, 500);
}
} else {
console.log(260, res.data);
console.log("newImgList", newImgList);
let obj = {
type: "sendFile",
value: newImgList.map((el, index) => {
......@@ -539,9 +544,11 @@ export default {
},
async cutImgFn(arr) {
if (!arr.length) return;
console.log(arr);
try {
const processQueue = await Promise.all(
arr.map(async (el) => {
arr.map(async (el, index) => {
try {
const outputDir = path.dirname(el.productionFile);
const outputFileName = `${uuid.v4()}.png`;
......@@ -555,7 +562,7 @@ export default {
return {
fileName: outputFileName,
productionFile: res.msg[0]?.outputPath,
designId: el.designId,
designId: el.designId || index,
};
} catch (error) {
console.error(`处理失败: ${el.productionFile}`, error);
......@@ -566,6 +573,8 @@ export default {
// 等待所有异步操作完成
await new Promise((resolve) => setTimeout(resolve, 100));
const newMap = new Map(processQueue.map((el) => [el.designId, el]));
console.log("newMap", newMap);
processQueue.forEach((el) => {
if (newMap.has(el.designId)) {
el.fileName = newMap.get(el.designId).fileName;
......
......@@ -9,6 +9,7 @@ export default {
data() {
return {
user: {},
factoryType: "CN",
};
},
mounted() {
......@@ -27,8 +28,8 @@ export default {
<template>
<div class="page">
<p-head :user="user" />
<p-main />
<p-head :user="user" :factoryType="factoryType" />
<p-main :factoryType="factoryType" />
<update-dialog ref="updateDialog" />
</div>
</template>
......
......@@ -24,6 +24,7 @@ export default {
ImgSetting,
PicScrollbarBox,
},
props: { factoryType: { type: String, default: "CN" } },
destroyed() {
document.removeEventListener("keyup", this.keyup);
document.removeEventListener("dragover", this.dragover);
......@@ -192,7 +193,7 @@ export default {
},
watch: {
imgList: {
handler(newValue) {
handler() {
// console.log(169, newValue);
if (this.imgList.length > 0) {
......@@ -205,7 +206,7 @@ export default {
dom_i.style.zIndex === "" || !dom_i.style.zIndex
? 0
: dom_i.style.zIndex;
dom[i].addEventListener("click", (e) => {
dom[i].addEventListener("click", () => {
this.selectIndex = i;
this.selectItem(i);
});
......@@ -226,7 +227,7 @@ export default {
this.showImgSetting = false;
}
},
desktopDevice(newValue, oldValue) {
desktopDevice(newValue) {
if (newValue == 2) {
this.imgList = [];
this.selectImgList = [];
......@@ -261,7 +262,7 @@ export default {
immediate: true,
},
systemSetting: {
handler(newValue) {
handler() {
if (this.imgList.length > 0) {
this.$refs.imgSetting?.getCurrentItem(this.imgList[this.selectIndex]);
}
......@@ -295,7 +296,7 @@ export default {
},
});
that.selectImgIndex = 0;
that.addFile(data, (file) => {
that.addFile(data, () => {
that.imgHistoryList.push(JSON.parse(JSON.stringify(that.imgList)));
});
}
......@@ -400,7 +401,7 @@ export default {
console.log(this.detail.designImageSize, "this.detail.size");
this.getBackFile(
{ files: [img], size: this.detail.designImageSize },
(file) => {
() => {
this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList)));
}
);
......@@ -427,7 +428,7 @@ export default {
height: this.detail.mssHeight,
};
}
this.getBackFile({ files: [it], size }, (file) => {
this.getBackFile({ files: [it], size }, () => {
this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList)));
});
this.imgDom = document.getElementById("imgBox");
......@@ -529,7 +530,7 @@ export default {
}
this.getCutArea();
},
resizing(index) {},
resizing() {},
rotating(data, item) {
this.$set(item, "r", data.angle);
this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList)));
......@@ -557,7 +558,7 @@ export default {
}
this.selectIndex = index;
},
deSelect(index) {
deSelect() {
this.close();
this.selectIndex = -1;
},
......@@ -856,10 +857,11 @@ export default {
this.$store.commit("setIsPreView", this.isView);
},
async downloadImg() {
let res = await this.$api.post("/downloadBySubOrderNumber", [
this.detail.id,
this.$store.state.desktopDevice,
]);
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("未找到素材图!");
let imgList = [];
res.data.forEach((el) => {
......@@ -890,7 +892,7 @@ export default {
getInset(top = 100, right = 0, bottom = 0, left = 100) {
return `inset(${100 - top}% ${right}% ${bottom}% ${100 - left}%)`;
},
getDrag(e) {
getDrag() {
this.drrDom = document.getElementsByClassName("drr")[0];
this.imgDom = document.getElementById("imgBox");
......@@ -1025,7 +1027,7 @@ export default {
this.selectImgIndex = 0;
this.getBackFile(
{ files: [value[0]], size: this.detail.designImageSize || null },
(file) => {
() => {
this.imgHistoryList.push(
JSON.parse(JSON.stringify(this.imgList))
);
......@@ -1111,6 +1113,7 @@ export default {
v-for="(img, i) in selectImgList"
:key="i"
class="img-item showImg"
style="max-width: 50%;"
@click.stop.prevent="selectImg(img, i)"
>
<img
......
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