Commit f89489d4 by linjinhong

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

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