Commit 4e672b59 by zhuzhequan

修改图片获取逻辑,添加erp存储dr_param自动获取图片

parent 443d230e
......@@ -2,7 +2,7 @@
"name": "JomallProductionAssistant",
"productName": "JomallProductionAssistant",
"description": "",
"version": "1.0.13",
"version": "1.0.14",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
......@@ -29,7 +29,7 @@
"electron-updater": "^6.2.1",
"element-ui": "^2.13.0",
"express": "^4.17.1",
"fabric": "^5.2.4",
"fabric": "^6.7.0",
"html2canvas": "^1.4.1",
"lodash-id": "^0.14.0",
"log4js": "^6.9.1",
......
......@@ -8,6 +8,7 @@ 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");
import { mapState } from "vuex";
......@@ -18,11 +19,11 @@ export default {
user: {
default: {
avatar: "",
factory: {},
factory: {}
},
type: Object,
type: Object
},
factoryType: { type: String, default: "CN" },
factoryType: { type: String, default: "CN" }
},
data() {
return {
......@@ -33,20 +34,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,
......@@ -61,7 +62,7 @@ export default {
unit: "inch",
language: "cn",
autoPrint: false,
gridSpacing: 1,
gridSpacing: 1
},
imgList: [],
detail: null,
......@@ -80,8 +81,8 @@ export default {
"hsva(120, 40, 94, 0.5)",
"hsl(181, 100%, 37%)",
"hsla(209, 100%, 56%, 0.73)",
"#c7158577",
],
"#c7158577"
]
};
},
computed: {
......@@ -89,7 +90,7 @@ export default {
return this.$store.getters.getActionList;
},
...mapState(["grid", "defaultProportion", "countryList"]),
...mapState(["grid", "defaultProportion", "countryList"])
},
mounted() {
// console.log(pkg, "pkg");
......@@ -114,8 +115,8 @@ export default {
bus.$emit("busEmit", { type: "updateSystemSetting" });
},
deep: true,
},
deep: true
}
},
methods: {
checkUpdate() {
......@@ -134,13 +135,14 @@ export default {
this.$confirm("是否退出登录?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
})
.then(() => {
this.$dataStore.delete("user");
this.$router.push("/");
})
.catch(() => {});
.catch(() => {
});
break;
case "cache":
......@@ -155,9 +157,10 @@ export default {
.post("/completeDelivery", {
id: data.id,
type: this.factoryType,
podJomallOrderUsId: data.podJomallOrderUsId,
podJomallOrderUsId: data.podJomallOrderUsId
})
.then(() => {});
.then(() => {
});
this.$message.success("操作成功");
},
async sureData() {
......@@ -167,7 +170,7 @@ export default {
this.$confirm(`确定生产完成?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
}).then(async () => {
await this.setData(this.detail);
});
......@@ -179,7 +182,7 @@ export default {
this.$confirm("是否确定清除?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
type: "warning"
})
.then(() => {
for (let k of this.checkList) {
......@@ -201,14 +204,15 @@ export default {
}
window.location.reload();
})
.catch(() => {});
.catch(() => {
});
},
drawImage(canvas, item) {
return new Promise((resolve, reject) => {
try {
axios
.get(item?.src, {
responseType: "blob",
responseType: "blob"
})
.then((res) => {
// console.log("item", item);
......@@ -287,7 +291,7 @@ export default {
return this.$message.warning("请扫描生产单号");
let params = {
productionNo: this.detail.factorySubOrderNumber,
imgList: this.imgList,
imgList: this.imgList
};
let res = await this.$api.post("/downloadByDesignId", params);
......@@ -308,7 +312,7 @@ export default {
if (!this.isAutoFinish && !this.isFirst)
this.$confirm("请注意自动完成上一单未勾选", "提示", {
confirmButtonText: "确定",
type: "warning",
type: "warning"
});
try {
......@@ -317,35 +321,46 @@ export default {
"/findByPodProductionNo",
{
thirdSubOrderNumber: this.productionNo,
type: this.factoryType,
type: this.factoryType
}
);
this.detail = findByPodProductionNo.data;
// console.log("detail111111", findByPodProductionNo);
let imageResList = [];
let designImagesCanvasJsonList = this.detail.drParam
this.imgList = [];
let designImagesCanvasJsonList = this.detail.drParam
if (designImagesCanvasJsonList) {
designImagesCanvasJsonList = JSON.parse(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));
}
// console.log("fm", fm);
let Sres = await this.$api.post("/saveToPng", fm);
Sres.data.forEach((item, i) => {
item.title = designImagesCanvasJsonList[i].options.title;
item.productionFile = item.url;
});
console.log("Sres", Sres);
imageResList = Sres.data;
this.imgList = [];
if (this.checked) {
imageResList = await this.cutImgFn(imageResList);
imageResList.forEach((el) => {
el.isCut = true;
if (this.detail.adjustable) {
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));
}
// console.log("fm", fm);
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;
this.imgList = [];
if (this.checked) {
imageResList = await this.cutImgFn(imageResList);
imageResList.forEach((el) => {
el.isCut = true;
});
}
} else {
this.imgList = [];
designImagesCanvasJsonList.forEach((el) => {
el.images.forEach((item) => {
this.imgList.push({
productionFile: item,
title: el.title
});
});
});
}
}
......@@ -358,7 +373,7 @@ export default {
value: imageResList.map((el, index) => {
el.designId = el.designId || index;
return el;
}),
})
};
if (
this.detail.mssWidth &&
......@@ -367,40 +382,37 @@ export default {
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
} else {
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
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 = [];
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);
if(!this.imgList.length){
// 根据生产单号查找 素材图片 下载到本地 然后返回本地地址去显示
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("未找到素材图!");
res.data.forEach((el) => {
this.imgList = this.imgList.concat(el.list || []);
});
}
// res.data = arr.filter((el) => el.type !== 1);
let newImgList;
if(this.imgList.length)
if (this.checked) {
newImgList = await this.cutImgFn(res.data);
newImgList = await this.cutImgFn(this.imgList);
newImgList.forEach((el) => {
el.isCut = true;
});
} else {
newImgList = res.data;
newImgList = this.imgList;
}
// 延迟后强制激活窗口
if (this.desktopDevice !== 1) {
......@@ -423,7 +435,7 @@ export default {
value: newImgList.map((el, index) => {
el.designId = el.designId || index;
return el;
}),
})
};
if (
this.detail.mssWidth &&
......@@ -432,7 +444,7 @@ export default {
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight,
height: this.detail.mssHeight
};
}
bus.$emit("busEmit", obj);
......@@ -489,7 +501,7 @@ export default {
unit: "mm",
language: "cn",
autoPrint: false,
gridSpacing: 10,
gridSpacing: 10
};
this.$message.success("重置应用程序设置成功");
},
......@@ -510,8 +522,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;
......@@ -531,7 +543,7 @@ export default {
this.$store.commit("updateSystemSetting", {
field: "gridValue",
value: this.grid[i],
value: this.grid[i]
});
bus.$emit("busEmit", { type: "grid", value: this.grid[i] });
},
......@@ -556,14 +568,14 @@ export default {
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 || index,
designId: el.designId || index
};
} catch (error) {
console.error(`处理失败: ${el.productionFile}`, error);
......@@ -598,8 +610,8 @@ export default {
}
return "";
},
},
}
}
};
</script>
<style scoped>
......@@ -656,7 +668,7 @@ export default {
:disabled="true"
>
<el-button style="height: 100%;margin-right: 0" size="small"
>{{ grid[selectGridIndex].label }}
>{{ grid[selectGridIndex].label }}
</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item :command="i" v-for="(it, i) in grid" :key="i">
......@@ -783,7 +795,7 @@ export default {
@click="checkUpdate"
style="margin-left: 15px"
type="text"
>检查更新
>检查更新
</el-button>
</el-form-item>
......@@ -830,7 +842,7 @@ export default {
size="medium"
style="margin-left: 10px"
type="primary"
>查询
>查询
</el-button>
<div class="sure-btn">
<el-button
......@@ -838,7 +850,7 @@ export default {
size="medium"
style="margin-left: 10px;width: 100%;"
type="success"
>生产完成
>生产完成
</el-button>
<div class="check">
<el-checkbox v-model="isAutoFinish">自动完成上一单</el-checkbox>
......@@ -852,7 +864,7 @@ export default {
size="medium"
style="margin-left: 15px"
type="primary"
>下载素材
>下载素材
</el-button>
</div>
<div class="right-user">
......@@ -863,8 +875,8 @@ export default {
{{
user.factory.countryCode
? `${user.factory.countryCode}${getCountryName(
user.factory.countryCode
)}`
user.factory.countryCode
)}`
: "CN(中国)"
}}
</div>
......@@ -893,7 +905,7 @@ export default {
:label="item.value"
v-for="(item, i) in cacheList"
:key="i"
>{{ item.label }}
>{{ item.label }}
</el-checkbox>
</el-checkbox-group>
<template #footer>
......
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