Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
factory_front
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
1
Merge Requests
1
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
qinjianhui
factory_front
Commits
5a5da75f
Commit
5a5da75f
authored
Sep 02, 2025
by
zhuzhequan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
查询生产单功能添加自动打印生产单
parent
b553e00f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
217 additions
and
21 deletions
+217
-21
src/api/podOrder.ts
+12
-0
src/components/searchProdOrder.vue
+201
-21
src/utils/hooks/useLodop.ts
+4
-0
No files found.
src/api/podOrder.ts
View file @
5a5da75f
...
...
@@ -48,6 +48,18 @@ export function getSubOrderBySubOrder(factorySubOrderNumber: string, orderFrom:
},
)
}
export
function
printProductionQrCode
(
id
:
number
,
orderFrom
:
string
)
{
return
axios
.
get
<
never
,
BaseRespData
<
PodProductList
>>
(
'factory/podJomallOrderProductCnUs/printProductionQrCode'
,
{
params
:{
orderFrom
,
id
}
},
)
}
export
function
refreshJMProductInfo
(
data
:
number
[])
{
return
axios
.
post
<
never
,
BaseRespData
<
never
>>
(
'factory/podJomallOrder/refreshJomallPodProduct '
,
...
...
src/components/searchProdOrder.vue
View file @
5a5da75f
<
script
setup
lang=
"ts"
>
import
{
getSubOrderBySubOrder
}
from
'@/api/podOrder.ts'
import
{
getSubOrderBySubOrder
,
printProductionQrCode
}
from
'@/api/podOrder.ts'
import
{
SearchOrderRes
}
from
'@/types/api/podOrder.ts'
import
{
nextTick
,
ref
}
from
'vue'
import
{
DocumentCopy
}
from
'@element-plus/icons-vue'
import
{
copyText
}
from
'@/utils'
import
useLodop
,
{
LODOPObject
}
from
'@/utils/hooks/useLodop.ts'
import
{
ElMessage
}
from
'element-plus'
import
{
filePath
}
from
'@/api/axios.ts'
defineProps
({
detailData
:
{
default
:
null
,
type
:
Object
,
},
})
const
{
getCLodop
}
=
useLodop
()
const
type
=
{
'A'
:
'正面'
,
'B'
:
'反面'
,
...
...
@@ -25,6 +23,9 @@ const imageList = ref<{
const
detail
=
ref
<
SearchOrderRes
>
({
imgList
:
[],
id
:
0
,
})
const
printDevice
=
ref
(
''
)
const
isPrint
=
ref
(
false
)
const
printList
=
ref
<
string
[]
>
([])
type
AudioKey
=
keyof
typeof
audios
// 创建一个类型,确保 key 只能是 audios 对象的键之一
const
TrackingNumber
=
ref
(
''
)
const
trackingNumberRef
=
ref
(
null
)
...
...
@@ -80,22 +81,17 @@ const trackcodeInput = async () => {
}
const
user
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
'{}'
)
const
orderNumber
=
TrackingNumber
.
value
// if (user.factory?.countryCode.toLowerCase() !== 'us') {
// const regex = /^[A-Z]{4}_/ //是否以四个大写字母加下划线开头
// if (regex.test(orderNumber)) {
// orderNumber =
// orderNumber.split('_')[0] +
// '-' +
// orderNumber.split('_')[orderNumber.split('_').length - 1]
// }
// }
try
{
const
res
=
await
getSubOrderBySubOrder
(
orderNumber
,
user
.
factory
?.
countryCode
.
toLowerCase
())
if
(
!
res
.
data
)
{
return
ElMessage
.
error
(
'生产单不存在'
)
}
if
(
printDevice
.
value
&&
isPrint
.
value
)
{
const
data
=
await
printProductionQrCode
(
res
.
data
.
id
,
user
.
factory
?.
countryCode
.
toLowerCase
())
// const path = 'http://10.168.1.209/local_files/factory' + data.message
const
path
=
filePath
+
data
.
message
print
(
path
)
}
res
.
data
.
inputNum
=
TrackingNumber
.
value
TrackingNumber
.
value
=
''
if
(
typeof
res
.
data
.
imageAry
===
'string'
)
{
...
...
@@ -128,6 +124,181 @@ const trackcodeInput = async () => {
})
}
}
// 初始化打印机
const
initPrintDevice
=
()
=>
{
const
lodop
=
getCLodop
(
null
,
null
)
if
(
!
lodop
)
{
printList
.
value
=
[]
return
}
const
arr
=
[]
// 获取打印机数量
const
length
=
lodop
.
GET_PRINTER_COUNT
()
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
// 根据设备序号获取设备名
const
name
=
lodop
.
GET_PRINTER_NAME
(
i
)
if
(
name
)
{
arr
.
push
(
name
)
}
}
// 获取默认打印机
// const defaultPrinter = lodop.GET_PRINTER_NAME(0)
// if (defaultPrinter) {
// // printDevice.value = defaultPrinter
// }
printList
.
value
=
arr
}
const
lodopCall
=
async
(
fn
:
(
lodop
:
LODOPObject
)
=>
string
)
=>
{
if
(
!
window
.
_lodop
)
{
window
.
_lodop
=
getCLodop
(
null
,
null
)
if
(
window
.
_lodop
)
{
window
.
_lodop
.
On_Return_Remain
=
true
window
.
_lodop
.
SET_PRINT_MODE
(
'CATCH_PRINT_STATUS'
,
true
)
window
.
_lodopCallback
=
{}
window
.
_lodop
.
On_Return
=
function
(
id
,
value
)
{
const
cb
=
window
.
_lodopCallback
[
id
]
if
(
!
cb
)
return
delete
window
.
_lodopCallback
[
id
]
cb
(
value
)
}
}
}
return
new
Promise
((
resolve
)
=>
{
let
id
if
(
window
.
_lodop
)
{
id
=
fn
(
window
.
_lodop
)
}
window
.
_lodopCallback
[
id
||
0
]
=
resolve
})
}
function
downloadPDF
(
url
:
string
)
{
if
(
!
/^https
?
:/i
.
test
(
url
))
return
url
let
xhr
,
arrybuffer
=
false
,
dataArray
=
null
if
(
window
.
XMLHttpRequest
)
{
xhr
=
new
XMLHttpRequest
()
}
else
{
xhr
=
new
window
.
ActiveXObject
(
'MSXML2.XMLHTTP'
)
}
xhr
.
open
(
'GET'
,
url
,
false
)
//同步方式
if
(
xhr
.
overrideMimeType
)
try
{
xhr
.
responseType
=
'arraybuffer'
arrybuffer
=
true
}
catch
(
err
)
{
xhr
.
overrideMimeType
(
'text/plain; charset=x-user-defined'
)
}
xhr
.
send
(
null
)
const
data
=
xhr
.
response
||
xhr
.
responseBody
if
(
typeof
Uint8Array
!==
'undefined'
)
{
if
(
arrybuffer
)
{
dataArray
=
new
Uint8Array
(
data
)
}
else
{
dataArray
=
new
Uint8Array
(
data
.
length
)
for
(
let
i
=
0
;
i
<
dataArray
.
length
;
i
++
)
{
dataArray
[
i
]
=
data
.
charCodeAt
(
i
)
}
}
}
else
{
dataArray
=
window
.
VBS_BinaryToArray
(
data
).
toArray
()
//兼容IE低版本
}
const
digits
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
let
strData
=
''
for
(
let
i
=
0
,
ii
=
dataArray
.
length
;
i
<
ii
;
i
+=
3
)
{
if
(
isNaN
(
dataArray
[
i
]))
break
const
b1
=
dataArray
[
i
]
&
0xff
,
b2
=
dataArray
[
i
+
1
]
&
0xff
,
b3
=
dataArray
[
i
+
2
]
&
0xff
const
d1
=
b1
>>
2
,
d2
=
((
b1
&
3
)
<<
4
)
|
(
b2
>>
4
)
const
d3
=
i
+
1
<
ii
?
((
b2
&
0xf
)
<<
2
)
|
(
b3
>>
6
)
:
64
const
d4
=
i
+
2
<
ii
?
b3
&
0x3f
:
64
strData
+=
digits
.
substring
(
d1
,
d1
+
1
)
+
digits
.
substring
(
d2
,
d2
+
1
)
+
digits
.
substring
(
d3
,
d3
+
1
)
+
digits
.
substring
(
d4
,
d4
+
1
)
}
return
strData
}
const
print
=
async
(
url
:
string
)
=>
{
const
lodop
=
getCLodop
(
null
,
null
)
//调用getLodop获取LODOP对象
if
(
!
lodop
)
return
lodop
.
PRINT_INIT
(
'打印内容'
)
// SET_PRINTER_INDEX 指定打印设备
const
setPrintRes
=
lodop
.
SET_PRINTER_INDEX
(
printDevice
.
value
)
if
(
!
setPrintRes
)
{
ElMessage
.
warning
(
'设置面单打印机出错'
)
return
}
lodop
.
ADD_PRINT_PDF
(
0
,
0
,
'100%'
,
'100%'
,
downloadPDF
(
url
),
)
console
.
log
(
lodop
)
if
(
lodop
.
CVERSION
)
{
const
startTime
=
Date
.
now
()
const
jobCode
=
await
lodopCall
((
lodop
:
LODOPObject
)
=>
{
lodop
.
SET_PRINT_MODE
(
'CATCH_PRINT_STATUS'
,
true
)
return
lodop
.
PRINT
()
})
console
.
log
(
'[LODOP] job '
+
jobCode
)
// eslint-disable-next-line no-constant-condition
while
(
true
)
{
const
ok
=
await
lodopCall
((
lodop
:
LODOPObject
)
=>
lodop
.
GET_VALUE
(
'PRINT_STATUS_OK'
,
jobCode
),
)
if
(
ok
==
1
)
{
// 打印状态:成功
return
}
// 如果打印状态表示未成功或者返回了空,继续获取任务是否存在
const
exist
=
await
lodopCall
((
lodop
:
LODOPObject
)
=>
lodop
.
GET_VALUE
(
'PRINT_STATUS_EXIST'
,
jobCode
),
)
console
.
log
(
'[LODOP] PRINT_STATUS OK,EXIST'
,
jobCode
,
ok
,
exist
,
`(
${
Date
.
now
()
-
startTime
}
ms)`
,
)
if
(
exist
==
0
)
{
// 任务不存在了
return
}
await
new
Promise
((
r
)
=>
setTimeout
(
r
,
500
))
if
(
Date
.
now
()
-
startTime
>=
30000
)
{
ElMessage
.
error
(
'打印超时(30秒)'
)
return
}
}
}
else
{
lodop
.
PRINT
()
}
}
// 处理打印机选择变化,保存到 localStorage
const
handlePrinterChange
=
(
value
:
string
)
=>
{
printDevice
.
value
=
value
if
(
!
value
)
return
}
onMounted
(()
=>
{
initPrintDevice
()
})
</
script
>
<
template
>
...
...
@@ -143,7 +314,6 @@ const trackcodeInput = async () => {
</div>
<div
class=
"right"
>
<div
v-if=
"!detailData || Object.keys(detailData).length === 0"
class=
"input"
>
<el-input
...
...
@@ -154,10 +324,20 @@ const trackcodeInput = async () => {
clearable
@
keydown
.
enter=
"trackcodeInput()"
></el-input>
<el-button
type=
"primary"
@
click=
"trackcodeInput()"
>
<el-button
style=
"width: 138px;"
type=
"primary"
@
click=
"trackcodeInput()"
>
查询
</el-button>
</div>
<div
class=
"input"
>
<el-select
v-model=
"printDevice"
placeholder=
"请选择打印机"
clearable
filterable
@
change=
"handlePrinterChange"
>
<el-option
v-for=
"(item,i) in printList"
:key=
"i"
:label=
"item"
:value=
"item"
></el-option>
</el-select>
<el-checkbox
v-model=
"isPrint"
:disabled=
"!printDevice"
style=
"margin-left: 10px"
>
打印生产码
</el-checkbox>
</div>
<div
class=
"div-text"
>
<b>
生产单信息
</b>
<div
class=
"div-content"
>
...
...
@@ -441,7 +621,7 @@ const trackcodeInput = async () => {
.input
{
display
:
flex
;
align-items
:
center
;
margin
:
30
px
0
;
margin
:
15
px
0
;
}
}
...
...
src/utils/hooks/useLodop.ts
View file @
5a5da75f
...
...
@@ -11,8 +11,10 @@ export interface LODOPObject extends HTMLObjectElement {
SET_PRINT_MODE
:
(
mode
:
string
,
value
:
boolean
)
=>
void
;
On_Return
:
(
id
:
string
,
value
:
string
)
=>
void
;
On_Return_Remain
:
boolean
;
SEND_PRINT_RAWDATA
:
(
data
:
string
)
=>
void
;
ADD_PRINT_PDF
:
(
x
:
number
,
y
:
number
,
width
:
string
,
height
:
string
,
url
:
string
)
=>
void
;
ADD_PRINT_IMAGE
:
(
x
:
number
,
y
:
number
,
width
:
string
,
height
:
string
,
url
:
string
)
=>
void
;
GET_VALUE
:
(
valueType
:
string
,
valueIndex
:
string
|
unknown
)
=>
string
;
PRINT
:
()
=>
string
;
PRINTA
:
()
=>
string
;
...
...
@@ -27,6 +29,8 @@ export interface CLodopObject {
declare
global
{
interface
Window
{
LODOP
:
new
()
=>
LODOPObject
;
_lodop
:
LODOPObject
|
null
;
_lodopCallback
:{
[
key
:
string
]:
Function
};
CLODOP
:
CLodopObject
;
getCLodop
:
()
=>
LODOPObject
;
}
...
...
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