Commit 25a79519 by linjinhong

修改管理员权限问题

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