Commit 165fd6cb by 朱哲铨

功能定版

parent 7a728788
import { downloadImage, toSend, writeProfileXml } from "@/backend/webserver/utils"; import {
downloadImage,
toSend,
writeProfileXml
} from "@/backend/webserver/utils";
const compressing = require("compressing"); const compressing = require("compressing");
var uuid = require("uuid"); var uuid = require("uuid");
...@@ -15,51 +19,64 @@ fn.getPodProductionInfo = async (req, res) => { ...@@ -15,51 +19,64 @@ fn.getPodProductionInfo = async (req, res) => {
const company = req.headers["company"]; const company = req.headers["company"];
const productionNo = req.body.productionNo; const productionNo = req.body.productionNo;
try { try {
let { data } = await axios.post(`https://${company}/api/podDesignCenter/getPodImageByProduction`, { productionNo }, { headers: { "jwt-token": token } }); let { data } = await axios.post(
`https://${company}/api/podDesignCenter/getPodImageByProduction`,
{ productionNo },
{ headers: { "jwt-token": token } }
);
console.log(data); console.log(data);
if (data.code === 200 && data.data && data.data.length > 0) { if (data.code === 200 && data.data && data.data.length > 0) {
let f = data.data.find(el => !el.productionFile); let f = data.data.find(el => !el.productionFile);
data.data.forEach((el ) => { data.data.forEach(el => {
if (!el.productionFile.includes("http")) { if (!el.productionFile.includes("http")) {
el.productionFile = el.productionFile.replace("/data/upload/erp", ""); el.productionFile = el.productionFile.replace(
el.productionFile = `https://${company}/upload/erp/${el.productionFile}`; "/data/upload/erp/",
""
);
el.productionFile = `https://${company}/upload/erp${el.productionFile}`;
} }
}); });
if (f) { if (f) {
return res.json({ code: 500, msg: "存在地址错误的素材图" }); return res.json({ code: 500, msg: "存在地址错误的素材图" });
} }
downloadImage(data.data, company, data => {
res.json({ code: 200, data }); downloadImage(data.data)
}, (err) => { .then(data => {
res.json({ code: 500, msg: "素材图下载失败" }); res.json({ code: 200, data });
}); })
.catch(err => {
res.json({ code: 500, msg: err });
});
} else { } else {
res.json({ code: 200, msg: "未找到素材图", data: [] }); res.json({ code: 200, msg: "未找到素材图", data: [] });
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);
res.json({ code: 500, msg: "接口调用失败" }); res.json({ code: 500, msg: err });
} }
}; };
fn.findByPodProductionNo = async (req, res) => { fn.findByPodProductionNo = async (req, res) => {
const token = req.headers["jwt-token"]; const token = req.headers["jwt-token"];
const company = req.headers["company"]; const company = req.headers["company"];
const q = req.body; const q = req.body;
try { try {
let { data } = await axios.get(`https://${company}/api/pod/podProductionInfo/findByPodProductionNo`, { let { data } = await axios.get(
params: q, `https://${company}/api/pod/podProductionInfo/findByPodProductionNo`,
headers: { "jwt-token": token } {
}); params: q,
headers: { "jwt-token": token }
}
);
res.json(data); res.json(data);
} catch (err) { } catch (err) {
res.json({ code: 500, msg: err }); res.json({ code: 500, msg: err });
} }
}; };
fn.getCompanyList = async (req, res) => { fn.getCompanyList = async (req, res) => {
try { try {
let { data } = await axios.get("https://platform.jomalls.com/api/tools/getCompanyList"); let { data } = await axios.get(
"https://platform.jomalls.com/api/tools/getCompanyList"
);
res.send(data); res.send(data);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
...@@ -70,7 +87,10 @@ fn.commitApply = async (req, res) => { ...@@ -70,7 +87,10 @@ fn.commitApply = async (req, res) => {
const company = req.headers["company"]; const company = req.headers["company"];
const q = req.body; const q = req.body;
try { try {
let { data } = await axios.post(`https://${company}/api/sysDeviceInfo/commitApply`, q); let { data } = await axios.post(
`https://${company}/api/sysDeviceInfo/commitApply`,
q
);
res.send(data); res.send(data);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
...@@ -82,14 +102,17 @@ fn.completeDelivery = async (req, res) => { ...@@ -82,14 +102,17 @@ fn.completeDelivery = async (req, res) => {
const company = req.headers["company"]; const company = req.headers["company"];
const q = req.body; const q = req.body;
try { try {
let { data } = await axios.post(`https://${company}/api/pod/podProductionInfo/completeDelivery`, q, { let { data } = await axios.post(
headers: { "jwt-token": token } `https://${company}/api/pod/podProductionInfo/completeDelivery`,
}); q,
{
headers: { "jwt-token": token }
}
);
res.json(data); res.json(data);
} catch (err) { } catch (err) {
res.json({ code: 500, msg: err }); res.json({ code: 500, msg: err });
} }
}; };
fn.downloadByDesignId = async (req, res) => { fn.downloadByDesignId = async (req, res) => {
let q = req.body; let q = req.body;
...@@ -98,12 +121,16 @@ fn.downloadByDesignId = async (req, res) => { ...@@ -98,12 +121,16 @@ fn.downloadByDesignId = async (req, res) => {
const zipStream = new compressing.zip.Stream(); const zipStream = new compressing.zip.Stream();
for (let k in q.imgList) { for (let k in q.imgList) {
const p = path.join(process.cwd(), "./print/Input/" + q.imgList[k].fileName); const p = path.join(
process.cwd(),
"./print/Input/" + q.imgList[k].fileName
);
zipStream.addEntry(p); zipStream.addEntry(p);
} }
const destStream = fs.createWriteStream(dir); const destStream = fs.createWriteStream(dir);
zipStream.pipe(destStream) zipStream
.pipe(destStream)
.on("finish", () => { .on("finish", () => {
console.log("success"); console.log("success");
res.json({ code: 200, msg: q.productionNo + ".zip" + "已下载到桌面" }); res.json({ code: 200, msg: q.productionNo + ".zip" + "已下载到桌面" });
...@@ -125,12 +152,10 @@ fn.downloadByDesignId = async (req, res) => { ...@@ -125,12 +152,10 @@ fn.downloadByDesignId = async (req, res) => {
// //
// }); // });
// ws.end() // ws.end()
} catch (err) { } catch (err) {
console.log(err); console.log(err);
res.json({ code: 500, msg: err }); res.json({ code: 500, msg: err });
} }
}; };
fn.uploadImage = async (req, res) => { fn.uploadImage = async (req, res) => {
try { try {
...@@ -145,24 +170,33 @@ fn.uploadImage = async (req, res) => { ...@@ -145,24 +170,33 @@ fn.uploadImage = async (req, res) => {
res.send({ code: 500, err }); res.send({ code: 500, err });
} else { } else {
fs.renameSync(files.file[0].path, path.join(p, fileName)); fs.renameSync(files.file[0].path, path.join(p, fileName));
res.json({ code: 200, data: { fileName, url: path.join(process.cwd(), "./print/Input/" + fileName) } }); res.json({
code: 200,
data: {
fileName,
url: path.join(process.cwd(), "./print/Input/" + fileName)
}
});
} }
}); });
} catch (err) { } catch (err) {
console.log(err); console.log(err);
res.json({ code: 500, msg: err }); res.json({ code: 500, msg: err });
} }
}; };
fn.getPngImg = async (req, res) => { fn.getPngImg = async (req, res) => {
try { try {
const filePath = path.join(process.cwd(), `./print/Input/${req.body.fileName}`); const filePath = path.join(
process.cwd(),
`./print/Input/${req.body.fileName}`
);
console.log(filePath); console.log(filePath);
// 给客户端返回一个文件流 type类型 // 给客户端返回一个文件流 type类型
res.set("content-type", { "png": "image/png", "jpg": "image/jpeg" });//设置返回类型 res.set("content-type", { png: "image/png", jpg: "image/jpeg" }); //设置返回类型
let stream = fs.createReadStream(filePath); let stream = fs.createReadStream(filePath);
let responseData = [];//存储文件流 let responseData = []; //存储文件流
if (stream) {//判断状态 if (stream) {
//判断状态
stream.on("data", function(chunk) { stream.on("data", function(chunk) {
responseData.push(chunk); responseData.push(chunk);
}); });
...@@ -175,14 +209,16 @@ fn.getPngImg = async (req, res) => { ...@@ -175,14 +209,16 @@ fn.getPngImg = async (req, res) => {
} catch (err) { } catch (err) {
res.send({ code: 500, msg: err }); res.send({ code: 500, msg: err });
} }
}; };
fn.login = async (req, res) => { fn.login = async (req, res) => {
const { loginName, company, password, deviceId } = req.body; const { loginName, company, password, deviceId } = req.body;
try { try {
let { data } = await axios.post(`https://${company}/api/sysLogin/login`, { loginName, password, deviceId }); let { data } = await axios.post(`https://${company}/api/sysLogin/login`, {
loginName,
password,
deviceId
});
res.send(data); res.send(data);
} catch (err) { } catch (err) {
...@@ -191,16 +227,17 @@ fn.login = async (req, res) => { ...@@ -191,16 +227,17 @@ fn.login = async (req, res) => {
} }
}; };
fn.toPrint = (req, res) => { fn.toPrint = (req, res) => {
let body = req.body; let body = req.body;
writeProfileXml(body); // 写入xml文件 writeProfileXml(body); // 写入xml文件
// GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254 // GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254
toSend(body).then(r => { toSend(body)
res.send({ code: 200, msg: "操作成功" }); .then(r => {
}).catch(err => { res.send({ code: 200, msg: "操作成功" });
res.send({ code: 500, msg: err }); })
}); .catch(err => {
res.send({ code: 500, msg: err });
});
}; };
export { fn as default }; export { fn as default };
import express from "express"; import express from "express";
import fn from "../entity/function.js"; import fn from "../entity/function.js";
import {getPodProductionInfo, sendImg} from "@/backend/webserver/utils";
let router = express.Router(); let router = express.Router();
......
import { exec, execSync } from "child_process"; import { exec } from "child_process";
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
...@@ -6,102 +6,106 @@ var request = require("request"); ...@@ -6,102 +6,106 @@ var request = require("request");
var uuid = require("uuid"); var uuid = require("uuid");
const compressing = require("compressing"); const compressing = require("compressing");
function zip(from, to, callback, errorback) { function zip(from, to) {
let dirName = path.join(to, uuid.v4()); return new Promise((resolve, reject) => {
console.log(dirName); let dirName = path.join(to, uuid.v4());
if (!fs.existsSync(dirName)) { console.log(dirName);
fs.mkdirSync(dirName); if (!fs.existsSync(dirName)) {
} fs.mkdirSync(dirName);
let arr = [];
compressing.zip
.uncompress(from, dirName, { zipFileNameEncoding: "gbk" })
.then(() => {
console.log("success");
let data = fs.readdirSync(dirName);
data.forEach(el => {
let file_path = path.join(dirName, el);
console.log(file_path, to);
fs.renameSync(file_path, path.join(to, el));
arr.push({
fileName: el,
productionFile: path.join(to, el)
});
});
fs.unlinkSync(from); // 删除压缩包
fs.rmdirSync(dirName); // 删除目录文件
console.log(arr);
callback && callback(arr);
})
.catch(err => {
console.log(err);
errorback && errorback("压缩包解压失败");
});
}
// 下载素材
export const downloadImage = (list, company, callback, errorBack = null) => {
try {
let dirPath = path.join(process.cwd(), "./print/Input/");
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
} }
for (let i = 0; i < list.length; i++) { let arr = [];
if (list[i].productionFile && list[i].productionFile.includes("http")) { compressing.zip
let fileName = ""; .uncompress(from, dirName, { zipFileNameEncoding: "gbk" })
let type = 2; .then(() => {
let flag =[ console.log("success");
".zip", let data = fs.readdirSync(dirName);
".gzip", for (let i = 0; i < data.length; i++) {
".tar", let el = data[i];
".taz", let file_path = path.join(dirName, el);
".rar", console.log(file_path, to);
".7z", fs.renameSync(file_path, path.join(to, el));
".gz", arr.push({
".bz2" fileName: el,
].filter(el=>list[i].productionFile.toLowerCase().includes(el)).length>0 productionFile: path.join(to, el)
if ( });
flag
) {
fileName = list[i].productionFile.split("/")[
list[i].productionFile.split("/").length - 1
];
type = 1;
} else {
fileName = uuid.v4() + ".png";
type = 2;
} }
let p = path.join(process.cwd(), "./print/Input/" + fileName); fs.unlinkSync(from); // 删除压缩包
let stream = fs.createWriteStream(p); fs.rmdirSync(dirName); // 删除目录文件
list[i].fileName = fileName; // console.log(arr);
list[i].type = type; resolve(arr);
console.log(list[i].productionFile); })
request(list[i].productionFile) .catch(err => {
.pipe(stream) console.log(err);
.on("close", function(err) { reject("压缩包解压失败");
console.log(6666666666,list[i]); });
if (type === 1) { });
}
zip( // 下载素材
p, export const downloadImage = list => {
dirPath, return new Promise((resolve, reject) => {
data => { try {
list[i].list = data; let dirPath = path.join(process.cwd(), "./print/Input/");
}, if (!fs.existsSync(dirPath)) {
errorBack fs.mkdirSync(dirPath);
); }
} else { let count = 0;
if (i === list.length - 1) { for (let i = 0; i < list.length; i++) {
callback && callback(list); if (list[i].productionFile && list[i].productionFile.includes("http")) {
let fileName = "";
let type = 2;
let flag =
[
".zip",
".gzip",
".tar",
".taz",
".rar",
".7z",
".gz",
".bz2"
].filter(el => list[i].productionFile.toLowerCase().includes(el))
.length > 0;
if (flag) {
fileName = list[i].productionFile.split("/")[
list[i].productionFile.split("/").length - 1
];
type = 1;
} else {
fileName = uuid.v4() + ".png";
type = 2;
}
list[i].fileName = fileName;
list[i].type = type;
let p = path.join(process.cwd(), "./print/Input/" + fileName);
let stream = fs.createWriteStream(p);
request(list[i].productionFile)
.pipe(stream)
.on("close", async function() {
if (type === 1) {
let res_data = await zip(p, dirPath);
res_data.forEach(item => {
item.designId = list[i].designId;
});
list[i].list = res_data;
if (count === list.length - 1) {
resolve(list);
}
} }
} if (count === list.length - 1) {
}); console.log(list);
resolve(list);
}
count++;
});
}
} }
} catch (err) {
console.log(err);
reject(err);
} }
} catch (err) { });
console.log(err);
errorBack && errorBack(err);
}
}; };
// 传递素材给前端 // 传递素材给前端
...@@ -128,13 +132,27 @@ export const toSend = body => { ...@@ -128,13 +132,27 @@ 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, stdout2, stderr2) => { err2 => {
console.log(err2); console.log(err2);
if (!err2) { if (!err2) {
// 成功后删除 素材图,xml,output文件 // 成功后删除 素材图,xml,output文件
// fs.unlinkSync(path.join(process.cwd(), 'print/Input/' + body.fileName)) // fs.unlinkSync(path.join(process.cwd(), 'print/Input/' + body.fileName))
// fs.unlinkSync(path.join(process.cwd(), 'print/Profile/' + body.fileName.replace('.png', '') + '.xml')) fs.unlinkSync(
// fs.unlinkSync(path.join(process.cwd(), 'print/Output/' + body.fileName.replace('.png', '') + '.arxp')) path.join(
process.cwd(),
"print/Profile/" +
body.fileName.replace(".png", "") +
".xml"
)
);
fs.unlinkSync(
path.join(
process.cwd(),
"print/Output/" +
body.fileName.replace(".png", "") +
".arxp"
)
);
resolve("操作成功"); resolve("操作成功");
} else { } else {
reject("打印机参数错误"); reject("打印机参数错误");
......
"use strict"; "use strict";
import {contextBridge, ipcMain, ipcRenderer} from 'electron' import { contextBridge, ipcMain, ipcRenderer } from "electron";
import {app, protocol, BrowserWindow, Menu, screen} from "electron"; import { app, protocol, BrowserWindow, Menu, screen } from "electron";
import {createProtocol} from "vue-cli-plugin-electron-builder/lib"; import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import webApp from "@/backend/webserver/be_nodeSrv.js" import webApp from "@/backend/webserver/be_nodeSrv.js";
let isCreateWin = false let isCreateWin = false;
const isDevelopment = process.env.NODE_ENV !== "production"; const isDevelopment = process.env.NODE_ENV !== "production";
let win; let win;
let otherWindow; let otherWindow;
protocol.registerSchemesAsPrivileged([ protocol.registerSchemesAsPrivileged([
{scheme: "app", privileges: {secure: true, standard: true}} { scheme: "app", privileges: { secure: true, standard: true } }
]); ]);
const winURL = process.env.NODE_ENV === 'development' const winURL =
? 'http://localhost:8090' process.env.NODE_ENV === "development"
: `file://${__dirname}/index.html` ? "http://localhost:8090"
: `file://${__dirname}/index.html`;
function createWindow() { function createWindow() {
win = new BrowserWindow({ win = new BrowserWindow({
width: 1500, width: 1500,
height: 1000, height: 1000,
icon: "./src/assets/logo.jpg", icon: "./src/assets/logo.jpg",
webPreferences: { webPreferences: {
webSecurity: false, webSecurity: false,
nodeIntegration: true, nodeIntegration: true
// preload: path.join(__dirname, "./preload.js") // preload: path.join(__dirname, "./preload.js")
}
});
let displays = screen.getAllDisplays();
//寻找副屏幕
let externalDisplay = displays.find((display) => {
return display.bounds.x !== 0 || display.bounds.y !== 0
})
if (externalDisplay) {
otherWindow = new BrowserWindow({
fullscreen: false,
width: externalDisplay.bounds.width,
height: externalDisplay.bounds.height,
x: externalDisplay.bounds.x,
y: externalDisplay.bounds.y,
webPreferences: {
nodeIntegration: true,
//配置预加载脚本文件(preload),此处起名为preloadOther
//p.s.路径为绝对路径
// preload: path.join(__dirname, "./preloadOther.js")
}
})
//指定副屏幕打开的网页
otherWindow.loadURL(winURL + '#' + `/design-detail`);
otherWindow.on('closed', () => { //这一段放外面的话,如果你电脑没双屏会报错。
otherWindow = null
})
}
ipcMain.on('allPrint', () => {
// 获取到打印机列表
const printers = win.webContents.getPrinters()
// 把获取的打印机列表发送给渲染进程
win.webContents.send('printName', printers)
})
ipcMain.on('win-subScreen', (data, v) => {
if(otherWindow) otherWindow.webContents.send('getProductionNoInfo', v)
})
if (process.env.WEBPACK_DEV_SERVER_URL) {
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
win.loadURL("app://./index.html");
} }
});
let displays = screen.getAllDisplays();
//寻找副屏幕
let externalDisplay = displays.find(display => {
return display.bounds.x !== 0 || display.bounds.y !== 0;
});
if (externalDisplay) {
otherWindow = new BrowserWindow({
fullscreen: false,
width: externalDisplay.bounds.width,
height: externalDisplay.bounds.height,
x: externalDisplay.bounds.x,
y: externalDisplay.bounds.y,
webPreferences: {
nodeIntegration: true
//配置预加载脚本文件(preload),此处起名为preloadOther
//p.s.路径为绝对路径
// preload: path.join(__dirname, "./preloadOther.js")
}
});
ipcMain.on('send-card', (event, obj) => { //指定副屏幕打开的网页
win.webContents.send('sendWebsockt', obj); otherWindow.loadURL(winURL + "#" + `/design-detail`);
}) otherWindow.on("closed", () => {
win.on("closed", () => { //这一段放外面的话,如果你电脑没双屏会报错。
win = null; otherWindow = null;
otherWindow = null;
}); });
}
ipcMain.on("allPrint", () => {
// 获取到打印机列表
const printers = win.webContents.getPrinters();
// 把获取的打印机列表发送给渲染进程
win.webContents.send("printName", printers);
});
ipcMain.on("win-subScreen", (data, v) => {
if (otherWindow) otherWindow.webContents.send("getProductionNoInfo", v);
});
if (process.env.WEBPACK_DEV_SERVER_URL) {
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
win.loadURL("app://./index.html");
}
ipcMain.on("send-card", (event, obj) => {
win.webContents.send("sendWebsockt", obj);
});
win.on("closed", () => {
win = null;
otherWindow = null;
});
} }
app.on("activate", () => { app.on("activate", () => {
if (win === null) { if (win === null) {
createWindow(); createWindow();
}
}
}); });
app.on("ready", async () => { app.on("ready", async () => {
createWindow(); createWindow();
}); });
if (isDevelopment) { if (isDevelopment) {
if (process.platform === "win32") { if (process.platform === "win32") {
process.on("message", data => { process.on("message", data => {
if (data === "graceful-exit") { if (data === "graceful-exit") {
app.quit(); app.quit();
} }
}); });
} else { } else {
process.on("SIGTERM", () => { process.on("SIGTERM", () => {
app.quit(); app.quit();
}); });
} }
} }
...@@ -48,7 +48,12 @@ const router = new VueRouter({ ...@@ -48,7 +48,12 @@ const router = new VueRouter({
routes routes
}); });
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
let user = Vue.prototype.$dataStore.get("user"); let user = Vue.prototype.$dataStore.get("user");
if (to.path.includes("design-detail")) {
return next();
}
if (to.name === "login") { if (to.name === "login") {
if (user) { if (user) {
console.log(1); console.log(1);
......
...@@ -859,7 +859,7 @@ img { ...@@ -859,7 +859,7 @@ img {
width: 120px; width: 120px;
z-index: 5; z-index: 5;
overflow: auto; overflow: auto;
background-color: #333; background-color: gray;
height: calc(100% - 72px); height: calc(100% - 72px);
padding: 10px; padding: 10px;
position: fixed; position: fixed;
......
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