Commit 25a79519 by linjinhong

修改管理员权限问题

parent 79810b7c
......@@ -2,7 +2,7 @@
"name": "JomallProductionAssistant",
"productName": "JomallProductionAssistant",
"description": "",
"version": "1.0.17",
"version": "1.0.18",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
......
......@@ -408,6 +408,34 @@ export default {
res.json({ code: 500, msg: err.message });
}
},
//删除图片
cleanDirectorySync: async (req, res) => {
let dirPath = path.join(process.cwd(), `./print/Input`);
if (!fs.existsSync(dirPath)) {
console.log(`目录不存在: ${dirPath}`);
return;
}
try {
const files = fs.readdirSync(dirPath, { withFileTypes: true });
let deletedFiles = [];
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);
deletedFiles.push(fullPath);
console.log(`已删除文件: ${fullPath}`);
}
}
res.json({ code: 200, msg: `已删除文件: ${deletedFiles.join(",")}` });
} catch (error) {
if (error.code === "ENOENT") {
console.warn(`目录不存在: ${dirPath}`);
} else {
console.error(`清理错误: ${error.message}`);
}
res.json({ code: 500, msg: error.message });
}
},
saveToPng: async (req, res) => {
try {
const p = path.join(process.cwd(), "./print/Input/");
......
......@@ -36,6 +36,8 @@ router.post("/imageTransparentEdges", fn.imageTransparentEdges);
router.post("/imageListTransparentEdges", fn.imageListTransparentEdges);
// 处理图片并输出结果
router.post("/processImage", fn.processImage);
// 删除图片
router.post("/cleanDirectorySync", fn.cleanDirectorySync);
// 保存生成后得图片返回地址
router.post("/saveToPng", fn.saveToPng);
......
......@@ -408,9 +408,9 @@ export default {
});
try {
this.cleanDirectorySync();
await this.$api.post("/cleanDirectorySync");
} catch (error) {
console.error("清理目录时发生错误:", error.message);
console.error("清理目录时发生错误:", error.msg);
}
const regex = /^[A-Z]{4}_/; //是否以四个大写字母加下划线开头
......@@ -598,32 +598,32 @@ 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}`);
}
}
},
// 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>
......
......@@ -117,6 +117,10 @@ module.exports = {
filter: ["**/*"], // 包含所有文件
},
],
win: {
requestedExecutionLevel: "requireAdministrator",
},
},
},
},
......
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