Commit 53ce34c9 by linjinhong

添加设备类型 以及扫描单号打开对应的素材文件功能

parent b83558c0
GTXproCMD.exe print -X "Profile\CO12.xml" -I "Input\sample.png" -A "Output\pO12.arxp" -S 01000200 -L 02540254
echo %errorlevel%
\ No newline at end of file
param(
[string]$folderPath
)
# 1. 确保资源管理器窗口已打开,如果没有则打开
Start-Process "explorer.exe" -ArgumentList $folderPath
# 等待文件资源管理器打开
Start-Sleep -Seconds 1
# 获取 WScript.Shell 对象
$wshell = New-Object -ComObject wscript.shell
# 激活资源管理器窗口(确保窗口获得焦点)
$wshell.AppActivate('File Explorer')
# 等待几秒钟,确保窗口已获得焦点
Start-Sleep -Seconds 1
# 尝试发送 Ctrl+A 全选快捷键
$wshell.SendKeys('^a')
# # 尝试发送 Ctrl+A 全选快捷键
# $wshell.SendKeys('^A')
......@@ -4,6 +4,8 @@ import { app, protocol, BrowserWindow, screen, globalShortcut } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import { createServer } from "@/server/index.js";
import { autoUpdater } from "electron-updater";
import path from "path"; // 引入 path 模块
const { exec } = require("child_process");
Object.defineProperty(app, "isPackaged", {
get() {
......@@ -136,6 +138,33 @@ async function createWindow() {
autoUpdater.downloadUpdate();
});
});
// 监听渲染进程发来的请求,执行 PowerShell 脚本
ipcMain.on("select-files", (event, folderPath) => {
return new Promise((resolve, reject) => {
let psScriptPath;
if (process.env.NODE_ENV === "development") {
psScriptPath = path.join(__dirname, "..", "scripts", "script.ps1");
} else {
psScriptPath = path.join(
path.dirname(app.getPath("exe")),
"resources",
"scripts",
"script.ps1"
);
}
// 构建 PowerShell 命令
const psCommand = `powershell -ExecutionPolicy Bypass -File "${psScriptPath}" -folderPath "${folderPath}"`;
exec(psCommand, (error, stdout, stderr) => {
if (error) {
reject(`exec error: ${error}`);
}
resolve(stdout || stderr);
});
});
});
}
app.on("activate", async () => {
......
......@@ -66,16 +66,16 @@ export default {
req.body,
{ headers: { "jwt-token": token } }
);
console.log(data);
let files = [];
if (data.code === 200) {
files = data.data;
files = files.map((el) => {
return { url: `${fileEnv}${el}` };
});
console.log(75, files);
downloadImage(files)
.then((data) => {
console.log(77, data);
res.json({ code: 200, data });
})
.catch((err) => {
......
......@@ -2,7 +2,6 @@ import express from "express";
import router from "./routes/index.js";
import { logMiddleWare } from "./utils/log";
// const { app } = require("electron");
// import path from "path"; // 引入 path 模块
const PORT = 3000;
// const printPORT = 3030;
// // 获取应用程序的安装目录
......
......@@ -28,7 +28,7 @@ function zip(from, to) {
arr.push({
fileName: fileName,
designId: data[i].split("_GCPS")[0],
productionFile: path.join(to, fileName)
productionFile: path.join(to, fileName),
});
}
......@@ -37,7 +37,7 @@ function zip(from, to) {
// console.log(arr);
resolve(arr);
})
.catch(err => {
.catch((err) => {
console.log(err);
reject("压缩包解压失败");
});
......@@ -45,10 +45,33 @@ function zip(from, to) {
}
// 下载素材
export const downloadImage = list => {
export const downloadImage = (list) => {
return new Promise((resolve, reject) => {
try {
let dirPath = path.join(process.cwd(), "./print/Input/");
const currentDate = new Date();
// 将 UTC 时间转换为中国时间 (UTC + 8小时)
const chinaTimeOffset = 8 * 60 * 60 * 1000; // 8小时,单位是毫秒
const chinaTime = new Date(currentDate.getTime() + chinaTimeOffset);
// 将当前中国时间格式化为ISO字符串
let isoString = chinaTime.toISOString();
console.log("Original China Time ISO String:", isoString); // 检查格式
// 替换掉时间中的 ':' 字符
const folderName =
isoString.split("T")[0] +
"_" +
isoString
.split("T")[1]
.replace(/:/g, "-")
.split(".")[0];
console.log("Formatted Folder Name:", folderName); // 检查替换结果
// let dirPath = path.join(process.cwd(), `./print/Input/`);
let dirPath = path.join(process.cwd(), `./print/Input/${folderName}`);
console.log(64, dirPath);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
......@@ -66,8 +89,8 @@ export const downloadImage = list => {
".rar",
".7z",
".gz",
".bz2"
].filter(el => list[i].url.toLowerCase().includes(el)).length > 0;
".bz2",
].filter((el) => list[i].url.toLowerCase().includes(el)).length > 0;
if (flag) {
fileName = list[i].url.split("/")[
list[i].url.split("/").length - 1
......@@ -77,7 +100,8 @@ export const downloadImage = list => {
fileName = uuid.v4() + ".png";
type = 2;
}
let p = path.join(process.cwd(), "./print/Input/" + fileName);
let p = path.join(dirPath, fileName); // 保存到新文件夹
// let p = path.join(process.cwd(), "./print/Input/" + fileName);
let stream = fs.createWriteStream(p);
request(list[i].url)
.pipe(stream)
......@@ -95,7 +119,7 @@ export const downloadImage = list => {
list[i].list.push({
fileName,
productionFile: p,
designId: filename.split("_GCPS")[0]
designId: filename.split("_GCPS")[0],
});
}
if (count === list.length - 1) {
......@@ -124,7 +148,7 @@ export const sendImg = (filename = "sample.png") => {
return "data:" + "png" + ";base64," + data;
};
export const toSend = body => {
export const toSend = (body) => {
return new Promise((resolve, reject) => {
exec(
body.cmd,
......@@ -137,7 +161,7 @@ export const toSend = body => {
exec(
body.print_cmd,
{ cwd: path.join(process.cwd(), "print"), shell: true },
err2 => {
(err2) => {
console.log(err2);
if (!err2) {
// 成功后删除 素材图,xml,output文件
......@@ -172,7 +196,7 @@ export const toSend = body => {
});
};
export const writeProfileXml = b => {
export const writeProfileXml = (b) => {
try {
let p = path.join(process.cwd(), `./print/Profile/${b.byInk}.xml`);
let file = fs.readFileSync(p, { encoding: "utf8" });
......
<script>
import bus from "@/bus";
import PrintDialog from "./printDialog.vue";
import { ipcRenderer, app, shell } from "electron";
import { ipcRenderer } from "electron";
import { grid } from "../data";
import pkg from "../../../../package.json";
import UpdateDialog from "@/views/design/updateDialog.vue";
import path from "path"; // 引入 path 模块
// import path from "path"; // 引入 path 模块
export default {
components: { PrintDialog, UpdateDialog },
......@@ -248,13 +248,19 @@ export default {
this.productionNo = "";
this.$refs.searchRef.focus();
console.log(228, this.imgList);
// 延迟后强制激活窗口
if (this.desktopDevice !== 1) {
if (this.imgList.length) {
let pathUrl = this.imgList[0].productionFile;
console.log(236, pathUrl);
shell.showItemInFolder(pathUrl);
setTimeout(async () => {
// await this.focusExplorerWindow(pathUrl);
const pathParts = pathUrl.split("\\");
pathParts.pop();
// 使用 join() 将剩余部分重新拼接成路径
const folderPath = pathParts.join("\\");
ipcRenderer.send("select-files", folderPath);
// 删除最后一个部分,即文件名
}, 500);
}
}
} catch (err) {
......@@ -262,6 +268,20 @@ export default {
this.$refs.searchRef.focus();
}
},
// // 聚焦资源管理器窗口(Windows)
focusExplorerWindow(path) {
const { exec } = require("child_process");
const fs = require("fs");
const command = `start explorer /select, "${path}"`;
// 检查路径是否存在
if (fs.existsSync(path)) {
exec(`cmd /c "${command}"`, (err) => {
if (err) console.error("激活窗口失败:", err);
});
} else {
console.error("路径不存在:", path);
}
},
changeActionIndex(t) {
let index = this.actionIndex;
if (t === "+") {
......
......@@ -10,7 +10,7 @@ module.exports = {
/** vue3.0内置了webpack所有东西,
* webpack配置,see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
**/
chainWebpack: config => {
chainWebpack: (config) => {
const svgRule = config.module.rule("svg");
svgRule.uses.clear();
svgRule
......@@ -18,7 +18,7 @@ module.exports = {
.loader("svg-sprite-loader")
.options({
symbolId: "icon-[name]",
include: ["./src/icons"]
include: ["./src/icons"],
});
config.module
......@@ -28,15 +28,15 @@ module.exports = {
.loader("pug-html-loader")
.end();
},
configureWebpack: config => {
configureWebpack: (config) => {
config.resolve = {
// 配置解析别名
extensions: [".js", ".json", ".vue"], // 自动添加文件名后缀
alias: {
vue: "vue/dist/vue.js",
"@": path.resolve(__dirname, "./src"),
"@c": path.resolve(__dirname, "./src/components")
}
"@c": path.resolve(__dirname, "./src/components"),
},
};
},
// 生产环境是否生成 sourceMap 文件
......@@ -50,11 +50,11 @@ module.exports = {
// css预设器配置项
loaderOptions: {
sass: {
prependData: `@import "./src/styles/main.css";`
}
prependData: `@import "./src/styles/main.css";`,
},
},
// 启用 CSS modules for all css / pre-processor files.
requireModuleExtension: true // 是否开启支持‘foo.module.css’样式
requireModuleExtension: true, // 是否开启支持‘foo.module.css’样式
},
// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
......@@ -80,16 +80,16 @@ module.exports = {
ws: true,
changOrigin: true,
pathRewrite: {
"^/devApi": ""
}
}
"^/devApi": "",
},
},
},
overlay: {
// 全屏模式下是否显示脚本错误
warnings: true,
errors: true
errors: true,
},
before: app => {}
before: (app) => {},
},
/**
* 第三方插件配置
......@@ -101,18 +101,23 @@ module.exports = {
extraResources: [
{
from: "./print/",
to: "../print"
to: "../print",
},
{
from: "./logs/",
to: "../logs"
to: "../logs",
},
{
from: "./config/",
to: "../config"
}
]
}
}
}
to: "../config",
},
{
from: "scripts", // 本地脚本目录
to: "scripts", // 输出到 resources/scripts
filter: ["**/*"], // 包含所有文件
},
],
},
},
},
};
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