Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes-ui
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mes
mes-ui
Commits
ba078303
Commit
ba078303
authored
Mar 06, 2024
by
张海景
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update: 提交打印方法
parent
b9bf8ecb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
56 deletions
+146
-56
index.js
src/api/mes/test/index.js
+11
-0
ruoyi.js
src/utils/ruoyi.js
+105
-55
index.vue
src/views/mes/test/index.vue
+29
-0
index.vue
src/views/mes/tm/toolmachinesrecord/index.vue
+1
-1
No files found.
src/api/mes/test/index.js
0 → 100644
View file @
ba078303
import
request
from
"@/utils/request"
;
//打印pdf
export
function
postPrintPdf
(
data
)
{
return
request
({
url
:
"/common/print"
,
method
:
"post"
,
responseType
:
'blob'
,
data
});
}
src/utils/ruoyi.js
View file @
ba078303
import
request
from
"@/utils/request"
;
/**
* 通用js方法封装处理
...
...
@@ -8,22 +8,25 @@
// 日期格式化
export
function
parseTime
(
time
,
pattern
)
{
if
(
arguments
.
length
===
0
||
!
time
)
{
return
null
return
null
;
}
const
format
=
pattern
||
'{y}-{m}-{d} {h}:{i}:{s}'
let
date
if
(
typeof
time
===
'object'
)
{
date
=
time
const
format
=
pattern
||
"{y}-{m}-{d} {h}:{i}:{s}"
;
let
date
;
if
(
typeof
time
===
"object"
)
{
date
=
time
;
}
else
{
if
((
typeof
time
===
'string'
)
&&
(
/^
[
0-9
]
+$/
.
test
(
time
)))
{
time
=
parseInt
(
time
)
}
else
if
(
typeof
time
===
'string'
)
{
time
=
time
.
replace
(
new
RegExp
(
/-/gm
),
'/'
).
replace
(
'T'
,
' '
).
replace
(
new
RegExp
(
/
\.[\d]{3}
/gm
),
''
);
if
(
typeof
time
===
"string"
&&
/^
[
0-9
]
+$/
.
test
(
time
))
{
time
=
parseInt
(
time
);
}
else
if
(
typeof
time
===
"string"
)
{
time
=
time
.
replace
(
new
RegExp
(
/-/gm
),
"/"
)
.
replace
(
"T"
,
" "
)
.
replace
(
new
RegExp
(
/
\.[\d]{3}
/gm
),
""
);
}
if
(
(
typeof
time
===
'number'
)
&&
(
time
.
toString
().
length
===
10
)
)
{
time
=
time
*
1000
if
(
typeof
time
===
"number"
&&
time
.
toString
().
length
===
10
)
{
time
=
time
*
1000
;
}
date
=
new
Date
(
time
)
date
=
new
Date
(
time
)
;
}
const
formatObj
=
{
y
:
date
.
getFullYear
(),
...
...
@@ -32,18 +35,20 @@ export function parseTime(time, pattern) {
h
:
date
.
getHours
(),
i
:
date
.
getMinutes
(),
s
:
date
.
getSeconds
(),
a
:
date
.
getDay
()
}
a
:
date
.
getDay
()
,
}
;
const
time_str
=
format
.
replace
(
/{
(
y|m|d|h|i|s|a
)
+}/g
,
(
result
,
key
)
=>
{
let
value
=
formatObj
[
key
]
let
value
=
formatObj
[
key
]
;
// Note: getDay() returns 0 on Sunday
if
(
key
===
'a'
)
{
return
[
'日'
,
'一'
,
'二'
,
'三'
,
'四'
,
'五'
,
'六'
][
value
]
}
if
(
key
===
"a"
)
{
return
[
"日"
,
"一"
,
"二"
,
"三"
,
"四"
,
"五"
,
"六"
][
value
];
}
if
(
result
.
length
>
0
&&
value
<
10
)
{
value
=
'0'
+
value
value
=
"0"
+
value
;
}
return
value
||
0
})
return
time_str
return
value
||
0
;
})
;
return
time_str
;
}
// 表单重置
...
...
@@ -56,14 +61,19 @@ export function resetForm(refName) {
// 添加日期范围
export
function
addDateRange
(
params
,
dateRange
,
propName
)
{
let
search
=
params
;
search
.
params
=
typeof
(
search
.
params
)
===
'object'
&&
search
.
params
!==
null
&&
!
Array
.
isArray
(
search
.
params
)
?
search
.
params
:
{};
search
.
params
=
typeof
search
.
params
===
"object"
&&
search
.
params
!==
null
&&
!
Array
.
isArray
(
search
.
params
)
?
search
.
params
:
{};
dateRange
=
Array
.
isArray
(
dateRange
)
?
dateRange
:
[];
if
(
typeof
(
propName
)
===
'undefined'
)
{
search
.
params
[
'beginTime'
]
=
dateRange
[
0
];
search
.
params
[
'endTime'
]
=
dateRange
[
1
];
if
(
typeof
propName
===
"undefined"
)
{
search
.
params
[
"beginTime"
]
=
dateRange
[
0
];
search
.
params
[
"endTime"
]
=
dateRange
[
1
];
}
else
{
search
.
params
[
'begin'
+
propName
]
=
dateRange
[
0
];
search
.
params
[
'end'
+
propName
]
=
dateRange
[
1
];
search
.
params
[
"begin"
+
propName
]
=
dateRange
[
0
];
search
.
params
[
"end"
+
propName
]
=
dateRange
[
1
];
}
return
search
;
}
...
...
@@ -75,15 +85,15 @@ export function selectDictLabel(datas, value) {
}
var
actions
=
[];
Object
.
keys
(
datas
).
some
((
key
)
=>
{
if
(
datas
[
key
].
value
==
(
''
+
value
)
)
{
if
(
datas
[
key
].
value
==
""
+
value
)
{
actions
.
push
(
datas
[
key
].
label
);
return
true
;
}
})
})
;
if
(
actions
.
length
===
0
)
{
actions
.
push
(
value
);
}
return
actions
.
join
(
''
);
return
actions
.
join
(
""
);
}
// 回显数据字典(字符串数组)
...
...
@@ -97,30 +107,32 @@ export function selectDictLabels(datas, value, separator) {
Object
.
keys
(
value
.
split
(
currentSeparator
)).
some
((
val
)
=>
{
var
match
=
false
;
Object
.
keys
(
datas
).
some
((
key
)
=>
{
if
(
datas
[
key
].
value
==
(
''
+
temp
[
val
])
)
{
if
(
datas
[
key
].
value
==
""
+
temp
[
val
]
)
{
actions
.
push
(
datas
[
key
].
label
+
currentSeparator
);
match
=
true
;
}
})
})
;
if
(
!
match
)
{
actions
.
push
(
temp
[
val
]
+
currentSeparator
);
}
})
return
actions
.
join
(
''
).
substring
(
0
,
actions
.
join
(
''
).
length
-
1
);
})
;
return
actions
.
join
(
""
).
substring
(
0
,
actions
.
join
(
""
).
length
-
1
);
}
// 字符串格式化(%s )
export
function
sprintf
(
str
)
{
var
args
=
arguments
,
flag
=
true
,
i
=
1
;
var
args
=
arguments
,
flag
=
true
,
i
=
1
;
str
=
str
.
replace
(
/%s/g
,
function
()
{
var
arg
=
args
[
i
++
];
if
(
typeof
arg
===
'undefined'
)
{
if
(
typeof
arg
===
"undefined"
)
{
flag
=
false
;
return
''
;
return
""
;
}
return
arg
;
});
return
flag
?
str
:
''
;
return
flag
?
str
:
""
;
}
// 转换字符串,undefined,null等转化为""
...
...
@@ -145,7 +157,7 @@ export function mergeRecursive(source, target) {
}
}
return
source
;
}
;
}
/**
* 构造树型结构数据
...
...
@@ -156,9 +168,9 @@ export function mergeRecursive(source, target) {
*/
export
function
handleTree
(
data
,
id
,
parentId
,
children
)
{
let
config
=
{
id
:
id
||
'id'
,
parentId
:
parentId
||
'parentId'
,
childrenList
:
children
||
'children'
id
:
id
||
"id"
,
parentId
:
parentId
||
"parentId"
,
childrenList
:
children
||
"children"
,
};
var
childrenListMap
=
{};
...
...
@@ -199,19 +211,19 @@ export function handleTree(data, id, parentId, children) {
}
/**
* 参数处理
* @param {*} params 参数
*/
* 参数处理
* @param {*} params 参数
*/
export
function
tansParams
(
params
)
{
let
result
=
''
let
result
=
""
;
for
(
const
propName
of
Object
.
keys
(
params
))
{
const
value
=
params
[
propName
];
var
part
=
encodeURIComponent
(
propName
)
+
"="
;
if
(
value
!==
null
&&
typeof
(
value
)
!==
"undefined"
)
{
if
(
typeof
value
===
'object'
)
{
if
(
value
!==
null
&&
typeof
value
!==
"undefined"
)
{
if
(
typeof
value
===
"object"
)
{
for
(
const
key
of
Object
.
keys
(
value
))
{
if
(
value
[
key
]
!==
null
&&
typeof
(
value
[
key
])
!==
'undefined'
)
{
let
params
=
propName
+
'['
+
key
+
']'
;
if
(
value
[
key
]
!==
null
&&
typeof
value
[
key
]
!==
"undefined"
)
{
let
params
=
propName
+
"["
+
key
+
"]"
;
var
subPart
=
encodeURIComponent
(
params
)
+
"="
;
result
+=
subPart
+
encodeURIComponent
(
value
[
key
])
+
"&"
;
}
...
...
@@ -221,7 +233,7 @@ export function tansParams(params) {
}
}
}
return
result
return
result
;
}
// 验证是否为blob格式
...
...
@@ -238,10 +250,48 @@ export async function blobValidate(data) {
/**
* 格式化金钱
*/
export
function
formatMoney
(
val
,
prefix
=
'¥ '
)
{
if
(
val
===
''
||
val
==
null
)
return
null
export
function
formatMoney
(
val
,
prefix
=
"¥ "
)
{
if
(
val
===
""
||
val
==
null
)
return
null
;
let
str
=
Number
(
val
).
toFixed
(
2
);
let
intSum
=
str
.
substring
(
0
,
str
.
indexOf
(
"."
)).
replace
(
/
\B(?=(?:\d{3})
+$
)
/g
,
','
);
//取到整数部分
let
dot
=
str
.
substring
(
str
.
length
,
str
.
indexOf
(
"."
))
//取到小数部分搜索
let
intSum
=
str
.
substring
(
0
,
str
.
indexOf
(
"."
))
.
replace
(
/
\B(?=(?:\d{3})
+$
)
/g
,
","
);
//取到整数部分
let
dot
=
str
.
substring
(
str
.
length
,
str
.
indexOf
(
"."
));
//取到小数部分搜索
return
prefix
+
intSum
+
dot
;
}
function
printPdf
(
res
)
{
const
blob
=
new
Blob
([
res
],
{
type
:
"application/pdf"
});
var
date
=
new
Date
().
getTime
();
var
ifr
=
document
.
createElement
(
"iframe"
);
ifr
.
style
.
frameborder
=
"no"
;
ifr
.
style
.
display
=
"none"
;
ifr
.
style
.
pageBreakBefore
=
"always"
;
ifr
.
setAttribute
(
"id"
,
"printPdf"
+
date
);
ifr
.
setAttribute
(
"name"
,
"printPdf"
+
date
);
ifr
.
src
=
window
.
URL
.
createObjectURL
(
blob
);
document
.
body
.
appendChild
(
ifr
);
var
ordonnance
=
document
.
getElementById
(
"printPdf"
+
date
).
contentWindow
;
setTimeout
(()
=>
{
ordonnance
.
print
();
},
100
);
window
.
URL
.
revokeObjectURL
(
ifr
.
src
);
// 释放URL 对象
}
/**
* 打印pdf方法
* responseType: 'blob',
* 接口请求加上responseType
*/
export
function
postPrintPdf
(
data
)
{
request
({
url
:
"/common/print"
,
method
:
"post"
,
responseType
:
'blob'
,
data
}).
then
(
res
=>
{
printPdf
(
res
)
})
}
src/views/mes/test/index.vue
0 → 100644
View file @
ba078303
<
template
>
<div>
<el-button
type=
"primary"
@
click=
"PrintBtnClick"
>
打印
</el-button>
</div>
</
template
>
<
script
>
import
{
postPrintPdf
}
from
'@/utils/ruoyi'
export
default
{
data
()
{
return
{
}
},
methods
:
{
PrintBtnClick
()
{
postPrintPdf
({
reportName
:
"mysql:qrcode-100*100"
,
values
:{
"header"
:{
"qrcode"
:
"123456789"
,
"other"
:
"q"
},
"detail"
:
[{
"name"
:
"lily"
,
"age"
:
12
,
"qrcode"
:
"123"
},{
"name"
:
"jeff"
,
"age"
:
32
,
"qrcode"
:
"qqq"
},
{
"name"
:
"jeff"
,
"age"
:
32
,
"qrcode"
:
"qqq1"
},{
"name"
:
"jeff"
,
"age"
:
32
,
"qrcode"
:
"qqq2"
}],
"detail2"
:[{
"orderno"
:
"123"
,
"quantity"
:
20031
}]
}
})
},
}
}
</
script
>
src/views/mes/tm/toolmachinesrecord/index.vue
View file @
ba078303
...
...
@@ -328,7 +328,7 @@ export default {
"toolMachinesRecordId"
:
this
.
form
.
toolMachinesRecordId
,
"warehouseDesc"
:
this
.
form
.
warehouseDesc
}
updateRecordWarehouse
(
this
.
form
).
then
(
response
=>
{
updateRecordWarehouse
(
params
).
then
(
response
=>
{
this
.
$modal
.
msgSuccess
(
"修改成功"
);
this
.
open
=
false
;
this
.
getList
();
...
...
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