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"; ...@@ -4,6 +4,8 @@ import { app, protocol, BrowserWindow, screen, globalShortcut } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import { createServer } from "@/server/index.js"; import { createServer } from "@/server/index.js";
import { autoUpdater } from "electron-updater"; import { autoUpdater } from "electron-updater";
import path from "path"; // 引入 path 模块
const { exec } = require("child_process");
Object.defineProperty(app, "isPackaged", { Object.defineProperty(app, "isPackaged", {
get() { get() {
...@@ -136,6 +138,33 @@ async function createWindow() { ...@@ -136,6 +138,33 @@ async function createWindow() {
autoUpdater.downloadUpdate(); 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 () => { app.on("activate", async () => {
......
...@@ -66,16 +66,16 @@ export default { ...@@ -66,16 +66,16 @@ export default {
req.body, req.body,
{ headers: { "jwt-token": token } } { headers: { "jwt-token": token } }
); );
console.log(data);
let files = []; let files = [];
if (data.code === 200) { if (data.code === 200) {
files = data.data; files = data.data;
files = files.map((el) => { files = files.map((el) => {
return { url: `${fileEnv}${el}` }; return { url: `${fileEnv}${el}` };
}); });
console.log(75, files);
downloadImage(files) downloadImage(files)
.then((data) => { .then((data) => {
console.log(77, data);
res.json({ code: 200, data }); res.json({ code: 200, data });
}) })
.catch((err) => { .catch((err) => {
......
...@@ -2,7 +2,6 @@ import express from "express"; ...@@ -2,7 +2,6 @@ import express from "express";
import router from "./routes/index.js"; import router from "./routes/index.js";
import { logMiddleWare } from "./utils/log"; import { logMiddleWare } from "./utils/log";
// const { app } = require("electron"); // const { app } = require("electron");
// import path from "path"; // 引入 path 模块
const PORT = 3000; const PORT = 3000;
// const printPORT = 3030; // const printPORT = 3030;
// // 获取应用程序的安装目录 // // 获取应用程序的安装目录
......
...@@ -28,7 +28,7 @@ function zip(from, to) { ...@@ -28,7 +28,7 @@ function zip(from, to) {
arr.push({ arr.push({
fileName: fileName, fileName: fileName,
designId: data[i].split("_GCPS")[0], designId: data[i].split("_GCPS")[0],
productionFile: path.join(to, fileName) productionFile: path.join(to, fileName),
}); });
} }
...@@ -37,7 +37,7 @@ function zip(from, to) { ...@@ -37,7 +37,7 @@ function zip(from, to) {
// console.log(arr); // console.log(arr);
resolve(arr); resolve(arr);
}) })
.catch(err => { .catch((err) => {
console.log(err); console.log(err);
reject("压缩包解压失败"); reject("压缩包解压失败");
}); });
...@@ -45,10 +45,33 @@ function zip(from, to) { ...@@ -45,10 +45,33 @@ function zip(from, to) {
} }
// 下载素材 // 下载素材
export const downloadImage = list => { export const downloadImage = (list) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { 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)) { if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
} }
...@@ -66,8 +89,8 @@ export const downloadImage = list => { ...@@ -66,8 +89,8 @@ export const downloadImage = list => {
".rar", ".rar",
".7z", ".7z",
".gz", ".gz",
".bz2" ".bz2",
].filter(el => list[i].url.toLowerCase().includes(el)).length > 0; ].filter((el) => list[i].url.toLowerCase().includes(el)).length > 0;
if (flag) { if (flag) {
fileName = list[i].url.split("/")[ fileName = list[i].url.split("/")[
list[i].url.split("/").length - 1 list[i].url.split("/").length - 1
...@@ -77,7 +100,8 @@ export const downloadImage = list => { ...@@ -77,7 +100,8 @@ export const downloadImage = list => {
fileName = uuid.v4() + ".png"; fileName = uuid.v4() + ".png";
type = 2; 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); let stream = fs.createWriteStream(p);
request(list[i].url) request(list[i].url)
.pipe(stream) .pipe(stream)
...@@ -95,7 +119,7 @@ export const downloadImage = list => { ...@@ -95,7 +119,7 @@ export const downloadImage = list => {
list[i].list.push({ list[i].list.push({
fileName, fileName,
productionFile: p, productionFile: p,
designId: filename.split("_GCPS")[0] designId: filename.split("_GCPS")[0],
}); });
} }
if (count === list.length - 1) { if (count === list.length - 1) {
...@@ -124,7 +148,7 @@ export const sendImg = (filename = "sample.png") => { ...@@ -124,7 +148,7 @@ export const sendImg = (filename = "sample.png") => {
return "data:" + "png" + ";base64," + data; return "data:" + "png" + ";base64," + data;
}; };
export const toSend = body => { export const toSend = (body) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec( exec(
body.cmd, body.cmd,
...@@ -137,7 +161,7 @@ export const toSend = body => { ...@@ -137,7 +161,7 @@ export const toSend = body => {
exec( exec(
body.print_cmd, body.print_cmd,
{ cwd: path.join(process.cwd(), "print"), shell: true }, { cwd: path.join(process.cwd(), "print"), shell: true },
err2 => { (err2) => {
console.log(err2); console.log(err2);
if (!err2) { if (!err2) {
// 成功后删除 素材图,xml,output文件 // 成功后删除 素材图,xml,output文件
...@@ -172,7 +196,7 @@ export const toSend = body => { ...@@ -172,7 +196,7 @@ export const toSend = body => {
}); });
}; };
export const writeProfileXml = b => { export const writeProfileXml = (b) => {
try { try {
let p = path.join(process.cwd(), `./print/Profile/${b.byInk}.xml`); let p = path.join(process.cwd(), `./print/Profile/${b.byInk}.xml`);
let file = fs.readFileSync(p, { encoding: "utf8" }); let file = fs.readFileSync(p, { encoding: "utf8" });
......
<script> <script>
import bus from "@/bus"; import bus from "@/bus";
import PrintDialog from "./printDialog.vue"; import PrintDialog from "./printDialog.vue";
import { ipcRenderer, app, shell } from "electron"; import { ipcRenderer } from "electron";
import { grid } from "../data"; import { grid } from "../data";
import pkg from "../../../../package.json"; import pkg from "../../../../package.json";
import UpdateDialog from "@/views/design/updateDialog.vue"; import UpdateDialog from "@/views/design/updateDialog.vue";
import path from "path"; // 引入 path 模块 // import path from "path"; // 引入 path 模块
export default { export default {
components: { PrintDialog, UpdateDialog }, components: { PrintDialog, UpdateDialog },
...@@ -248,13 +248,19 @@ export default { ...@@ -248,13 +248,19 @@ export default {
this.productionNo = ""; this.productionNo = "";
this.$refs.searchRef.focus(); this.$refs.searchRef.focus();
// 延迟后强制激活窗口
console.log(228, this.imgList);
if (this.desktopDevice !== 1) { if (this.desktopDevice !== 1) {
if (this.imgList.length) { if (this.imgList.length) {
let pathUrl = this.imgList[0].productionFile; let pathUrl = this.imgList[0].productionFile;
console.log(236, pathUrl); setTimeout(async () => {
shell.showItemInFolder(pathUrl); // await this.focusExplorerWindow(pathUrl);
const pathParts = pathUrl.split("\\");
pathParts.pop();
// 使用 join() 将剩余部分重新拼接成路径
const folderPath = pathParts.join("\\");
ipcRenderer.send("select-files", folderPath);
// 删除最后一个部分,即文件名
}, 500);
} }
} }
} catch (err) { } catch (err) {
...@@ -262,6 +268,20 @@ export default { ...@@ -262,6 +268,20 @@ export default {
this.$refs.searchRef.focus(); 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) { changeActionIndex(t) {
let index = this.actionIndex; let index = this.actionIndex;
if (t === "+") { if (t === "+") {
......
...@@ -10,7 +10,7 @@ module.exports = { ...@@ -10,7 +10,7 @@ module.exports = {
/** vue3.0内置了webpack所有东西, /** vue3.0内置了webpack所有东西,
* webpack配置,see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md * webpack配置,see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
**/ **/
chainWebpack: config => { chainWebpack: (config) => {
const svgRule = config.module.rule("svg"); const svgRule = config.module.rule("svg");
svgRule.uses.clear(); svgRule.uses.clear();
svgRule svgRule
...@@ -18,7 +18,7 @@ module.exports = { ...@@ -18,7 +18,7 @@ module.exports = {
.loader("svg-sprite-loader") .loader("svg-sprite-loader")
.options({ .options({
symbolId: "icon-[name]", symbolId: "icon-[name]",
include: ["./src/icons"] include: ["./src/icons"],
}); });
config.module config.module
...@@ -28,15 +28,15 @@ module.exports = { ...@@ -28,15 +28,15 @@ module.exports = {
.loader("pug-html-loader") .loader("pug-html-loader")
.end(); .end();
}, },
configureWebpack: config => { configureWebpack: (config) => {
config.resolve = { config.resolve = {
// 配置解析别名 // 配置解析别名
extensions: [".js", ".json", ".vue"], // 自动添加文件名后缀 extensions: [".js", ".json", ".vue"], // 自动添加文件名后缀
alias: { alias: {
vue: "vue/dist/vue.js", vue: "vue/dist/vue.js",
"@": path.resolve(__dirname, "./src"), "@": path.resolve(__dirname, "./src"),
"@c": path.resolve(__dirname, "./src/components") "@c": path.resolve(__dirname, "./src/components"),
} },
}; };
}, },
// 生产环境是否生成 sourceMap 文件 // 生产环境是否生成 sourceMap 文件
...@@ -50,11 +50,11 @@ module.exports = { ...@@ -50,11 +50,11 @@ module.exports = {
// css预设器配置项 // css预设器配置项
loaderOptions: { loaderOptions: {
sass: { sass: {
prependData: `@import "./src/styles/main.css";` prependData: `@import "./src/styles/main.css";`,
} },
}, },
// 启用 CSS modules for all css / pre-processor files. // 启用 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 // use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores // enabled by default if the machine has more than 1 cores
...@@ -80,16 +80,16 @@ module.exports = { ...@@ -80,16 +80,16 @@ module.exports = {
ws: true, ws: true,
changOrigin: true, changOrigin: true,
pathRewrite: { pathRewrite: {
"^/devApi": "" "^/devApi": "",
} },
} },
}, },
overlay: { overlay: {
// 全屏模式下是否显示脚本错误 // 全屏模式下是否显示脚本错误
warnings: true, warnings: true,
errors: true errors: true,
}, },
before: app => {} before: (app) => {},
}, },
/** /**
* 第三方插件配置 * 第三方插件配置
...@@ -101,18 +101,23 @@ module.exports = { ...@@ -101,18 +101,23 @@ module.exports = {
extraResources: [ extraResources: [
{ {
from: "./print/", from: "./print/",
to: "../print" to: "../print",
}, },
{ {
from: "./logs/", from: "./logs/",
to: "../logs" to: "../logs",
}, },
{ {
from: "./config/", 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