Commit ba8ecc99 by zhuzhequan

裁切逻辑处理

parent 29101503
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"name": "JomallProductionAssistant", "name": "JomallProductionAssistant",
"productName": "JomallProductionAssistant", "productName": "JomallProductionAssistant",
"description": "", "description": "",
"version": "1.0.15", "version": "1.0.16",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
......
...@@ -44,6 +44,43 @@ function readEnv() { ...@@ -44,6 +44,43 @@ function readEnv() {
} }
readEnv(); readEnv();
export default { export default {
saveImgByUrl:async (req, res) => {
try {
const response = await axios({
url:req.body.url,
method: 'GET',
responseType: 'stream',
});
let fileName = uuid.v4() + ".png";
const filePath = path.join(
process.cwd(),
"./print/Input/" +fileName
);
const writer = fs.createWriteStream(filePath);
response.data.pipe(writer);
writer.on('finish', () => {
res.json({
code: 200,
data:filePath
})
});
writer.on('error', (err) => {
res.json({
code: 500,
data:err.message
})
});
} catch (error) {
console.error('Error downloading image:', error);
res.json({
code: 500,
data:error.message
})
}
},
writePrintLog: async (req, res) => { writePrintLog: async (req, res) => {
try { try {
let body = req.body; let body = req.body;
......
...@@ -42,4 +42,7 @@ router.post("/saveToPng", fn.saveToPng); ...@@ -42,4 +42,7 @@ router.post("/saveToPng", fn.saveToPng);
// 保存生成后得图片返回地址 // 保存生成后得图片返回地址
router.post("/getAllCountry", fn.getAllCountry); router.post("/getAllCountry", fn.getAllCountry);
//根据图片地址保存文件到本地
router.post("/saveImgByUrl", fn.saveImgByUrl);
export { router as default }; export { router as default };
...@@ -297,11 +297,22 @@ export default { ...@@ -297,11 +297,22 @@ export default {
let res = await this.$api.post("/downloadByDesignId", params); let res = await this.$api.post("/downloadByDesignId", params);
this.$message.success(res.msg); this.$message.success(res.msg);
}, },
async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList){ async saveImgByUrl(url) {
let imageResList = [] return new Promise(async (resolve, reject) => {
try {
let res = await this.$api.post("/saveImgByUrl", { url });
console.log(res);
resolve(res.data);
} catch (e) {
reject(e.message);
}
});
},
async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList) {
let imageResList = [];
if (this.detail.adjustable && designImagesCanvasJsonList) { if (this.detail.adjustable && designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList); designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
if(designImagesCanvasJsonList[0].images){ if (designImagesCanvasJsonList[0].images) {
designImagesCanvasJsonList.forEach((el) => { designImagesCanvasJsonList.forEach((el) => {
el.images.forEach((item) => { el.images.forEach((item) => {
imageResList.push({ imageResList.push({
...@@ -310,7 +321,10 @@ export default { ...@@ -310,7 +321,10 @@ export default {
}); });
}); });
}); });
}else{ for (let item of imageResList) {
item.productionFile = await this.saveImgByUrl(item.productionFile);
}
} else {
let imageList = await this.canvasToImage(designImagesCanvasJsonList); let imageList = await this.canvasToImage(designImagesCanvasJsonList);
let fm = new FormData(); let fm = new FormData();
for (let img of imageList) { for (let img of imageList) {
...@@ -326,12 +340,12 @@ export default { ...@@ -326,12 +340,12 @@ export default {
imageResList = Sres.data; imageResList = Sres.data;
} }
} }
if(!imageResList.length){ if (!imageResList.length) {
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示 // 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", { let res = await this.$api.post("/downloadBySubOrderNumber", {
ids: [this.detail.id], ids: [this.detail.id],
device: this.$store.state.desktopDevice, device: this.$store.state.desktopDevice,
type: this.factoryType, type: this.factoryType
}); });
if (!res.data.length) return this.$message.warning("未找到素材图!"); if (!res.data.length) return this.$message.warning("未找到素材图!");
res.data.forEach((el) => { res.data.forEach((el) => {
...@@ -359,7 +373,7 @@ export default { ...@@ -359,7 +373,7 @@ export default {
// 删除最后一个部分,即文件名 // 删除最后一个部分,即文件名
}, 500); }, 500);
} }
}else{ } else {
let obj = { let obj = {
type: "sendFile", type: "sendFile",
value: imageResList.map((el, index) => { value: imageResList.map((el, index) => {
...@@ -410,7 +424,7 @@ export default { ...@@ -410,7 +424,7 @@ export default {
); );
this.detail = findByPodProductionNo.data; this.detail = findByPodProductionNo.data;
this.imgList = []; this.imgList = [];
let designImagesCanvasJsonList = this.detail.drParam let designImagesCanvasJsonList = this.detail.drParam;
await this.hasDesignImagesCanvasJsonList(designImagesCanvasJsonList); await this.hasDesignImagesCanvasJsonList(designImagesCanvasJsonList);
this.$store.commit("setProductDetail", findByPodProductionNo.data); this.$store.commit("setProductDetail", findByPodProductionNo.data);
ipcRenderer.send("win-subScreen", findByPodProductionNo.data); ipcRenderer.send("win-subScreen", findByPodProductionNo.data);
......
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