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
{
import
{
downloadImage
,
toSend
,
writeProfileXml
}
from
"@/server/utils"
;
downloadImage
,
toSend
,
var
request
=
require
(
"request"
);
writeProfileXml
const
compressing
=
require
(
"compressing"
);
}
from
"@/server/utils"
;
const
uuid
=
require
(
"uuid"
);
const
path
=
require
(
"path"
);
var
request
=
require
(
"request"
);
const
fs
=
require
(
"fs"
);
const
compressing
=
require
(
"compressing"
);
const
os
=
require
(
"os"
);
const
uuid
=
require
(
"uuid"
);
import
axios
from
"axios"
;
const
path
=
require
(
"path"
);
import
{
returnLogFilePath
}
from
"../utils/log"
;
const
fs
=
require
(
"fs"
);
const
os
=
require
(
"os"
);
axios
.
defaults
.
timeout
=
12600000
;
import
axios
from
"axios"
;
const
multiparty
=
require
(
"multiparty"
);
import
{
returnLogFilePath
}
from
"../utils/log"
;
export
default
{
writePrintLog
:
async
(
req
,
res
)
=>
{
axios
.
defaults
.
timeout
=
12600000
;
try
{
const
multiparty
=
require
(
"multiparty"
);
let
body
=
req
.
body
;
export
default
{
let
p
=
path
.
join
(
returnLogFilePath
(),
"print.json"
);
writePrintLog
:
async
(
req
,
res
)
=>
{
p
=
p
.
replace
(
"
\\
api.log"
,
""
);
try
{
console
.
log
(
p
);
let
body
=
req
.
body
;
let
data
=
[];
let
p
=
path
.
join
(
returnLogFilePath
(),
"print.json"
);
if
(
!
fs
.
existsSync
(
p
))
{
p
=
p
.
replace
(
"
\\
api.log"
,
""
);
fs
.
writeFileSync
(
p
,
"[]"
);
console
.
log
(
p
);
data
=
[];
let
data
=
[];
}
else
{
if
(
!
fs
.
existsSync
(
p
))
{
data
=
fs
.
readFileSync
(
p
,
{
encoding
:
"utf-8"
});
fs
.
writeFileSync
(
p
,
"[]"
);
data
=
JSON
.
parse
(
data
);
data
=
[];
}
}
else
{
data
.
unshift
(
body
);
data
=
fs
.
readFileSync
(
p
,
{
encoding
:
"utf-8"
});
fs
.
writeFileSync
(
p
,
JSON
.
stringify
(
data
));
data
=
JSON
.
parse
(
data
);
res
.
json
({
code
:
200
});
}
}
catch
(
e
)
{
data
.
unshift
(
body
);
res
.
json
({
code
:
500
,
msg
:
e
});
fs
.
writeFileSync
(
p
,
JSON
.
stringify
(
data
));
}
res
.
json
({
code
:
200
});
},
}
catch
(
e
)
{
getPodProductionInfo
:
async
(
req
,
res
)
=>
{
res
.
json
({
code
:
500
,
msg
:
e
});
const
token
=
req
.
headers
[
"jwt-token"
];
}
const
company
=
req
.
headers
[
"company"
];
const
productionNo
=
req
.
body
.
productionNo
;
},
try
{
getPodProductionInfo
:
async
(
req
,
res
)
=>
{
let
{
data
}
=
await
axios
.
post
(
const
token
=
req
.
headers
[
"jwt-token"
];
`https://
${
company
}
/api/podDesignCenter/getPodImageByProduction`
,
const
company
=
req
.
headers
[
"company"
];
{
productionNo
},
const
productionNo
=
req
.
body
.
productionNo
;
{
headers
:
{
"jwt-token"
:
token
}
}
try
{
);
let
{
data
}
=
await
axios
.
post
(
console
.
log
(
data
);
`https://
${
company
}
/api/podDesignCenter/getPodImageByProduction`
,
if
(
data
.
code
===
200
&&
data
.
data
&&
data
.
data
.
length
>
0
)
{
{
productionNo
},
let
f
=
data
.
data
.
find
(
el
=>
!
el
.
productionFile
);
{
headers
:
{
"jwt-token"
:
token
}
}
if
(
f
)
{
);
return
res
.
json
({
code
:
500
,
msg
:
"存在地址错误的素材图"
});
console
.
log
(
data
);
}
if
(
data
.
code
===
200
&&
data
.
data
&&
data
.
data
.
length
>
0
)
{
data
.
data
.
forEach
(
el
=>
{
let
f
=
data
.
data
.
find
(
el
=>
!
el
.
productionFile
);
if
(
!
el
.
productionFile
.
includes
(
"http"
))
{
if
(
f
)
{
el
.
productionFile
=
el
.
productionFile
.
replace
(
return
res
.
json
({
code
:
500
,
msg
:
"存在地址错误的素材图"
});
"/data/upload/erp/"
,
}
""
data
.
data
.
forEach
(
el
=>
{
);
if
(
!
el
.
productionFile
.
includes
(
"http"
))
{
el
.
productionFile
=
`https://
${
company
}
/upload/erp
${
el
.
productionFile
}
`
;
el
.
productionFile
=
el
.
productionFile
.
replace
(
}
"/data/upload/erp/"
,
});
""
downloadImage
(
data
.
data
)
);
.
then
(
data
=>
{
el
.
productionFile
=
`https://
${
company
}
/upload/erp
${
el
.
productionFile
}
`
;
res
.
json
({
code
:
200
,
data
});
}
})
});
.
catch
(
err
=>
{
downloadImage
(
data
.
data
)
res
.
json
({
code
:
500
,
msg
:
err
});
.
then
(
data
=>
{
});
res
.
json
({
code
:
200
,
data
});
}
else
{
})
res
.
json
(
data
);
.
catch
(
err
=>
{
}
res
.
json
({
code
:
500
,
msg
:
err
});
}
catch
(
err
)
{
});
console
.
log
(
err
);
}
else
{
res
.
json
({
code
:
500
,
msg
:
err
});
res
.
json
(
data
);
}
}
},
}
catch
(
err
)
{
findByPodProductionNo
:
async
(
req
,
res
)
=>
{
console
.
log
(
err
);
const
token
=
req
.
headers
[
"jwt-token"
];
res
.
json
({
code
:
500
,
msg
:
err
});
const
company
=
req
.
headers
[
"company"
];
}
const
q
=
req
.
body
;
},
try
{
findByPodProductionNo
:
async
(
req
,
res
)
=>
{
let
{
data
}
=
await
axios
.
get
(
const
token
=
req
.
headers
[
"jwt-token"
];
`https://
${
company
}
/api/pod/podProductionInfo/findByPodProductionNo`
,
const
company
=
req
.
headers
[
"company"
];
{
const
q
=
req
.
body
;
params
:
q
,
try
{
headers
:
{
"jwt-token"
:
token
}
let
{
data
}
=
await
axios
.
get
(
}
`https://
${
company
}
/api/pod/podProductionInfo/findByPodProductionNo`
,
);
{
res
.
json
(
data
);
params
:
q
,
}
catch
(
err
)
{
headers
:
{
"jwt-token"
:
token
}
res
.
json
({
code
:
500
,
msg
:
err
});
}
}
);
},
res
.
json
(
data
);
getCompanyList
:
async
(
req
,
res
)
=>
{
}
catch
(
err
)
{
try
{
res
.
json
({
code
:
500
,
msg
:
err
});
let
{
data
}
=
await
axios
.
get
(
}
"https://platform.jomalls.com/api/tools/getCompanyList"
},
);
getCompanyList
:
async
(
req
,
res
)
=>
{
res
.
send
(
data
);
try
{
}
catch
(
err
)
{
let
{
data
}
=
await
axios
.
get
(
console
.
log
(
err
);
"https://platform.jomalls.com/api/tools/getCompanyList"
res
.
json
({
code
:
500
,
msg
:
err
});
);
}
res
.
send
(
data
);
},
}
catch
(
err
)
{
commitApply
:
async
(
req
,
res
)
=>
{
console
.
log
(
err
);
const
company
=
req
.
headers
[
"company"
];
res
.
json
({
code
:
500
,
msg
:
err
});
const
q
=
req
.
body
;
}
try
{
},
let
{
data
}
=
await
axios
.
post
(
commitApply
:
async
(
req
,
res
)
=>
{
`https://
${
company
}
/api/sysDeviceInfo/commitApply`
,
const
company
=
req
.
headers
[
"company"
];
q
const
q
=
req
.
body
;
);
try
{
res
.
send
(
data
);
let
{
data
}
=
await
axios
.
post
(
}
catch
(
err
)
{
`https://
${
company
}
/api/sysDeviceInfo/commitApply`
,
console
.
log
(
err
);
q
res
.
json
({
code
:
500
,
msg
:
err
});
);
}
res
.
send
(
data
);
},
}
catch
(
err
)
{
completeDelivery
:
async
(
req
,
res
)
=>
{
console
.
log
(
err
);
const
token
=
req
.
headers
[
"jwt-token"
];
res
.
json
({
code
:
500
,
msg
:
err
});
const
company
=
req
.
headers
[
"company"
];
}
const
q
=
req
.
body
;
},
try
{
completeDelivery
:
async
(
req
,
res
)
=>
{
let
{
data
}
=
await
axios
.
post
(
const
token
=
req
.
headers
[
"jwt-token"
];
`https://
${
company
}
/api/pod/podProductionInfo/completeDelivery`
,
const
company
=
req
.
headers
[
"company"
];
q
,
const
q
=
req
.
body
;
{
try
{
headers
:
{
"jwt-token"
:
token
}
let
{
data
}
=
await
axios
.
post
(
}
`https://
${
company
}
/api/pod/podProductionInfo/completeDelivery`
,
);
q
,
res
.
json
(
data
);
{
}
catch
(
err
)
{
headers
:
{
"jwt-token"
:
token
}
res
.
json
({
code
:
500
,
msg
:
err
});
}
}
);
},
res
.
json
(
data
);
downloadByDesignId
:
async
(
req
,
res
)
=>
{
}
catch
(
err
)
{
let
q
=
req
.
body
;
res
.
json
({
code
:
500
,
msg
:
err
});
try
{
}
let
dir
=
path
.
join
(
os
.
homedir
(),
"/Desktop/"
+
q
.
productionNo
+
".zip"
);
},
const
zipStream
=
new
compressing
.
zip
.
Stream
();
downloadByDesignId
:
async
(
req
,
res
)
=>
{
let
q
=
req
.
body
;
for
(
let
k
in
q
.
imgList
)
{
try
{
const
p
=
path
.
join
(
let
dir
=
path
.
join
(
os
.
homedir
(),
"/Desktop/"
+
q
.
productionNo
+
".zip"
);
process
.
cwd
(),
const
zipStream
=
new
compressing
.
zip
.
Stream
();
"./print/Input/"
+
q
.
imgList
[
k
].
fileName
);
for
(
let
k
in
q
.
imgList
)
{
zipStream
.
addEntry
(
p
);
const
p
=
path
.
join
(
}
process
.
cwd
(),
"./print/Input/"
+
q
.
imgList
[
k
].
fileName
const
destStream
=
fs
.
createWriteStream
(
dir
);
);
zipStream
zipStream
.
addEntry
(
p
);
.
pipe
(
destStream
)
}
.
on
(
"finish"
,
()
=>
{
console
.
log
(
"success"
);
const
destStream
=
fs
.
createWriteStream
(
dir
);
res
.
json
({
zipStream
code
:
200
,
.
pipe
(
destStream
)
msg
:
q
.
productionNo
+
".zip"
+
"已下载到桌面"
.
on
(
"finish"
,
()
=>
{
});
console
.
log
(
"success"
);
})
res
.
json
({
code
:
200
,
msg
:
q
.
productionNo
+
".zip"
+
"已下载到桌面"
});
.
on
(
"error"
,
()
=>
{
})
res
.
json
({
code
:
500
,
msg
:
"文件下载失败"
});
.
on
(
"error"
,
()
=>
{
});
res
.
json
({
code
:
500
,
msg
:
"文件下载失败"
});
// let ws=fs.createWriteStream(dir );
});
// console.log(downloadByDesignId)
// let ws=fs.createWriteStream(dir );
//
// console.log(downloadByDesignId)
// ws.write(downloadByDesignId.data);
//
// ws.on('drain',function () {
// ws.write(downloadByDesignId.data);
// console.log("内存干了");
// ws.on('drain',function () {
// });
// console.log("内存干了");
// ws.on('error',function (err) {
// });
// res.json({code: 500, msg: '文件下载失败'})
// ws.on('error',function (err) {
// });
// res.json({code: 500, msg: '文件下载失败'})
// ws.on('close',function (err) {
// });
//
// ws.on('close',function (err) {
// });
//
// ws.end()
// });
}
catch
(
err
)
{
// ws.end()
console
.
log
(
err
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
console
.
log
(
err
);
}
res
.
json
({
code
:
500
,
msg
:
err
});
},
}
uploadImage
:
async
(
req
,
res
)
=>
{
},
try
{
uploadImage
:
async
(
req
,
res
)
=>
{
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
);
try
{
let
fileName
=
uuid
.
v4
()
+
".png"
;
const
p
=
path
.
join
(
process
.
cwd
(),
"./print/Input/"
);
console
.
log
(
fileName
);
let
fileName
=
uuid
.
v4
()
+
".png"
;
console
.
log
(
fileName
);
const
form
=
new
multiparty
.
Form
({
uploadDir
:
p
});
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
const
form
=
new
multiparty
.
Form
({
uploadDir
:
p
});
console
.
log
(
fields
,
files
,
err
);
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
if
(
err
)
{
console
.
log
(
fields
,
files
,
err
);
res
.
send
({
code
:
500
,
err
});
if
(
err
)
{
}
else
{
res
.
send
({
code
:
500
,
err
});
fs
.
renameSync
(
files
.
file
[
0
].
path
,
path
.
join
(
p
,
fileName
));
}
else
{
res
.
json
({
fs
.
renameSync
(
files
.
file
[
0
].
path
,
path
.
join
(
p
,
fileName
));
code
:
200
,
res
.
json
({
data
:
{
code
:
200
,
fileName
,
data
:
{
url
:
path
.
join
(
process
.
cwd
(),
"./print/Input/"
+
fileName
)
fileName
,
}
url
:
path
.
join
(
process
.
cwd
(),
"./print/Input/"
+
fileName
)
});
}
}
});
});
}
}
catch
(
err
)
{
});
console
.
log
(
err
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
console
.
log
(
err
);
}
res
.
json
({
code
:
500
,
msg
:
err
});
},
}
getPngImg
:
async
(
req
,
res
)
=>
{
},
try
{
getPngImg
:
async
(
req
,
res
)
=>
{
const
filePath
=
path
.
join
(
try
{
process
.
cwd
(),
const
filePath
=
path
.
join
(
`./print/Input/
${
req
.
body
.
fileName
}
`
process
.
cwd
(),
);
`./print/Input/
${
req
.
body
.
fileName
}
`
console
.
log
(
filePath
);
);
// 给客户端返回一个文件流 type类型
console
.
log
(
filePath
);
res
.
set
(
"content-type"
,
{
png
:
"image/png"
,
jpg
:
"image/jpeg"
});
//设置返回类型
// 给客户端返回一个文件流 type类型
let
stream
=
fs
.
createReadStream
(
filePath
);
res
.
set
(
"content-type"
,
{
png
:
"image/png"
,
jpg
:
"image/jpeg"
});
//设置返回类型
let
responseData
=
[];
//存储文件流
let
stream
=
fs
.
createReadStream
(
filePath
);
if
(
stream
)
{
let
responseData
=
[];
//存储文件流
//判断状态
if
(
stream
)
{
stream
.
on
(
"data"
,
function
(
chunk
)
{
//判断状态
responseData
.
push
(
chunk
);
stream
.
on
(
"data"
,
function
(
chunk
)
{
});
responseData
.
push
(
chunk
);
stream
.
on
(
"end"
,
function
()
{
});
const
finalData
=
Buffer
.
concat
(
responseData
);
stream
.
on
(
"end"
,
function
()
{
res
.
write
(
finalData
);
const
finalData
=
Buffer
.
concat
(
responseData
);
res
.
end
();
res
.
write
(
finalData
);
});
res
.
end
();
}
});
}
catch
(
err
)
{
}
res
.
send
({
code
:
500
,
msg
:
err
});
}
catch
(
err
)
{
}
res
.
send
({
code
:
500
,
msg
:
err
});
},
}
login
:
async
(
req
,
res
)
=>
{
},
const
{
loginName
,
company
,
password
,
deviceId
}
=
req
.
body
;
login
:
async
(
req
,
res
)
=>
{
try
{
const
{
loginName
,
company
,
password
,
deviceId
}
=
req
.
body
;
let
{
data
}
=
await
axios
.
post
(
`https://
${
company
}
/api/sysLogin/login`
,
{
try
{
loginName
,
let
{
data
}
=
await
axios
.
post
(
`https://
${
company
}
/api/sysLogin/login`
,
{
password
,
loginName
,
deviceId
password
,
});
deviceId
});
res
.
send
(
data
);
}
catch
(
err
)
{
res
.
send
(
data
);
console
.
log
(
err
);
}
catch
(
err
)
{
res
.
json
({
code
:
500
,
msg
:
err
});
console
.
log
(
err
);
}
res
.
json
({
code
:
500
,
msg
:
err
});
},
}
toPrint
:
(
req
,
res
)
=>
{
},
let
body
=
req
.
body
;
toPrint
:
(
req
,
res
)
=>
{
writeProfileXml
(
body
);
// 写入xml文件
let
body
=
req
.
body
;
// GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254
writeProfileXml
(
body
);
// 写入xml文件
toSend
(
body
)
// GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254
.
then
(
r
=>
{
toSend
(
body
)
res
.
send
({
code
:
200
,
msg
:
"操作成功"
});
.
then
(
r
=>
{
})
res
.
send
({
code
:
200
,
msg
:
"操作成功"
});
.
catch
(
err
=>
{
})
res
.
send
({
code
:
500
,
msg
:
err
});
.
catch
(
err
=>
{
});
res
.
send
({
code
:
500
,
msg
:
err
});
},
});
checkUpdate
:
async
(
req
,
res
)
=>
{
},
// const company = "http://10.168.31.188:8096";
checkUpdate
:
async
(
req
,
res
)
=>
{
const
company
=
"https://admin.jomalls.com"
;
// const company = "http://10.168.31.188:8096";
try
{
const
company
=
"https://admin.jomalls.com"
;
let
q
=
`
${
company
}
/api/manage/rest/app/checkUpdate?version=
${
req
.
query
.
version
}
&businessType=production_assistant`
;
try
{
let
{
data
}
=
await
axios
.
get
(
q
);
let
q
=
`
${
company
}
/api/manage/rest/app/checkUpdate?version=
${
req
.
query
.
version
}
&businessType=production_assistant`
;
if
(
data
.
data
)
{
let
{
data
}
=
await
axios
.
get
(
q
);
q
=
`
${
company
}
/api/manage/rest/app/getLatest?businessType=production_assistant`
;
if
(
data
.
data
)
{
let
r
=
await
axios
.
get
(
q
);
q
=
`
${
company
}
/api/manage/rest/app/getLatest?businessType=production_assistant`
;
res
.
send
(
r
.
data
);
let
r
=
await
axios
.
get
(
q
);
}
else
{
res
.
send
(
r
.
data
);
res
.
send
(
data
);
}
else
{
}
res
.
send
(
data
);
}
catch
(
err
)
{
}
console
.
log
(
err
);
res
.
json
({
code
:
500
,
msg
:
err
});
}
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"
);
incrementalUpdates
:
async
(
req
,
res
)
=>
{
let
dirName
=
path
.
join
(
process
.
cwd
(),
"./resources/app/"
);
try
{
let
stream
=
fs
.
createWriteStream
(
from
);
let
from
=
path
.
join
(
process
.
cwd
(),
"./resources/app/css.zip"
);
const
company
=
req
.
headers
[
"company"
];
let
dirName
=
path
.
join
(
process
.
cwd
(),
"./resources/app/"
);
req
.
body
.
url
=
"https://"
+
company
+
req
.
body
.
url
;
let
stream
=
fs
.
createWriteStream
(
from
);
console
.
log
(
req
.
body
.
url
,
"下载zip地址"
);
const
company
=
req
.
headers
[
"company"
];
request
(
req
.
body
.
url
)
req
.
body
.
url
=
"https://"
+
company
+
req
.
body
.
url
;
.
pipe
(
stream
)
console
.
log
(
req
.
body
.
url
,
"下载zip地址"
);
.
on
(
"close"
,
function
()
{
request
(
req
.
body
.
url
)
compressing
.
zip
.
pipe
(
stream
)
.
uncompress
(
from
,
dirName
,
{
zipFileNameEncoding
:
"gbk"
})
.
on
(
"close"
,
function
()
{
.
then
(()
=>
{
compressing
.
zip
fs
.
unlinkSync
(
from
);
.
uncompress
(
from
,
dirName
,
{
zipFileNameEncoding
:
"gbk"
})
res
.
json
({
code
:
200
,
msg
:
"更新成功"
});
.
then
(()
=>
{
})
fs
.
unlinkSync
(
from
);
.
catch
(
err
=>
{
res
.
json
({
code
:
200
,
msg
:
"更新成功"
});
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
}).
catch
(
err
=>
{
});
res
.
json
({
code
:
500
,
msg
:
err
.
message
});
});
});
}
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