Commit f3919697 by zhuzhequan

添加自动打印逻辑

parent f487e64e
......@@ -2,12 +2,12 @@ import {
downloadImage,
downloadOtherImage,
toSend,
writeProfileXml,
writeProfileXml
} from "@/server/utils";
const {
cropImageTransparentEdges,
cropTransparentEdges,
processImages,
processImages
} = require("../utils/setImage");
import axios from "axios";
import { returnLogFilePath } from "../utils/log";
......@@ -15,13 +15,11 @@ var request = require("request");
const compressing = require("compressing");
const uuid = require("uuid");
const path = require("path");
const fs = require("fs");
const os = require("os");
const { app } = require("electron");
let fileEnv, env, visionUrl;
axios.defaults.timeout = 12600000;
const multiparty = require("multiparty");
function readEnv() {
......@@ -74,7 +72,7 @@ export default {
const token = req.headers["jwt-token"];
try {
let {
data,
data
} = await axios.post(
`${env}/factory/podJomallOrder/downloadByProduction`,
[req.body[0]],
......@@ -83,27 +81,27 @@ export default {
let files = [];
if (data.code === 200) {
files = data.data;
files = files.map((el) => {
files = files.map(el => {
return { url: `${fileEnv}${el}` };
});
// res.json({ code: 200, data: "" });
// return;
if (req.body[1] === 1) {
downloadImage(files)
.then((data) => {
.then(data => {
res.json({ code: 200, data });
})
.catch((err) => {
.catch(err => {
res.json({ code: 500, msg: err });
});
} else {
downloadOtherImage(files)
.then((data) => {
.then(data => {
console.log(77, data);
res.json({ code: 200, data });
})
.catch((err) => {
.catch(err => {
res.json({ code: 500, msg: err });
});
}
......@@ -123,7 +121,7 @@ export default {
`${env}/factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber`,
{
params: q,
headers: { "jwt-token": token },
headers: { "jwt-token": token }
}
);
res.json(data);
......@@ -147,7 +145,7 @@ export default {
const token = req.headers["jwt-token"];
try {
let {
data,
data
} = await axios.post(
`${env}/factory/podJomallOrderProduct/completeDelivery`,
req.body,
......@@ -180,7 +178,7 @@ export default {
console.log("success");
res.json({
code: 200,
msg: q.productionNo + ".zip" + "已下载到桌面",
msg: q.productionNo + ".zip" + "已下载到桌面"
});
})
.on("error", () => {
......@@ -222,8 +220,8 @@ export default {
code: 200,
data: {
fileName,
url: path.join(process.cwd(), "./print/Input/" + fileName),
},
url: path.join(process.cwd(), "./print/Input/" + fileName)
}
});
}
});
......@@ -275,10 +273,10 @@ export default {
console.log(249, body);
toSend(body)
.then((r) => {
.then(r => {
res.send({ code: 200, msg: "操作成功" });
})
.catch((err) => {
.catch(err => {
res.send({ code: 500, msg: err });
});
},
......@@ -317,7 +315,7 @@ export default {
fs.unlinkSync(from);
res.json({ code: 200, msg: "更新成功" });
})
.catch((err) => {
.catch(err => {
res.json({ code: 500, msg: err.message });
});
});
......@@ -358,4 +356,33 @@ export default {
res.json({ code: 500, msg: err.message });
}
},
saveToPng: async (req, res) => {
try {
const p = path.join(process.cwd(), "./print/Input/");
const form = new multiparty.Form({ uploadDir: p });
form.parse(req, function(err, fields, files) {
console.log(fields, files, err);
if (err) {
res.send({ code: 500, err });
} else {
let list = [];
files.files.forEach(file => {
let fileName = uuid.v4() + ".png";
fs.renameSync(file.path, path.join(p, fileName));
list.push({
fileName,
url: path.join(process.cwd(), "./print/Input/" + fileName)
});
});
res.json({
code: 200,
data: list
});
}
});
} catch (err) {
console.log(err);
res.json({ code: 500, msg: err });
}
}
};
......@@ -37,4 +37,7 @@ router.post("/imageListTransparentEdges", fn.imageListTransparentEdges);
// 处理图片并输出结果
router.post("/processImage", fn.processImage);
// 保存生成后得图片返回地址
router.post("/saveToPng", fn.saveToPng);
export { router as default };
......@@ -7,6 +7,7 @@ import pkg from "../../../../package.json";
import UpdateDialog from "@/views/design/updateDialog.vue";
import path from "path"; // 引入 path 模块
import store from "@/store/index.js";
import axios from "axios";
const uuid = require("uuid");
const fs = require("fs");
......@@ -16,10 +17,10 @@ export default {
user: {
default: {
avatar: "",
factory: {},
factory: {}
},
type: Object,
},
type: Object
}
},
data() {
return {
......@@ -29,20 +30,20 @@ export default {
cacheList: [
{
label: "清除当前登录信息",
value: "token",
value: "token"
},
{
label: "登录记录",
value: "userList",
value: "userList"
},
{
label: "打印预设",
value: "print-setting",
value: "print-setting"
},
{
label: "系统设置",
value: "setting",
},
value: "setting"
}
],
selectGridIndex: 0,
pkg,
......@@ -57,7 +58,7 @@ export default {
unit: "mm",
language: "cn",
autoPrint: false,
gridSpacing: 10,
gridSpacing: 10
},
imgList: [],
detail: null,
......@@ -76,15 +77,15 @@ export default {
"hsva(120, 40, 94, 0.5)",
"hsl(181, 100%, 37%)",
"hsla(209, 100%, 56%, 0.73)",
"#c7158577",
"#c7158577"
],
grid,
grid
};
},
computed: {
actionList() {
return this.$store.getters.getActionList;
},
}
},
mounted() {
// console.log(pkg, "pkg");
......@@ -105,12 +106,12 @@ export default {
this.$dataStore.set("setting", this.setting);
bus.$emit("busEmit", { type: "updateSystemSetting" });
},
deep: true,
},
deep: true
}
},
methods: {
checkUpdate() {
this.$refs.updateDialog.checkUpdate().then((data) => {
this.$refs.updateDialog.checkUpdate().then(data => {
if (data) {
// 有新版本更新
this.$refs.updateDialog.open(data);
......@@ -125,7 +126,7 @@ export default {
this.$confirm("是否退出登录?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
})
.then(() => {
this.$dataStore.delete("user");
......@@ -152,7 +153,7 @@ export default {
this.$confirm(`确定生产完成?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
}).then(async () => {
await this.setData(this.detail);
});
......@@ -164,15 +165,15 @@ export default {
this.$confirm("是否确定清除?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
})
.then(() => {
for (let k of this.checkList) {
if (k === "print-setting" || k === "deviceId") {
let list = Object.keys(this.$dataStore.store).filter((el) =>
let list = Object.keys(this.$dataStore.store).filter(el =>
el.includes(k)
);
list.forEach((el) => {
list.forEach(el => {
this.$dataStore.delete(el);
});
} else if (k === "token") {
......@@ -188,12 +189,87 @@ export default {
})
.catch(() => {});
},
drawImage(canvas, item) {
return new Promise((resolve, reject) => {
try {
axios
.get(item?.src, {
responseType: "blob"
})
.then(res => {
var url = URL.createObjectURL(res.data);
let img = new Image();
img.crossorigin = "";
img.src = url;
img.style.width = item.img_width + "px";
img.style.height = item.img_height + "px";
img.onerror = function() {
reject();
};
img.onload = function() {
console.log(img, "img");
img.onload = null;
const ctx = canvas.getContext("2d");
ctx.drawImage(img, ...item.drawImage);
URL.revokeObjectURL(url);
resolve();
};
})
.catch(e => {
console.log(e);
reject(e);
});
} catch (e) {
console.log(e, "error");
reject(e);
}
});
},
async canvasToImage(canvasList) {
return new Promise(async (resolve, reject) => {
let imageList = [];
try {
for (let canvasItem of canvasList) {
const canvas = document.createElement("canvas");
canvas.className = "createCanvas";
canvas.width = canvasItem.canvasWidth;
canvas.height = canvasItem.canvasHeight;
let objects = canvasItem.options.objects.filter(
el => el.type === "image"
);
let list = [];
for (let i in objects) {
list.push(this.drawImage(canvas, canvasItem.list[i]));
}
await Promise.all(list);
let base = canvas.toDataURL("image/png", 1);
canvas.remove();
imageList.push(base);
}
resolve(imageList);
} catch (e) {
console.log(e);
reject(e);
}
});
},
base64ToFile(base64, fileName) {
let arr = base64.split(",");
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], fileName, { type: 'image/png' });
},
async downloadImage() {
if (!this.detail || Object.keys(this.detail).length === 0)
return this.$message.warning("请扫描生产单号");
let params = {
productionNo: this.detail.factorySubOrderNumber,
imgList: this.imgList,
imgList: this.imgList
};
let res = await this.$api.post("/downloadByDesignId", params);
......@@ -215,73 +291,107 @@ export default {
const findByPodProductionNo = await this.$api.post(
"/findByPodProductionNo",
{
thirdSubOrderNumber: this.productionNo,
thirdSubOrderNumber: this.productionNo
}
);
this.detail = findByPodProductionNo.data;
console.log(219, this.detail);
let imageResList = []
let designImagesCanvasJsonList = "[{\"options\":{\"rect_info\":{\"rectWidth\":278,\"rectHeight\":311,\"leftDistance\":164,\"topDistance\":134},\"title\":\"\",\"json\":{\"version\":\"5.4.0\",\"objects\":[{\"type\":\"rect\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":239.6414188934889,\"top\":100.125,\"width\":536.7171622130222,\"height\":603.75,\"fill\":\"rgba(255,255,255,0)\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"rx\":0,\"ry\":0,\"mediaType\":\"bg\",\"objectCaching\":true},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":386.625,\"top\":236.62500000000006,\"width\":319,\"height\":345,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.464984939759036,\"scaleY\":0.464984939759036,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":319,\"origHeight\":345,\"originImgUrl\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/17/wdtq66-hzu9vgr-m9kyp1uk.png\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/17/wdtq66-hzu9vgr-m9kyp1uk.png\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":368.9238341968912,\"top\":378.725,\"width\":2584,\"height\":1544,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.1080310880829015,\"scaleY\":0.1080310880829015,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":2584,\"origHeight\":1544,\"originImgUrl\":\"https://jomalls-test.oss-cn-hangzhou.aliyuncs.com/local/design/2503/06/v3b1yw-m4y92pr-m7wt14fi.png\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls-test.oss-cn-hangzhou.aliyuncs.com/local/design/2503/06/v3b1yw-m4y92pr-m7wt14fi.png\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"}],\"id\":\"canvas_6378\",\"width\":1017,\"height\":805,\"oldCutWidth\":536.7171622130222,\"oldCutHeight\":603.75,\"origWidth\":2362,\"origHeight\":2657,\"objectCaching\":false},\"objects\":[{\"type\":\"rect\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":239.6414188934889,\"top\":100.125,\"width\":536.7171622130222,\"height\":603.75,\"fill\":\"rgba(255,255,255,0)\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"rx\":0,\"ry\":0,\"mediaType\":\"bg\",\"objectCaching\":true},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":386.625,\"top\":236.62500000000006,\"width\":319,\"height\":345,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.464984939759036,\"scaleY\":0.464984939759036,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":319,\"origHeight\":345,\"originImgUrl\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/17/wdtq66-hzu9vgr-m9kyp1uk.png\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/17/wdtq66-hzu9vgr-m9kyp1uk.png\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":368.9238341968912,\"top\":378.725,\"width\":2584,\"height\":1544,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.1080310880829015,\"scaleY\":0.1080310880829015,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":2584,\"origHeight\":1544,\"originImgUrl\":\"https://jomalls-test.oss-cn-hangzhou.aliyuncs.com/local/design/2503/06/v3b1yw-m4y92pr-m7wt14fi.png\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls-test.oss-cn-hangzhou.aliyuncs.com/local/design/2503/06/v3b1yw-m4y92pr-m7wt14fi.png\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"}]},\"canvasWidth\":536.7171622130222,\"canvasHeight\":603.75,\"list\":[{\"rate\":1.930637274147562,\"drawImage\":[30.88054319999026,3.8612745482952335,286.371804860521,309.71245353253846],\"y\":2.000000000000057,\"x\":15.995000000000005,\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/17/wdtq66-hzu9vgr-m9kyp1uk.png\",\"img_width\":148.33019578313247,\"img_height\":160.41980421686742},{\"rate\":1.930637274147562,\"drawImage\":[-3.2939872953577103,278.2048312046637,538.941896564164,322.0302973278132],\"y\":144.10000000000002,\"x\":-1.7061658031087745,\"src\":\"https://jomalls-test.oss-cn-hangzhou.aliyuncs.com/local/design/2503/06/v3b1yw-m4y92pr-m7wt14fi.png\",\"img_width\":279.1523316062175,\"img_height\":166.79999999999993}]},{\"options\":{\"rect_info\":{\"rectWidth\":278,\"rectHeight\":311,\"leftDistance\":164,\"topDistance\":134},\"title\":\"\",\"json\":{\"version\":\"5.4.0\",\"objects\":[{\"type\":\"rect\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":239.6414188934889,\"top\":100.125,\"width\":536.7171622130222,\"height\":603.75,\"fill\":\"rgba(255,255,255,0)\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"rx\":0,\"ry\":0,\"mediaType\":\"bg\",\"objectCaching\":true},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":370.625,\"top\":292.82500000000005,\"width\":612,\"height\":408,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.4466176470588235,\"scaleY\":0.4466176470588235,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":612,\"origHeight\":408,\"originImgUrl\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/18/1x7lat8-3xppur-m9mk4w2u.jpg\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/18/1x7lat8-3xppur-m9mk4w2u.jpg\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"}],\"id\":\"canvas_6379\",\"width\":1017,\"height\":805,\"oldCutWidth\":536.7171622130222,\"oldCutHeight\":603.75,\"origWidth\":2362,\"origHeight\":2657,\"objectCaching\":false},\"objects\":[{\"type\":\"rect\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":239.6414188934889,\"top\":100.125,\"width\":536.7171622130222,\"height\":603.75,\"fill\":\"rgba(255,255,255,0)\",\"stroke\":null,\"strokeWidth\":1,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":1,\"scaleY\":1,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"rx\":0,\"ry\":0,\"mediaType\":\"bg\",\"objectCaching\":true},{\"type\":\"image\",\"version\":\"5.4.0\",\"originX\":\"left\",\"originY\":\"top\",\"left\":370.625,\"top\":292.82500000000005,\"width\":612,\"height\":408,\"fill\":\"rgb(0,0,0)\",\"stroke\":null,\"strokeWidth\":0,\"strokeDashArray\":null,\"strokeLineCap\":\"butt\",\"strokeDashOffset\":0,\"strokeLineJoin\":\"miter\",\"strokeUniform\":false,\"strokeMiterLimit\":4,\"scaleX\":0.4466176470588235,\"scaleY\":0.4466176470588235,\"angle\":0,\"flipX\":false,\"flipY\":false,\"opacity\":1,\"shadow\":null,\"visible\":true,\"backgroundColor\":\"\",\"fillRule\":\"nonzero\",\"paintFirst\":\"fill\",\"globalCompositeOperation\":\"source-over\",\"skewX\":0,\"skewY\":0,\"cropX\":0,\"cropY\":0,\"origWidth\":612,\"origHeight\":408,\"originImgUrl\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/18/1x7lat8-3xppur-m9mk4w2u.jpg\",\"mediaType\":\"material\",\"filters\":[],\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/18/1x7lat8-3xppur-m9mk4w2u.jpg\",\"objectCaching\":true,\"crossOrigin\":\"anonymous\"}]},\"canvasWidth\":536.7171622130222,\"canvasHeight\":603.75,\"list\":[{\"rate\":1.930637274147562,\"drawImage\":[-0.00965318637072903,112.3630893553882,527.7010861427531,351.80072409516873],\"y\":58.200000000000045,\"x\":-0.0049999999999954525,\"src\":\"https://jomalls.oss-cn-hangzhou.aliyuncs.com/local/design/2504/18/1x7lat8-3xppur-m9mk4w2u.jpg\",\"img_width\":273.33,\"img_height\":182.22}]}]"
if (designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(designImagesCanvasJsonList);
console.log(designImagesCanvasJsonList, "designImagesCanvasJsonList");
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));
}
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
console.log(imageResList,'imageResList');
this.imgList = []
}
this.$store.commit("setProductDetail", findByPodProductionNo.data);
ipcRenderer.send("win-subScreen", findByPodProductionNo.data);
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", [
this.detail.id,
this.$store.state.desktopDevice,
]);
this.imgList = [];
res.data.forEach((el) => {
this.imgList = this.imgList.concat(el.list || []);
});
this.$dataStore.set("production_no", this.productionNo);
if (res.data.length === 0)
return this.$message.warning("未找到素材图!");
let arr = [];
res.data.forEach((el) => {
if (el.list) {
el.list.forEach((it) => {
arr.push(it);
});
}
});
res.data = arr.filter((el) => el.type !== 1);
let newImgList;
if (this.checked) {
newImgList = await this.cutImgFn(res.data);
} else {
newImgList = res.data;
}
// 延迟后强制激活窗口
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(260, res.data);
if(imageResList && imageResList.length){
this.checked = false
let obj = {
type: "sendFile",
value: newImgList,
value: imageResList
};
if (this.detail.mssWidth && this.detail.mssHeight) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
};
}
if(this.detail.mssWidth && this.detail.mssHeight){
obj.size = { width: this.detail.mssWidth, height: this.detail.mssHeight }
bus.$emit("busEmit", obj);
}else{
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
let res = await this.$api.post("/downloadBySubOrderNumber", [
this.detail.id,
this.$store.state.desktopDevice
]);
if (res.data.length === 0)
return this.$message.warning("未找到素材图!");
this.imgList = [];
res.data.forEach(el => {
this.imgList = this.imgList.concat(el.list || []);
});
let arr = [];
res.data.forEach(el => {
if (el.list) {
el.list.forEach(it => {
arr.push(it);
});
}
});
res.data = arr.filter(el => el.type !== 1);
let newImgList;
if (this.checked) {
newImgList = await this.cutImgFn(res.data);
} else {
newImgList = res.data;
}
// 延迟后强制激活窗口
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(260, res.data);
let obj = {
type: "sendFile",
value: newImgList
};
if (this.detail.mssWidth && this.detail.mssHeight) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
}
bus.$emit("busEmit",obj);
}
this.$dataStore.set("production_no", this.productionNo);
this.productionNo = "";
this.$refs.searchRef.focus();
} catch (err) {
console.log(err);
this.productionNo = "";
this.$refs.searchRef.focus();
}
......@@ -293,7 +403,7 @@ export default {
const command = `start explorer /select, "${path}"`;
// 检查路径是否存在
if (fs.existsSync(path)) {
exec(`cmd /c "${command}"`, (err) => {
exec(`cmd /c "${command}"`, err => {
if (err) console.error("激活窗口失败:", err);
});
} else {
......@@ -321,7 +431,7 @@ export default {
unit: "mm",
language: "cn",
autoPrint: false,
gridSpacing: 10,
gridSpacing: 10
};
this.$message.success("重置应用程序设置成功");
},
......@@ -342,8 +452,8 @@ export default {
formData.append("file", f);
let { data } = await this.$api.post("/uploadImage", formData, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
"Content-Type": "application/x-www-form-urlencoded"
}
});
bus.$emit("busEmit", { type: "uploadImage", value: data });
return false;
......@@ -353,7 +463,7 @@ export default {
this.setting.gridValue = i;
this.$store.commit("updateSystemSetting", {
field: "gridValue",
value: this.grid[i],
value: this.grid[i]
});
bus.$emit("busEmit", { type: "grid", value: this.grid[i] });
},
......@@ -369,21 +479,21 @@ export default {
if (!arr.length) return;
try {
const processQueue = await Promise.all(
arr.map(async (el) => {
arr.map(async el => {
try {
const outputDir = path.dirname(el.productionFile);
const outputFileName = `${uuid.v4()}.png`;
const outputPath = path.join(outputDir, outputFileName);
const params = {
inputPath: el.productionFile,
outputPath: outputPath,
outputPath: outputPath
};
const res = await this.$api.post("/processImage", params);
fs.unlinkSync(el.productionFile);
return {
fileName: outputFileName,
productionFile: res.msg[0]?.outputPath,
designId: el.designId,
designId: el.designId
};
} catch (error) {
console.error(`处理失败: ${el.productionFile}`, error);
......@@ -392,9 +502,9 @@ export default {
);
// 等待所有异步操作完成
await new Promise((resolve) => setTimeout(resolve, 100));
const newMap = new Map(processQueue.map((el) => [el.designId, el]));
processQueue.forEach((el) => {
await new Promise(resolve => setTimeout(resolve, 100));
const newMap = new Map(processQueue.map(el => [el.designId, el]));
processQueue.forEach(el => {
if (newMap.has(el.designId)) {
el.fileName = newMap.get(el.designId).fileName;
el.productionFile = newMap.get(el.designId).productionFile;
......@@ -406,8 +516,8 @@ export default {
console.error("错误", error);
return [];
}
},
},
}
}
};
</script>
<style scoped>
......@@ -452,8 +562,8 @@ export default {
@change="changeDesktopDeviceFn"
placeholder="请选择设备类型"
>
<el-option label="兄弟" :value="1"> </el-option>
<el-option label="其他" :value="2"> </el-option>
<el-option label="兄弟" :value="1"></el-option>
<el-option label="其他" :value="2"></el-option>
</el-select>
</div>
......@@ -525,7 +635,7 @@ export default {
>
<el-form-item prop="setting" label="网格显示">
<el-select
@change="(e) => settingChange('gridShow', e)"
@change="e => settingChange('gridShow', e)"
clearable
v-model="setting.gridShow"
>
......@@ -535,7 +645,7 @@ export default {
</el-form-item>
<el-form-item prop="gridSpacing" label="单位">
<el-select
@change="(e) => settingChange('unit', e)"
@change="e => settingChange('unit', e)"
clearable
v-model="setting.unit"
>
......@@ -545,7 +655,7 @@ export default {
</el-form-item>
<el-form-item prop="gridSpacing" label="网格间隔">
<el-select
@change="(e) => settingChange('gridSpacing', e)"
@change="e => settingChange('gridSpacing', e)"
clearable
v-model="setting.gridSpacing"
>
......@@ -573,7 +683,7 @@ export default {
</el-form-item>
<el-form-item prop="language" label="语言设置">
<el-select
@change="(e) => settingChange('language', e)"
@change="e => settingChange('language', e)"
clearable
v-model="setting.language"
>
......@@ -586,8 +696,8 @@ export default {
@click="checkUpdate"
style="margin-left: 15px"
type="text"
>检查更新</el-button
>
>检查更新
</el-button>
</el-form-item>
<!-- <el-form-item label="自动打印模式">-->
......@@ -684,8 +794,8 @@ export default {
:label="item.value"
v-for="(item, i) in cacheList"
:key="i"
>{{ item.label }}</el-checkbox
>
>{{ item.label }}
</el-checkbox>
</el-checkbox-group>
<template #footer>
<el-button @click="cacheVisible = false">取消</el-button>
......@@ -781,17 +891,21 @@ export default {
z-index: 2;
color: white;
}
::v-deep .el-color-picker__trigger {
background: white;
width: 41px;
}
::v-deep .el-color-picker__color {
border: none !important;
}
.selectInput {
display: flex;
align-items: center;
margin: 0 10px;
::v-deep {
.el-select .el-input {
max-width: 150px;
......
......@@ -226,10 +226,7 @@ export default {
productDetail(newValue) {
this.detail = { ...newValue };
if (typeof this.detail.imageAry == "string") {
this.detail.imageAry = JSON.parse(this.detail.imageAry).map((el) => {
if (!el.title) el.title = 1;
return el;
});
this.detail.imageAry = JSON.parse(this.detail.imageAry).filter(el=>el.title)
const otherArr = this.detail.imageAry.filter((el) => el.title == 1);
this.detail.AimageAry = [
...this.detail.imageAry.filter((el) => el.title === "正"),
......@@ -366,12 +363,21 @@ export default {
return mm1.width;
},
setDesignImg(title){
let img = this.selectImgList.find(it=>it.title===title)
if(img){
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)));
});
}
},
selectImg(it, i) {
// this.selectImgIndexList.push(i)
let item = this.imgList.find((img) => img.fileName === it.fileName);
if (item) return;
// this.selectImgIndexList = Array.from(new Set(this.selectImgIndexList))
this.getBackFile({ files: [it] }, (file) => {
this.getBackFile({ files: [it],size:null }, (file) => {
this.imgHistoryList.push(JSON.parse(JSON.stringify(this.imgList)));
});
},
......@@ -526,18 +532,27 @@ export default {
};
});
},
getComputedName(title){
let img = this.selectImgList.find(it=>it.title===title)
return img?.fileName
},
getComputedTitle(title){
console.log(this.selectImgList,'this.selectImgList');
let img = this.selectImgList.find(it=>it.title===title)
return img?.url
},
getBackFile({ files, size }, callback) {
let that = this;
let bw = document.getElementById("line").clientWidth;
let bw = window.getComputedStyle(document.getElementsByClassName('grid')[0]).width
bw = Number(bw.replace('px',''))
for (let i = 0; i < files.length; i++) {
files[i].url = files[i].productionFile;
files[i].url = files[i].productionFile || files[i].url
that.$nextTick(async () => {
let w = document.getElementById("line").clientWidth / 2;
let w = bw / 2;
let width_px, height_px, rate;
if (size) {
width_px = mmToPx(size.width);
height_px = mmToPx(size.height);
console.log(width_px, height_px, "w,h");
rate = height_px / width_px;
} else {
let data = await that.getImageSize(files[i].url);
......@@ -783,17 +798,19 @@ export default {
});
break;
case "sendFile":
console.log('sendFile');
if(size){
this.hasSize = true
}else{
this.hasSize = false
}
this.imgList = [];
this.detail.designImageSize = size
this.imgList = []
this.selectIndex = -1;
if (value.length > 0) {
this.selectImgList = value;
this.selectImgIndex = 0;
this.getBackFile({ files: [value[0]], size }, (file) => {
this.getBackFile({ files: [value[0]], size:this.detail.designImageSize || null }, (file) => {
this.imgHistoryList.push(
JSON.parse(JSON.stringify(this.imgList))
);
......@@ -845,113 +862,20 @@ export default {
>
</div>
</div>
<el-row class="main">
<el-col :span="6">
<div class="text-center">打印区域</div>
</el-col>
<el-col :span="9" class="effectPic border-col">
<div class="pic-title">效果图</div>
</el-col>
<el-col :span="9">
<div class="pic-title">素材图</div>
</el-col>
<el-row class="border-row">
<el-col :span="6" class="text-center"><div>A面</div></el-col>
<el-col :span="9" class="border-col text-center">
<el-carousel
v-if="detail.AimageAry?.length"
height="170px"
:autoplay="false"
indicator-position="none"
style="width: 100%;"
>
<el-carousel-item
v-for="(item, index) in detail.AimageAry"
:key="index"
>
<img class="full-width" :src="item.url" alt="" />
</el-carousel-item>
</el-carousel>
<div v-else>&nbsp;</div>
</el-col>
<el-col
:span="9"
style="overflow: hidden;align-items: stretch;flex-grow: 1"
>
<el-checkbox-group
v-if="selectImgList.length"
v-model="checkList"
>
<el-checkbox
:label="selectImgList[0]"
:class="{
imgchecked: checkList.includes(selectImgList[0]),
}"
>
<div
class="img-item"
@click.stop.prevent="selectImg(selectImgList[0], 0)"
>
<img
style="width: 140px"
:src="selectImgList[0].productionFile"
/>
<span>{{ selectImgList[0].designId }}</span>
</div>
</el-checkbox>
</el-checkbox-group>
</el-col>
</el-row>
<el-row class="border-row">
<el-col :span="6" class="text-center"><div>B面</div></el-col>
<el-col :span="9" class="border-col text-center">
<el-carousel
v-if="detail.BimageAry?.length"
height="170px"
:autoplay="false"
indicator-position="none"
style="width: 100%;"
>
<el-carousel-item
v-for="(item, index) in detail.BimageAry"
:key="index"
>
<img class="full-width" :src="item.url" alt="" />
</el-carousel-item>
</el-carousel>
<div v-else>&nbsp;</div>
</el-col>
<el-col :span="9" style="overflow: hidden;">
<el-checkbox-group
v-if="selectImgList.length > 1"
v-model="checkList"
>
<el-checkbox
:label="selectImgList[1]"
:class="{
imgchecked: checkList.includes(selectImgList[1]),
}"
>
<div
class="img-item"
@click.stop.prevent="selectImg(selectImgList[1], 1)"
>
<img
style="width: 140px"
:src="selectImgList[1].productionFile"
/>
<span>{{ selectImgList[1].designId }}</span>
</div>
</el-checkbox>
</el-checkbox-group>
</el-col>
</el-row>
</el-row>
<el-table border :data="detail.imageAry">
<el-table-column label="打印区域" prop="title"></el-table-column>
<el-table-column label="效果图" prop="title">
<template slot-scope="{row}">
<img class="full-width" :src="row.url" alt="" />
</template>
</el-table-column>
<el-table-column label="素材图" prop="title">
<template slot-scope="{row}">
<img style="cursor: pointer" @click="setDesignImg(row.title)" v-if="getComputedTitle(row.title)" class="full-width" :src="getComputedTitle(row.title)" alt="" />
<span>{{getComputedName(row.title)}}</span>
</template>
</el-table-column>
</el-table>
</div>
<div class="product-information">
<div class="title">
......@@ -1224,7 +1148,7 @@ export default {
</div>
</div>
</div>
<div class="print-tip" v-if="imgList.length">
<div class="print-tip" v-if="detail && detail.designImageSize && selectImgList.length">
<b style="color: green" v-if="hasSize ">该生产单无需拖动设计,直接打印</b>
<b style="color: red" v-else>该生产单需要拖动设计打印</b>
</div>
......
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