Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
electron-printer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhuzhequan
electron-printer
Commits
a7b73f94
Commit
a7b73f94
authored
Feb 25, 2025
by
zhuzhequan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eslint
parent
f06833f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
305 additions
and
309 deletions
+305
-309
src/server/entity/function.js
+305
-309
No files found.
src/server/entity/function.js
View file @
a7b73f94
import
{
downloadImage
,
toSend
,
writeProfileXml
}
from
"@/server/utils"
;
var
request
=
require
(
"request"
);
const
compressing
=
require
(
"compressing"
);
const
uuid
=
require
(
"uuid"
);
const
path
=
require
(
"path"
);
const
fs
=
require
(
"fs"
);
const
os
=
require
(
"os"
);
import
axios
from
"axios"
;
import
{
returnLogFilePath
}
from
"../utils/log"
;
axios
.
defaults
.
timeout
=
12600000
;
const
multiparty
=
require
(
"multiparty"
);
export
default
{
writePrintLog
:
async
(
req
,
res
)
=>
{
try
{
let
body
=
req
.
body
;
let
p
=
path
.
join
(
returnLogFilePath
(),
"print.json"
);
p
=
p
.
replace
(
"
\\
api.log"
,
""
);
console
.
log
(
p
);
let
data
=
[];
if
(
!
fs
.
existsSync
(
p
))
{
fs
.
writeFileSync
(
p
,
"[]"
);
data
=
[];
}
else
{
data
=
fs
.
readFileSync
(
p
,
{
encoding
:
"utf-8"
});
data
=
JSON
.
parse
(
data
);
}
data
.
unshift
(
body
);
fs
.
writeFileSync
(
p
,
JSON
.
stringify
(
data
));
res
.
json
({
code
:
200
});
}
catch
(
e
)
{
res
.
json
({
code
:
500
,
msg
:
e
});
}
},
getPodProductionInfo
:
async
(
req
,
res
)
=>
{
const
token
=
req
.
headers
[
"jwt-token"
];
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
}
}
);
console
.
log
(
data
);
if
(
data
.
code
===
200
&&
data
.
data
&&
data
.
data
.
length
>
0
)
{
let
f
=
data
.
data
.
find
(
el
=>
!
el
.
productionFile
);
if
(
f
)
{
return
res
.
json
({
code
:
500
,
msg
:
"存在地址错误的素材图"
});
}
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
}
`
;
}
});
downloadImage
(
data
.
data
)
.
then
(
data
=>
{
res
.
json
({
code
:
200
,
data
});
})
.
catch
(
err
=>
{
res
.
json
({
code
:
500
,
msg
:
err
});
});
}
else
{
res
.
json
(
data
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
}
}
);
res
.
json
(
data
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
getCompanyList
:
async
(
req
,
res
)
=>
{
try
{
let
{
data
}
=
await
axios
.
get
(
"https://platform.jomalls.com/api/tools/getCompanyList"
);
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
);
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
completeDelivery
:
async
(
req
,
res
)
=>
{
const
token
=
req
.
headers
[
"jwt-token"
];
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
}
}
);
res
.
json
(
data
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
downloadByDesignId
:
async
(
req
,
res
)
=>
{
let
q
=
req
.
body
;
try
{
let
dir
=
path
.
join
(
os
.
homedir
(),
"/Desktop/"
+
q
.
productionNo
+
".zip"
);
const
zipStream
=
new
compressing
.
zip
.
Stream
();
for
(
let
k
in
q
.
imgList
)
{
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
+
q
.
imgList
[
k
].
fileName
);
zipStream
.
addEntry
(
p
);
}
const
destStream
=
fs
.
createWriteStream
(
dir
);
zipStream
.
pipe
(
destStream
)
.
on
(
"finish"
,
()
=>
{
console
.
log
(
"success"
);
res
.
json
({
code
:
200
,
msg
:
q
.
productionNo
+
".zip"
+
"已下载到桌面"
});
})
.
on
(
"error"
,
()
=>
{
res
.
json
({
code
:
500
,
msg
:
"文件下载失败"
});
});
// let ws=fs.createWriteStream(dir );
// console.log(downloadByDesignId)
//
// ws.write(downloadByDesignId.data);
// ws.on('drain',function () {
// console.log("内存干了");
// });
// ws.on('error',function (err) {
// res.json({code: 500, msg: '文件下载失败'})
// });
// ws.on('close',function (err) {
//
// });
// ws.end()
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
uploadImage
:
async
(
req
,
res
)
=>
{
try
{
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
);
let
fileName
=
uuid
.
v4
()
+
".png"
;
console
.
log
(
fileName
);
const
form
=
new
multiparty
.
Form
({
uploadDir
:
p
});
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
console
.
log
(
fields
,
files
,
err
);
if
(
err
)
{
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
)
}
});
}
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
getPngImg
:
async
(
req
,
res
)
=>
{
try
{
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"
});
//设置返回类型
let
stream
=
fs
.
createReadStream
(
filePath
);
let
responseData
=
[];
//存储文件流
if
(
stream
)
{
//判断状态
stream
.
on
(
"data"
,
function
(
chunk
)
{
responseData
.
push
(
chunk
);
});
stream
.
on
(
"end"
,
function
()
{
const
finalData
=
Buffer
.
concat
(
responseData
);
res
.
write
(
finalData
);
res
.
end
();
});
}
}
catch
(
err
)
{
res
.
send
({
code
:
500
,
msg
:
err
});
}
},
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
});
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
});
});
},
checkUpdate
:
async
(
req
,
res
)
=>
{
// const company = "http://10.168.31.188:8096";
const
company
=
"https://admin.jomalls.com"
;
try
{
let
q
=
`
${
company
}
/api/manage/rest/app/checkUpdate?version=
${
req
.
query
.
version
}
&businessType=production_assistant`
;
let
{
data
}
=
await
axios
.
get
(
q
);
if
(
data
.
data
)
{
q
=
`
${
company
}
/api/manage/rest/app/getLatest?businessType=production_assistant`
;
let
r
=
await
axios
.
get
(
q
);
res
.
send
(
r
.
data
);
}
else
{
res
.
send
(
data
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
incrementalUpdates
:
async
(
req
,
res
)
=>
{
try
{
let
from
=
path
.
join
(
process
.
cwd
(),
"./resources/app/css.zip"
);
let
dirName
=
path
.
join
(
process
.
cwd
(),
"./resources/app/"
);
let
stream
=
fs
.
createWriteStream
(
from
);
const
company
=
req
.
headers
[
"company"
];
req
.
body
.
url
=
"https://"
+
company
+
req
.
body
.
url
;
console
.
log
(
req
.
body
.
url
,
"下载zip地址"
);
request
(
req
.
body
.
url
)
.
pipe
(
stream
)
.
on
(
"close"
,
function
()
{
compressing
.
zip
.
uncompress
(
from
,
dirName
,
{
zipFileNameEncoding
:
"gbk"
})
.
then
(()
=>
{
fs
.
unlinkSync
(
from
);
res
.
json
({
code
:
200
,
msg
:
"更新成功"
});
}).
catch
(
err
=>
{
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
});
});
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
}
}
};
import
{
downloadImage
,
toSend
,
writeProfileXml
}
from
"@/server/utils"
;
var
request
=
require
(
"request"
);
const
compressing
=
require
(
"compressing"
);
const
uuid
=
require
(
"uuid"
);
const
path
=
require
(
"path"
);
const
fs
=
require
(
"fs"
);
const
os
=
require
(
"os"
);
import
axios
from
"axios"
;
import
{
returnLogFilePath
}
from
"../utils/log"
;
axios
.
defaults
.
timeout
=
12600000
;
const
multiparty
=
require
(
"multiparty"
);
export
default
{
writePrintLog
:
async
(
req
,
res
)
=>
{
try
{
let
body
=
req
.
body
;
let
p
=
path
.
join
(
returnLogFilePath
(),
"print.json"
);
p
=
p
.
replace
(
"
\\
api.log"
,
""
);
console
.
log
(
p
);
let
data
=
[];
if
(
!
fs
.
existsSync
(
p
))
{
fs
.
writeFileSync
(
p
,
"[]"
);
data
=
[];
}
else
{
data
=
fs
.
readFileSync
(
p
,
{
encoding
:
"utf-8"
});
data
=
JSON
.
parse
(
data
);
}
data
.
unshift
(
body
);
fs
.
writeFileSync
(
p
,
JSON
.
stringify
(
data
));
res
.
json
({
code
:
200
});
}
catch
(
e
)
{
res
.
json
({
code
:
500
,
msg
:
e
});
}
},
getPodProductionInfo
:
async
(
req
,
res
)
=>
{
const
token
=
req
.
headers
[
"jwt-token"
];
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
}
}
);
console
.
log
(
data
);
if
(
data
.
code
===
200
&&
data
.
data
&&
data
.
data
.
length
>
0
)
{
let
f
=
data
.
data
.
find
(
el
=>
!
el
.
productionFile
);
if
(
f
)
{
return
res
.
json
({
code
:
500
,
msg
:
"存在地址错误的素材图"
});
}
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
}
`
;
}
});
downloadImage
(
data
.
data
)
.
then
(
data
=>
{
res
.
json
({
code
:
200
,
data
});
})
.
catch
(
err
=>
{
res
.
json
({
code
:
500
,
msg
:
err
});
});
}
else
{
res
.
json
(
data
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
}
}
);
res
.
json
(
data
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
getCompanyList
:
async
(
req
,
res
)
=>
{
try
{
let
{
data
}
=
await
axios
.
get
(
"https://platform.jomalls.com/api/tools/getCompanyList"
);
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
);
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
completeDelivery
:
async
(
req
,
res
)
=>
{
const
token
=
req
.
headers
[
"jwt-token"
];
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
}
}
);
res
.
json
(
data
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
downloadByDesignId
:
async
(
req
,
res
)
=>
{
let
q
=
req
.
body
;
try
{
let
dir
=
path
.
join
(
os
.
homedir
(),
"/Desktop/"
+
q
.
productionNo
+
".zip"
);
const
zipStream
=
new
compressing
.
zip
.
Stream
();
for
(
let
k
in
q
.
imgList
)
{
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
+
q
.
imgList
[
k
].
fileName
);
zipStream
.
addEntry
(
p
);
}
const
destStream
=
fs
.
createWriteStream
(
dir
);
zipStream
.
pipe
(
destStream
)
.
on
(
"finish"
,
()
=>
{
console
.
log
(
"success"
);
res
.
json
({
code
:
200
,
msg
:
q
.
productionNo
+
".zip"
+
"已下载到桌面"
});
})
.
on
(
"error"
,
()
=>
{
res
.
json
({
code
:
500
,
msg
:
"文件下载失败"
});
});
// let ws=fs.createWriteStream(dir );
// console.log(downloadByDesignId)
//
// ws.write(downloadByDesignId.data);
// ws.on('drain',function () {
// console.log("内存干了");
// });
// ws.on('error',function (err) {
// res.json({code: 500, msg: '文件下载失败'})
// });
// ws.on('close',function (err) {
//
// });
// ws.end()
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
uploadImage
:
async
(
req
,
res
)
=>
{
try
{
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
);
let
fileName
=
uuid
.
v4
()
+
".png"
;
console
.
log
(
fileName
);
const
form
=
new
multiparty
.
Form
({
uploadDir
:
p
});
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
console
.
log
(
fields
,
files
,
err
);
if
(
err
)
{
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
)
}
});
}
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
getPngImg
:
async
(
req
,
res
)
=>
{
try
{
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"
});
//设置返回类型
let
stream
=
fs
.
createReadStream
(
filePath
);
let
responseData
=
[];
//存储文件流
if
(
stream
)
{
//判断状态
stream
.
on
(
"data"
,
function
(
chunk
)
{
responseData
.
push
(
chunk
);
});
stream
.
on
(
"end"
,
function
()
{
const
finalData
=
Buffer
.
concat
(
responseData
);
res
.
write
(
finalData
);
res
.
end
();
});
}
}
catch
(
err
)
{
res
.
send
({
code
:
500
,
msg
:
err
});
}
},
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
});
res
.
send
(
data
);
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
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
});
});
},
checkUpdate
:
async
(
req
,
res
)
=>
{
// const company = "http://10.168.31.188:8096";
const
company
=
"https://admin.jomalls.com"
;
try
{
let
q
=
`
${
company
}
/api/manage/rest/app/checkUpdate?version=
${
req
.
query
.
version
}
&businessType=production_assistant`
;
let
{
data
}
=
await
axios
.
get
(
q
);
if
(
data
.
data
)
{
q
=
`
${
company
}
/api/manage/rest/app/getLatest?businessType=production_assistant`
;
let
r
=
await
axios
.
get
(
q
);
res
.
send
(
r
.
data
);
}
else
{
res
.
send
(
data
);
}
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
},
incrementalUpdates
:
async
(
req
,
res
)
=>
{
try
{
let
from
=
path
.
join
(
process
.
cwd
(),
"./resources/app/css.zip"
);
let
dirName
=
path
.
join
(
process
.
cwd
(),
"./resources/app/"
);
let
stream
=
fs
.
createWriteStream
(
from
);
const
company
=
req
.
headers
[
"company"
];
req
.
body
.
url
=
"https://"
+
company
+
req
.
body
.
url
;
console
.
log
(
req
.
body
.
url
,
"下载zip地址"
);
request
(
req
.
body
.
url
)
.
pipe
(
stream
)
.
on
(
"close"
,
function
()
{
compressing
.
zip
.
uncompress
(
from
,
dirName
,
{
zipFileNameEncoding
:
"gbk"
})
.
then
(()
=>
{
fs
.
unlinkSync
(
from
);
res
.
json
({
code
:
200
,
msg
:
"更新成功"
});
})
.
catch
(
err
=>
{
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
});
});
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
}
}
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment