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");
var uuid = require("uuid");
......@@ -15,51 +19,64 @@ fn.getPodProductionInfo = async (req, res) => {
const company = req.headers["company"];
const productionNo = req.body.productionNo;
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);
if (data.code === 200 && data.data && data.data.length > 0) {
let f = data.data.find(el => !el.productionFile);
data.data.forEach((el ) => {
data.data.forEach(el => {
if (!el.productionFile.includes("http")) {
el.productionFile = el.productionFile.replace("/data/upload/erp", "");
el.productionFile = `https://${company}/upload/erp/${el.productionFile}`;
el.productionFile = el.productionFile.replace(
"/data/upload/erp/",
""
);
el.productionFile = `https://${company}/upload/erp${el.productionFile}`;
}
});
if (f) {
return res.json({ code: 500, msg: "存在地址错误的素材图" });
}
downloadImage(data.data, company, data => {
res.json({ code: 200, data });
}, (err) => {
res.json({ code: 500, msg: "素材图下载失败" });
});
downloadImage(data.data)
.then(data => {
res.json({ code: 200, data });
})
.catch(err => {
res.json({ code: 500, msg: err });
});
} else {
res.json({ code: 200, msg: "未找到素材图", data: [] });
}
} catch (err) {
console.log(err);
res.json({ code: 500, msg: "接口调用失败" });
res.json({ code: 500, msg: err });
}
};
fn.findByPodProductionNo = async (req, res) => {
const token = req.headers["jwt-token"];
const company = req.headers["company"];
const q = req.body;
try {
let { data } = await axios.get(`https://${company}/api/pod/podProductionInfo/findByPodProductionNo`, {
params: q,
headers: { "jwt-token": token }
});
let { data } = await axios.get(
`https://${company}/api/pod/podProductionInfo/findByPodProductionNo`,
{
params: q,
headers: { "jwt-token": token }
}
);
res.json(data);
} catch (err) {
res.json({ code: 500, msg: err });
}
};
fn.getCompanyList = async (req, res) => {
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);
} catch (err) {
console.log(err);
......@@ -70,7 +87,10 @@ fn.commitApply = async (req, res) => {
const company = req.headers["company"];
const q = req.body;
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);
} catch (err) {
console.log(err);
......@@ -82,14 +102,17 @@ fn.completeDelivery = async (req, res) => {
const company = req.headers["company"];
const q = req.body;
try {
let { data } = await axios.post(`https://${company}/api/pod/podProductionInfo/completeDelivery`, q, {
headers: { "jwt-token": token }
});
let { data } = await axios.post(
`https://${company}/api/pod/podProductionInfo/completeDelivery`,
q,
{
headers: { "jwt-token": token }
}
);
res.json(data);
} catch (err) {
res.json({ code: 500, msg: err });
}
};
fn.downloadByDesignId = async (req, res) => {
let q = req.body;
......@@ -98,12 +121,16 @@ fn.downloadByDesignId = async (req, res) => {
const zipStream = new compressing.zip.Stream();
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);
}
const destStream = fs.createWriteStream(dir);
zipStream.pipe(destStream)
zipStream
.pipe(destStream)
.on("finish", () => {
console.log("success");
res.json({ code: 200, msg: q.productionNo + ".zip" + "已下载到桌面" });
......@@ -125,12 +152,10 @@ fn.downloadByDesignId = async (req, res) => {
//
// });
// ws.end()
} catch (err) {
console.log(err);
res.json({ code: 500, msg: err });
}
};
fn.uploadImage = async (req, res) => {
try {
......@@ -145,24 +170,33 @@ fn.uploadImage = async (req, res) => {
res.send({ code: 500, err });
} else {
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) {
console.log(err);
res.json({ code: 500, msg: err });
}
};
fn.getPngImg = async (req, res) => {
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);
// 给客户端返回一个文件流 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 responseData = [];//存储文件流
if (stream) {//判断状态
let responseData = []; //存储文件流
if (stream) {
//判断状态
stream.on("data", function(chunk) {
responseData.push(chunk);
});
......@@ -175,14 +209,16 @@ fn.getPngImg = async (req, res) => {
} catch (err) {
res.send({ code: 500, msg: err });
}
};
fn.login = async (req, res) => {
const { loginName, company, password, deviceId } = req.body;
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);
} catch (err) {
......@@ -191,16 +227,17 @@ fn.login = async (req, res) => {
}
};
fn.toPrint = (req, res) => {
let body = req.body;
writeProfileXml(body); // 写入xml文件
// GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254
toSend(body).then(r => {
res.send({ code: 200, msg: "操作成功" });
}).catch(err => {
res.send({ code: 500, msg: err });
});
toSend(body)
.then(r => {
res.send({ code: 200, msg: "操作成功" });
})
.catch(err => {
res.send({ code: 500, msg: err });
});
};
export { fn as default };
import express from "express";
import fn from "../entity/function.js";
import {getPodProductionInfo, sendImg} from "@/backend/webserver/utils";
let router = express.Router();
......
import { exec, execSync } from "child_process";
import { exec } from "child_process";
var fs = require("fs");
var path = require("path");
......@@ -6,102 +6,106 @@ var request = require("request");
var uuid = require("uuid");
const compressing = require("compressing");
function zip(from, to, callback, errorback) {
let dirName = path.join(to, uuid.v4());
console.log(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);
function zip(from, to) {
return new Promise((resolve, reject) => {
let dirName = path.join(to, uuid.v4());
console.log(dirName);
if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName);
}
for (let i = 0; i < list.length; i++) {
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;
let arr = [];
compressing.zip
.uncompress(from, dirName, { zipFileNameEncoding: "gbk" })
.then(() => {
console.log("success");
let data = fs.readdirSync(dirName);
for (let i = 0; i < data.length; i++) {
let el = data[i];
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)
});
}
let p = path.join(process.cwd(), "./print/Input/" + fileName);
let stream = fs.createWriteStream(p);
list[i].fileName = fileName;
list[i].type = type;
console.log(list[i].productionFile);
request(list[i].productionFile)
.pipe(stream)
.on("close", function(err) {
console.log(6666666666,list[i]);
if (type === 1) {
fs.unlinkSync(from); // 删除压缩包
fs.rmdirSync(dirName); // 删除目录文件
// console.log(arr);
resolve(arr);
})
.catch(err => {
console.log(err);
reject("压缩包解压失败");
});
});
}
zip(
p,
dirPath,
data => {
list[i].list = data;
},
errorBack
);
} else {
if (i === list.length - 1) {
callback && callback(list);
// 下载素材
export const downloadImage = list => {
return new Promise((resolve, reject) => {
try {
let dirPath = path.join(process.cwd(), "./print/Input/");
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
let count = 0;
for (let i = 0; i < list.length; i++) {
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 => {
exec(
body.print_cmd,
{ cwd: path.join(process.cwd(), "print"), shell: true },
(err2, stdout2, stderr2) => {
err2 => {
console.log(err2);
if (!err2) {
// 成功后删除 素材图,xml,output文件
// 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(path.join(process.cwd(), 'print/Output/' + body.fileName.replace('.png', '') + '.arxp'))
fs.unlinkSync(
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("操作成功");
} else {
reject("打印机参数错误");
......
"use strict";
import {contextBridge, ipcMain, ipcRenderer} from 'electron'
import {app, protocol, BrowserWindow, Menu, screen} from "electron";
import {createProtocol} from "vue-cli-plugin-electron-builder/lib";
import webApp from "@/backend/webserver/be_nodeSrv.js"
import { contextBridge, ipcMain, ipcRenderer } from "electron";
import { app, protocol, BrowserWindow, Menu, screen } from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import webApp from "@/backend/webserver/be_nodeSrv.js";
let isCreateWin = false
let isCreateWin = false;
const isDevelopment = process.env.NODE_ENV !== "production";
let win;
let otherWindow;
protocol.registerSchemesAsPrivileged([
{scheme: "app", privileges: {secure: true, standard: true}}
{ scheme: "app", privileges: { secure: true, standard: true } }
]);
const winURL = process.env.NODE_ENV === 'development'
? 'http://localhost:8090'
: `file://${__dirname}/index.html`
const winURL =
process.env.NODE_ENV === "development"
? "http://localhost:8090"
: `file://${__dirname}/index.html`;
function createWindow() {
win = new BrowserWindow({
width: 1500,
height: 1000,
icon: "./src/assets/logo.jpg",
webPreferences: {
webSecurity: false,
nodeIntegration: true,
// 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");
win = new BrowserWindow({
width: 1500,
height: 1000,
icon: "./src/assets/logo.jpg",
webPreferences: {
webSecurity: false,
nodeIntegration: true
// 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")
}
});
ipcMain.on('send-card', (event, obj) => {
win.webContents.send('sendWebsockt', obj);
})
win.on("closed", () => {
win = null;
otherWindow = null;
//指定副屏幕打开的网页
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");
}
ipcMain.on("send-card", (event, obj) => {
win.webContents.send("sendWebsockt", obj);
});
win.on("closed", () => {
win = null;
otherWindow = null;
});
}
app.on("activate", () => {
if (win === null) {
createWindow();
}
if (win === null) {
createWindow();
}
});
app.on("ready", async () => {
createWindow();
createWindow();
});
if (isDevelopment) {
if (process.platform === "win32") {
process.on("message", data => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
if (process.platform === "win32") {
process.on("message", data => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
}
......@@ -48,7 +48,12 @@ const router = new VueRouter({
routes
});
router.beforeEach((to, from, next) => {
let user = Vue.prototype.$dataStore.get("user");
if (to.path.includes("design-detail")) {
return next();
}
if (to.name === "login") {
if (user) {
console.log(1);
......
......@@ -859,7 +859,7 @@ img {
width: 120px;
z-index: 5;
overflow: auto;
background-color: #333;
background-color: gray;
height: calc(100% - 72px);
padding: 10px;
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