Commit 56dcbfaa by linjinhong

添加清空原图片素材方法

parent 9f39d741
......@@ -51,8 +51,6 @@ export const downloadImage = (list) => {
// console.log("Formatted Folder Name:", folderName); // 检查替换结果
let dirPath = path.join(process.cwd(), `./print/Input/`);
console.log(64, dirPath);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
......
......@@ -19,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 {
......@@ -34,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,
......@@ -62,7 +62,7 @@ export default {
unit: "inch",
language: "cn",
autoPrint: false,
gridSpacing: 1
gridSpacing: 1,
},
imgList: [],
detail: null,
......@@ -81,8 +81,8 @@ export default {
"hsva(120, 40, 94, 0.5)",
"hsl(181, 100%, 37%)",
"hsla(209, 100%, 56%, 0.73)",
"#c7158577"
]
"#c7158577",
],
};
},
computed: {
......@@ -90,7 +90,7 @@ export default {
return this.$store.getters.getActionList;
},
...mapState(["grid", "defaultProportion", "countryList"])
...mapState(["grid", "defaultProportion", "countryList"]),
},
mounted() {
// console.log(pkg, "pkg");
......@@ -115,8 +115,8 @@ export default {
bus.$emit("busEmit", { type: "updateSystemSetting" });
},
deep: true
}
deep: true,
},
},
methods: {
checkUpdate() {
......@@ -135,14 +135,13 @@ export default {
this.$confirm("是否退出登录?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
type: "warning",
})
.then(() => {
this.$dataStore.delete("user");
this.$router.push("/");
})
.catch(() => {
});
.catch(() => {});
break;
case "cache":
......@@ -157,10 +156,9 @@ export default {
.post("/completeDelivery", {
id: data.id,
type: this.factoryType,
podJomallOrderUsId: data.podJomallOrderUsId
podJomallOrderUsId: data.podJomallOrderUsId,
})
.then(() => {
});
.then(() => {});
this.$message.success("操作成功");
},
async sureData() {
......@@ -170,7 +168,7 @@ export default {
this.$confirm(`确定生产完成?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
type: "warning",
}).then(async () => {
await this.setData(this.detail);
});
......@@ -182,7 +180,7 @@ export default {
this.$confirm("是否确定清除?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
type: "warning",
})
.then(() => {
for (let k of this.checkList) {
......@@ -204,15 +202,14 @@ 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);
......@@ -291,7 +288,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);
......@@ -317,7 +314,7 @@ export default {
el.images.forEach((item) => {
imageResList.push({
productionFile: item,
title: el.title
title: el.title,
});
});
});
......@@ -345,7 +342,7 @@ export default {
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) => {
......@@ -379,7 +376,7 @@ export default {
value: imageResList.map((el, index) => {
el.designId = el.designId || index;
return el;
})
}),
};
if (
this.detail.mssWidth &&
......@@ -388,12 +385,11 @@ export default {
) {
obj.size = {
width: this.detail.mssWidth,
height: this.detail.mssHeight
height: this.detail.mssHeight,
};
}
bus.$emit("busEmit", obj);
}
},
async getDataInfo() {
if (
......@@ -410,16 +406,22 @@ export default {
if (!this.isAutoFinish && !this.isFirst)
this.$confirm("请注意自动完成上一单未勾选", "提示", {
confirmButtonText: "确定",
type: "warning"
type: "warning",
});
try {
this.cleanDirectorySync();
} catch (error) {
console.error("清理目录时发生错误:", error.message);
}
try {
//查找生产单号信息传给第二个显示器
const findByPodProductionNo = await this.$api.post(
"/findByPodProductionNo",
{
thirdSubOrderNumber: this.productionNo,
type: this.factoryType
type: this.factoryType,
}
);
this.detail = findByPodProductionNo.data;
......@@ -479,7 +481,7 @@ export default {
unit: "mm",
language: "cn",
autoPrint: false,
gridSpacing: 10
gridSpacing: 10,
};
this.$message.success("重置应用程序设置成功");
},
......@@ -500,8 +502,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;
......@@ -521,7 +523,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] });
},
......@@ -546,14 +548,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);
......@@ -588,8 +590,34 @@ export default {
}
return "";
}
}
},
async cleanDirectorySync() {
let dirPath = path.join(process.cwd(), `./print/Input`);
if (!fs.existsSync(dirPath)) {
console.log(`目录不存在: ${dirPath}`);
return;
}
try {
const files = fs.readdirSync(dirPath, { withFileTypes: true });
for (const file of files) {
const fullPath = path.join(dirPath, file.name);
if (
file.isFile() &&
path.extname(file.name).toLowerCase() === ".png"
) {
await fs.promises.unlink(fullPath);
console.log(`已删除文件: ${fullPath}`);
}
}
} catch (error) {
if (error.code === "ENOENT") {
console.warn(`目录不存在: ${dirPath}`);
} else {
console.error(`清理错误: ${error.message}`);
}
}
},
},
};
</script>
<style scoped>
......@@ -646,7 +674,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">
......@@ -773,7 +801,7 @@ export default {
@click="checkUpdate"
style="margin-left: 15px"
type="text"
>检查更新
>检查更新
</el-button>
</el-form-item>
......@@ -820,7 +848,7 @@ export default {
size="medium"
style="margin-left: 10px"
type="primary"
>查询
>查询
</el-button>
<div class="sure-btn">
<el-button
......@@ -828,7 +856,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>
......@@ -842,7 +870,7 @@ export default {
size="medium"
style="margin-left: 15px"
type="primary"
>下载素材
>下载素材
</el-button>
</div>
<div class="right-user">
......@@ -853,8 +881,8 @@ export default {
{{
user.factory.countryCode
? `${user.factory.countryCode}${getCountryName(
user.factory.countryCode
)}`
user.factory.countryCode
)}`
: "CN(中国)"
}}
</div>
......@@ -883,7 +911,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>
......
......@@ -820,6 +820,8 @@ export default {
this.checkList.map(async (el) => {
try {
const outputDir = path.dirname(el.productionFile);
console.log(outputDir);
const outputFileName = `${uuid.v4()}.png`;
const outputPath = path.join(outputDir, outputFileName);
const params = {
......@@ -839,6 +841,7 @@ export default {
})
);
console.log("processQueue", processQueue);
// 等待所有异步操作完成
await new Promise((resolve) => setTimeout(resolve, 100));
const newMap = new Map(processQueue.map((el) => [el.designId, el]));
......
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