Commit ba8ecc99 by zhuzhequan

裁切逻辑处理

parent 29101503
......@@ -2,7 +2,7 @@
"name": "JomallProductionAssistant",
"productName": "JomallProductionAssistant",
"description": "",
"version": "1.0.15",
"version": "1.0.16",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
......
......@@ -44,6 +44,43 @@ function readEnv() {
}
readEnv();
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) => {
try {
let body = req.body;
......
......@@ -42,4 +42,7 @@ router.post("/saveToPng", fn.saveToPng);
// 保存生成后得图片返回地址
router.post("/getAllCountry", fn.getAllCountry);
//根据图片地址保存文件到本地
router.post("/saveImgByUrl", fn.saveImgByUrl);
export { router as default };
......@@ -297,11 +297,22 @@ export default {
let res = await this.$api.post("/downloadByDesignId", params);
this.$message.success(res.msg);
},
async hasDesignImagesCanvasJsonList(designImagesCanvasJsonList){
let imageResList = []
async saveImgByUrl(url) {
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) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
if(designImagesCanvasJsonList[0].images){
if (designImagesCanvasJsonList[0].images) {
designImagesCanvasJsonList.forEach((el) => {
el.images.forEach((item) => {
imageResList.push({
......@@ -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 fm = new FormData();
for (let img of imageList) {
......@@ -326,12 +340,12 @@ export default {
imageResList = Sres.data;
}
}
if(!imageResList.length){
if (!imageResList.length) {
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", {
ids: [this.detail.id],
device: this.$store.state.desktopDevice,
type: this.factoryType,
type: this.factoryType
});
if (!res.data.length) return this.$message.warning("未找到素材图!");
res.data.forEach((el) => {
......@@ -359,7 +373,7 @@ export default {
// 删除最后一个部分,即文件名
}, 500);
}
}else{
} else {
let obj = {
type: "sendFile",
value: imageResList.map((el, index) => {
......@@ -410,7 +424,7 @@ export default {
);
this.detail = findByPodProductionNo.data;
this.imgList = [];
let designImagesCanvasJsonList = this.detail.drParam
let designImagesCanvasJsonList = this.detail.drParam;
await this.hasDesignImagesCanvasJsonList(designImagesCanvasJsonList);
this.$store.commit("setProductDetail", 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